-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataViews: Refactor the edit function to be based on discrete controls (
#64404) Co-authored-by: youknowriad <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: ntsekouras <[email protected]>
- Loading branch information
Showing
11 changed files
with
201 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { BaseControl, TimePicker } from '@wordpress/components'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormControlProps } from '../types'; | ||
|
||
export default function DateTime< Item >( { | ||
data, | ||
field, | ||
onChange, | ||
}: DataFormControlProps< Item > ) { | ||
const { id, label } = field; | ||
const value = field.getValue( { item: data } ); | ||
|
||
const onChangeControl = useCallback( | ||
( newValue: string | null ) => onChange( { [ id ]: newValue } ), | ||
[ id, onChange ] | ||
); | ||
|
||
return ( | ||
<fieldset> | ||
<BaseControl.VisualLabel as="legend"> | ||
{ label } | ||
</BaseControl.VisualLabel> | ||
<TimePicker | ||
currentTime={ value } | ||
onChange={ onChangeControl } | ||
hideLabelFromVision | ||
/> | ||
</fieldset> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalNumberControl as NumberControl } from '@wordpress/components'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormControlProps } from '../types'; | ||
|
||
export default function Integer< Item >( { | ||
data, | ||
field, | ||
onChange, | ||
hideLabelFromVision, | ||
}: DataFormControlProps< Item > ) { | ||
const { id, label, description } = field; | ||
const value = field.getValue( { item: data } ) ?? ''; | ||
const onChangeControl = useCallback( | ||
( newValue: string | undefined ) => | ||
onChange( { | ||
[ id ]: Number( newValue ), | ||
} ), | ||
[ id, onChange ] | ||
); | ||
|
||
return ( | ||
<NumberControl | ||
label={ label } | ||
help={ description } | ||
value={ value } | ||
onChange={ onChangeControl } | ||
__next40pxDefaultSize | ||
hideLabelFromVision={ hideLabelFromVision } | ||
/> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { SelectControl } from '@wordpress/components'; | ||
import { useCallback } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormControlProps } from '../types'; | ||
|
||
export default function Select< Item >( { | ||
data, | ||
field, | ||
onChange, | ||
hideLabelFromVision, | ||
}: DataFormControlProps< Item > ) { | ||
const { id, label } = field; | ||
const value = field.getValue( { item: data } ) ?? ''; | ||
const onChangeControl = useCallback( | ||
( newValue: any ) => | ||
onChange( { | ||
[ id ]: newValue, | ||
} ), | ||
[ id, onChange ] | ||
); | ||
|
||
const elements = [ | ||
/* | ||
* Value can be undefined when: | ||
* | ||
* - the field is not required | ||
* - in bulk editing | ||
* | ||
*/ | ||
{ label: __( 'Select item' ), value: '' }, | ||
...( field?.elements ?? [] ), | ||
]; | ||
|
||
return ( | ||
<SelectControl | ||
label={ label } | ||
value={ value } | ||
options={ elements } | ||
onChange={ onChangeControl } | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
hideLabelFromVision={ hideLabelFromVision } | ||
/> | ||
); | ||
} |
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,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { TextControl } from '@wordpress/components'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormControlProps } from '../types'; | ||
|
||
export default function Text< Item >( { | ||
data, | ||
field, | ||
onChange, | ||
hideLabelFromVision, | ||
}: DataFormControlProps< Item > ) { | ||
const { id, label, placeholder } = field; | ||
const value = field.getValue( { item: data } ); | ||
|
||
const onChangeControl = useCallback( | ||
( newValue: string ) => | ||
onChange( { | ||
[ id ]: newValue, | ||
} ), | ||
[ id, onChange ] | ||
); | ||
|
||
return ( | ||
<TextControl | ||
label={ label } | ||
placeholder={ placeholder } | ||
value={ value ?? '' } | ||
onChange={ onChangeControl } | ||
__next40pxDefaultSize | ||
__nextHasNoMarginBottom | ||
hideLabelFromVision={ hideLabelFromVision } | ||
/> | ||
); | ||
} |
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.