In this issue, we want to expand their usage across our codebase by adding a new helper function getReadableOptions.
This function will utilize getReadable to dynamically generate the appropriate data structure for rendering options (labels and values) in Grommet’s Select and RadioButtonGroup built-in components. This approach will reduce redundancy by eliminating the need for separate options definitions for each component and simplifying our implementation.
Problem or idea
Currently, we explicitly define an array of options objects for each Select and RadioButtonGroup, and pass them directly to the components.
e.g.) The current approach for the aggregation select dropdown is as follows:
// The aggregation options explicitly defined in config/options
const options = { aggregation: [
{ label: 'Experiment', value: 'EXPERIMENT' },
{ label: 'Species', value: 'SPECIES' }
],
}
// AggregateOptions component
import { options } from 'config'; // import the options
export const AggregateOptions = () => (
<Select
labelKey="label"
name={name}
options={options.aggregation} // pass the options here
/>
);
This helper will take an array of option names and return the corresponding options for Select which matches with the aggregation data structure in config/options.
Solution or next step
Add a new helper function getReadableOptions that utilizes getReadable to return the correct options format for Select and RadioButtonGroup
Replace the passed options prop with getReadableOptions for Select and RadioButtonGroup
Update config/readable to support the new implementation and clean up properties for Select and RadioButtonGroup in config/options
Context
Epic: #366
Target branch:
dev
In PR #321, we introduced
helpers/getReadable
andconfig/readable
.In this issue, we want to expand their usage across our codebase by adding a new helper function
getReadableOptions
.This function will utilize
getReadable
to dynamically generate the appropriate data structure for rendering options (labels and values) in Grommet’sSelect
andRadioButtonGroup
built-in components. This approach will reduce redundancy by eliminating the need for separateoptions
definitions for each component and simplifying our implementation.Problem or idea
Currently, we explicitly define an array of
options
objects for eachSelect
andRadioButtonGroup
, and pass them directly to the components.e.g.) The current approach for the aggregation select dropdown is as follows:
e.g., ) The updated approach:
This helper will take an array of option names and return the corresponding
options
forSelect
which matches with theaggregation
data structure inconfig/options
.Solution or next step
getReadableOptions
that utilizesgetReadable
to return the correct options format forSelect
andRadioButtonGroup
options
prop withgetReadableOptions
forSelect
andRadioButtonGroup
config/readable
to support the new implementation and clean up properties forSelect
andRadioButtonGroup
inconfig/options