Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions js/apps/admin-ui/src/page/PageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export default function PageList() {

const page = pages?.find((p) => p.id === providerId)!;

const loader = async () => {
const params: ComponentQuery = {
parent: realm?.id,
type: PAGE_PROVIDER,
providerId,
};
return await adminClient.components.find({ ...params });
const loader = {
signal: { providerId },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an elegant way to notify KeycloakDataTable that the route changed, so the useFetch dependencies will trigger it to run again.

loader: async () => {
const params: ComponentQuery = {
parent: realm?.id,
type: PAGE_PROVIDER,
providerId,
};
return await adminClient.components.find({ ...params });
},
};

const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
Expand Down
25 changes: 18 additions & 7 deletions js/libs/ui-shared/src/controls/table/KeycloakDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
rowsSelectedOnPage.length > 0;
}
}
}, [selectedRows, canSelectAll, rows]);

Check warning on line 151 in js/libs/ui-shared/src/controls/table/KeycloakDataTable.tsx

View workflow job for this annotation

GitHub Actions / UI Shared

React Hook useEffect has a missing dependency: 'rowsSelectedOnPage.length'. Either include it or remove the dependency array

const updateSelectedRows = (selected: T[]) => {
setSelectedRows(selected);
Expand Down Expand Up @@ -318,11 +318,16 @@
search?: string,
) => Promise<T[]>;

export type SignaledLoader<T> = {
readonly signal: any;
loader: LoaderFunction<T>;
};

export type DataListProps<T> = Omit<
TableProps,
"rows" | "cells" | "onSelect"
> & {
loader: T[] | LoaderFunction<T>;
loader: T[] | LoaderFunction<T> | SignaledLoader<T>;
onSelect?: (value: T[]) => void;
canSelectAll?: boolean;
detailColumns?: DetailField<T>[];
Expand Down Expand Up @@ -486,7 +491,7 @@
),
)
.slice(first, first + max + 1),
[search, first, max],

Check warning on line 494 in js/libs/ui-shared/src/controls/table/KeycloakDataTable.tsx

View workflow job for this annotation

GitHub Actions / UI Shared

React Hook useMemo has missing dependencies: 'convertToColumns', 'getNodeText', 'isPaginated', and 'unPaginatedData'. Either include them or remove the dependency array
);

useFetch(
Expand All @@ -498,11 +503,13 @@
setFirst(0);
}
prevSearch.current = search;
return typeof loader === "function"
? key === prevKey.current && unPaginatedData
? unPaginatedData
: await loader(newSearch ? 0 : first, max + 1, search)
: loader;
const loaderFn =
typeof loader === "function"
? loader
: "loader" in loader
? loader.loader
: async () => loader;
return await loaderFn(newSearch ? 0 : first, max + 1, search);
},
(data) => {
prevKey.current = key;
Expand All @@ -524,7 +531,11 @@
first,
max,
search,
typeof loader !== "function" ? loader : undefined,
typeof loader !== "function"
? "signal" in loader
? loader.signal
: loader
: undefined,
],
);

Expand Down
1 change: 1 addition & 0 deletions js/libs/ui-shared/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type {
Field,
DetailField,
LoaderFunction,
SignaledLoader,
} from "./controls/table/KeycloakDataTable";
export { PaginatingTableToolbar } from "./controls/table/PaginatingTableToolbar";
export { TableToolbar } from "./controls/table/TableToolbar";
Expand Down
Loading