@@ -330,23 +330,38 @@ export default class ConfigValidator implements IConfigValidator {
330330 return showInTransformedToObject as ShowIn ;
331331 }
332332
333- validateFieldGroups ( fieldGroups : {
334- groupName : string ;
335- columns : string [ ] ;
336- } [ ] , resourceColumns : string [ ] ) : void {
337- if ( ! fieldGroups ) return ;
333+ validateFieldGroups ( fieldGroups : { groupName : string ; columns : string [ ] } [ ] , allColumnsList : string [ ] ) : string [ ] {
334+ if ( ! fieldGroups ) return allColumnsList ;
335+
336+ const columnPositions = new Map < string , number > ( ) ;
337+ let position = 0 ;
338338
339339 fieldGroups . forEach ( ( group ) => {
340340 group . columns . forEach ( ( col ) => {
341- if ( ! resourceColumns . includes ( col ) ) {
342- const similar = suggestIfTypo ( resourceColumns , col ) ;
341+ if ( ! allColumnsList . includes ( col ) ) {
342+ const similar = suggestIfTypo ( allColumnsList , col ) ;
343343 throw new Error (
344- `Group '${ group . groupName } ' has an unknown column '${ col } '. ${ similar ? `Did you mean '${ similar } '?` : ''
344+ `Group '${ group . groupName } ' has an unknown column '${ col } '. ${
345+ similar ? `Did you mean '${ similar } '?` : ''
345346 } `
346347 ) ;
347348 }
349+ if ( ! columnPositions . has ( col ) ) {
350+ columnPositions . set ( col , position ++ ) ;
351+ }
348352 } ) ;
349353 } ) ;
354+
355+ allColumnsList . forEach ( ( col ) => {
356+ if ( ! columnPositions . has ( col ) ) {
357+ columnPositions . set ( col , position ++ ) ;
358+ }
359+ } ) ;
360+ return allColumnsList . sort ( ( a , b ) => {
361+ const posA = columnPositions . get ( a ) ;
362+ const posB = columnPositions . get ( b ) ;
363+ return posA - posB ;
364+ } ) ;
350365 }
351366
352367 validateAndNormalizeCustomActions ( resInput : AdminForthResourceInput , res : Partial < AdminForthResource > , errors : string [ ] ) : any [ ] {
@@ -422,7 +437,7 @@ export default class ConfigValidator implements IConfigValidator {
422437 res . columns = [ ] ;
423438 }
424439 res . columns = resInput . columns . map ( ( inCol : AdminForthResourceColumnInput , inColIndex ) => {
425- const col : Partial < AdminForthResourceColumn > = { ...inCol , showIn : undefined , required : undefined , editingNote : undefined } ;
440+ const col : Partial < AdminForthResourceColumn > = { ...inCol , showIn : undefined , editingNote : undefined } ;
426441
427442 // check for duplicate column names
428443 if ( resInput . columns . findIndex ( ( c ) => c . name === col . name ) !== inColIndex ) {
@@ -476,9 +491,6 @@ export default class ConfigValidator implements IConfigValidator {
476491 }
477492 }
478493
479- // force required to be object
480- col . required = typeof inCol . required === 'boolean' ? { create : inCol . required , edit : inCol . required } : inCol . required ;
481-
482494
483495 // same for editingNote
484496 if ( inCol . editingNote && ! ( ( typeof inCol . editingNote === 'string' ) || ( typeof inCol . editingNote === 'object' ) ) ) {
@@ -706,10 +718,11 @@ export default class ConfigValidator implements IConfigValidator {
706718 options . actions = this . validateAndNormalizeCustomActions ( resInput , res , errors ) ;
707719
708720 const allColumnsList = res . columns . map ( ( col ) => col . name ) ;
709- this . validateFieldGroups ( options . fieldGroups , allColumnsList ) ;
710- this . validateFieldGroups ( options . showFieldGroups , allColumnsList ) ;
711- this . validateFieldGroups ( options . createFieldGroups , allColumnsList ) ;
712- this . validateFieldGroups ( options . editFieldGroups , allColumnsList ) ;
721+ const sortedColumns = this . validateFieldGroups ( options . fieldGroups , allColumnsList ) ;
722+
723+ res . columns = res . columns . sort ( ( a , b ) => {
724+ return sortedColumns . indexOf ( a . name ) - sortedColumns . indexOf ( b . name ) ;
725+ } ) ;
713726
714727 // if pageInjection is a string, make array with one element. Also check file exists
715728 const possibleInjections = [ 'beforeBreadcrumbs' , 'afterBreadcrumbs' , 'bottom' , 'threeDotsDropdownItems' , 'customActionIcons' ] ;
0 commit comments