feat(ui): enabledSchedulers -> favoriteSchedulers

This commit is contained in:
psychedelicious
2023-06-18 20:01:05 +10:00
parent 450641c414
commit b96b95bc95
7 changed files with 45 additions and 79 deletions

View File

@ -1,42 +1,44 @@
import { SCHEDULER_SELECT_ITEMS } from 'app/constants';
import { SCHEDULER_LABEL_MAP, SCHEDULER_NAMES } from 'app/constants';
import { RootState } from 'app/store/store';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import IAIMantineMultiSelect from 'common/components/IAIMantineMultiSelect';
import { SchedulerParam } from 'features/parameters/store/parameterZodSchemas';
import { enabledSchedulersChanged } from 'features/ui/store/uiSlice';
import { favoriteSchedulersChanged } from 'features/ui/store/uiSlice';
import { map } from 'lodash-es';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
const data = map(SCHEDULER_SELECT_ITEMS).sort((a, b) =>
a.label.localeCompare(b.label)
);
const data = map(SCHEDULER_NAMES, (s) => ({
value: s,
label: SCHEDULER_LABEL_MAP[s],
})).sort((a, b) => a.label.localeCompare(b.label));
export default function SettingsSchedulers() {
const dispatch = useAppDispatch();
const { t } = useTranslation();
const enabledSchedulers = useAppSelector(
(state: RootState) => state.ui.enabledSchedulers
(state: RootState) => state.ui.favoriteSchedulers
);
const handleChange = useCallback(
(v: string[]) => {
dispatch(enabledSchedulersChanged(v as SchedulerParam[]));
dispatch(favoriteSchedulersChanged(v as SchedulerParam[]));
},
[dispatch]
);
return (
<IAIMantineMultiSelect
label={t('settings.availableSchedulers')}
label={t('settings.favoriteSchedulers')}
value={enabledSchedulers}
data={data}
onChange={handleChange}
clearable
searchable
maxSelectedValues={99}
placeholder={t('settings.favoriteSchedulersPlaceholder')}
/>
);
}