-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cms): add HomepageConfig global schema for DP-17 #37
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { checkCollectionAccess } from '@/access/checkCollectionAccess' | ||
| import { getCollectionGroupLabel } from '@/constants/collections' | ||
| import { GlobalConfig } from 'payload' | ||
|
|
||
| // We will let VS Code import these automatically! | ||
| // 1. Click on getCollectionGroupLabel below, press Ctrl + . (or Cmd + .), and click "Update import" or "Add import" | ||
| // 2. Click on checkCollectionAccess below, press Ctrl + . (or Cmd + .), and click "Add import" | ||
|
|
||
| export const HomepageConfig: GlobalConfig = { | ||
| slug: 'homepage-config', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a constant from our Also, let's update the literal slug value to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this, let's create a new You can take inspiration from how we structure export const GLOBALS = {
DURIANPY_WEBSITE_HOMEPAGE_CONFIG: 'durianpy-website-homepage-config',
} as const
export type GlobalSlug = (typeof GLOBALS)[keyof typeof GLOBALS]
export const GLOBAL_LABELS: Record<GlobalSlug, { singular: string; plural: string }> = {
[GLOBALS.DURIANPY_WEBSITE_HOMEPAGE_CONFIG]: { singular: 'Homepage Config', plural: 'Homepage Configs' },
}Once created, you can use it in import { GLOBALS, GLOBAL_LABELS } from '@/constants/globals'
export const HomepageConfig: GlobalConfig = {
slug: GLOBALS.DURIANPY_WEBSITE_HOMEPAGE_CONFIG,
label: GLOBAL_LABELS[GLOBALS.DURIANPY_WEBSITE_HOMEPAGE_CONFIG].singular,
admin: {
// ...
},
// ...
} |
||
| admin: { | ||
| group: getCollectionGroupLabel('durianpy-website'), | ||
| }, | ||
| access: { | ||
| read: () => true, | ||
| // We explicitly type args as 'any' to satisfy TS, and removed the invalid 'admin' access rule! | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment |
||
| update: (args: any) => checkCollectionAccess(args, 'homepage-config' as any, 'update'), | ||
|
Check warning on line 17 in src/globals/durianpy-website/HomepageConfig.ts
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's refactor the access control to use the same higher-order function pattern we use in It should look something like this: const checkHomepageConfigAccess = (accessType?: AccessType) => (access: AccessArgs) =>
checkCollectionAccess(access, GLOBALS.DURIANPY_WEBSITE_HOMEPAGE_CONFIG, accessType)
// ... inside the config:
access: {
read: anyone,
update: checkHomepageConfigAccess('update'),
}, |
||
| }, | ||
| versions: { | ||
| // Globals use 'max' instead of 'maxPerDoc' | ||
| max: 50, | ||
| drafts: { | ||
| autosave: { | ||
| showSaveDraftButton: true, | ||
| }, | ||
| schedulePublish: true, | ||
| }, | ||
| }, | ||
| fields: [ | ||
| { | ||
| name: 'heroImageDesktop', | ||
| type: 'upload', | ||
| relationTo: 'media', | ||
| required: true, | ||
| label: 'Hero Image (Desktop)', | ||
| }, | ||
| { | ||
| name: 'heroImageMobile', | ||
| type: 'upload', | ||
| relationTo: 'media', | ||
| required: true, | ||
| label: 'Hero Image (Mobile)', | ||
| }, | ||
| { | ||
| name: 'heroTitle', | ||
| type: 'text', | ||
| label: 'Hero Title', | ||
| }, | ||
| { | ||
| name: 'heroSubtitle', | ||
| type: 'text', | ||
| label: 'Hero Subtitle', | ||
| }, | ||
| ], | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment