-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gowtham Shanmugasundaram <gshanmug@redhat.com>
- Loading branch information
1 parent
59dec8a
commit 835cc2f
Showing
22 changed files
with
646 additions
and
63 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
241 changes: 241 additions & 0 deletions
241
packages/odf/components/s3-browser/buckets-list-page/bucketsListPage.tsx
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,241 @@ | ||
import * as React from 'react'; | ||
import { odfDocLinks } from '@odf/shared/constants'; | ||
import EmptyPage from '@odf/shared/empty-state-page/empty-page'; | ||
import { | ||
DOC_VERSION as odfDocVersion, | ||
useUserSettingsLocalStorage, | ||
} from '@odf/shared/hooks'; | ||
import { PaginatedListPage } from '@odf/shared/list-page'; | ||
import { RowComponentType } from '@odf/shared/table'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { sortByFavorite, sortRows, ViewDocumentation } from '@odf/shared/utils'; | ||
import { | ||
Timestamp, | ||
useListPageFilter, | ||
} from '@openshift-console/dynamic-plugin-sdk'; | ||
import { TFunction, Trans } from 'react-i18next'; | ||
import { Link, useNavigate } from 'react-router-dom-v5-compat'; | ||
import useSWR from 'swr'; | ||
import { Bullseye, Button, ButtonVariant, Label } from '@patternfly/react-core'; | ||
import { SyncAltIcon } from '@patternfly/react-icons'; | ||
import { ActionsColumn, Td, Tr } from '@patternfly/react-table'; | ||
import { | ||
BUCKET_BOOKMARKS_USER_SETTINGS_KEY, | ||
LIST_BUCKET, | ||
} from '../../../constants'; | ||
import { S3BucketKind } from '../../../types'; | ||
import { convertBucketDataToCrFormat } from '../../utils/s3-browser'; | ||
import { NoobaaS3Context, NoobaaS3Provider } from '../noobaa-context'; | ||
|
||
const CREATE_BUCKET_PAGE_PATH = '/odf/object-storage/create-bucket'; | ||
const BUCKET_DETAILS_PAGE_BASE_PATH = '/odf/object-storage/buckets'; | ||
|
||
const getColumnNames = (t: TFunction<string>) => [ | ||
'', // favoritable, | ||
t('Name'), | ||
t('Storage endpoint'), | ||
t('Create on'), | ||
'', // action kebab | ||
]; | ||
|
||
const getHeaderColumns = (t: TFunction<string>, favorites: string[]) => { | ||
const columnNames = getColumnNames(t); | ||
return [ | ||
{ | ||
columnName: columnNames[0], | ||
sortFunction: (a, b, c) => | ||
sortByFavorite(a, b, c, 'apiResponse.Name', favorites), | ||
}, | ||
{ | ||
columnName: columnNames[1], | ||
sortFunction: (a, b, c) => sortRows(a, b, c, 'apiResponse.Name'), | ||
thProps: { | ||
className: 'pf-v5-u-w-16-on-2xl', | ||
}, | ||
}, | ||
{ | ||
columnName: columnNames[2], | ||
thProps: { | ||
className: 'pf-v5-u-w-16-on-lg', | ||
}, | ||
}, | ||
{ | ||
columnName: columnNames[3], | ||
thProps: { | ||
className: 'pf-v5-u-w-16-on-lg', | ||
}, | ||
}, | ||
{ | ||
columnName: columnNames[4], | ||
}, | ||
]; | ||
}; | ||
|
||
// ToDo(Gowtham): Update the sync logic after: https://github.com/red-hat-storage/odf-console/pull/1591 | ||
const BucketSyncButton: React.FC = () => { | ||
return ( | ||
<div className="pf-v5-u-ml-md pf-v5-u-mt-md"> | ||
<Button | ||
data-test="bucket-list-sync-button" | ||
variant={ButtonVariant.plain} | ||
onClick={() => null} | ||
> | ||
<SyncAltIcon /> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
const EmptyRowMessage: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
return <Bullseye className="pf-v5-u-mt-xl">{t('No buckets found')}</Bullseye>; | ||
}; | ||
|
||
const NoDataMessage: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
const navigate = useNavigate(); | ||
return ( | ||
<EmptyPage | ||
onClick={() => navigate(CREATE_BUCKET_PAGE_PATH)} | ||
buttonText={t('Create bucket')} | ||
title={t('Create and manage your buckets')} | ||
isLoaded | ||
canAccess | ||
> | ||
<Trans t={t}> | ||
Navigate through your buckets effortlessly. View the contents of your | ||
S3-managed and Openshift-managed buckets, making it easy to locate and | ||
inspect objects. | ||
</Trans> | ||
</EmptyPage> | ||
); | ||
}; | ||
|
||
const ListPageHeaderHelper: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
return ( | ||
<Trans t={t}> | ||
Browse, upload, and manage objects in buckets. | ||
<ViewDocumentation | ||
doclink={odfDocLinks(odfDocVersion).S3_BUCKET} | ||
text={t('Help materials')} | ||
/> | ||
</Trans> | ||
); | ||
}; | ||
|
||
const BucketsTableRow: React.FC<RowComponentType<S3BucketKind>> = ({ | ||
row: bucket, | ||
rowIndex, | ||
extraProps, | ||
}) => { | ||
const { t } = useCustomTranslation(); | ||
const columnNames = getColumnNames(t); | ||
const { Name: name, CreationDate: creationDate } = bucket.apiResponse; | ||
const { favorites, setFavorites }: RowExtraPropsType = extraProps; | ||
|
||
const onSetFavorite = (key, active) => { | ||
setFavorites((oldFavorites) => [ | ||
...oldFavorites.filter((oldFavorite) => oldFavorite !== key), | ||
...(active ? [key] : []), | ||
]); | ||
}; | ||
|
||
return ( | ||
<Tr translate={null} key={rowIndex}> | ||
<Td | ||
translate={null} | ||
favorites={{ | ||
isFavorited: favorites.includes(name), | ||
onFavorite: (_event, isFavoriting) => | ||
onSetFavorite(name, isFavoriting), | ||
rowIndex, | ||
}} | ||
/> | ||
<Td translate={null} dataLabel={columnNames[1]}> | ||
<Link to={`${BUCKET_DETAILS_PAGE_BASE_PATH}/${name}`}>{name}</Link> | ||
</Td> | ||
<Td translate={null} dataLabel={columnNames[2]}> | ||
{/* ToDo: Currently we only support MCG, make is configurable once RGW is supported as well */} | ||
<Label color="gold">{t('MCG')}</Label> | ||
</Td> | ||
<Td translate={null} dataLabel={columnNames[3]}> | ||
{<Timestamp timestamp={creationDate} />} | ||
</Td> | ||
<Td translate={null} isActionCell> | ||
<ActionsColumn items={[]} translate={null} /> | ||
</Td> | ||
</Tr> | ||
); | ||
}; | ||
|
||
const BucketsListPage: React.FC = () => { | ||
const { t } = useCustomTranslation(); | ||
const { noobaaS3 } = React.useContext(NoobaaS3Context); | ||
const { data, error, isLoading } = useSWR(LIST_BUCKET, () => | ||
noobaaS3.listBuckets() | ||
); | ||
const [buckets, filteredData, onFilterChange] = useListPageFilter( | ||
convertBucketDataToCrFormat(data) | ||
); | ||
const [favorites, setFavorites] = useUserSettingsLocalStorage<string[]>( | ||
BUCKET_BOOKMARKS_USER_SETTINGS_KEY, | ||
true, | ||
[] | ||
); | ||
|
||
const isLoadedWOAnyError = !isLoading && !error; | ||
const noData = !isLoadedWOAnyError || !buckets.length; | ||
|
||
return ( | ||
<> | ||
<PaginatedListPage | ||
filteredData={filteredData} | ||
CreateButton={BucketSyncButton} | ||
noData={noData} | ||
listPageHeaderProps={{ | ||
title: t('Buckets'), | ||
}} | ||
ListPageHeaderHelper={ListPageHeaderHelper} | ||
listPageCreateLinkProps={{ | ||
to: CREATE_BUCKET_PAGE_PATH, | ||
}} | ||
createButtonText={t('Create bucket')} | ||
listPageFilterProps={{ | ||
data: data, | ||
loaded: !isLoading, | ||
hideLabelFilter: true, | ||
nameFilterPlaceholder: t('Search a bucket by name'), | ||
onFilterChange: onFilterChange, | ||
}} | ||
composableTableProps={{ | ||
columns: getHeaderColumns(t, favorites), | ||
RowComponent: BucketsTableRow, | ||
emptyRowMessage: EmptyRowMessage, | ||
unfilteredData: buckets as [], | ||
noDataMsg: NoDataMessage, | ||
loaded: !isLoading, | ||
loadError: error, | ||
isFavorites: true, | ||
isCompact: true, | ||
extraProps: { favorites, setFavorites }, | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
const BucketsListPage_: React.FC = () => { | ||
return ( | ||
<NoobaaS3Provider loading={false}> | ||
<BucketsListPage /> | ||
</NoobaaS3Provider> | ||
); | ||
}; | ||
|
||
type RowExtraPropsType = { | ||
favorites: string[]; | ||
setFavorites: React.Dispatch<React.SetStateAction<string[]>>; | ||
}; | ||
|
||
export default BucketsListPage_; |
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,10 @@ | ||
import { ListBucketsCommandOutput } from '@aws-sdk/client-s3'; | ||
import { S3BucketKind } from '../../types'; | ||
|
||
export const convertBucketDataToCrFormat = ( | ||
listBucketsCommandOutput: ListBucketsCommandOutput | ||
): S3BucketKind[] => | ||
listBucketsCommandOutput?.Buckets.map((bucket) => ({ | ||
metadata: { name: bucket.Name }, | ||
apiResponse: bucket, | ||
})) || []; |
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
File renamed without changes.
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 @@ | ||
export { default as EmptyPage } from './empty-page'; |
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
Oops, something went wrong.