mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
* feat: strategies list * feat: dnd * fix: resolve reference issues * feat: configure strategy wip * feat: rearrange list * feat: add debounce and execution plan * feat: add separator * feat: update strategy * fix: feature strategy accordion key * fix: localize parameter update logic * feat: ts conversion * fix: perf issues * feat: production guard * fix: clean up environment list * fix: implement markup hooks for environment list * feat: wip constraints * fix: handle nested data structure reference issue * fix: clone deep on child props * fix: remove constraints check * fix: revert to strategies length * fix: refactor useFeature * feat: cache revalidation * fix: set correct starting tab * fix: reset params on adding new strategy * fix: refactor to use useSWR instead of local cache * fix: check dirty directly from new params * fix: dialogue ts * fix: Clean-up typescript warnings * fix: some more typescript nits * feat: strategy execution * feat: strategy execution for environment * fix: refactor execution separator * fix: remove unused property * fix: add header * fix: 0 value for rollout * fix: update snapshots * fix: remove empty deps * fix: use constant for env type * fix: use default for useFeatureStrategy * fix: update snapshot * Update src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/useDeleteStrategyMarkup.tsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> * Update src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> * Update src/component/feature/strategy/EditStrategyModal/general-strategy.jsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: UnleashTeam <79193084+UnleashTeam@users.noreply.github.com>
126 lines
4.0 KiB
TypeScript
126 lines
4.0 KiB
TypeScript
import { Button, Tooltip, Typography } from '@material-ui/core';
|
|
import { Info } from '@material-ui/icons';
|
|
|
|
import { IConstraint } from '../../../../../../interfaces/strategy';
|
|
import { useCommonStyles } from '../../../../../../common.styles';
|
|
import useUiConfig from '../../../../../../hooks/api/getters/useUiConfig/useUiConfig';
|
|
import { C } from '../../../../../common/flags';
|
|
import useUnleashContext from '../../../../../../hooks/api/getters/useUnleashContext/useUnleashContext';
|
|
import StrategyConstraintInputField from '../../../../strategy/StrategyConstraint/StrategyConstraintInputField';
|
|
import { useEffect } from 'react';
|
|
|
|
interface IStrategyConstraintProps {
|
|
constraints: IConstraint[];
|
|
updateConstraints: (constraints: IConstraint[]) => void;
|
|
constraintError: string;
|
|
setConstraintError: () => void;
|
|
}
|
|
|
|
const StrategyConstraints: React.FC<IStrategyConstraintProps> = ({
|
|
constraints,
|
|
updateConstraints,
|
|
constraintError,
|
|
setConstraintError,
|
|
}) => {
|
|
const { uiConfig } = useUiConfig();
|
|
const { context } = useUnleashContext();
|
|
const commonStyles = useCommonStyles();
|
|
|
|
useEffect(() => {
|
|
if (constraints.length === 0) {
|
|
addConstraint();
|
|
}
|
|
/* eslint-disable-next-line */
|
|
}, []);
|
|
|
|
const contextFields = context;
|
|
|
|
const enabled = uiConfig.flags[C];
|
|
const contextNames = contextFields.map(context => context.name);
|
|
|
|
const onClick = evt => {
|
|
evt.preventDefault();
|
|
addConstraint();
|
|
};
|
|
|
|
const addConstraint = () => {
|
|
const updatedConstraints = [...constraints];
|
|
updatedConstraints.push(createConstraint());
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
const createConstraint = () => {
|
|
return {
|
|
contextName: contextNames[0],
|
|
operator: 'IN',
|
|
values: [],
|
|
};
|
|
};
|
|
|
|
const removeConstraint = index => evt => {
|
|
evt.preventDefault();
|
|
const updatedConstraints = [...constraints];
|
|
updatedConstraints.splice(index, 1);
|
|
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
const updateConstraint = index => (value, field) => {
|
|
const updatedConstraints = [...constraints];
|
|
const constraint = updatedConstraints[index];
|
|
constraint[field] = value;
|
|
updateConstraints(updatedConstraints);
|
|
};
|
|
|
|
if (!enabled) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className={commonStyles.contentSpacingY}>
|
|
<Tooltip
|
|
placement="right-start"
|
|
title={
|
|
<span>
|
|
Use context fields to constrain the activation strategy.
|
|
</span>
|
|
}
|
|
>
|
|
<Typography variant="subtitle2">
|
|
{'Constraints '}
|
|
|
|
<Info style={{ fontSize: '0.9rem', color: 'gray' }} />
|
|
</Typography>
|
|
</Tooltip>
|
|
<table style={{ margin: 0 }}>
|
|
<tbody>
|
|
{constraints.map((c, index) => (
|
|
<StrategyConstraintInputField
|
|
key={`${c.contextName}-${index}`}
|
|
id={`${c.contextName}-${index}`}
|
|
constraint={c}
|
|
contextFields={contextFields}
|
|
updateConstraint={updateConstraint(index)}
|
|
removeConstraint={removeConstraint(index)}
|
|
constraintError={constraintError}
|
|
setConstraintError={setConstraintError}
|
|
/>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
<small>
|
|
<Button
|
|
title="Add constraint"
|
|
variant="contained"
|
|
color="primary"
|
|
onClick={onClick}
|
|
>
|
|
Add constraint
|
|
</Button>
|
|
</small>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default StrategyConstraints;
|