From c45de338c0f96a975c18e9b46e865b9aefc2e1d1 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 31 Mar 2021 10:48:14 +0200 Subject: [PATCH] added `isRowDisabled` function to disble rows fixing: #462 --- src/components/table-toolbar/KeycloakDataTable.tsx | 5 ++++- .../table-toolbar/PaginatingTableToolbar.tsx | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/table-toolbar/KeycloakDataTable.tsx b/src/components/table-toolbar/KeycloakDataTable.tsx index 7cb31d97b3..22caa3227f 100644 --- a/src/components/table-toolbar/KeycloakDataTable.tsx +++ b/src/components/table-toolbar/KeycloakDataTable.tsx @@ -16,13 +16,13 @@ import { Spinner } from "@patternfly/react-core"; import _ from "lodash"; import { PaginatingTableToolbar } from "./PaginatingTableToolbar"; -import { TableToolbar } from "./TableToolbar"; import { asyncStateFetch } from "../../context/auth/AdminClient"; import { ListEmptyState } from "../list-empty-state/ListEmptyState"; type Row = { data: T; selected: boolean; + disableSelection: boolean; cells: (keyof T | JSX.Element)[]; }; @@ -89,6 +89,7 @@ export type DataListProps = { loader: (first?: number, max?: number, search?: string) => Promise; onSelect?: (value: T[]) => void; canSelectAll?: boolean; + isRowDisabled?: (value: T) => boolean; isPaginated?: boolean; ariaLabelKey: string; searchPlaceholderKey?: string; @@ -128,6 +129,7 @@ export function KeycloakDataTable({ isPaginated = false, onSelect, canSelectAll = false, + isRowDisabled, loader, columns, actions, @@ -191,6 +193,7 @@ export function KeycloakDataTable({ return data!.map((value) => { return { data: value, + disableSelection: isRowDisabled ? isRowDisabled(value) : false, selected: !!selected.find((v) => (v as any).id === (value as any).id), cells: columns.map((col) => { if (col.cellRenderer) { diff --git a/src/components/table-toolbar/PaginatingTableToolbar.tsx b/src/components/table-toolbar/PaginatingTableToolbar.tsx index 3dba84b6f4..3be2ac9d1f 100644 --- a/src/components/table-toolbar/PaginatingTableToolbar.tsx +++ b/src/components/table-toolbar/PaginatingTableToolbar.tsx @@ -59,19 +59,20 @@ export const PaginatingTableToolbar = ({ /> ); - if (count === 0) { - <>{children}; - } return ( {toolbarItem} - {pagination()} + {count !== 0 && ( + {pagination()} + )} } - toolbarItemFooter={{pagination("bottom")}} + toolbarItemFooter={ + count !== 0 ? {pagination("bottom")} : <> + } inputGroupName={inputGroupName} inputGroupPlaceholder={inputGroupPlaceholder} inputGroupOnChange={inputGroupOnChange}