Skip to content

Commit

Permalink
feat: Remove unused legacy methods and refactor project (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Dec 25, 2023
1 parent ee49f78 commit 05fdf9c
Show file tree
Hide file tree
Showing 24 changed files with 278 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@

public class RemoteProject implements Serializable {

private String projectName;
private String projectUrl;
private List<String> commitHashes;
private List<GitHubCommit> commits;
private final String projectName;
private final String projectUrl;
private final List<GitHubCommit> commits;

public RemoteProject(String projectName, String projectUrl) {
this.projectName = Objects.requireNonNull(projectName);
this.projectUrl = Objects.requireNonNull(projectUrl);
commitHashes = new ArrayList<>();
commits = new ArrayList<>();
}

Expand All @@ -33,36 +31,15 @@ public String getProjectUrl() {
return projectUrl;
}

/**
* @param commitHash the commitHash to add
*/
public void addCommitHash(String commitHash) {
if (!commitHashes.contains(commitHash)) {
commitHashes.add(commitHash);
}
}

public boolean removeCommitHash(String commitHash) {
return commitHashes.remove(commitHash);
}

/**
* @return the commits
*/
public List<GitHubCommit> getCommits() {
return commits;
}

public boolean addCommitHash(GitHubCommit commit) {
addCommitHash(commit.getCommitHash());
return commits.add(commit);
}

/**
* @return the commitHashes
*/
public List<String> getCommitHashes() {
return commitHashes;
public void addCommitHash(GitHubCommit commit) {
commits.add(commit);
}

/**
Expand All @@ -72,7 +49,7 @@ public List<String> getCommitHashes() {
*/
@Override
public int hashCode() {
return Objects.hash(projectName, projectUrl, commitHashes);
return Objects.hash(projectName, projectUrl);
}

/**
Expand All @@ -87,8 +64,7 @@ public boolean equals(Object obj) {
}
if (obj instanceof RemoteProject project) {
return Objects.equals(projectName, project.projectName)
&& Objects.equals(projectUrl, project.projectUrl)
&& Objects.equals(commitHashes, project.commitHashes);
&& Objects.equals(projectUrl, project.projectUrl);
}
return false;
}
Expand Down
14 changes: 13 additions & 1 deletion frontend/src/ProjectData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const fetchProjectQuery = gql`
getProjects {
projectName
projectUrl
commitHashes
commits {
analyzerStatuses {
analyzerName
Expand All @@ -26,11 +25,24 @@ export const recentAnalyzerRuns = gql`
recentAnalyzerRuns(size: 30) {
analyzerName
commitHash
numberOfIssues
projectName
projectUrl
status
timestamp
}
}
`;
export const recentRuns = gql`
query recentRuns {
recentRuns(size: 30) {
analyzerName
commitHash
numberOfIssues
projectName
projectUrl
status
timestamp
}
}
`;
Expand Down
65 changes: 48 additions & 17 deletions frontend/src/component/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,76 @@
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Divider from '@mui/material/Divider';
import List from '@mui/material/List';
import ListItemIcon from '@mui/material/ListItemIcon';
import ListItemText from '@mui/material/ListItemText';
import ListItemButton from '@mui/material/ListItemButton';
import MenuIcon from '@mui/icons-material/Menu';
import Collapse from '@mui/material/Collapse';
import { LoginButton } from './LoginButton';
import { ListItemButton } from '@mui/material';
import { useNavigate } from 'react-router-dom';

export type LinkType = { title: string; url: string };

type Props = { links: LinkType[] };
interface Props {
links: LinkType[];
}

interface ListItemsProps {
links: LinkType[];
subLinks: LinkType[];
}

function ListItems(props: ListItemsProps) {
const { links } = props;
const { links, subLinks } = props;
const navigate = useNavigate();
const [open, setOpen] = React.useState(true);

return (
<>
{links.map(({ title, url }) => (
<ListItemButton key={url}>
<ListItemIcon>
<MenuIcon />
</ListItemIcon>
<ListItemText
primary={title}
sx={{ color: '#fff' }}
onClick={() => navigate(url)}
/>
</ListItemButton>
))}
{links.map((link) =>
link.title === 'Home' ? (
<div key={link.url}>
<ListItemButton onClick={() => setOpen(!open)}>
<ListItemIcon>
<MenuIcon />
</ListItemIcon>
<ListItemText primary={link.title} sx={{ color: '#fff' }} />
</ListItemButton>
<Collapse in={open} timeout="auto" unmountOnExit>
<List component="div" disablePadding>
{subLinks.map((subLink) => (
<ListItemButton
key={subLink.url}
sx={{ pl: 4 }}
onClick={() => navigate(subLink.url)}
>
<ListItemText
primary={subLink.title}
sx={{ color: '#fff' }}
/>
</ListItemButton>
))}
</List>
</Collapse>
</div>
) : (
<ListItemButton key={link.url} onClick={() => navigate(link.url)}>
<ListItemIcon>
<MenuIcon />
</ListItemIcon>
<ListItemText primary={link.title} sx={{ color: '#fff' }} />
</ListItemButton>
)
)}
</>
);
}

function Sidebar(props: Props) {
const subLinks: LinkType[] = [{ title: 'LiveFeed', url: '/livefeed' }];

return (
<Box sx={{ width: 250, bgcolor: '#272727', height: '100vh' }}>
<Typography
Expand All @@ -53,7 +84,7 @@ function Sidebar(props: Props) {
</Typography>
<Divider />
<List>
<ListItems links={props.links} />
<ListItems links={props.links} subLinks={subLinks} />
</List>
<LoginButton
sx={{ mx: 1, my: 1, color: '#fff', borderColor: '#fff', width: '90%' }}
Expand Down
88 changes: 67 additions & 21 deletions frontend/src/gql/graphql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type Mutation = {
addProject?: Maybe<Project>;
/** Deletes a project from the database */
deleteProject?: Maybe<Array<Maybe<Project>>>;
mineProject: Scalars['Boolean']['output'];
/** Refactoring the given bad smells */
refactor?: Maybe<Scalars['String']['output']>;
};
Expand All @@ -85,6 +86,12 @@ export type MutationDeleteProjectArgs = {
};


/** Mutation root */
export type MutationMineProjectArgs = {
url?: InputMaybe<Scalars['String']['input']>;
};


/** Mutation root */
export type MutationRefactorArgs = {
badSmellIdentifier?: InputMaybe<Array<InputMaybe<Scalars['String']['input']>>>;
Expand All @@ -102,7 +109,6 @@ export type Position = {

export type Project = {
__typename?: 'Project';
commitHashes?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
commits?: Maybe<Array<Maybe<GitHubCommit>>>;
projectName?: Maybe<Scalars['String']['output']>;
projectUrl?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -150,12 +156,8 @@ export type Query = {
byRuleIDAndAnalyzerAndCommitHash?: Maybe<Array<Maybe<BadSmell>>>;
/** Gets all fixable bad smells rules */
fixableBadSmells?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
/** Gets all fixable bad smells from the database by projectUrl */
fixableByProjectName?: Maybe<Array<Maybe<BadSmell>>>;
/** Returns all github commits for a project from the database */
getGitHubCommitsForProject?: Maybe<Array<Maybe<GitHubCommit>>>;
/** Gets all commit hashes for a project from the database */
getHashesForProject?: Maybe<Array<Maybe<Scalars['String']['output']>>>;
/** Gets project with given name from the database */
getProjectWithName?: Maybe<Project>;
/** Gets all projects from the database */
Expand All @@ -164,6 +166,7 @@ export type Query = {
login?: Maybe<Scalars['String']['output']>;
/** Returns a sorted by date list of recent analyzer runs */
recentAnalyzerRuns?: Maybe<Array<Maybe<AnalyzerRun>>>;
recentRuns?: Maybe<Array<Maybe<AnalyzerRun>>>;
};


Expand Down Expand Up @@ -206,24 +209,12 @@ export type QueryByRuleIdAndAnalyzerAndCommitHashArgs = {
};


/** Query root */
export type QueryFixableByProjectNameArgs = {
projectUrl?: InputMaybe<Scalars['String']['input']>;
};


/** Query root */
export type QueryGetGitHubCommitsForProjectArgs = {
projectName?: InputMaybe<Scalars['String']['input']>;
};


/** Query root */
export type QueryGetHashesForProjectArgs = {
projectName?: InputMaybe<Scalars['String']['input']>;
};


/** Query root */
export type QueryGetProjectWithNameArgs = {
projectName?: InputMaybe<Scalars['String']['input']>;
Expand All @@ -241,6 +232,12 @@ export type QueryRecentAnalyzerRunsArgs = {
size: Scalars['Int']['input'];
};


/** Query root */
export type QueryRecentRunsArgs = {
size: Scalars['Int']['input'];
};

export type RuleId = {
__typename?: 'RuleId';
id?: Maybe<Scalars['String']['output']>;
Expand All @@ -261,12 +258,17 @@ export enum Status {
export type GetProjectsQueryVariables = Exact<{ [key: string]: never; }>;


export type GetProjectsQuery = { __typename?: 'Query', getProjects?: Array<{ __typename?: 'Project', projectName?: string | null, projectUrl?: string | null, commitHashes?: Array<string | null> | null, commits?: Array<{ __typename?: 'GitHubCommit', commitHash?: string | null, analyzerStatuses?: Array<{ __typename?: 'AnalyzerStatus', analyzerName?: string | null, commitHash?: string | null, localDateTime?: string | null, numberOfIssues: number, status?: Status | null } | null> | null } | null> | null } | null> | null };
export type GetProjectsQuery = { __typename?: 'Query', getProjects?: Array<{ __typename?: 'Project', projectName?: string | null, projectUrl?: string | null, commits?: Array<{ __typename?: 'GitHubCommit', commitHash?: string | null, analyzerStatuses?: Array<{ __typename?: 'AnalyzerStatus', analyzerName?: string | null, commitHash?: string | null, localDateTime?: string | null, numberOfIssues: number, status?: Status | null } | null> | null } | null> | null } | null> | null };

export type RecentAnalyzerRunsQueryVariables = Exact<{ [key: string]: never; }>;


export type RecentAnalyzerRunsQuery = { __typename?: 'Query', recentAnalyzerRuns?: Array<{ __typename?: 'AnalyzerRun', analyzerName?: string | null, commitHash?: string | null, timestamp?: string | null, numberOfIssues: number, projectName?: string | null, projectUrl?: string | null, status?: string | null } | null> | null };
export type RecentAnalyzerRunsQuery = { __typename?: 'Query', recentAnalyzerRuns?: Array<{ __typename?: 'AnalyzerRun', analyzerName?: string | null, commitHash?: string | null, numberOfIssues: number, projectName?: string | null, projectUrl?: string | null, status?: string | null, timestamp?: string | null } | null> | null };

export type RecentRunsQueryVariables = Exact<{ [key: string]: never; }>;


export type RecentRunsQuery = { __typename?: 'Query', recentRuns?: Array<{ __typename?: 'AnalyzerRun', analyzerName?: string | null, commitHash?: string | null, numberOfIssues: number, projectName?: string | null, projectUrl?: string | null, status?: string | null, timestamp?: string | null } | null> | null };

export type GetAvailableRefactoringsQueryVariables = Exact<{ [key: string]: never; }>;

Expand Down Expand Up @@ -315,7 +317,6 @@ export const GetProjectsDocument = gql`
getProjects {
projectName
projectUrl
commitHashes
commits {
analyzerStatuses {
analyzerName
Expand Down Expand Up @@ -366,11 +367,11 @@ export const RecentAnalyzerRunsDocument = gql`
recentAnalyzerRuns(size: 30) {
analyzerName
commitHash
timestamp
numberOfIssues
projectName
projectUrl
status
timestamp
}
}
`;
Expand Down Expand Up @@ -406,6 +407,51 @@ export type RecentAnalyzerRunsQueryHookResult = ReturnType<typeof useRecentAnaly
export type RecentAnalyzerRunsLazyQueryHookResult = ReturnType<typeof useRecentAnalyzerRunsLazyQuery>;
export type RecentAnalyzerRunsSuspenseQueryHookResult = ReturnType<typeof useRecentAnalyzerRunsSuspenseQuery>;
export type RecentAnalyzerRunsQueryResult = Apollo.QueryResult<RecentAnalyzerRunsQuery, RecentAnalyzerRunsQueryVariables>;
export const RecentRunsDocument = gql`
query recentRuns {
recentRuns(size: 30) {
analyzerName
commitHash
numberOfIssues
projectName
projectUrl
status
timestamp
}
}
`;

/**
* __useRecentRunsQuery__
*
* To run a query within a React component, call `useRecentRunsQuery` and pass it any options that fit your needs.
* When your component renders, `useRecentRunsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useRecentRunsQuery({
* variables: {
* },
* });
*/
export function useRecentRunsQuery(baseOptions?: Apollo.QueryHookOptions<RecentRunsQuery, RecentRunsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<RecentRunsQuery, RecentRunsQueryVariables>(RecentRunsDocument, options);
}
export function useRecentRunsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<RecentRunsQuery, RecentRunsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<RecentRunsQuery, RecentRunsQueryVariables>(RecentRunsDocument, options);
}
export function useRecentRunsSuspenseQuery(baseOptions?: Apollo.SuspenseQueryHookOptions<RecentRunsQuery, RecentRunsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useSuspenseQuery<RecentRunsQuery, RecentRunsQueryVariables>(RecentRunsDocument, options);
}
export type RecentRunsQueryHookResult = ReturnType<typeof useRecentRunsQuery>;
export type RecentRunsLazyQueryHookResult = ReturnType<typeof useRecentRunsLazyQuery>;
export type RecentRunsSuspenseQueryHookResult = ReturnType<typeof useRecentRunsSuspenseQuery>;
export type RecentRunsQueryResult = Apollo.QueryResult<RecentRunsQuery, RecentRunsQueryVariables>;
export const GetAvailableRefactoringsDocument = gql`
query getAvailableRefactorings {
availableRefactorings {
Expand Down
Loading

0 comments on commit 05fdf9c

Please sign in to comment.