Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Parameters Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-unleash committed Aug 8, 2022
1 parent bd36164 commit b8d4c3f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Chip, Typography, useTheme } from '@mui/material';
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 { CancelOutlined } from '@mui/icons-material';
import classnames from 'classnames';

interface IConstraintItemProps {
value: string[];
value: Array<string | number>;
text: string;
input?: string | number | boolean | 'no value';
showReason?: boolean;
}

export const PlaygroundConstraintItem = ({
export const PlaygroundParameterItem = ({
value,
text,
input,
Expand Down Expand Up @@ -56,13 +56,13 @@ export const PlaygroundConstraintItem = ({
{value.length > 1 ? `${text}s` : text} will get
access.
</p>
{value.map((v: string) => (
{value.map((v: string | number) => (
<Chip
key={v}
label={
<StringTruncator
maxWidth="300"
text={v}
text={v.toString()}
maxLength={50}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PlaygroundResultConstraintExecution = ({
{constraints?.map((constraint, index) => (
<Fragment key={objectId(constraint)}>
<ConditionallyRender
condition={index > 0}
condition={index > 0 && constraints?.length > 1}
show={<StrategySeparator text="AND" />}
/>
<PlaygroundResultConstraintAccordionView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const PlaygroundResultStrategyExecution = ({
const { classes: styles } = useStyles();

const hasConstraints = Boolean(constraints && constraints.length > 0);
const hasParameters = Object.keys(parameters).length === 0;

if (!parameters) {
return null;
Expand Down Expand Up @@ -68,7 +69,7 @@ export const PlaygroundResultStrategyExecution = ({
/>
<ConditionallyRender
condition={Boolean(
constraints && constraints.length > 0
constraints && constraints.length > 0 && !hasParameters
)}
show={<StrategySeparator text="AND" />}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import {
parseParameterStrings,
} from 'utils/parseParameter';
import React, { Fragment } from 'react';
import { PlaygroundConstraintItem } from '../PlaygroundConstraintItem/PlaygroundConstraintItem';
import { PlaygroundParameterItem } from '../PlaygroundParamteterItem/PlaygroundParameterItem';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
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 StringTruncator from 'component/common/StringTruncator/StringTruncator';
import { PlaygroundConstraintSchema } from 'hooks/api/actions/usePlayground/playground.model';
import { useStyles } from '../PlaygroundResultStrategyExecution.styles';
import { useStrategies } from 'hooks/api/getters/useStrategies/useStrategies';

interface PlaygroundResultStrategyExecutionCustomStrategyProps {
Expand All @@ -25,15 +23,16 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
constraints,
parameters,
}: PlaygroundResultStrategyExecutionCustomStrategyProps) => {
const { classes: styles } = useStyles();
const { strategies } = useStrategies();

const definition = strategies.find(strategyDefinition => {
return strategyDefinition.name === strategyName;
});

if (!definition?.editable) {
return null;
}

const renderCustomStrategyParameters = () => {
if (!definition?.editable) return null;
return definition?.parameters.map((param: any, index: number) => {
const notLastItem = index !== definition?.parameters?.length - 1;
switch (param?.type) {
Expand All @@ -43,7 +42,7 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
);
return (
<Fragment key={param?.name}>
<PlaygroundConstraintItem
<PlaygroundParameterItem
value={values}
text={param.name}
/>
Expand Down Expand Up @@ -81,93 +80,52 @@ export const PlaygroundResultStrategyExecutionCustomStrategyParams = ({
</Fragment>
);
case 'boolean':
const bool = Boolean(parameters[param?.name]);
return (
<Fragment key={param.name}>
<p key={param.name}>
<StringTruncator
maxLength={15}
maxWidth="150"
text={param.name}
/>{' '}
{parameters[param.name]}
</p>
<Fragment key={param?.name}>
<PlaygroundParameterItem
value={bool ? ['True'] : []}
text={param.name}
showReason={!bool}
input={bool ? bool : 'no value'}
/>
<ConditionallyRender
condition={
typeof parameters[param.name] !==
'undefined'
}
show={
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
}
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</Fragment>
);
case 'string':
const value = parseParameterString(parameters[param.name]);
const value = parseParameterString(parameters[param.name]) ?? 'no value';
return (
<ConditionallyRender
condition={
typeof parameters[param.name] !== 'undefined'
}
key={param.name}
show={
<>
<p className={styles.valueContainer}>
<StringTruncator
maxWidth="150"
maxLength={15}
text={param.name}
/>
<span className={styles.valueSeparator}>
is set to
</span>
<StringTruncator
maxWidth="300"
text={value}
maxLength={50}
/>
</p>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</>
}
/>
<Fragment key={param?.name}>
<PlaygroundParameterItem
value={value !== '' ? [value] : []}
text={param.name}
showReason={value === ''}
input={value !== '' ? value : 'no value'}
/>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</Fragment>
);
case 'number':
const number = parseParameterNumber(parameters[param.name]);
return (
<ConditionallyRender
condition={number !== undefined}
key={param.name}
show={
<>
<p className={styles.valueContainer}>
<StringTruncator
maxLength={15}
maxWidth="150"
text={param.name}
/>
<span className={styles.valueSeparator}>
is set to
</span>
<StringTruncator
maxWidth="300"
text={String(number)}
maxLength={50}
/>
</p>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</>
}
/>
<Fragment key={param?.name}>
<PlaygroundParameterItem
value={Boolean(number) ? [number] : []}
text={param.name}
showReason={Boolean(number)}
input={Boolean(number) ? number : 'no value'}
/>
<ConditionallyRender
condition={notLastItem}
show={<StrategySeparator text="AND" />}
/>
</Fragment>
);
case 'default':
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
} from 'utils/parseParameter';
import { Box, Chip } from '@mui/material';
import PercentageCircle from 'component/common/PercentageCircle/PercentageCircle';
import { PlaygroundConstraintItem } from '../PlaygroundConstraintItem/PlaygroundConstraintItem';
import { PlaygroundParameterItem } from '../PlaygroundParamteterItem/PlaygroundParameterItem';
import React from 'react';
import { useStyles } from '../PlaygroundResultStrategyExecution.styles';
import {
PlaygroundConstraintSchema,
PlaygroundRequestSchema,
} from 'hooks/api/actions/usePlayground/playground.model';
import { getMappedParam } from '../helepers';
import { getMappedParam } from '../helpers';

export interface PlaygroundResultStrategyExecutionParametersProps {
parameters: { [key: string]: string };
Expand Down Expand Up @@ -62,7 +62,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'UserIds':
const users = parseParameterStrings(parameters[key]);
return (
<PlaygroundConstraintItem
<PlaygroundParameterItem
key={key}
value={users}
text="user"
Expand All @@ -84,7 +84,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'HostNames':
const hosts = parseParameterStrings(parameters[key]);
return (
<PlaygroundConstraintItem
<PlaygroundParameterItem
key={key}
value={hosts}
text={'host'}
Expand All @@ -105,7 +105,7 @@ export const PlaygroundResultStrategyExecutionParameters = ({
case 'IPs':
const IPs = parseParameterStrings(parameters[key]);
return (
<PlaygroundConstraintItem
<PlaygroundParameterItem
key={key}
value={IPs}
text={'IP'}
Expand Down

0 comments on commit b8d4c3f

Please sign in to comment.