Added ability to provide custom slug validation#36
Open
mariusGundersen wants to merge 1 commit intoQ42:mainfrom
Open
Added ability to provide custom slug validation#36mariusGundersen wants to merge 1 commit intoQ42:mainfrom
mariusGundersen wants to merge 1 commit intoQ42:mainfrom
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.
tstikvoort
requested changes
Jul 12, 2024
| ]; | ||
|
|
||
| const getSlugSourceField = (config: PageTreeConfig, options: Options) => config.titleFieldName ?? options.slugSource; | ||
| const toArray = <T>(t: undefined | T | T[]) => t === undefined ? [] : Array.isArray(t) ? t : [t]; |
Member
There was a problem hiding this comment.
Bit nitpicky, but could you move this to an array-utils.ts in the utils folder?
Comment on lines
+39
to
+44
| export type GlobalOptions = { | ||
| fieldsGroupName?: string; | ||
| slugSource?: SlugOptions['source']; | ||
| slugValidationRules?: ValidationBuilder<SlugRule, SlugValue> | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
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 |
Member
There was a problem hiding this comment.
The same goes for this propertyName then.
Author
|
I'm on holiday now, so I won't be able to make any further changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The validation rules can be supplied either to each
definePageTreeoption or to a newglobalOptions. This also fixes the problem where thetitleFieldNameis preferred ahead of theslugSourceprovided to a specific page definition.