-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add google sheets field selection in settings (#259)
* fix GoogleSheetsSettings form fields state management * extract field selection UI to FieldSelection component * update CustomFormFieldToken to add custom help text * add field selection for google-sheets data source * Improve types for useForm and handleChange * update GoogleSheets data source sheet id field type to string --------- Co-authored-by: chriszarate <[email protected]>
- Loading branch information
1 parent
4dae381
commit 5e9a8e2
Showing
19 changed files
with
341 additions
and
171 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
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
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,57 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { CustomFormFieldToken } from '@/data-sources/components/CustomFormFieldToken'; | ||
|
||
interface FieldsSelectionProps { | ||
selectedFields: string[]; | ||
availableFields: string[]; | ||
onFieldsChange: ( fields: string[] ) => void; | ||
disabled?: boolean; | ||
customHelpText?: string | null; | ||
} | ||
|
||
export const FieldsSelection = ( { | ||
selectedFields, | ||
availableFields, | ||
onFieldsChange, | ||
customHelpText, | ||
disabled = false, | ||
}: FieldsSelectionProps ) => { | ||
return ( | ||
<CustomFormFieldToken | ||
label={ __( 'Fields', 'remote-data-blocks' ) } | ||
onChange={ selection => { | ||
let newFields: string[]; | ||
if ( selection.includes( 'Select All' ) ) { | ||
newFields = Array.from( new Set( availableFields ) ); | ||
} else if ( selection.includes( 'Deselect All' ) ) { | ||
newFields = []; | ||
} else { | ||
newFields = Array.from( | ||
new Set( | ||
selection | ||
.filter( item => item !== 'Select All' && item !== 'Deselect All' ) | ||
.map( item => ( 'object' === typeof item ? item.value : item ) ) | ||
) | ||
); | ||
} | ||
onFieldsChange( newFields ); | ||
} } | ||
suggestions={ [ | ||
...( selectedFields.length === availableFields.length | ||
? [ 'Deselect All' ] | ||
: [ 'Select All' ] ), | ||
...availableFields, | ||
] } | ||
value={ selectedFields } | ||
__experimentalValidateInput={ input => | ||
availableFields.includes( input ) || input === 'Select All' || input === 'Deselect All' | ||
} | ||
__nextHasNoMarginBottom | ||
__experimentalExpandOnFocus | ||
__next40pxDefaultSize | ||
disabled={ disabled } | ||
customHelpText={ customHelpText } | ||
/> | ||
); | ||
}; |
Oops, something went wrong.