-
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.
Add
isVisible
option to fields within DataForm (#65826)
Co-authored-by: louwie17 <louwie17@git.wordpress.org> Co-authored-by: oandregal <oandregal@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
- Loading branch information
1 parent
e62588a
commit 3e151e2
Showing
6 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
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
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
32 changes: 32 additions & 0 deletions
32
packages/dataviews/src/components/form-field-visibility/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,32 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { NormalizedField } from '../../types'; | ||
|
||
type FormFieldVisibilityProps< Item > = React.PropsWithChildren< { | ||
field: NormalizedField< Item >; | ||
data: Item; | ||
} >; | ||
|
||
export default function FormFieldVisibility< Item >( { | ||
data, | ||
field, | ||
children, | ||
}: FormFieldVisibilityProps< Item > ) { | ||
const isVisible = useMemo( () => { | ||
if ( field.isVisible ) { | ||
return field.isVisible( data ); | ||
} | ||
return true; | ||
}, [ field.isVisible, data ] ); | ||
|
||
if ( ! isVisible ) { | ||
return null; | ||
} | ||
return children; | ||
} |
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
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
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
3e151e2
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 3e151e2.
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/11596877060
📝 Reported issues:
/test/e2e/specs/editor/plugins/custom-taxonomies.spec.js
/test/e2e/specs/editor/various/taxonomies.spec.js