-
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
f142826
commit 03573e8
Showing
21 changed files
with
466 additions
and
68 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
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
250 changes: 250 additions & 0 deletions
250
packages/odf/components/s3-browser/bucket/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,250 @@ | ||
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 } 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, | ||
// ToDo (Gowtham): Update sdk (stable & internal) version and remove these comments | ||
// @ts-ignore | ||
useUserSettings, | ||
} from '@openshift-console/dynamic-plugin-sdk'; | ||
import * as _ from 'lodash-es'; | ||
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 { convertS3ListBucketOutputToK8sCompatible } 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. Track and manage object versions and deleted items. | ||
View and restore previous versions of objects and access a history of | ||
deleted items, ensuring you can recover or review data as needed. | ||
</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 = React.useCallback( | ||
(key, active) => { | ||
setFavorites((oldFavorites) => ({ | ||
...oldFavorites, | ||
[key]: active ? true : undefined, | ||
})); | ||
}, | ||
[setFavorites] | ||
); | ||
|
||
return ( | ||
<Tr translate={null} key={rowIndex}> | ||
<Td | ||
translate={null} | ||
favorites={{ | ||
isFavorited: _.has(favorites, 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]}> | ||
<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( | ||
convertS3ListBucketOutputToK8sCompatible(data) | ||
); | ||
const [favorites, setFavorites] = useUserSettings<BucketFavoritesType>( | ||
BUCKET_BOOKMARKS_USER_SETTINGS_KEY, | ||
undefined, | ||
true | ||
); | ||
|
||
const isLoadeddWOAnyError = !isLoading && !error; | ||
const noData = !isLoadeddWOAnyError || !buckets.length; | ||
|
||
return ( | ||
<> | ||
<PaginatedListPage | ||
filteredData={filteredData} | ||
SecondaryAction={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, Object.keys(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 BucketFavoritesType = { | ||
[key in string]: boolean; | ||
}; | ||
|
||
type RowExtraPropsType = { | ||
favorites: BucketFavoritesType; | ||
setFavorites: React.Dispatch<React.SetStateAction<RowExtraPropsType>>; | ||
}; | ||
|
||
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 convertS3ListBucketOutputToK8sCompatible = ( | ||
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.
File renamed without changes.
Oops, something went wrong.