diff --git a/components/views/List.ts b/components/views/List.ts index 561a7257d3..1d14c3a0a6 100644 --- a/components/views/List.ts +++ b/components/views/List.ts @@ -1,2 +1,2 @@ export { default as List } from '../../dist/admin/components/views/collections/List/Default'; -export type { Props } from '../../dist/admin/components/views/collections/Edit/types'; +export type { Props } from '../../dist/admin/components/views/collections/List/types'; diff --git a/docs/admin/components.mdx b/docs/admin/components.mdx index fb96ae48b6..d281719517 100644 --- a/docs/admin/components.mdx +++ b/docs/admin/components.mdx @@ -85,7 +85,14 @@ You can override components on a Collection-by-Collection basis via each Collect | **`edit.SaveDraftButton`** | Replace the default `Save Draft` button with a custom component. Drafts must be enabled and autosave must be disabled. | | **`edit.PublishButton`** | Replace the default `Publish` button with a custom component. Drafts must be enabled. | | **`edit.PreviewButton`** | Replace the default `Preview` button with a custom component. | - +| **`BeforeList`** | Array of components to inject _before_ the built-in List view + | +| **`BeforeListTable`** | Array of components to inject _before_ the built-in List view's table + | +| **`AfterListTable`** | Array of components to inject _after_ the built-in List view's table + | +| **`AfterList`** | Array of components to inject _after_ the built-in List view + | #### Examples ```tsx @@ -136,6 +143,38 @@ export const CustomPreviewButton: CustomPreviewButtonProps = ({ }; ``` +##### Custom Collection List View Example + +Collection.ts +```tsx +import { MyListComponent } from './MyListComponent'; +export const MyCollection: CollectionConfig = { + slug: 'mycollection', + admin: { + components: { + views: { + List: MyListComponent, + }, + }, + }, + fields: [ + ... + ], +}; +``` + +MyListComponent.tsx +```tsx +import React from 'react'; +import {List, type Props} from 'payload/components/views/List' // Payload's default List view component and its props +export const MyListComponent: React.FC = (props) => ( +
+

Some text before the default list view component. If you just want to do that, you can also use the admin.components.list.BeforeList hook

+ +
+); +``` + ### Globals As with Collections, You can override components on a global-by-global basis via their `admin` property. diff --git a/src/admin/components/Routes.tsx b/src/admin/components/Routes.tsx index 3919e2535b..422ec3a67a 100644 --- a/src/admin/components/Routes.tsx +++ b/src/admin/components/Routes.tsx @@ -198,9 +198,9 @@ const Routes: React.FC = () => { > - ) : ( - - )} + ) : ( + + )} , { collection={collection} /> - ) : } + ) : } , ]; @@ -230,7 +230,7 @@ const Routes: React.FC = () => { > {permissions?.collections?.[collection.slug]?.readVersions?.permission ? ( - ) : } + ) : } , ); @@ -247,7 +247,7 @@ const Routes: React.FC = () => { > - ) : } + ) : } , ); } @@ -272,7 +272,7 @@ const Routes: React.FC = () => { > - ) : } + ) : } , ]; @@ -297,7 +297,7 @@ const Routes: React.FC = () => { > {permissions?.globals?.[global.slug]?.readVersions?.permission ? ( - ) : } + ) : } , ); } diff --git a/src/admin/components/views/collections/List/Default.tsx b/src/admin/components/views/collections/List/Default.tsx index b175ebdcd6..c0190272b4 100644 --- a/src/admin/components/views/collections/List/Default.tsx +++ b/src/admin/components/views/collections/List/Default.tsx @@ -37,6 +37,12 @@ const DefaultList: React.FC = (props) => { }, admin: { description, + components: { + BeforeList, + BeforeListTable, + AfterListTable, + AfterList, + } = {}, } = {}, }, data, @@ -68,6 +74,13 @@ const DefaultList: React.FC = (props) => { return (
+ {Array.isArray(BeforeList) && BeforeList.map((Component, i) => ( + + ))} + @@ -111,6 +124,12 @@ const DefaultList: React.FC = (props) => { handleWhereChange={handleWhereChange} resetParams={resetParams} /> + {Array.isArray(BeforeListTable) && BeforeListTable.map((Component, i) => ( + + ))} {!data.docs && ( = (props) => { )}
)} + {Array.isArray(AfterListTable) && AfterListTable.map((Component, i) => ( + + ))} +
= (props) => {
+ {Array.isArray(AfterList) && AfterList.map((Component, i) => ( + + ))} ); }; diff --git a/src/collections/config/schema.ts b/src/collections/config/schema.ts index 80332f01df..326c4dc7d3 100644 --- a/src/collections/config/schema.ts +++ b/src/collections/config/schema.ts @@ -69,6 +69,10 @@ const collectionSchema = joi.object().keys({ SaveDraftButton: componentSchema, PreviewButton: componentSchema, }), + BeforeList: joi.array().items(componentSchema), + BeforeListTable: joi.array().items(componentSchema), + AfterListTable: joi.array().items(componentSchema), + AfterList: joi.array().items(componentSchema), }), pagination: joi.object({ defaultLimit: joi.number(), diff --git a/src/collections/config/types.ts b/src/collections/config/types.ts index f2650cda57..782ef94aff 100644 --- a/src/collections/config/types.ts +++ b/src/collections/config/types.ts @@ -12,6 +12,8 @@ import { IncomingUploadType, Upload } from '../../uploads/types'; import { IncomingCollectionVersions, SanitizedCollectionVersions } from '../../versions/types'; import { BuildQueryArgs } from '../../mongoose/buildQuery'; import { CustomPreviewButtonProps, CustomPublishButtonProps, CustomSaveButtonProps, CustomSaveDraftButtonProps } from '../../admin/components/elements/types'; +import type { Props as ListProps } from '../../admin/components/views/collections/List/types'; +import type { Props as EditProps } from '../../admin/components/views/collections/Edit/types'; type Register = (doc: T, password: string) => T; @@ -220,9 +222,13 @@ export type CollectionAdminOptions = { PreviewButton?: CustomPreviewButtonProps }, views?: { - Edit?: React.ComponentType - List?: React.ComponentType - } + Edit?: React.ComponentType + List?: React.ComponentType + }, + BeforeList?: React.ComponentType[], + BeforeListTable?: React.ComponentType[], + AfterListTable?: React.ComponentType[], + AfterList?: React.ComponentType[], }; pagination?: { defaultLimit?: number