From 7d4adc683f74d3cde778553ddf9418b6e7d30c9a Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 16 Mar 2021 13:42:05 +0100 Subject: [PATCH] added search empty state (#435) --- src/common-messages.json | 2 ++ .../table-toolbar/KeycloakDataTable.tsx | 34 ++++++++++++++----- .../table-toolbar/PaginatingTableToolbar.tsx | 8 +++-- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/common-messages.json b/src/common-messages.json index e5b2691815..9b28ff89a2 100644 --- a/src/common-messages.json +++ b/src/common-messages.json @@ -14,6 +14,8 @@ "delete": "Delete", "remove": "Remove", "search": "Search", + "noSearchResults": "No search results", + "noSearchResultsInstructions": "Click on the search bar above to search", "next": "Next", "back": "Back", "finish": "Finish", diff --git a/src/components/table-toolbar/KeycloakDataTable.tsx b/src/components/table-toolbar/KeycloakDataTable.tsx index d50d0106b5..81574ea515 100644 --- a/src/components/table-toolbar/KeycloakDataTable.tsx +++ b/src/components/table-toolbar/KeycloakDataTable.tsx @@ -17,6 +17,7 @@ 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; @@ -212,11 +213,10 @@ export function KeycloakDataTable({ }); const searchOnChange = (value: string) => { - if (isPaginated) { - setSearch(value); - } else { - filter(value); + if (value === "") { + refresh(); } + setSearch(value); }; const Loading = () => ( @@ -242,7 +242,7 @@ export function KeycloakDataTable({ return ( <> - {rows && (rows.length > 0 || !emptyState) && isPaginated && ( + {rows && isPaginated && ( ({ searchTypeComponent={searchTypeComponent} toolbarItem={toolbarItem} > - {!loading && ( + {!loading && rows.length > 0 && ( ({ ariaLabelKey={ariaLabelKey} /> )} + {!loading && rows.length === 0 && search !== "" && ( + + )} {loading && } )} @@ -282,12 +290,12 @@ export function KeycloakDataTable({ searchPlaceholderKey ? `${ariaLabelKey}input` : undefined } inputGroupOnChange={searchOnChange} - inputGroupOnClick={() => {}} + inputGroupOnClick={() => filter(search)} inputGroupPlaceholder={t(searchPlaceholderKey || "")} toolbarItem={toolbarItem} searchTypeComponent={searchTypeComponent} > - {!loading && ( + {!loading && (filteredData || rows).length > 0 && ( ({ ariaLabelKey={ariaLabelKey} /> )} + {!loading && filteredData && filteredData.length === 0 && ( + + )} {loading && } )} - <>{!loading && rows?.length === 0 && emptyState} + <>{!loading && rows?.length === 0 && search === "" && emptyState} ); } diff --git a/src/components/table-toolbar/PaginatingTableToolbar.tsx b/src/components/table-toolbar/PaginatingTableToolbar.tsx index fb07822c04..2366064712 100644 --- a/src/components/table-toolbar/PaginatingTableToolbar.tsx +++ b/src/components/table-toolbar/PaginatingTableToolbar.tsx @@ -65,10 +65,14 @@ export const PaginatingTableToolbar = ({ toolbarItem={ <> {toolbarItem} - {pagination()} + {count !== 0 && ( + {pagination()} + )} } - toolbarItemFooter={{pagination("bottom")}} + toolbarItemFooter={ + count !== 0 && {pagination("bottom")} + } inputGroupName={inputGroupName} inputGroupPlaceholder={inputGroupPlaceholder} inputGroupOnChange={inputGroupOnChange}