Skip to content

Commit

Permalink
Admin UI: moved no-lists-found display to a better location, fixed a …
Browse files Browse the repository at this point in the history
…warning (#2982)
  • Loading branch information
Vultraz committed May 18, 2020
1 parent fdfb014 commit da8ca88
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-fans-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/app-admin-ui': patch
---

Fixed an issue with the no-lists-defined display.
2 changes: 1 addition & 1 deletion packages/app-admin-ui/client/components/PageError.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StopIcon } from '@arch-ui/icons';
import { colors } from '@arch-ui/theme';
import { Container } from '@arch-ui/layout';

export default function PageError({ children, Icon = StopIcon, ...props }) {
export default function PageError({ children, icon: Icon = StopIcon, ...props }) {
return (
<Container>
<div
Expand Down
26 changes: 24 additions & 2 deletions packages/app-admin-ui/client/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { Suspense, useMemo } from 'react';
import React, { Fragment, Suspense, useMemo } from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from '@apollo/react-hooks';
import { BrowserRouter, Redirect, Route, Switch } from 'react-router-dom';
import { ToastProvider } from 'react-toast-notifications';
import { Global } from '@emotion/core';

import { globalStyles } from '@arch-ui/theme';
import { InfoIcon } from '@arch-ui/icons';

import { initApolloClient } from './apolloClient';
import Nav from './components/Nav';
Expand All @@ -14,6 +15,8 @@ import ConnectivityListener from './components/ConnectivityListener';
import KeyboardShortcuts from './components/KeyboardShortcuts';
import PageLoading from './components/PageLoading';
import ToastContainer from './components/ToastContainer';
import DocTitle from './components/DocTitle';
import PageError from './components/PageError';
import { AdminMetaProvider, useAdminMeta } from './providers/AdminMeta';
import { ListProvider } from './providers/List';
import { HooksProvider } from './providers/Hooks';
Expand All @@ -27,6 +30,7 @@ import SignoutPage from './pages/Signout';

export const KeystoneAdminUI = () => {
const {
listKeys,
getListByPath,
adminPath,
signinPath,
Expand Down Expand Up @@ -54,7 +58,25 @@ export const KeystoneAdminUI = () => {
}),
{
path: `${adminPath}`,
component: () => <HomePage />,
component: () => {
if (listKeys.length === 0) {
return (
<Fragment>
<DocTitle title="Home" />
<PageError icon={InfoIcon}>
<p>
No lists defined.{' '}
<a target="_blank" href="https://keystonejs.com/tutorials/add-lists">
Get started by creating your first list.
</a>
</p>
</PageError>
</Fragment>
);
}

return <HomePage />;
},
exact: true,
},
{
Expand Down
25 changes: 2 additions & 23 deletions packages/app-admin-ui/client/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Fragment, useState, useMemo } from 'react';
import { Link } from 'react-router-dom';
import { useLazyQuery } from '@apollo/react-hooks';
import { useQuery } from '@apollo/react-hooks';

import { Container, Grid, Cell } from '@arch-ui/layout';
import { PageTitle } from '@arch-ui/typography';
Expand Down Expand Up @@ -32,7 +31,7 @@ const Homepage = () => {
// TODO: A permission query to limit which lists are visible
const lists = listKeys.map(key => getListByKey(key));

const [getLists, { data, error, called }] = useLazyQuery(getCountQuery(lists), {
const { data, error } = useQuery(getCountQuery(lists), {
fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
});
Expand All @@ -52,26 +51,6 @@ const Homepage = () => {
},
});

if (lists.length === 0) {
return (
<Fragment>
<DocTitle title="Home" />
<PageError>
<p>
No lists defined.{' '}
<Link href="https://keystonejs.com/tutorials/add-lists">
Get started by creating your first list.
</Link>
</p>
</PageError>
</Fragment>
);
}

if (!called) {
getLists();
}

let allowedLists = lists;

if (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-admin-ui/client/pages/ListNotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ListNotFoundPage = ({ listKey }) => {
const { adminPath } = useAdminMeta();

return (
<PageError Icon={IssueOpenedIcon}>
<PageError icon={IssueOpenedIcon}>
<p>
The list &ldquo;
{listKey}
Expand Down

0 comments on commit da8ca88

Please sign in to comment.