Skip to content

Commit f26634d

Browse files
committed
feat: add WorkerpoolAccessTable component and integrate it into WorkerpoolsRoute
1 parent 9a9ac27 commit f26634d

File tree

4 files changed

+165
-1
lines changed

4 files changed

+165
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ColumnDef } from '@tanstack/react-table';
2+
import { PublishedWorkerpoolorder } from 'iexec/IExecOrderbookModule';
3+
import CopyButton from '@/components/CopyButton';
4+
import { truncateAddress } from '@/utils/truncateAddress';
5+
6+
export const columns: ColumnDef<PublishedWorkerpoolorder>[] = [
7+
{
8+
accessorKey: 'order.apprestrict',
9+
header: 'App Restriction',
10+
cell: ({ row }) => (
11+
<CopyButton
12+
displayText={truncateAddress(row.original.order.apprestrict, {
13+
startLen: 8,
14+
})}
15+
textToCopy={row.original.order.apprestrict}
16+
/>
17+
),
18+
},
19+
{
20+
accessorKey: 'order.requesterrestrict',
21+
header: 'Requester Restriction',
22+
cell: ({ row }) => (
23+
<CopyButton
24+
displayText={truncateAddress(row.original.order.requesterrestrict, {
25+
startLen: 8,
26+
})}
27+
textToCopy={row.original.order.requesterrestrict}
28+
/>
29+
),
30+
},
31+
{
32+
accessorKey: 'order.datasetrestrict',
33+
header: 'Dataset Restriction',
34+
cell: ({ row }) => (
35+
<CopyButton
36+
displayText={truncateAddress(row.original.order.datasetrestrict, {
37+
startLen: 8,
38+
})}
39+
textToCopy={row.original.order.datasetrestrict}
40+
/>
41+
),
42+
},
43+
{
44+
accessorKey: 'order.volume',
45+
header: 'Volume',
46+
cell: ({ row }) => <span>{row.original.order.volume}</span>,
47+
},
48+
{
49+
accessorKey: 'remaining',
50+
header: 'Remaining',
51+
cell: ({ row }) => <span>{row.original.remaining}</span>,
52+
},
53+
];
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { DETAIL_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
2+
import { useQuery } from '@tanstack/react-query';
3+
import { DataTable } from '@/components/DataTable';
4+
import { PaginatedNavigation } from '@/components/PaginatedNavigation';
5+
import { getIExec } from '@/externals/iexecSdkClient';
6+
import { usePageParam } from '@/hooks/usePageParam';
7+
import { ErrorAlert } from '@/modules/ErrorAlert';
8+
import { columns } from '@/modules/access/workerpoolColumns';
9+
import useUserStore from '@/stores/useUser.store';
10+
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
11+
12+
function useWorkerpoolAccessData({
13+
workerpoolAddress,
14+
currentPage,
15+
}: {
16+
workerpoolAddress: string;
17+
currentPage: number;
18+
}) {
19+
const { chainId } = useUserStore();
20+
21+
const queryKey = [
22+
chainId,
23+
'workerpool',
24+
'access',
25+
workerpoolAddress,
26+
currentPage,
27+
];
28+
const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery(
29+
{
30+
queryKey,
31+
queryFn: async () => {
32+
const iexec = await getIExec();
33+
34+
const { count, orders } =
35+
await iexec.orderbook.fetchWorkerpoolOrderbook();
36+
37+
return { count, orders };
38+
},
39+
refetchInterval: TABLE_REFETCH_INTERVAL,
40+
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
41+
}
42+
);
43+
44+
const access = data?.orders || [];
45+
const count = data?.count || 0;
46+
const hasNextPage = count > DETAIL_TABLE_LENGTH;
47+
const additionalPages = hasNextPage
48+
? Math.ceil(count / DETAIL_TABLE_LENGTH) - 1
49+
: 0;
50+
51+
return {
52+
data: access,
53+
isLoading,
54+
isRefetching,
55+
isError,
56+
additionalPages,
57+
hasPastError: isError || errorUpdateCount > 0,
58+
};
59+
}
60+
61+
export function WorkerpoolAccessTable({
62+
workerpoolAddress,
63+
setLoading,
64+
setOutdated,
65+
}: {
66+
workerpoolAddress: string;
67+
setLoading: (loading: boolean) => void;
68+
setOutdated: (outdated: boolean) => void;
69+
}) {
70+
const [currentPage, setCurrentPage] = usePageParam('workerpoolAccessPage');
71+
const {
72+
data: access,
73+
isError,
74+
isLoading,
75+
isRefetching,
76+
additionalPages,
77+
hasPastError,
78+
} = useWorkerpoolAccessData({
79+
workerpoolAddress,
80+
currentPage: currentPage - 1,
81+
});
82+
83+
setLoading(isLoading || isRefetching);
84+
setOutdated(access.length > 0 && isError);
85+
86+
return (
87+
<div className="space-y-6">
88+
{hasPastError && !access.length ? (
89+
<ErrorAlert message="A error occurred during workerpool access loading." />
90+
) : (
91+
<DataTable
92+
columns={columns}
93+
data={access}
94+
tableLength={DETAIL_TABLE_LENGTH}
95+
/>
96+
)}
97+
<PaginatedNavigation
98+
currentPage={currentPage}
99+
totalPages={currentPage + additionalPages}
100+
onPageChange={setCurrentPage}
101+
/>
102+
</div>
103+
);
104+
}

src/modules/workerpools/workerpool/WorkerpoolDealsTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DETAIL_TABLE_LENGTH, TABLE_REFETCH_INTERVAL } from '@/config';
22
import { execute } from '@/graphql/poco/execute';
33
import { useQuery } from '@tanstack/react-query';
4-
import { LoaderCircle } from 'lucide-react';
54
import { DataTable } from '@/components/DataTable';
65
import { PaginatedNavigation } from '@/components/PaginatedNavigation';
76
import { usePageParam } from '@/hooks/usePageParam';

src/routes/$chainSlug/_layout/workerpool/$workerpoolAddress.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Tabs } from '@/modules/Tabs';
1313
import { SearcherBar } from '@/modules/search/SearcherBar';
1414
import { WorkerpoolDealsTable } from '@/modules/workerpools/workerpool/WorkerpoolDealsTable';
1515
import { buildWorkerpoolDetails } from '@/modules/workerpools/workerpool/buildWorkerpoolDetails';
16+
import { WorkerpoolAccessTable } from '@/modules/workerpools/workerpool/workerpoolAccessTable';
1617
import { WorkerpoolBreadcrumbs } from '@/modules/workerpools/workerpool/workerpoolBreadcrumbs';
1718
import { workerpoolQuery } from '@/modules/workerpools/workerpool/workerpoolQuery';
1819
import useUserStore from '@/stores/useUser.store';
@@ -138,6 +139,13 @@ function WorkerpoolsRoute() {
138139
setOutdated={setIsOutdatedChild}
139140
/>
140141
)}
142+
{currentTab === 2 && (
143+
<WorkerpoolAccessTable
144+
workerpoolAddress={workerpoolAddress}
145+
setLoading={setIsLoadingChild}
146+
setOutdated={setIsOutdatedChild}
147+
/>
148+
)}
141149
</div>
142150
);
143151
}

0 commit comments

Comments
 (0)