File tree Expand file tree Collapse file tree 4 files changed +25
-9
lines changed
Expand file tree Collapse file tree 4 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -111,5 +111,18 @@ describe('Plugin tests', () => {
111111 const exists = globalFields . some ( ( f ) => f . name === 'extraSetting' ) ;
112112 expect ( exists ) . toBe ( true ) ;
113113 } ) ;
114+
115+ it ( 'hides default sitemap fields in admin' , ( ) => {
116+ const fields = payload . collections [ 'posts' ] . config . fields as FieldBase [ ] ;
117+
118+ const sitemapFields = [ 'sitemapPriority' , 'excludeFromSitemap' ] ;
119+
120+ sitemapFields . forEach ( fieldName => {
121+ const field = fields . find ( f => f . name === fieldName ) ;
122+ expect ( field ) . toBeDefined ( ) ;
123+ expect ( field ?. admin ) . toBeDefined ( ) ;
124+ expect ( field ?. admin ?. hidden ) . toBe ( true ) ;
125+ } ) ;
126+ } ) ;
114127} ) ;
115128
Original file line number Diff line number Diff line change 11import { mongooseAdapter } from '@payloadcms/db-mongodb' ;
22import { lexicalEditor } from '@payloadcms/richtext-lexical' ;
33import path from 'path' ;
4- import { buildConfig } from 'payload' ;
4+ import { buildConfig , Field } from 'payload' ;
55import sharp from 'sharp' ;
66import { fileURLToPath } from 'url' ;
77
@@ -59,7 +59,12 @@ export default buildConfig({
5959 collections : {
6060 posts : {
6161 fieldOverrides : ( { defaultFields } ) => [
62- ...defaultFields ,
62+ // Make all fields hidden in the UI for testing field overrides.
63+ ...defaultFields . map ( f => ( {
64+ ...f ,
65+ admin : { ...( f . admin || { } ) , hidden : true } ,
66+ } ) ) as Field [ ] ,
67+ // Add a random field in to assert that one exists.
6368 {
6469 name : 'customSEO' ,
6570 type : 'text' ,
Original file line number Diff line number Diff line change 11{
22 "name" : " payload-sitemap-plugin" ,
3- "version" : " 0.0.5 " ,
3+ "version" : " 0.0.6 " ,
44 "description" : " Payload Sitemap Plugin" ,
55 "license" : " MIT" ,
66 "type" : " module" ,
Original file line number Diff line number Diff line change @@ -51,20 +51,18 @@ export const sitemapPlugin = (pluginConfig: SitemapPluginConfig) => (config: Con
5151 }
5252
5353 let defaultFields : Field [ ] = [
54- ...( collection . fields || [ ] ) ,
5554 SitemapPriority ,
5655 ExcludeFromSitemap ,
5756 ] ;
5857
59- // Apply per-collection field overrides if provided,
58+ // Apply per-collection field overrides if provided.
6059 const collConfig = pluginConfig . collections [ collectionSlug ] ;
6160 if ( typeof collConfig !== 'boolean' && collConfig ?. fieldOverrides ) {
62- defaultFields = collConfig . fieldOverrides ( {
63- defaultFields,
64- } ) ;
61+ defaultFields = collConfig . fieldOverrides ( { defaultFields } ) ;
6562 }
6663
67- collection . fields = defaultFields ;
64+ // Merge the sitemap fields into the collection without overwriting other fields.
65+ collection . fields = [ ...( collection . fields || [ ] ) , ...defaultFields ] ;
6866 }
6967 }
7068
You can’t perform that action at this time.
0 commit comments