Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to toggle counts at admin dashboard #421

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changeset/smart-pumpkins-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/app-admin-ui': minor
---

Add ability to toggle dashboard counts at admin dashboard
1 change: 1 addition & 0 deletions packages/app-admin-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down
4 changes: 3 additions & 1 deletion packages/app-admin-ui/client/pages/Home/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;

Expand All @@ -52,7 +54,7 @@ const BoxComponent = ({ focusOrigin, isActive, isHover, isFocus, meta, ...props
>
{label}
</Name>
<Count meta={meta} />
{showDashboardCounts && <Count meta={meta} />}
<CreateButton
title={`Create ${singular}`}
isHover={isHover || isFocus}
Expand Down
3 changes: 2 additions & 1 deletion packages/app-admin-ui/client/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const getCountQuery = lists => {
};

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));

const { data, error } = useQuery(getCountQuery(lists), {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
skip: !showDashboardCounts,
});

const [cellWidth, setCellWidth] = useState(3);
Expand Down
5 changes: 4 additions & 1 deletion packages/app-admin-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down Expand Up @@ -56,6 +57,7 @@ class AdminUIApp {
signinPath: `${this.adminPath}/signin`,
signoutPath: `${this.adminPath}/signout`,
};
this.showDashboardCounts = showDashboardCounts;
}

isAccessAllowed(req) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +151,7 @@ class AdminUIApp {
authStrategy,
lists,
name,
showDashboardCounts,
...this._adminMeta,
};
}
Expand Down