Skip to content

Commit

Permalink
Fix ui.hideCreate not being respected on the home page (#6777)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Oct 12, 2021
1 parent 2e733c9 commit 30fc08b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-islands-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Fixed the home page of the Admin UI not respecting `ui.hideCreate`
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import { useRouter, Link } from '../../../../admin-ui/router';

type ListCardProps = {
listKey: string;
hideCreate: boolean;
count:
| { type: 'success'; count: number }
| { type: 'no-access' }
| { type: 'error'; message: string }
| { type: 'loading' };
};

const ListCard = ({ listKey, count }: ListCardProps) => {
const ListCard = ({ listKey, count, hideCreate }: ListCardProps) => {
const { colors, palette, radii, spacing } = useTheme();
const list = useList(listKey);
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
Expand Down Expand Up @@ -65,16 +66,18 @@ const ListCard = ({ listKey, count }: ListCardProps) => {
'No access'
)}
</Link>
<CreateButton
title={`Create ${list.singular}`}
disabled={isCreateModalOpen}
onClick={() => {
setIsCreateModalOpen(true);
}}
>
<PlusIcon size="large" />
<VisuallyHidden>Create {list.singular}</VisuallyHidden>
</CreateButton>
{hideCreate === false && (
<CreateButton
title={`Create ${list.singular}`}
disabled={isCreateModalOpen}
onClick={() => {
setIsCreateModalOpen(true);
}}
>
<PlusIcon size="large" />
<VisuallyHidden>Create {list.singular}</VisuallyHidden>
</CreateButton>
)}
<DrawerController isOpen={isCreateModalOpen}>
<CreateItemDrawer
listKey={list.key}
Expand Down Expand Up @@ -132,12 +135,7 @@ export const HomePage = () => {
adminMeta {
lists {
key
fields {
path
createView {
fieldMode
}
}
hideCreate
}
}
}
Expand Down Expand Up @@ -191,6 +189,10 @@ export const HomePage = () => {
: { type: 'success', count: data[key] }
: { type: 'loading' }
}
hideCreate={
data?.keystone.adminMeta.lists.find((list: any) => list.key === key)
?.hideCreate ?? false
}
key={key}
listKey={key}
/>
Expand Down

0 comments on commit 30fc08b

Please sign in to comment.