1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

refactor: fix override field selection (#925)

This commit is contained in:
olav 2022-04-29 13:51:25 +02:00 committed by GitHub
parent efe52cb1aa
commit 96ccc24b8b
2 changed files with 11 additions and 19 deletions

View File

@ -25,6 +25,7 @@ import Input from 'component/common/Input/Input';
import { formatUnknownError } from 'utils/formatUnknownError';
import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext';
import { HelpIcon } from 'component/common/HelpIcon/HelpIcon';
import produce from 'immer';
const payloadOptions = [
{ key: 'string', label: 'string' },
@ -199,27 +200,18 @@ export const AddVariant = ({
closeDialog();
};
const updateOverrideType =
(index: number, contextName: string) => (value: string) => {
setOverrides(
overrides.map((o, i) => {
if (i === index) {
// @ts-expect-error
o[contextName] = value;
}
return o;
})
);
};
const updateOverrideType = (index: number) => (value: string) => {
setOverrides(
produce(draft => {
draft[index].contextName = value;
})
);
};
const updateOverrideValues = (index: number, values: string[]) => {
setOverrides(
overrides.map((o, i) => {
if (i === index) {
o.values = values;
}
return o;
produce(draft => {
draft[index].values = values;
})
);
};

View File

@ -54,7 +54,7 @@ export const OverrideConfig = ({
classes={{
root: classnames(commonStyles.fullWidth),
}}
onChange={updateOverrideType(i, o.contextName)}
onChange={updateOverrideType(i)}
/>
</Grid>
<Grid md={7} sm={7} xs={6} item>