Skip to content

Commit e69e991

Browse files
committed
refactor(ui): Refactor the repository runs table
Signed-off-by: Jyrki Keisala <[email protected]>
1 parent 3217b09 commit e69e991

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

ui/src/routes/organizations/$orgId/products/$productId/repositories/$repoId/-components/repository-runs-table.tsx

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
* License-Filename: LICENSE
1818
*/
1919

20-
import { useQueryClient } from '@tanstack/react-query';
20+
import {
21+
useMutation,
22+
useQuery,
23+
useQueryClient,
24+
useSuspenseQuery,
25+
} from '@tanstack/react-query';
2126
import { Link } from '@tanstack/react-router';
2227
import {
2328
createColumnHelper,
@@ -26,13 +31,7 @@ import {
2631
} from '@tanstack/react-table';
2732
import { Repeat, View } from 'lucide-react';
2833

29-
import {
30-
useRepositoriesServiceDeleteApiV1RepositoriesByRepositoryIdRunsByOrtRunIndex,
31-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdRuns,
32-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdRunsKey,
33-
} from '@/api/queries';
34-
import { useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdSuspense } from '@/api/queries/suspense';
35-
import { ApiError, OrtRunSummary } from '@/api/requests';
34+
import { ApiError } from '@/api/requests';
3635
import { DataTable } from '@/components/data-table/data-table';
3736
import { DeleteDialog } from '@/components/delete-dialog';
3837
import { DeleteIconButton } from '@/components/delete-icon-button';
@@ -50,6 +49,13 @@ import {
5049
} from '@/components/ui/tooltip';
5150
import { config } from '@/config';
5251
import { getStatusBackgroundColor } from '@/helpers/get-status-class';
52+
import { OrtRunSummary } from '@/hey-api';
53+
import {
54+
deleteOrtRunByIndexMutation,
55+
getOrtRunsByRepositoryIdOptions,
56+
getOrtRunsByRepositoryIdQueryKey,
57+
getRepositoryByIdOptions,
58+
} from '@/hey-api/@tanstack/react-query.gen';
5359
import { toast } from '@/lib/toast';
5460
import { useTablePrefsStore } from '@/store/table-prefs.store';
5561

@@ -158,41 +164,46 @@ const columns = [
158164
cell: function Row({ row }) {
159165
const queryClient = useQueryClient();
160166

161-
const repository =
162-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdSuspense({
163-
repositoryId: row.original.repositoryId,
164-
});
167+
const repository = useSuspenseQuery({
168+
...getRepositoryByIdOptions({
169+
path: {
170+
repositoryId: row.original.repositoryId,
171+
},
172+
}),
173+
});
165174

166-
const { mutateAsync: deleteRun } =
167-
useRepositoriesServiceDeleteApiV1RepositoriesByRepositoryIdRunsByOrtRunIndex(
168-
{
169-
onSuccess() {
170-
toast.info('Delete Run', {
171-
description: `Run "${row.original.index}" deleted successfully.`,
172-
});
173-
queryClient.invalidateQueries({
174-
queryKey: [
175-
useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdRunsKey,
176-
],
177-
});
178-
},
179-
onError(error: ApiError) {
180-
toast.error(error.message, {
181-
description: <ToastError error={error} />,
182-
duration: Infinity,
183-
cancel: {
184-
label: 'Dismiss',
185-
onClick: () => {},
186-
},
187-
});
175+
const { mutateAsync: deleteRun } = useMutation({
176+
...deleteOrtRunByIndexMutation(),
177+
onSuccess() {
178+
toast.info('Delete Run', {
179+
description: `Run "${row.original.index}" deleted successfully.`,
180+
});
181+
queryClient.invalidateQueries({
182+
queryKey: getOrtRunsByRepositoryIdQueryKey({
183+
path: {
184+
repositoryId: row.original.repositoryId,
185+
},
186+
}),
187+
});
188+
},
189+
onError(error: ApiError) {
190+
toast.error(error.message, {
191+
description: <ToastError error={error} />,
192+
duration: Infinity,
193+
cancel: {
194+
label: 'Dismiss',
195+
onClick: () => {},
188196
},
189-
}
190-
);
197+
});
198+
},
199+
});
191200

192201
async function handleDelete() {
193202
await deleteRun({
194-
ortRunIndex: row.original.index,
195-
repositoryId: row.original.repositoryId,
203+
path: {
204+
ortRunIndex: row.original.index,
205+
repositoryId: row.original.repositoryId,
206+
},
196207
});
197208
}
198209

@@ -264,23 +275,21 @@ export const RepositoryRunsTable = ({
264275
search,
265276
}: RepositoryTableProps) => {
266277
const setRunPageSize = useTablePrefsStore((state) => state.setRunPageSize);
278+
267279
const {
268280
data: runs,
269281
error: runsError,
270282
isPending: runsIsPending,
271283
isError: runsIsError,
272-
} = useRepositoriesServiceGetApiV1RepositoriesByRepositoryIdRuns(
273-
{
274-
repositoryId: Number.parseInt(repoId),
275-
limit: pageSize,
276-
offset: pageIndex * pageSize,
277-
sort: '-index',
278-
},
279-
undefined,
280-
{
281-
refetchInterval: pollInterval,
282-
}
283-
);
284+
} = useQuery({
285+
...getOrtRunsByRepositoryIdOptions({
286+
path: {
287+
repositoryId: Number.parseInt(repoId),
288+
},
289+
query: { limit: pageSize, offset: pageIndex * pageSize, sort: '-index' },
290+
}),
291+
refetchInterval: pollInterval,
292+
});
284293

285294
const table = useReactTable({
286295
data: runs?.data || [],

0 commit comments

Comments
 (0)