Skip to content

Commit

Permalink
feat: Apply translation automation from select option to multi-select…
Browse files Browse the repository at this point in the history
… option (ajnart#1963)
  • Loading branch information
SeDemal authored Mar 15, 2024
1 parent 030f05b commit 81e51d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/components/Dashboard/Tiles/Widgets/WidgetsEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ const WidgetOptionTypeSwitch: FC<{
</Stack>
);
case 'multi-select':
const multiSelectItems = typeof option.data === 'function' ? option.data() : option.data;
const multiSelectData = multiSelectItems.map((dataType) => {
return !dataType.label
? {
value: dataType.value,
label: t(`descriptor.settings.${key}.data.${dataType.value}`),
}
: dataType;
});
return (
<Stack spacing={0}>
<Group align="center" spacing="sm">
Expand All @@ -179,18 +188,19 @@ const WidgetOptionTypeSwitch: FC<{
{info && <InfoCard message={t(`descriptor.settings.${key}.info`)} link={link} />}
</Group>
<MultiSelect
data={option.data}
value={value as string[]}
searchable
defaultValue={option.defaultValue}
data={multiSelectData}
value={value as string[]}
onChange={(v) => handleChange(key, v)}
withinPortal
{...option.inputProps}
/>
</Stack>
);
case 'select':
const items = typeof option.data === 'function' ? option.data() : option.data;
const data = items.map((dataType) => {
const selectItems = typeof option.data === 'function' ? option.data() : option.data;
const selectData = selectItems.map((dataType) => {
return !dataType.label
? {
value: dataType.value,
Expand All @@ -209,7 +219,7 @@ const WidgetOptionTypeSwitch: FC<{
<Select
searchable
defaultValue={option.defaultValue}
data={data}
data={selectData}
value={value as string}
onChange={(v) => handleChange(key, v ?? option.defaultValue)}
withinPortal
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface ICommonWidgetOptions {
export type IMultiSelectOptionValue = {
type: 'multi-select';
defaultValue: string[];
data: DataType[];
data: DataType[] | (() => DataType[]);
inputProps?: Partial<MultiSelectProps>;
};

Expand Down

0 comments on commit 81e51d2

Please sign in to comment.