From 16ee56590882b93a0917ae1a8b4c2908544a22d1 Mon Sep 17 00:00:00 2001 From: Sitnikov Ivan Date: Mon, 20 May 2024 13:45:32 +0500 Subject: [PATCH 1/2] feat: add ability to hide admin dashboard counts via config --- packages/app-admin-ui/README.md | 1 + packages/app-admin-ui/client/pages/Home/components.js | 4 +++- packages/app-admin-ui/client/pages/Home/index.js | 3 ++- packages/app-admin-ui/index.js | 5 ++++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/app-admin-ui/README.md b/packages/app-admin-ui/README.md index fbaad2ec8f..dd48bedafa 100644 --- a/packages/app-admin-ui/README.md +++ b/packages/app-admin-ui/README.md @@ -49,6 +49,7 @@ module.exports = { | `schemaName` | `String` | `public` | | | `isAccessAllowed` | `Function` | `true` | Controls which users have access to the Admin UI. | | `adminMeta` | `Object` | `{}` | Provides additional `adminMeta`. Useful for Hooks and other customizations | +| `showDashboardCounts`| `Bool` | `true` | Switch for dashboard list count display and loading | | `defaultPageSize` | `Integer` | 50 | The default number of list items to show at once. | | `maximumPageSize` | `Integer` | 1000 | The maximum number of list items to show at once. | diff --git a/packages/app-admin-ui/client/pages/Home/components.js b/packages/app-admin-ui/client/pages/Home/components.js index 8984c0f442..7a9e954ea6 100644 --- a/packages/app-admin-ui/client/pages/Home/components.js +++ b/packages/app-admin-ui/client/pages/Home/components.js @@ -4,6 +4,7 @@ import { Fragment } from 'react'; import { Link } from 'react-router-dom'; import { withPseudoState } from 'react-pseudo-state'; import { useList } from '../../providers/List'; +import { useAdminMeta } from '../../providers/AdminMeta'; import CreateItemModal from '../../components/CreateItemModal'; @@ -37,6 +38,7 @@ const BoxElement = props => ( ); const BoxComponent = ({ focusOrigin, isActive, isHover, isFocus, meta, ...props }) => { + const { showDashboardCounts } = useAdminMeta(); const { list, openCreateItemModal } = useList(); const { label, singular } = list; @@ -52,7 +54,7 @@ const BoxComponent = ({ focusOrigin, isActive, isHover, isFocus, meta, ...props > {label} - + {showDashboardCounts && } { }; const Homepage = () => { - const { getListByKey, listKeys, adminPath } = useAdminMeta(); + const { getListByKey, listKeys, adminPath, showDashboardCounts } = useAdminMeta(); // TODO: A permission query to limit which lists are visible const lists = listKeys.map(key => getListByKey(key)); @@ -33,6 +33,7 @@ const Homepage = () => { const { data, error } = useQuery(getCountQuery(lists), { fetchPolicy: 'cache-and-network', errorPolicy: 'all', + skip: !showDashboardCounts, }); const [cellWidth, setCellWidth] = useState(3); diff --git a/packages/app-admin-ui/index.js b/packages/app-admin-ui/index.js index 8a2efda8eb..43f9f4ece2 100644 --- a/packages/app-admin-ui/index.js +++ b/packages/app-admin-ui/index.js @@ -24,6 +24,7 @@ class AdminUIApp { adminMeta = {}, defaultPageSize = 50, maximumPageSize = 1000, + showDashboardCounts = true, } = {}) { if (adminPath === '/') { throw new Error("Admin path cannot be the root path. Try; '/admin'"); @@ -56,6 +57,7 @@ class AdminUIApp { signinPath: `${this.adminPath}/signin`, signoutPath: `${this.adminPath}/signout`, }; + this.showDashboardCounts = showDashboardCounts; } isAccessAllowed(req) { @@ -111,7 +113,7 @@ class AdminUIApp { getAdminUIMeta(keystone) { // This is exposed as the global `KEYSTONE_ADMIN_META` in the client. - const { name, adminPath, apiPath, graphiqlPath, pages, hooks } = this; + const { name, adminPath, apiPath, graphiqlPath, pages, hooks, showDashboardCounts } = this; const { signinPath, signoutPath } = this.routes; const { lists } = keystone.getAdminMeta({ schemaName: this._schemaName }); const authStrategy = this.authStrategy ? this.authStrategy.getAdminMeta() : undefined; @@ -149,6 +151,7 @@ class AdminUIApp { authStrategy, lists, name, + showDashboardCounts, ...this._adminMeta, }; } From b7498154ea70acef53b8292837263ab20aece182 Mon Sep 17 00:00:00 2001 From: Sitnikov Ivan Date: Mon, 20 May 2024 15:04:27 +0500 Subject: [PATCH 2/2] chore: add changeset --- .changeset/smart-pumpkins-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/smart-pumpkins-raise.md diff --git a/.changeset/smart-pumpkins-raise.md b/.changeset/smart-pumpkins-raise.md new file mode 100644 index 0000000000..feb8a26597 --- /dev/null +++ b/.changeset/smart-pumpkins-raise.md @@ -0,0 +1,5 @@ +--- +'@keystonejs/app-admin-ui': minor +--- + +Add ability to toggle dashboard counts at admin dashboard