-
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.
Add
comment_status
field to quick edit (#64370)
Co-authored-by: oandregal <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: ntsekouras <[email protected]>
- Loading branch information
1 parent
651cc45
commit 02622ae
Showing
7 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/dataviews/src/components/dataform-controls/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,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentType } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { | ||
DataFormControlProps, | ||
Field, | ||
FieldTypeDefinition, | ||
} from '../../types'; | ||
import radio from './radio'; | ||
|
||
interface FormControls { | ||
[ key: string ]: ComponentType< DataFormControlProps< any > >; | ||
} | ||
|
||
const FORM_CONTROLS: FormControls = { | ||
radio, | ||
}; | ||
|
||
export function getControl< Item >( | ||
field: Field< Item >, | ||
fieldTypeDefinition: FieldTypeDefinition< Item > | ||
) { | ||
if ( typeof field.Edit === 'function' ) { | ||
return field.Edit; | ||
} | ||
|
||
let control; | ||
if ( typeof field.Edit === 'string' ) { | ||
control = getControlByType( field.Edit ); | ||
} | ||
|
||
return control || fieldTypeDefinition.Edit; | ||
} | ||
|
||
export function getControlByType( type: string ) { | ||
if ( Object.keys( FORM_CONTROLS ).includes( type ) ) { | ||
return FORM_CONTROLS[ type ]; | ||
} | ||
|
||
return null; | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/dataviews/src/components/dataform-controls/radio.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,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RadioControl } from '@wordpress/components'; | ||
import { useCallback } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { DataFormControlProps } from '../../types'; | ||
|
||
export default function Edit< Item >( { | ||
data, | ||
field, | ||
onChange, | ||
hideLabelFromVision, | ||
}: DataFormControlProps< Item > ) { | ||
const { id, label } = field; | ||
const value = field.getValue( { item: data } ); | ||
|
||
const onChangeControl = useCallback( | ||
( newValue: string ) => | ||
onChange( ( prevItem: Item ) => ( { | ||
...prevItem, | ||
[ id ]: newValue, | ||
} ) ), | ||
[ id, onChange ] | ||
); | ||
|
||
if ( field.elements ) { | ||
return ( | ||
<RadioControl | ||
label={ label } | ||
onChange={ onChangeControl } | ||
options={ field.elements } | ||
selected={ value } | ||
hideLabelFromVision={ hideLabelFromVision } | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
} |
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
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