-
Notifications
You must be signed in to change notification settings - Fork 6
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
Added ability to provide custom slug validation #36
base: main
Are you sure you want to change the base?
Conversation
The validation rules can be supplied either to each `definePageTree` option or to a new `globalOptions`. This also fixes the problem where the `titleFieldName` is preferred ahead of the `slugSource` provided to a specific page definition.
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.
Thanks for opening this PR. It's a nice and useful improvement! Just have some small remarks.
@@ -79,3 +81,4 @@ const basePageFields = (config: PageTreeConfig, options: Options, ownType: Docum | |||
]; | |||
|
|||
const getSlugSourceField = (config: PageTreeConfig, options: Options) => config.titleFieldName ?? options.slugSource; | |||
const toArray = <T>(t: undefined | T | T[]) => t === undefined ? [] : Array.isArray(t) ? t : [t]; |
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.
Bit nitpicky, but could you move this to an array-utils.ts in the utils folder?
export type GlobalOptions = { | ||
fieldsGroupName?: string; | ||
slugSource?: SlugOptions['source']; | ||
slugValidationRules?: ValidationBuilder<SlugRule, SlugValue> | ||
} | ||
|
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.
Now that we expose the Options outside of the definePageType function / file, a more specific name would be better, like PageTypeOptions.
By defining in the page tree config, global is implied.
languageFieldName?: string; | ||
}; | ||
/** Define options that apply to all pages. Can be overridden by options supplied using definePageType */ | ||
globalOptions?: GlobalOptions |
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.
The same goes for this propertyName then.
I'm on holiday now, so I won't be able to make any further changes. |
The validation rules can be supplied either to each
definePageTree
option or to a newglobalOptions
. This also fixes the problem where thetitleFieldName
is preferred ahead of theslugSource
provided to a specific page definition.