Skip to content

Commit

Permalink
feat: only show recent runs in landing page (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Nov 28, 2023
1 parent 33e1112 commit 951b5b3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 21 deletions.
30 changes: 24 additions & 6 deletions frontend/src/ProjectData.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql } from '@apollo/client';
import { BadSmell } from './data/BadSmell';
import { Project } from './data/Project';
import {gql} from '@apollo/client';
import {BadSmell} from './data/BadSmell';
import {Project} from './data/Project';

export const fetchProjectQuery = gql`
query getProjects {
Expand All @@ -21,6 +21,25 @@ export const fetchProjectQuery = gql`
}
}
`;
export const fetchRecentProjectQuery = gql`
query getRecentProjects {
getRecentProjects(size: 30) {
projectName
projectUrl
commitHashes
commits {
analyzerStatuses {
analyzerName
commitHash
localDateTime
numberOfIssues
status
}
commitHash
}
}
}
`;
export const fetchAvailableRefactorings = gql`
query getAvailableRefactorings {
availableRefactorings {
Expand Down Expand Up @@ -75,10 +94,9 @@ export function filterDuplicateBadSmells(params: BadSmell[]) {
return badSmell.snippet != null;
});
const ids = params.map((o) => o.snippet);
const filtered = params.filter(
({ snippet }, index) => !ids.includes(snippet, index + 1)
return params.filter(
({snippet}, index) => !ids.includes(snippet, index + 1)
);
return filtered;
}

export const fetchProjectConfigQuery = gql`
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/component/ProjectList.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { useQuery } from '@apollo/client';
import { fetchProjectQuery } from '../ProjectData';
import { Project } from '../data/Project';
import React, { useMemo } from 'react';
import ProjectTable from './ProjectTable';
import { LinearProgress } from '@mui/material';
import { fetchRecentProjectQuery } from '../ProjectData';

export function ProjectList({ filter }: { filter: string }) {
const { data, loading, error } = useQuery(fetchProjectQuery);
const { data, loading, error } = useQuery(fetchRecentProjectQuery);

const filteredProjects = useMemo(() => {
if (!data) {
return [];
}
return data.getProjects.filter((project: Project) => {
return data.getRecentProjects.filter((project: Project) => {
return project.projectName.toLowerCase().match(filter.toLowerCase());
});
}, [data, filter]);

if (error) {
console.error(error);
}
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/pages/DashBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { useNavigate } from 'react-router';
import { ProjectList } from '../component/ProjectList';

export default function DashBoard() {
const navigate = useNavigate();

const [filter, setFilter] = React.useState('');

return (
Expand All @@ -22,13 +20,7 @@ export default function DashBoard() {
/>
</Grid>
<Grid item xs={4} md={2} lg={1} marginLeft="auto">
<Button
onClick={() => navigate('/mutation/addproject')}
variant="contained"
sx={{ width: '100%' }}
>
Add Project
</Button>
<AddProjectButton />
</Grid>
</Grid>
</Box>
Expand All @@ -42,3 +34,16 @@ export default function DashBoard() {
</div>
);
}

function AddProjectButton() {
const navigate = useNavigate();
return (
<Button
onClick={() => navigate('/mutation/addproject')}
variant="contained"
sx={{ width: '100%' }}
>
Add Project
</Button>
);
}
2 changes: 1 addition & 1 deletion frontend/src/pages/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Navigation({ links }: NavigationProps) {
{links.map((link) => (
<>
<ListItem
key={link.href}
key={link.name}
onClick={() => navigate(link.href, { replace: true })}
>
<ListItemText primary={link.name} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public ProjectDao convertToDao(RemoteProject entity) {
.flatMap(List::stream)
.toList();
dao.setCommits(list);
list.stream()
.reduce(
(first, second) -> first.localDateTime.isAfter(second.localDateTime) ? first : second)
.map(v -> v.localDateTime)
.ifPresent(dao::setLatestRun);
return dao;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -12,6 +13,7 @@ public class ProjectDao extends PanacheEntity {

private String projectName;
private String projectUrl;
private LocalDateTime latestRun;

@OneToMany private List<AnalyzerRunDao> commits = new ArrayList<>();

Expand Down Expand Up @@ -61,4 +63,15 @@ public List<AnalyzerRunDao> getCommits() {
public void setCommits(List<AnalyzerRunDao> commits) {
this.commits = commits;
}

public LocalDateTime getLatestRun() {
if (null == latestRun) {
latestRun = LocalDateTime.MIN;
}
return latestRun;
}

public void setLatestRun(LocalDateTime localDateTime) {
latestRun = localDateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.martinwitt.laughing_train.persistence.dao.ProjectDao;
import io.github.martinwitt.laughing_train.persistence.repository.ProjectRepository;
import io.quarkus.hibernate.orm.panache.PanacheRepository;
import io.quarkus.panache.common.Sort;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.transaction.Transactional;
import java.util.List;
Expand Down Expand Up @@ -92,6 +93,8 @@ public RemoteProject save(RemoteProject project) {

@Override
public List<RemoteProject> getRecent(int size) {
return findAll().page(0, size).stream().map(projectDaoConverter::convertToEntity).toList();
return findAll(Sort.by("latestRun").descending()).page(0, size).stream()
.map(projectDaoConverter::convertToEntity)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ void insertProject() {
sqlProjectRepository.findByProjectName(remoteProject.getProjectName());
assertThat(byProjectName).isNotEmpty();
}

@Test
void getRecent() {
RemoteProject remoteProject = Instancio.create(RemoteProject.class);
sqlProjectRepository.save(remoteProject);
assertThat(sqlProjectRepository.getRecent(1)).isNotEmpty();
List<RemoteProject> recent = sqlProjectRepository.getRecent(1);
assertThat(recent).isNotEmpty();
}
}

0 comments on commit 951b5b3

Please sign in to comment.