-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
603 additions
and
40 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
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,15 @@ | ||
import { StatusIndicatorProps } from '@cloudscape-design/components'; | ||
|
||
export const getStatusIconType = (status: IVolume['status']): StatusIndicatorProps['type'] => { | ||
switch (status) { | ||
case 'failed': | ||
return 'error'; | ||
case 'active': | ||
return 'success'; | ||
case 'provisioning': | ||
return 'in-progress'; | ||
case 'submitted': | ||
default: | ||
console.error(new Error('Undefined volume status')); | ||
} | ||
}; |
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,57 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { format } from 'date-fns'; | ||
|
||
import { StatusIndicator } from 'components'; | ||
|
||
import { DATE_TIME_FORMAT } from 'consts'; | ||
import { getStatusIconType } from 'libs/volumes'; | ||
|
||
export const useColumnsDefinitions = () => { | ||
const { t } = useTranslation(); | ||
|
||
const columns = [ | ||
{ | ||
id: 'name', | ||
header: t('volume.name'), | ||
cell: (item: IVolume) => item.name, | ||
}, | ||
{ | ||
id: 'project', | ||
header: `${t('volume.project')}`, | ||
cell: (item: IVolume) => item.project_name, | ||
}, | ||
{ | ||
id: 'backend', | ||
header: `${t('volume.backend')}`, | ||
cell: (item: IVolume) => item.configuration.backend, | ||
}, | ||
{ | ||
id: 'region', | ||
header: `${t('volume.region')}`, | ||
cell: (item: IVolume) => item.configuration.backend, | ||
}, | ||
|
||
{ | ||
id: 'status', | ||
header: t('volume.status'), | ||
cell: (item: IVolume) => ( | ||
<StatusIndicator type={getStatusIconType(item.status)}>{t(`volume.statuses.${item.status}`)}</StatusIndicator> | ||
), | ||
}, | ||
{ | ||
id: 'created_at', | ||
header: t('volume.created_at'), | ||
cell: (item: IVolume) => format(new Date(item.created_at), DATE_TIME_FORMAT), | ||
}, | ||
{ | ||
id: 'price', | ||
header: `${t('volume.price')}`, | ||
cell: (item: IVolume) => { | ||
return `$${item.provisioning_data.price}`; | ||
}, | ||
}, | ||
]; | ||
|
||
return { columns } as const; | ||
}; |
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,96 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Button, FormField, Header, Pagination, SelectCSD, Table, Toggle } from 'components'; | ||
|
||
import { useCollection } from 'hooks'; | ||
|
||
import { useFilters, useVolumesData, useVolumesTableEmptyMessages } from '../List/hooks'; | ||
import { useColumnsDefinitions } from './hooks'; | ||
|
||
import styles from '../List/styles.module.scss'; | ||
|
||
export const AdministrationVolumeList: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const { renderEmptyMessage, renderNoMatchMessage } = useVolumesTableEmptyMessages(); | ||
|
||
const { | ||
onlyActive, | ||
setOnlyActive, | ||
isDisabledClearFilter, | ||
clearFilters, | ||
projectOptions, | ||
selectedProject, | ||
setSelectedProject, | ||
} = useFilters(); | ||
|
||
const { data, isLoading, pagesCount, disabledNext, prevPage, nextPage } = useVolumesData({ | ||
project_name: selectedProject?.value ?? undefined, | ||
only_active: onlyActive, | ||
}); | ||
|
||
const { columns } = useColumnsDefinitions(); | ||
|
||
const { items, actions, collectionProps } = useCollection(data, { | ||
filtering: { | ||
empty: renderEmptyMessage(), | ||
noMatch: renderNoMatchMessage(() => actions.setFiltering('')), | ||
}, | ||
pagination: { pageSize: 20 }, | ||
selection: {}, | ||
}); | ||
|
||
return ( | ||
<Table | ||
{...collectionProps} | ||
variant="full-page" | ||
columnDefinitions={columns} | ||
items={items} | ||
loading={isLoading} | ||
loadingText={t('common.loading')} | ||
stickyHeader={true} | ||
header={<Header>{t('volume.volumes')}</Header>} | ||
filter={ | ||
<div className={styles.filters}> | ||
<div className={styles.select}> | ||
<FormField label={t('projects.run.project')}> | ||
<SelectCSD | ||
disabled={!projectOptions?.length} | ||
options={projectOptions} | ||
selectedOption={selectedProject} | ||
onChange={(event) => { | ||
setSelectedProject(event.detail.selectedOption); | ||
}} | ||
placeholder={t('projects.run.project_placeholder')} | ||
expandToViewport={true} | ||
filteringType="auto" | ||
/> | ||
</FormField> | ||
</div> | ||
|
||
<div className={styles.activeOnly}> | ||
<Toggle onChange={({ detail }) => setOnlyActive(detail.checked)} checked={onlyActive}> | ||
{t('fleets.active_only')} | ||
</Toggle> | ||
</div> | ||
|
||
<div className={styles.clear}> | ||
<Button formAction="none" onClick={clearFilters} disabled={isDisabledClearFilter}> | ||
{t('common.clearFilter')} | ||
</Button> | ||
</div> | ||
</div> | ||
} | ||
pagination={ | ||
<Pagination | ||
currentPageIndex={pagesCount} | ||
pagesCount={pagesCount} | ||
openEnd={!disabledNext} | ||
disabled={isLoading || data.length === 0} | ||
onPreviousPageClick={prevPage} | ||
onNextPageClick={nextPage} | ||
/> | ||
} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.