Skip to content

Commit 4122224

Browse files
authored
Merge pull request #1837 from oasisprotocol/mz/roflInstances
ROFL app instances card
2 parents 8fba45b + 9ec9c17 commit 4122224

7 files changed

Lines changed: 353 additions & 26 deletions

File tree

.changelog/1837.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create ROFL app instances card
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { FC } from 'react'
2+
import { useTranslation } from 'react-i18next'
3+
import Typography from '@mui/material/Typography'
4+
import { RoflInstance } from '../../../oasis-nexus/api'
5+
import { Table, TableCellAlign, TableColProps } from '../../components/Table'
6+
import { TablePaginationProps } from '../../components/Table/TablePagination'
7+
8+
type InstancesListProps = {
9+
instances: RoflInstance[] | undefined
10+
isLoading: boolean
11+
limit: number
12+
pagination: false | TablePaginationProps
13+
}
14+
15+
export const InstancesList: FC<InstancesListProps> = ({ isLoading, limit, pagination, instances }) => {
16+
const { t } = useTranslation()
17+
const tableColumns: TableColProps[] = [
18+
{ key: 'rak', content: t('rofl.rak') },
19+
{ key: 'node', content: t('rofl.nodeId') },
20+
{ key: 'expiration', content: t('rofl.expirationEpoch'), align: TableCellAlign.Right },
21+
]
22+
23+
const tableRows = instances?.map(instance => {
24+
return {
25+
key: instance.rak,
26+
data: [
27+
{
28+
key: 'rak',
29+
content: <Typography variant="mono">{instance.rak}</Typography>,
30+
},
31+
{
32+
key: 'node',
33+
content: <Typography variant="mono">{instance.endorsing_node_id}</Typography>,
34+
},
35+
{
36+
key: 'expiration',
37+
content: instance.expiration_epoch.toLocaleString(),
38+
align: TableCellAlign.Right,
39+
},
40+
],
41+
}
42+
})
43+
44+
return (
45+
<Table
46+
columns={tableColumns}
47+
rows={tableRows}
48+
rowsNumber={limit}
49+
name={t('rofl.instances')}
50+
isLoading={isLoading}
51+
pagination={pagination}
52+
extraHorizontalSpaceOnMobile
53+
/>
54+
)
55+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { SearchScope } from '../../../types/searchScope'
2+
3+
export type RoflAppDetailsContext = {
4+
scope: SearchScope
5+
id: string
6+
}
7+
8+
// TOOD: Placeholder file for a hook used within a router. Add when details page is ready

src/app/utils/tabAnchors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const nftCollectionContainerId = 'nftCollection'
1111
export const transfersContainerId = 'transfers'
1212
export const tokenTransfersContainerId = 'tokenTransfers'
1313
export const tokenContainerId = 'tokens'
14+
export const instancesContainerId = 'instances'

src/locales/en/translation.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,10 @@
665665
"created": "Date created",
666666
"instances": "Instances",
667667
"listTitle": "ROFL Apps",
668-
"nameNotProvided": "Name not provided"
668+
"nameNotProvided": "Name not provided",
669+
"nodeId": "Node ID",
670+
"expirationEpoch": "Expiration epoch",
671+
"emptyInstancesList": "No ROFL app instances found."
669672
},
670673
"search": {
671674
"placeholder": "Address, Block, Contract, Transaction hash, Token name, etc.",

0 commit comments

Comments
 (0)