Skip to content

Commit

Permalink
Merge pull request #23 from AntaresSimulatorTeam/feature/ANT_2427_ref…
Browse files Browse the repository at this point in the history
…actoring_sorting_studies

feat: add sorting studies
  • Loading branch information
vargastat authored Dec 13, 2024
2 parents b47059d + 0caf63a commit a0fcd6b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/pages/pegase/home/components/StudyTableDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
),
}),

columnHelper.accessor('study_name', {
columnHelper.accessor('name', {
header: t('home.@study_name'),
cell: ({ getValue, row }) => {
const status = row.original.status;
Expand All @@ -72,7 +72,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
},
}),

columnHelper.accessor('user_name', {
columnHelper.accessor('createdBy', {
header: t('home.@user_name'),
cell: ({ getValue }: { getValue: () => string }) => (
<StdAvatar size="s" backgroundColor="gray" fullname={getValue()} initials={getValue().substring(0, 2)} />
Expand All @@ -91,7 +91,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =
</div>
),
}),
columnHelper.accessor('creation_date', { header: t('home.@creation_date') }),
columnHelper.accessor('creationDate', { header: t('home.@creation_date') }),
];

const [isHeaderHovered, setIsHeaderHovered] = useState<boolean>(false);
Expand All @@ -102,7 +102,7 @@ const StudyTableDisplay = ({ searchStudy, projectId }: StudyTableDisplayProps) =

function addSortColumn(headers: any[]) {
return headers.map((column) => {
const isSortable = column.accessorKey !== 'keywords';
const isSortable = column.accessorKey !== 'keywords' && column.id !== 'radioColumn';
return {
...column,
header: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ describe('useStudyTableDisplay', () => {
const mockResponse = {
content: [
{
study_name: 'study1',
user_name: 'Luis Perez',
name: 'study1',
createdBy: 'Luis Perez',
project: 'Project FE2050',
status: 'Closed',
horizon: '2050',
keywords: 'keyword1',
creation_date: '2023-01-01',
creationDate: '2023-01-01',
},
{
study_name: 'study2',
user_name: 'Maria Rojas',
name: 'study2',
createdBy: 'Maria Rojas',
project: 'Project PDH27',
status: 'Inactive',
horizon: '2027',
keywords: 'keyword2',
creation_date: '2023-01-01',
creationDate: '2023-01-01',
},
],
totalElements: 2,
Expand Down Expand Up @@ -65,13 +65,13 @@ describe('useStudyTableDisplay', () => {
const mockResponse = {
content: [
{
study_name: 'study1',
user_name: 'Luis Perez',
name: 'study1',
createdBy: 'Luis Perez',
project: 'Project FE2050',
status: 'Closed',
horizon: '2050',
keywords: 'keyword1',
creation_date: '2023-01-01',
creationDate: '2023-01-01',
},
],
totalElements: 1,
Expand Down
6 changes: 2 additions & 4 deletions src/pages/pegase/home/components/useStudyTableDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ export const useStudyTableDisplay = ({
}, [searchStudy, projectId, sortBy]);

useEffect(() => {
const sortParams = Object.entries(sortBy)
.map(([key, order]) => `${key},${order}`)
.join('&sort=');
const [sortColumn, sortDirection] = Object.entries(sortBy)[0] || ['', ''];

fetch(
`${BASE_URL}/v1/study/search?page=${current + 1}&size=${intervalSize}&projectId=${projectId}&search=${searchStudy}&sort=${sortParams}`,
`${BASE_URL}/v1/study/search?page=${current + 1}&size=${intervalSize}&projectId=${projectId}&search=${searchStudy}&sortColumn=${sortColumn}&sortDirection=${sortDirection}`,
)
.then((response) => response.json())
.then((json) => {
Expand Down
6 changes: 3 additions & 3 deletions src/shared/types/pegase/study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

export type StudyDTO = {
id: number;
study_name: string;
user_name: string;
creation_date: Date;
name: string;
createdBy: string;
creationDate: Date;
keywords: string[];
project: string;
status: string;
Expand Down

0 comments on commit a0fcd6b

Please sign in to comment.