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

Admin UI menu available for unauthenticated users #6459

Merged
merged 5 commits into from
Sep 3, 2021
Merged
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/swift-feet-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': minor
---

Updated Navigation component to show docs and playground links irrespective of authentication.
22 changes: 13 additions & 9 deletions packages/keystone/src/admin-ui/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Button } from '@keystone-ui/button';
import { Popover } from '@keystone-ui/popover';
import { MoreHorizontalIcon } from '@keystone-ui/icons/icons/MoreHorizontalIcon';
import { ChevronRightIcon } from '@keystone-ui/icons/icons/ChevronRightIcon';
import { NavigationProps, ListMeta } from '../../types';
import { NavigationProps, ListMeta, AuthenticatedItem } from '../../types';

import { useKeystone } from '../context';
import { Link } from '../router';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const NavItem = ({ href, children, isSelected: _isSelected }: NavItemProp
);
};

const AuthenticatedItem = ({ item }: { item: { id: string; label: string } }) => {
const AuthenticatedItemDialog = ({ item }: { item: AuthenticatedItem | undefined }) => {
const { spacing, typography } = useTheme();
return (
<div
Expand All @@ -73,9 +73,14 @@ const AuthenticatedItem = ({ item }: { item: { id: string; label: string } }) =>
marginBottom: 0,
}}
>
<div css={{ fontSize: typography.fontSize.small }}>
Signed in as <strong>{item.label}</strong>
</div>
{item && item.state === 'authenticated' ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to be able to pull this up into a single variable, but typescript can't infer the state otherwise so leaving it for now.

<div css={{ fontSize: typography.fontSize.small }}>
Signed in as <strong>{item.label}</strong>
</div>
) : (
<div css={{ fontSize: typography.fontSize.small }}>Graqhql Playground and Docs</div>
)}

<Popover
placement="bottom"
triggerRenderer={({ triggerProps }) => (
Expand All @@ -100,7 +105,7 @@ const AuthenticatedItem = ({ item }: { item: { id: string; label: string } }) =>
<PopoverLink target="_blank" href="https://keystonejs.com">
Keystone Documentation
</PopoverLink>
<SignoutButton />
{item && item.state === 'authenticated' && <SignoutButton />}
</Stack>
</Popover>
</div>
Expand Down Expand Up @@ -138,11 +143,10 @@ export const NavigationContainer = ({ authenticatedItem, children }: NavigationC
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
position: 'relative',
}}
>
{authenticatedItem?.state === 'authenticated' && (
<AuthenticatedItem item={authenticatedItem} />
)}
<AuthenticatedItemDialog item={authenticatedItem} />
<nav role="navigation" aria-label="Side Navigation" css={{ marginTop: spacing.xlarge }}>
<ul
css={{
Expand Down