|
| 1 | +import { FC } from 'react' |
| 2 | +import { useTranslation } from 'react-i18next' |
| 3 | +import { Layer, useGetRuntimeRoflAppsIdInstances } from '../../../oasis-nexus/api' |
| 4 | +import { NUMBER_OF_ITEMS_ON_SEPARATE_PAGE as limit } from '../../config' |
| 5 | +import { instancesContainerId } from '../../utils/tabAnchors' |
| 6 | +import { LinkableCardLayout } from '../../components/LinkableCardLayout' |
| 7 | +import { CardEmptyState } from '../../components/CardEmptyState' |
| 8 | +import { useSearchParamsPagination } from '../../components/Table/useSearchParamsPagination' |
| 9 | +import { InstancesList } from './InstancesList' |
| 10 | +import { RoflAppDetailsContext } from './hooks' |
| 11 | + |
| 12 | +export const InstancesCard: FC<RoflAppDetailsContext> = context => { |
| 13 | + return ( |
| 14 | + <LinkableCardLayout containerId={instancesContainerId} title=""> |
| 15 | + <InstancesView {...context} /> |
| 16 | + </LinkableCardLayout> |
| 17 | + ) |
| 18 | +} |
| 19 | + |
| 20 | +const InstancesView: FC<RoflAppDetailsContext> = ({ scope, id }) => { |
| 21 | + const { t } = useTranslation() |
| 22 | + const { network } = scope |
| 23 | + const pagination = useSearchParamsPagination('page') |
| 24 | + const offset = (pagination.selectedPage - 1) * limit |
| 25 | + const instancesQuery = useGetRuntimeRoflAppsIdInstances(network, Layer.sapphire, id, { |
| 26 | + limit, |
| 27 | + offset, |
| 28 | + }) |
| 29 | + const { isFetched, isLoading, data } = instancesQuery |
| 30 | + const instances = data?.data.instances |
| 31 | + |
| 32 | + return ( |
| 33 | + <> |
| 34 | + {isFetched && !instances?.length && <CardEmptyState label={t('rofl.emptyInstancesList')} />} |
| 35 | + <InstancesList |
| 36 | + instances={instances} |
| 37 | + isLoading={isLoading} |
| 38 | + limit={limit} |
| 39 | + pagination={{ |
| 40 | + selectedPage: pagination.selectedPage, |
| 41 | + linkToPage: pagination.linkToPage, |
| 42 | + totalCount: data?.data.total_count, |
| 43 | + isTotalCountClipped: data?.data.is_total_count_clipped, |
| 44 | + rowsPerPage: limit, |
| 45 | + }} |
| 46 | + /> |
| 47 | + </> |
| 48 | + ) |
| 49 | +} |
0 commit comments