1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

Parameters Bug fix

This commit is contained in:
andreas-unleash 2022-08-08 10:42:45 +03:00
parent c7507c6887
commit ff33308d8e
7 changed files with 55 additions and 96 deletions

View File

@ -1,18 +1,18 @@
import { Chip, Typography, useTheme } from '@mui/material'; import { Chip, Typography, useTheme } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useStyles } from './PlaygroundConstraintItem.styles'; import { useStyles } from './PlaygroundParametertem.styles';
import StringTruncator from 'component/common/StringTruncator/StringTruncator'; import StringTruncator from 'component/common/StringTruncator/StringTruncator';
import { CancelOutlined } from '@mui/icons-material'; import { CancelOutlined } from '@mui/icons-material';
import classnames from 'classnames'; import classnames from 'classnames';
interface IConstraintItemProps { interface IConstraintItemProps {
value: string[]; value: Array<string | number>;
text: string; text: string;
input?: string | number | boolean | 'no value'; input?: string | number | boolean | 'no value';
showReason?: boolean; showReason?: boolean;
} }
export const PlaygroundConstraintItem = ({ export const PlaygroundParameterItem = ({
value, value,
text, text,
input, input,
@ -56,13 +56,13 @@ export const PlaygroundConstraintItem = ({
{value.length > 1 ? `${text}s` : text} will get {value.length > 1 ? `${text}s` : text} will get
access. access.
</p> </p>
{value.map((v: string) => ( {value.map((v: string | number) => (
<Chip <Chip
key={v} key={v}
label={ label={
<StringTruncator <StringTruncator
maxWidth="300" maxWidth="300"
text={v} text={v.toString()}
maxLength={50} maxLength={50}
/> />
} }

View File

@ -33,7 +33,7 @@ export const PlaygroundResultConstraintExecution = ({
{constraints?.map((constraint, index) => ( {constraints?.map((constraint, index) => (
<Fragment key={objectId(constraint)}> <Fragment key={objectId(constraint)}>
<ConditionallyRender <ConditionallyRender
condition={index > 0} condition={index > 0 && constraints?.length > 1}
show={<StrategySeparator text="AND" />} show={<StrategySeparator text="AND" />}
/> />
<PlaygroundResultConstraintAccordionView <PlaygroundResultConstraintAccordionView

View File

@ -37,6 +37,7 @@ export const PlaygroundResultStrategyExecution = ({
const { classes: styles } = useStyles(); const { classes: styles } = useStyles();
const hasConstraints = Boolean(constraints && constraints.length > 0); const hasConstraints = Boolean(constraints && constraints.length > 0);
const hasParameters = Object.keys(parameters).length === 0;
if (!parameters) { if (!parameters) {
return null; return null;
@ -68,7 +69,7 @@ export const PlaygroundResultStrategyExecution = ({
/> />
<ConditionallyRender <ConditionallyRender
condition={Boolean( condition={Boolean(
constraints && constraints.length > 0 constraints && constraints.length > 0 && !hasParameters
)} )}
show={<StrategySeparator text="AND" />} show={<StrategySeparator text="AND" />}
/> />

View File

@ -4,14 +4,12 @@ import {
parseParameterStrings, parseParameterStrings,
} from 'utils/parseParameter'; } from 'utils/parseParameter';
import React, { Fragment } from 'react'; import React, { Fragment } from 'react';
import { PlaygroundConstraintItem } from '../PlaygroundConstraintItem/PlaygroundConstraintItem'; import { PlaygroundParameterItem } from '../PlaygroundParamteterItem/PlaygroundParameterItem';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
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 '../PlaygroundResultStrategyExecution.styles';
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies'; import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies';
interface PlaygroundResultStrategyExecutionCustomStrategyProps { interface PlaygroundResultStrategyExecutionCustomStrategyProps {
@ -25,15 +23,16 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
constraints, constraints,
parameters, parameters,
}: PlaygroundResultStrategyExecutionCustomStrategyProps) => { }: PlaygroundResultStrategyExecutionCustomStrategyProps) => {
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) {
@ -43,7 +42,7 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
); );
return ( return (
<Fragment key={param?.name}> <Fragment key={param?.name}>
<PlaygroundConstraintItem <PlaygroundParameterItem
value={values} value={values}
text={param.name} text={param.name}
/> />
@ -81,93 +80,52 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
</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} text={param.name}
maxWidth="150" showReason={!bool}
text={param.name} input={bool ? bool : 'no value'}
/>{' '} />
{parameters[param.name]}
</p>
<ConditionallyRender <ConditionallyRender
condition={ condition={notLastItem}
typeof parameters[param.name] !== show={<StrategySeparator text="AND" />}
'undefined'
}
show={
<ConditionallyRender
condition={notLastItem}
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] : []}
} text={param.name}
key={param.name} showReason={value === ''}
show={ input={value !== '' ? value : 'no value'}
<> />
<p className={styles.valueContainer}> <ConditionallyRender
<StringTruncator condition={notLastItem}
maxWidth="150" show={<StrategySeparator text="AND" />}
maxLength={15} />
text={param.name} </Fragment>
/>
<span className={styles.valueSeparator}>
is set to
</span>
<StringTruncator
maxWidth="300"
text={value}
maxLength={50}
/>
</p>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</>
}
/>
); );
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={ text={param.name}
<> showReason={Boolean(number)}
<p className={styles.valueContainer}> input={Boolean(number) ? number : 'no value'}
<StringTruncator />
maxLength={15} <ConditionallyRender
maxWidth="150" condition={notLastItem}
text={param.name} show={<StrategySeparator text="AND" />}
/> />
<span className={styles.valueSeparator}> </Fragment>
is set to
</span>
<StringTruncator
maxWidth="300"
text={String(number)}
maxLength={50}
/>
</p>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</>
}
/>
); );
case 'default': case 'default':
return null; return null;

View File

@ -4,14 +4,14 @@ import {
} from 'utils/parseParameter'; } from 'utils/parseParameter';
import { Box, Chip } from '@mui/material'; import { Box, Chip } from '@mui/material';
import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle'; import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle';
import { PlaygroundConstraintItem } from '../PlaygroundConstraintItem/PlaygroundConstraintItem'; import { PlaygroundParameterItem } from '../PlaygroundParamteterItem/PlaygroundParameterItem';
import React from 'react'; import React from 'react';
import { useStyles } from '../PlaygroundResultStrategyExecution.styles'; import { useStyles } from '../PlaygroundResultStrategyExecution.styles';
import { import {
PlaygroundConstraintSchema, PlaygroundConstraintSchema,
PlaygroundRequestSchema, PlaygroundRequestSchema,
} from 'hooks/api/actions/usePlayground/playground.model'; } from 'hooks/api/actions/usePlayground/playground.model';
import { getMappedParam } from '../helepers'; import { getMappedParam } from '../helpers';
export interface PlaygroundResultStrategyExecutionParametersProps { export interface PlaygroundResultStrategyExecutionParametersProps {
parameters: { [key: string]: string }; parameters: { [key: string]: string };
@ -62,7 +62,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'UserIds': case 'UserIds':
const users = parseParameterStrings(parameters[key]); const users = parseParameterStrings(parameters[key]);
return ( return (
<PlaygroundConstraintItem <PlaygroundParameterItem
key={key} key={key}
value={users} value={users}
text="user" text="user"
@ -84,7 +84,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'HostNames': case 'HostNames':
const hosts = parseParameterStrings(parameters[key]); const hosts = parseParameterStrings(parameters[key]);
return ( return (
<PlaygroundConstraintItem <PlaygroundParameterItem
key={key} key={key}
value={hosts} value={hosts}
text={'host'} text={'host'}
@ -105,7 +105,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'IPs': case 'IPs':
const IPs = parseParameterStrings(parameters[key]); const IPs = parseParameterStrings(parameters[key]);
return ( return (
<PlaygroundConstraintItem <PlaygroundParameterItem
key={key} key={key}
value={IPs} value={IPs}
text={'IP'} text={'IP'}