-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataForm: enable fields to declare a different layout (#66531)
Co-authored-by: louwie17 <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: gigitux <[email protected]> Co-authored-by: youknowriad <[email protected]>
- Loading branch information
1 parent
944e6b8
commit c38610a
Showing
18 changed files
with
645 additions
and
379 deletions.
There are no files selected for viewing
69 changes: 0 additions & 69 deletions
69
packages/dataviews/src/components/dataform-combined-edit/index.tsx
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
packages/dataviews/src/components/dataform-combined-edit/style.scss
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/dataviews/src/components/dataform-context/index.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createContext } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { NormalizedField } from '../../types'; | ||
|
||
type DataFormContextType< Item > = { | ||
fields: NormalizedField< Item >[]; | ||
}; | ||
|
||
const DataFormContext = createContext< DataFormContextType< any > >( { | ||
fields: [], | ||
} ); | ||
|
||
export function DataFormProvider< Item >( { | ||
fields, | ||
children, | ||
}: React.PropsWithChildren< { fields: NormalizedField< Item >[] } > ) { | ||
return ( | ||
<DataFormContext.Provider value={ { fields } }> | ||
{ children } | ||
</DataFormContext.Provider> | ||
); | ||
} | ||
|
||
export default DataFormContext; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormProps } from '../../types'; | ||
import { getFormLayout } from '../../dataforms-layouts'; | ||
import { DataFormProvider } from '../dataform-context'; | ||
import { normalizeFields } from '../../normalize-fields'; | ||
import { DataFormLayout } from '../../dataforms-layouts/data-form-layout'; | ||
|
||
export default function DataForm< Item >( { | ||
data, | ||
form, | ||
...props | ||
fields, | ||
onChange, | ||
}: DataFormProps< Item > ) { | ||
const layout = getFormLayout( form.type ?? 'regular' ); | ||
if ( ! layout ) { | ||
const normalizedFields = useMemo( | ||
() => normalizeFields( fields ), | ||
[ fields ] | ||
); | ||
|
||
if ( ! form.fields ) { | ||
return null; | ||
} | ||
|
||
return <layout.component form={ form } { ...props } />; | ||
return ( | ||
<DataFormProvider fields={ normalizedFields }> | ||
<DataFormLayout data={ data } form={ form } onChange={ onChange } /> | ||
</DataFormProvider> | ||
); | ||
} |
This file contains 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
Oops, something went wrong.
c38610a
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.
Flaky tests detected in c38610a.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11936764631
📝 Reported issues:
/test/e2e/specs/widgets/customizing-widgets.spec.js
/test/e2e/specs/site-editor/template-revert.spec.js