@payload-enchants/docs-reorder
v1.2.2
Published
## Install
Downloads
125
Readme
Docs reorder plugin for Payload 3.0 beta
Install
pnpm add @payload-enchants/docs-reorder
About
Adds an option to re-order collection documents with drag n drop (almost like array/blocks items). Then on your front end you can query documents with applied sort by docOrder
field.
Video
https://github.com/r1tsuu/payload-plugin-collections-docs-order/assets/64744993/2c13cdd9-f809-4c40-82c6-0b6f78997f74
In your payload.config.ts:
/// ....
import { docsReorder } from '@payload-enchants/docs-reorder';
export default buildConfig({
// ...
plugins: [
docsReorder({
collections: [{ slug: 'pages' }], // The feature will be enabled only for collections that are in this array.,
access: ({ req, data }) => {
// Optional, configure access for `saveChanges` endpoint, default: Boolean(req.user)
return req.user?.collection === 'admins';
},
}),
],
});
Querying with applied plugin's sort.
REST:
fetch('http://localhost:3000/api/examples?sort=docOrder').then((res) => res.json());
Local API:
payload.find({ collection: 'examples', sort: 'docOrder' });
GraphQL:
query {
Examples(sort: "docOrder") {
docs {
title
}
}
Script to setup for collections that had documents before installing the plugin
- Place this file to your src/scripts directory
- Change here list to your list of collection slugs with enabled plugin
const collections: (keyof GeneratedTypes['collections'])[] = ['docs-reoder-examples'];
- Run pnpm tsx ./src/scripts/docsReorderSetupScript.ts