-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from AntaresSimulatorTeam/feature/homepage_act…
…ion_buttons [FEATURE] Homepage buttons for studies actiosn added
- Loading branch information
Showing
6 changed files
with
235 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import StdTagList from '@/components/common/base/StdTagList/StdTagList'; | ||
import StdRadioButton from '@/components/common/forms/stdRadioButton/StdRadioButton'; | ||
import StdAvatar from '@/components/common/layout/stdAvatar/StdAvatar'; | ||
import { StudyStatus } from '@/shared/types/common/StudyStatus.type'; | ||
import { StudyDTO } from '@/shared/types/pegase/study'; | ||
import { createColumnHelper } from '@tanstack/react-table'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const columnHelper = createColumnHelper<StudyDTO>(); | ||
|
||
const getStudyTableHeaders = () => { | ||
const { t } = useTranslation(); | ||
return [ | ||
columnHelper.display({ | ||
id: 'radioColumn', | ||
header: () => <></>, | ||
cell: ({ row }) => ( | ||
<div className={`${row.getIsSelected() ? 'block' : 'hidden group-hover:block'}`}> | ||
<StdRadioButton | ||
value={row.original.id.toString()} | ||
label="" | ||
disabled={!row.getCanSelect()} | ||
checked={row.getIsSelected()} | ||
name={`radio-${row.original.id}`} | ||
/> | ||
</div> | ||
), | ||
}), | ||
|
||
columnHelper.accessor('name', { | ||
header: t('home.@study_name'), | ||
cell: ({ getValue, row }) => { | ||
const status = row.original.status; | ||
const textClass = status === StudyStatus.GENERATED ? 'text-primary-900' : 'group-hover:text-green-500'; | ||
return <span className={`transition-colors ${textClass}`}>{getValue()}</span>; | ||
}, | ||
}), | ||
|
||
columnHelper.accessor('createdBy', { | ||
header: t('home.@user_name'), | ||
cell: ({ getValue }) => ( | ||
<StdAvatar size="s" backgroundColor="gray" fullname={getValue()} initials={getValue().substring(0, 2)} /> | ||
), | ||
}), | ||
|
||
columnHelper.accessor('project', { | ||
header: t('home.@project'), | ||
}), | ||
|
||
columnHelper.accessor('status', { | ||
header: t('home.@status'), | ||
}), | ||
|
||
columnHelper.accessor('horizon', { | ||
header: t('home.@horizon'), | ||
}), | ||
|
||
columnHelper.accessor('keywords', { | ||
header: t('home.@keywords'), | ||
minSize: 500, | ||
size: 500, | ||
cell: ({ getValue, row }) => ( | ||
<div className="flex h-3 w-32"> | ||
<StdTagList id={`pegase-tags-${row.id}`} tags={getValue()} /> | ||
</div> | ||
), | ||
}), | ||
|
||
columnHelper.accessor('creationDate', { | ||
header: t('home.@creation_date'), | ||
}), | ||
]; | ||
}; | ||
|
||
export default getStudyTableHeaders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import StdIcon from '@/components/common/base/stdIcon/StdIcon'; | ||
import { StdIconId } from '@/shared/utils/common/mappings/iconMaps'; | ||
|
||
export function addSortColumn( | ||
headers: any[], | ||
handleSort: (column: string) => void, | ||
sortBy: { [key: string]: 'asc' | 'desc' }, | ||
sortedColumn: string | null, | ||
handleHeaderHover: (hovered: boolean) => void, | ||
isHeaderHovered: boolean, | ||
) { | ||
return headers.map((column) => { | ||
const isSortable = column.accessorKey !== 'keywords' && column.id !== 'radioColumn'; | ||
return { | ||
...column, | ||
header: ( | ||
<div | ||
className={`flex items-center ${isSortable ? 'cursor-pointer' : ''} header-container group`} | ||
onMouseEnter={() => isSortable && handleHeaderHover(true)} | ||
onMouseLeave={() => isSortable && handleHeaderHover(false)} | ||
onClick={() => { | ||
if (isSortable) { | ||
handleHeaderHover(false); | ||
handleSort(column.accessorKey as string); | ||
} | ||
}} | ||
> | ||
<div>{column.header}</div> | ||
{isSortable && ( | ||
<div> | ||
{sortBy[column.accessorKey as string] && sortedColumn === column.accessorKey ? ( | ||
sortBy[column.accessorKey as string] === 'asc' ? ( | ||
<span className="font-bold text-primary-600"> | ||
<StdIcon name={StdIconId.ArrowUpwardAlt} /> | ||
</span> | ||
) : ( | ||
<span className="font-bold text-primary-600"> | ||
<StdIcon name={StdIconId.ArrowDownwardAlt} /> | ||
</span> | ||
) | ||
) : ( | ||
<span | ||
className={`text-primary-900 ${ | ||
isHeaderHovered ? 'opacity-100' : 'opacity-0' | ||
} transition-opacity duration-100`} | ||
> | ||
<StdIcon name={StdIconId.ArrowUpwardAlt} /> | ||
</span> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
), | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
export enum StudyStatus { | ||
IN_PROGRESS = 'IN_PROGRESS', | ||
GENERATED = 'GENERATED', | ||
ERROR = 'ERROR', | ||
CLOSED = 'CLOSED', | ||
DELETED = 'DELETED', | ||
} |
Oops, something went wrong.