diff --git a/.changeset/real-pots-joke.md b/.changeset/real-pots-joke.md new file mode 100644 index 00000000000..9c8adb50eb3 --- /dev/null +++ b/.changeset/real-pots-joke.md @@ -0,0 +1,25 @@ +--- +'@keystonejs/app-admin-ui': minor +--- + +Enabled the use of `listHeaderActions` hook in the Admin UI. + +Usage: + +```js +// index.js +new AdminUIApp({ + hooks: require.resolve('./admin-ui/'), +}); +``` + +The index file in the `admin-ui` directory should export a hooks which will be packaged for use in the Admin UI during the Keystone build: + +```js +// ./admin-ui/index.js +import { CreateItem } '@keystonejs/admin-ui/components/' +export default { + // re-implement the default create item button + custom text + listHeaderActions: () => (

Hello world

), +}; +``` diff --git a/packages/app-admin-ui/client/pages/List/CreateItem.js b/packages/app-admin-ui/client/pages/List/CreateItem.js new file mode 100644 index 00000000000..8e880848efb --- /dev/null +++ b/packages/app-admin-ui/client/pages/List/CreateItem.js @@ -0,0 +1,28 @@ +/** @jsx jsx */ +import { jsx } from '@emotion/core'; + +import { IconButton } from '@arch-ui/button'; +import { PlusIcon } from '@arch-ui/icons'; + +import { useList } from '../../providers/List'; + +const CreateItem = () => { + const { + list: { access }, + openCreateItemModal, + } = useList(); + if (!access.create) return null; + const cypressCreateId = 'list-page-create-button'; + return ( + + Create + + ); +}; + +export default CreateItem; diff --git a/packages/app-admin-ui/client/pages/List/index.js b/packages/app-admin-ui/client/pages/List/index.js index 33ae854e65f..0f2d74a2fd0 100644 --- a/packages/app-admin-ui/client/pages/List/index.js +++ b/packages/app-admin-ui/client/pages/List/index.js @@ -5,8 +5,6 @@ import { Fragment, useEffect, Suspense } from 'react'; import { useHistory, useLocation } from 'react-router-dom'; import { useList } from '../../providers/List'; -import { IconButton } from '@arch-ui/button'; -import { PlusIcon } from '@arch-ui/icons'; import { Container, FlexGroup } from '@arch-ui/layout'; import { colors, gridSize } from '@arch-ui/theme'; import { PageTitle } from '@arch-ui/typography'; @@ -32,11 +30,13 @@ import Search from './Search'; import Management, { ManageToolbar } from './Management'; import { useListFilter, useListSelect, useListSort, useListUrlState } from './dataHooks'; import { captureSuspensePromises } from '@keystonejs/utils'; +import { useUIHooks } from '../../providers/Hooks'; +import CreateItem from './CreateItem'; export function ListLayout(props) { const { items, itemCount, queryErrors, query } = props; - const { list, openCreateItemModal } = useList(); + const { list } = useList(); const { urlState: { currentPage, fields, pageSize, search }, } = useListUrlState(list); @@ -45,6 +45,8 @@ export function ListLayout(props) { const [sortBy, handleSortChange] = useListSort(); const [selectedItems, onSelectChange] = useListSelect(items); + const { listHeaderActions } = useUIHooks(); + // Misc. // ------------------------------ @@ -57,7 +59,6 @@ export function ListLayout(props) { // Success // ------------------------------ - const cypressCreateId = 'list-page-create-button'; const cypressFiltersId = 'ks-list-active-filters'; const Render = ({ children }) => children(); @@ -67,16 +68,7 @@ export function ListLayout(props) { {list.plural} - {list.access.create ? ( - - Create - - ) : null} + {listHeaderActions ? listHeaderActions() : }