Help toggle and page default in local storage (#3547)

This commit is contained in:
Erik Jan de Wit 2022-10-11 13:09:07 +02:00 committed by GitHub
parent 3374780a1d
commit 558d67cd73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 4 deletions

View file

@ -68,6 +68,7 @@
"react-router": "^5.3.4", "react-router": "^5.3.4",
"react-router-dom": "^5.3.4", "react-router-dom": "^5.3.4",
"react-router-dom-v5-compat": "^6.4.2", "react-router-dom-v5-compat": "^6.4.2",
"react-use-localstorage": "^3.5.3",
"use-react-router-breadcrumbs": "^2.0.2" "use-react-router-breadcrumbs": "^2.0.2"
}, },
"devDependencies": { "devDependencies": {

View file

@ -11,6 +11,7 @@ import {
import { ExternalLinkAltIcon, HelpIcon } from "@patternfly/react-icons"; import { ExternalLinkAltIcon, HelpIcon } from "@patternfly/react-icons";
import { FunctionComponent, useState } from "react"; import { FunctionComponent, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import useLocalStorage from "react-use-localstorage";
import { createNamedContext } from "../../utils/createNamedContext"; import { createNamedContext } from "../../utils/createNamedContext";
import useRequiredContext from "../../utils/useRequiredContext"; import useRequiredContext from "../../utils/useRequiredContext";
@ -31,13 +32,13 @@ export const HelpContext = createNamedContext<HelpContextProps | undefined>(
export const useHelp = () => useRequiredContext(HelpContext); export const useHelp = () => useRequiredContext(HelpContext);
export const Help: FunctionComponent = ({ children }) => { export const Help: FunctionComponent = ({ children }) => {
const [enabled, setHelp] = useState(true); const [enabled, setHelp] = useLocalStorage("helpEnabled", "true");
function toggleHelp() { function toggleHelp() {
setHelp((help) => !help); setHelp(enabled === "true" ? "false" : "true");
} }
return ( return (
<HelpContext.Provider value={{ enabled, toggleHelp }}> <HelpContext.Provider value={{ enabled: enabled === "true", toggleHelp }}>
{children} {children}
</HelpContext.Provider> </HelpContext.Provider>
); );

View file

@ -21,6 +21,7 @@ import {
TableVariant, TableVariant,
} from "@patternfly/react-table"; } from "@patternfly/react-table";
import { get, cloneDeep, differenceBy } from "lodash-es"; import { get, cloneDeep, differenceBy } from "lodash-es";
import useLocalStorage from "react-use-localstorage";
import { PaginatingTableToolbar } from "./PaginatingTableToolbar"; import { PaginatingTableToolbar } from "./PaginatingTableToolbar";
import { ListEmptyState } from "../list-empty-state/ListEmptyState"; import { ListEmptyState } from "../list-empty-state/ListEmptyState";
@ -205,7 +206,11 @@ export function KeycloakDataTable<T>({
const [unPaginatedData, setUnPaginatedData] = useState<T[]>(); const [unPaginatedData, setUnPaginatedData] = useState<T[]>();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [max, setMax] = useState(10); const [defaultPageSize, setDefaultPageSize] = useLocalStorage(
"pageSize",
"10"
);
const [max, setMax] = useState(parseInt(defaultPageSize));
const [first, setFirst] = useState(0); const [first, setFirst] = useState(0);
const [search, setSearch] = useState<string>(""); const [search, setSearch] = useState<string>("");
const prevSearch = useRef<string>(); const prevSearch = useRef<string>();
@ -403,6 +408,7 @@ export function KeycloakDataTable<T>({
onPerPageSelect={(first, max) => { onPerPageSelect={(first, max) => {
setFirst(first); setFirst(first);
setMax(max); setMax(max);
setDefaultPageSize(`${max}`);
}} }}
inputGroupName={ inputGroupName={
searchPlaceholderKey ? `${ariaLabelKey}input` : undefined searchPlaceholderKey ? `${ariaLabelKey}input` : undefined

16
package-lock.json generated
View file

@ -104,6 +104,7 @@
"react-router": "^5.3.4", "react-router": "^5.3.4",
"react-router-dom": "^5.3.4", "react-router-dom": "^5.3.4",
"react-router-dom-v5-compat": "^6.4.2", "react-router-dom-v5-compat": "^6.4.2",
"react-use-localstorage": "^3.5.3",
"use-react-router-breadcrumbs": "^2.0.2" "use-react-router-breadcrumbs": "^2.0.2"
}, },
"devDependencies": { "devDependencies": {
@ -11883,6 +11884,14 @@
"react": ">=16.8" "react": ">=16.8"
} }
}, },
"node_modules/react-use-localstorage": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/react-use-localstorage/-/react-use-localstorage-3.5.3.tgz",
"integrity": "sha512-1oNvJmo72G4v5P9ytJZZTb6ywD3UzWBiainTtfbNlb+U08hc+SOD5HqgiLTKUF0MxGcIR9JSnZGmBttNLXaQYA==",
"peerDependencies": {
"react": ">=16.8.1"
}
},
"node_modules/readable-stream": { "node_modules/readable-stream": {
"version": "2.3.7", "version": "2.3.7",
"dev": true, "dev": true,
@ -17764,6 +17773,7 @@
"react-router": "^5.3.4", "react-router": "^5.3.4",
"react-router-dom": "^5.3.4", "react-router-dom": "^5.3.4",
"react-router-dom-v5-compat": "^6.4.2", "react-router-dom-v5-compat": "^6.4.2",
"react-use-localstorage": "*",
"tar-fs": "^2.1.1", "tar-fs": "^2.1.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"use-react-router-breadcrumbs": "^2.0.2", "use-react-router-breadcrumbs": "^2.0.2",
@ -22573,6 +22583,12 @@
} }
} }
}, },
"react-use-localstorage": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/react-use-localstorage/-/react-use-localstorage-3.5.3.tgz",
"integrity": "sha512-1oNvJmo72G4v5P9ytJZZTb6ywD3UzWBiainTtfbNlb+U08hc+SOD5HqgiLTKUF0MxGcIR9JSnZGmBttNLXaQYA==",
"requires": {}
},
"readable-stream": { "readable-stream": {
"version": "2.3.7", "version": "2.3.7",
"dev": true, "dev": true,