Skip to content

Commit

Permalink
DataForm: Use the fields array to define the order of the fields (#64335
Browse files Browse the repository at this point in the history
)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: Zealth57 <[email protected]>
  • Loading branch information
4 people authored Aug 8, 2024
1 parent ddadd1a commit d578bb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/dataviews/src/dataforms-layouts/panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { closeSmall } from '@wordpress/icons';
* Internal dependencies
*/
import { normalizeFields } from '../../normalize-fields';
import type { DataFormProps, NormalizedField } from '../../types';
import type { DataFormProps, NormalizedField, Field } from '../../types';

interface FormFieldProps< Item > {
data: Item;
Expand Down Expand Up @@ -142,7 +142,11 @@ export default function FormPanel< Item >( {
const visibleFields = useMemo(
() =>
normalizeFields(
fields.filter( ( { id } ) => !! form.fields?.includes( id ) )
( form.fields ?? [] )
.map( ( fieldId ) =>
fields.find( ( { id } ) => id === fieldId )
)
.filter( ( field ): field is Field< Item > => !! field )
),
[ fields, form.fields ]
);
Expand Down
8 changes: 6 additions & 2 deletions packages/dataviews/src/dataforms-layouts/regular/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useMemo } from '@wordpress/element';
* Internal dependencies
*/
import { normalizeFields } from '../../normalize-fields';
import type { DataFormProps } from '../../types';
import type { DataFormProps, Field } from '../../types';

export default function FormRegular< Item >( {
data,
Expand All @@ -19,7 +19,11 @@ export default function FormRegular< Item >( {
const visibleFields = useMemo(
() =>
normalizeFields(
fields.filter( ( { id } ) => !! form.fields?.includes( id ) )
( form.fields ?? [] )
.map( ( fieldId ) =>
fields.find( ( { id } ) => id === fieldId )
)
.filter( ( field ): field is Field< Item > => !! field )
),
[ fields, form.fields ]
);
Expand Down

0 comments on commit d578bb2

Please sign in to comment.