mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-18 01:18:23 +02:00
update custom strategy params from feature branch
This commit is contained in:
parent
6bf05d89e7
commit
b32b751f2c
@ -9,9 +9,7 @@ import { ConditionallyRender } from 'component/common/ConditionallyRender/Condit
|
|||||||
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
|
import { StrategySeparator } from 'component/common/StrategySeparator/StrategySeparator';
|
||||||
import { Chip } from '@mui/material';
|
import { Chip } from '@mui/material';
|
||||||
import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle';
|
import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle';
|
||||||
import StringTruncator from 'component/common/StringTruncator/StringTruncator';
|
|
||||||
import { PlaygroundConstraintSchema } from 'hooks/api/actions/usePlayground/playground.model';
|
import { PlaygroundConstraintSchema } from 'hooks/api/actions/usePlayground/playground.model';
|
||||||
import { useStyles } from '../StrategyExecution.styles';
|
|
||||||
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies';
|
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies';
|
||||||
|
|
||||||
interface ICustomStrategyProps {
|
interface ICustomStrategyProps {
|
||||||
@ -25,15 +23,16 @@ export const CustomStrategyParams: VFC<ICustomStrategyProps> = ({
|
|||||||
constraints,
|
constraints,
|
||||||
parameters,
|
parameters,
|
||||||
}) => {
|
}) => {
|
||||||
const { classes: styles } = useStyles();
|
|
||||||
const { strategies } = useStrategies();
|
const { strategies } = useStrategies();
|
||||||
|
|
||||||
const definition = strategies.find(strategyDefinition => {
|
const definition = strategies.find(strategyDefinition => {
|
||||||
return strategyDefinition.name === strategyName;
|
return strategyDefinition.name === strategyName;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!definition?.editable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const renderCustomStrategyParameters = () => {
|
const renderCustomStrategyParameters = () => {
|
||||||
if (!definition?.editable) return null;
|
|
||||||
return definition?.parameters.map((param: any, index: number) => {
|
return definition?.parameters.map((param: any, index: number) => {
|
||||||
const notLastItem = index !== definition?.parameters?.length - 1;
|
const notLastItem = index !== definition?.parameters?.length - 1;
|
||||||
switch (param?.type) {
|
switch (param?.type) {
|
||||||
@ -81,93 +80,54 @@ export const CustomStrategyParams: VFC<ICustomStrategyProps> = ({
|
|||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
|
const bool = Boolean(parameters[param?.name]);
|
||||||
return (
|
return (
|
||||||
<Fragment key={param.name}>
|
<Fragment key={param?.name}>
|
||||||
<p key={param.name}>
|
<PlaygroundParameterItem
|
||||||
<StringTruncator
|
value={bool ? ['True'] : []}
|
||||||
maxLength={15}
|
|
||||||
maxWidth="150"
|
|
||||||
text={param.name}
|
text={param.name}
|
||||||
/>{' '}
|
showReason={!bool}
|
||||||
{parameters[param.name]}
|
input={bool ? bool : 'no value'}
|
||||||
</p>
|
/>
|
||||||
<ConditionallyRender
|
|
||||||
condition={
|
|
||||||
typeof parameters[param.name] !==
|
|
||||||
'undefined'
|
|
||||||
}
|
|
||||||
show={
|
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={notLastItem}
|
condition={notLastItem}
|
||||||
show={<StrategySeparator text="AND" />}
|
show={<StrategySeparator text="AND" />}
|
||||||
/>
|
/>
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
case 'string':
|
case 'string':
|
||||||
const value = parseParameterString(parameters[param.name]);
|
const value =
|
||||||
|
parseParameterString(parameters[param.name]) ??
|
||||||
|
'no value';
|
||||||
return (
|
return (
|
||||||
<ConditionallyRender
|
<Fragment key={param?.name}>
|
||||||
condition={
|
<PlaygroundParameterItem
|
||||||
typeof parameters[param.name] !== 'undefined'
|
value={value !== '' ? [value] : []}
|
||||||
}
|
|
||||||
key={param.name}
|
|
||||||
show={
|
|
||||||
<>
|
|
||||||
<p className={styles.valueContainer}>
|
|
||||||
<StringTruncator
|
|
||||||
maxWidth="150"
|
|
||||||
maxLength={15}
|
|
||||||
text={param.name}
|
text={param.name}
|
||||||
|
showReason={value === ''}
|
||||||
|
input={value !== '' ? value : 'no value'}
|
||||||
/>
|
/>
|
||||||
<span className={styles.valueSeparator}>
|
|
||||||
is set to
|
|
||||||
</span>
|
|
||||||
<StringTruncator
|
|
||||||
maxWidth="300"
|
|
||||||
text={value}
|
|
||||||
maxLength={50}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={notLastItem}
|
condition={notLastItem}
|
||||||
show={<StrategySeparator text="AND" />}
|
show={<StrategySeparator text="AND" />}
|
||||||
/>
|
/>
|
||||||
</>
|
</Fragment>
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
case 'number':
|
case 'number':
|
||||||
const number = parseParameterNumber(parameters[param.name]);
|
const number = parseParameterNumber(parameters[param.name]);
|
||||||
return (
|
return (
|
||||||
<ConditionallyRender
|
<Fragment key={param?.name}>
|
||||||
condition={number !== undefined}
|
<PlaygroundParameterItem
|
||||||
key={param.name}
|
value={Boolean(number) ? [number] : []}
|
||||||
show={
|
|
||||||
<>
|
|
||||||
<p className={styles.valueContainer}>
|
|
||||||
<StringTruncator
|
|
||||||
maxLength={15}
|
|
||||||
maxWidth="150"
|
|
||||||
text={param.name}
|
text={param.name}
|
||||||
|
showReason={Boolean(number)}
|
||||||
|
input={Boolean(number) ? number : 'no value'}
|
||||||
/>
|
/>
|
||||||
<span className={styles.valueSeparator}>
|
|
||||||
is set to
|
|
||||||
</span>
|
|
||||||
<StringTruncator
|
|
||||||
maxWidth="300"
|
|
||||||
text={String(number)}
|
|
||||||
maxLength={50}
|
|
||||||
/>
|
|
||||||
</p>
|
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={notLastItem}
|
condition={notLastItem}
|
||||||
show={<StrategySeparator text="AND" />}
|
show={<StrategySeparator text="AND" />}
|
||||||
/>
|
/>
|
||||||
</>
|
</Fragment>
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
case 'default':
|
case 'default':
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user