Skip to content

Commit 9a39150

Browse files
Vixtirgermanosin
andauthored
FE: Add server side sorting to Schemas (#1337)
Co-authored-by: German Osin <[email protected]>
1 parent 7d950d8 commit 9a39150

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

frontend/src/components/Schemas/List/List.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import Search from 'components/common/Search/Search';
1313
import PlusIcon from 'components/common/Icons/PlusIcon';
1414
import Table, { LinkCell } from 'components/common/NewTable';
1515
import { ColumnDef } from '@tanstack/react-table';
16-
import { Action, SchemaSubject, ResourceType } from 'generated-sources';
16+
import {
17+
Action,
18+
SchemaSubject,
19+
ResourceType,
20+
SchemaColumnsToSort,
21+
SortOrder,
22+
} from 'generated-sources';
1723
import { useNavigate, useSearchParams } from 'react-router-dom';
1824
import { PER_PAGE } from 'lib/constants';
1925
import { useGetSchemas } from 'lib/hooks/api/schemas';
@@ -27,14 +33,18 @@ const List: React.FC = () => {
2733
const navigate = useNavigate();
2834
const [searchParams] = useSearchParams();
2935
const {
30-
isFetching,
36+
isInitialLoading,
3137
isError,
3238
data = { pageCount: 1, schemas: [] as SchemaSubject[] },
3339
} = useGetSchemas({
3440
clusterName,
3541
page: Number(searchParams.get('page') || 1),
3642
perPage: Number(searchParams.get('perPage') || PER_PAGE),
3743
search: searchParams.get('q') || '',
44+
orderBy: (searchParams.get('sortBy') as SchemaColumnsToSort) ?? undefined,
45+
sortOrder:
46+
(searchParams.get('sortDirection')?.toUpperCase() as SortOrder) ||
47+
undefined,
3848
});
3949

4050
const columns = React.useMemo<ColumnDef<SchemaSubject>[]>(
@@ -53,7 +63,12 @@ const List: React.FC = () => {
5363
},
5464
{ header: 'Id', accessorKey: 'id', size: 120 },
5565
{ header: 'Type', accessorKey: 'schemaType', size: 120 },
56-
{ header: 'Version', accessorKey: 'version', size: 120 },
66+
{
67+
header: 'Version',
68+
accessorKey: 'version',
69+
size: 120,
70+
enableSorting: false,
71+
},
5772
{
5873
header: 'Compatibility',
5974
accessorKey: 'compatibilityLevel',
@@ -86,7 +101,7 @@ const List: React.FC = () => {
86101
<ControlPanelWrapper hasInput>
87102
<Search placeholder="Search by Schema Name" />
88103
</ControlPanelWrapper>
89-
{isFetching || isError ? (
104+
{isInitialLoading || isError ? (
90105
<PageLoader />
91106
) : (
92107
<Table

frontend/src/components/Schemas/Schemas.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import React from 'react';
1+
import React, { Suspense } from 'react';
22
import { Route, Routes } from 'react-router-dom';
33
import {
44
clusterSchemaEditRelativePath,
55
clusterSchemaNewRelativePath,
66
clusterSchemaSchemaDiffRelativePath,
77
RouteParams,
88
} from 'lib/paths';
9-
import List from 'components/Schemas/List/List';
109
import Details from 'components/Schemas/Details/Details';
1110
import New from 'components/Schemas/New/New';
1211
import Edit from 'components/Schemas/Edit/Edit';
1312
import Diff from 'components/Schemas/Diff/Diff';
13+
import PageLoader from 'components/common/PageLoader/PageLoader';
14+
15+
const List = React.lazy(() => import('./List/List'));
1416

1517
const Schemas: React.FC = () => {
1618
return (
17-
<Routes>
18-
<Route index element={<List />} />
19-
<Route path={clusterSchemaNewRelativePath} element={<New />} />
20-
<Route path={RouteParams.subject} element={<Details />} />
21-
<Route path={clusterSchemaEditRelativePath} element={<Edit />} />
22-
<Route path={clusterSchemaSchemaDiffRelativePath} element={<Diff />} />
23-
</Routes>
19+
<Suspense fallback={<PageLoader />}>
20+
<Routes>
21+
<Route index element={<List />} />
22+
<Route path={clusterSchemaNewRelativePath} element={<New />} />
23+
<Route path={RouteParams.subject} element={<Details />} />
24+
<Route path={clusterSchemaEditRelativePath} element={<Edit />} />
25+
<Route path={clusterSchemaSchemaDiffRelativePath} element={<Diff />} />
26+
</Routes>
27+
</Suspense>
2428
);
2529
};
2630

frontend/src/lib/hooks/api/schemas.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ export function useGetSchemas({
4545
page,
4646
perPage,
4747
search,
48+
orderBy,
49+
sortOrder,
4850
}: GetSchemasRequest) {
4951
return useQuery<SchemaSubjectsResponse>({
50-
queryKey: [SCHEMA_QUERY_KEY, clusterName, page, perPage, search],
52+
queryKey: [
53+
SCHEMA_QUERY_KEY,
54+
clusterName,
55+
page,
56+
perPage,
57+
search,
58+
sortOrder,
59+
orderBy,
60+
],
61+
keepPreviousData: true,
5162
queryFn: () =>
5263
schemasApiClient.getSchemas({
5364
clusterName,
5465
page,
5566
perPage,
5667
search: search || undefined,
68+
sortOrder,
69+
orderBy,
5770
}),
5871
});
5972
}

0 commit comments

Comments
 (0)