From a0a7c833664f3fb0f873714cda9a925540437c5a Mon Sep 17 00:00:00 2001 From: andreas-unleash <104830839+andreas-unleash@users.noreply.github.com> Date: Fri, 29 Jul 2022 11:16:14 +0300 Subject: [PATCH] Playground context value --- .../ConstraintAccordionView.tsx | 12 ++- .../ConstraintAccordionViewHeader.tsx | 13 ++- .../ConstraintAccordionViewHeaderInfo.tsx | 95 ++++++++++++++----- ...raintAccordionViewHeaderMultipleValues.tsx | 20 +++- ...nstraintAccordionViewHeaderSingleValue.tsx | 16 +++- .../PlaygroundResultConstraintExecution.tsx | 26 ++++- .../actions/usePlayground/playground.model.ts | 1 + 7 files changed, 152 insertions(+), 31 deletions(-) diff --git a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView.tsx b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView.tsx index 59130f58ae..1377a2b2a0 100644 --- a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView.tsx +++ b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView.tsx @@ -16,11 +16,17 @@ import { semVerOperators, } from 'constants/operators'; import { useStyles } from '../ConstraintAccordion.styles'; +import { + PlaygroundFeatureStrategyConstraintResult, + SdkContextSchema, +} from '../../../../hooks/api/actions/usePlayground/playground.model'; interface IConstraintAccordionViewProps { - constraint: IConstraint; + constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult; onDelete?: () => void; onEdit?: () => void; + playgroundContext?: SdkContextSchema; + maxLength?: number; sx?: SxProps; } @@ -29,6 +35,8 @@ export const ConstraintAccordionView = ({ onEdit, onDelete, sx = undefined, + maxLength, + playgroundContext, }: IConstraintAccordionViewProps) => { const { classes: styles } = useStyles(); const [expandable, setExpandable] = useState(true); @@ -70,6 +78,8 @@ export const ConstraintAccordionView = ({ singleValue={singleValue} allowExpand={setExpandable} expanded={expanded} + maxLength={maxLength ?? 112} + playgroundContext={playgroundContext} /> diff --git a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ConstraintAccordionViewHeader.tsx b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ConstraintAccordionViewHeader.tsx index 897304438d..9a4b0bbb58 100644 --- a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ConstraintAccordionViewHeader.tsx +++ b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ConstraintAccordionViewHeader.tsx @@ -3,14 +3,20 @@ import { IConstraint } from 'interfaces/strategy'; import { ConstraintAccordionViewHeaderInfo } from './ConstraintAccordionViewHeaderInfo/ConstraintAccordionViewHeaderInfo'; import { ConstraintAccordionHeaderActions } from '../../ConstraintAccordionHeaderActions/ConstraintAccordionHeaderActions'; import { useStyles } from 'component/common/ConstraintAccordion/ConstraintAccordion.styles'; +import { + PlaygroundFeatureStrategyConstraintResult, + SdkContextSchema, +} from '../../../../../hooks/api/actions/usePlayground/playground.model'; interface IConstraintAccordionViewHeaderProps { - constraint: IConstraint; + constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult; onDelete?: () => void; onEdit?: () => void; singleValue: boolean; expanded: boolean; allowExpand: (shouldExpand: boolean) => void; + playgroundContext?: SdkContextSchema; + maxLength?: number; } export const ConstraintAccordionViewHeader = ({ @@ -20,6 +26,8 @@ export const ConstraintAccordionViewHeader = ({ singleValue, allowExpand, expanded, + maxLength, + playgroundContext, }: IConstraintAccordionViewHeaderProps) => { const { classes: styles } = useStyles(); @@ -31,6 +39,9 @@ export const ConstraintAccordionViewHeader = ({ singleValue={singleValue} allowExpand={allowExpand} expanded={expanded} + result={'result' in constraint ? constraint.result : undefined} + maxLength={maxLength} + playgroundContext={playgroundContext} /> ({ display: '-webkit-box', @@ -27,11 +29,21 @@ const StyledHeaderText = styled('span')(({ theme }) => ({ }, })); +const StyledHeaderWrapper = styled('div')(({ theme }) => ({ + display: 'flex', + width: '100%', + justifyContent: 'space-between', + borderRadius: '8px', +})); + interface ConstraintAccordionViewHeaderMetaInfoProps { constraint: IConstraint; singleValue: boolean; expanded: boolean; allowExpand: (shouldExpand: boolean) => void; + result?: boolean; + maxLength?: number; + playgroundContext?: SdkContextSchema; } export const ConstraintAccordionViewHeaderInfo = ({ @@ -39,31 +51,70 @@ export const ConstraintAccordionViewHeaderInfo = ({ singleValue, allowExpand, expanded, + result, + maxLength = 112, + playgroundContext, }: ConstraintAccordionViewHeaderMetaInfoProps) => { const { classes: styles } = useStyles(); + const theme = useTheme(); + return ( -
- - {constraint.contextName} - - + +
+ + + {constraint.contextName} + + {playgroundContext![ + constraint.contextName + ] || 'no value'} + + } + /> + + + + + } + elseShow={ + + } + /> +
- } - elseShow={ - - } + condition={result !== undefined && !Boolean(result)} + show={} /> -
+ ); }; diff --git a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ContraintAccordionViewHeaderMultipleValues/ConstraintAccordionViewHeaderMultipleValues.tsx b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ContraintAccordionViewHeaderMultipleValues/ConstraintAccordionViewHeaderMultipleValues.tsx index 9d063c1c94..da0cc1fcfc 100644 --- a/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ContraintAccordionViewHeaderMultipleValues/ConstraintAccordionViewHeaderMultipleValues.tsx +++ b/frontend/src/component/common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionViewHeader/ContraintAccordionViewHeaderMultipleValues/ConstraintAccordionViewHeaderMultipleValues.tsx @@ -1,9 +1,10 @@ import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender'; -import { styled } from '@mui/material'; +import { styled, Typography } from '@mui/material'; import React, { useEffect, useMemo, useState } from 'react'; import classnames from 'classnames'; import { IConstraint } from '../../../../../../interfaces/strategy'; import { useStyles } from '../../../ConstraintAccordion.styles'; +import { PlaygroundFeatureStrategyConstraintResult } from '../../../../../../hooks/api/actions/usePlayground/playground.model'; const StyledValuesSpan = styled('span')(({ theme }) => ({ display: '-webkit-box', @@ -20,7 +21,7 @@ const StyledValuesSpan = styled('span')(({ theme }) => ({ })); interface ConstraintSingleValueProps { - constraint: IConstraint; + constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult; expanded: boolean; maxLength: number; allowExpand: (shouldExpand: boolean) => void; @@ -50,6 +51,21 @@ export const ConstraintAccordionViewHeaderMultipleValues = ({ return (
+ + does not match any values{' '} + + } + /> {text} ({ margin: 'auto 0', @@ -13,7 +15,7 @@ const StyledSingleValueChip = styled(Chip)(({ theme }) => ({ })); interface ConstraintSingleValueProps { - constraint: IConstraint; + constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult; allowExpand: (shouldExpand: boolean) => void; } @@ -30,6 +32,16 @@ export const ConstraintAccordionViewHeaderSingleValue = ({ return (
+ + does not match any values{' '} + + } + /> diff --git a/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/PlaygroundResultConstraintExecution/PlaygroundResultConstraintExecution.tsx b/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/PlaygroundResultConstraintExecution/PlaygroundResultConstraintExecution.tsx index a68ab63404..4d3185afa9 100644 --- a/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/PlaygroundResultConstraintExecution/PlaygroundResultConstraintExecution.tsx +++ b/frontend/src/component/playground/Playground/PlaygroundResultsTable/FeatureResultInfoPopoverCell/PlaygroundResultConstraintExecution/PlaygroundResultConstraintExecution.tsx @@ -1,21 +1,39 @@ -import { PlaygroundFeatureStrategyConstraintResult } from 'hooks/api/actions/usePlayground/playground.model'; +import { + PlaygroundFeatureStrategyConstraintResult, + SdkContextSchema, +} from 'hooks/api/actions/usePlayground/playground.model'; import React, { Fragment } from 'react'; import { objectId } from '../../../../../../utils/objectId'; import { ConditionallyRender } from '../../../../../common/ConditionallyRender/ConditionallyRender'; import { StrategySeparator } from '../../../../../common/StrategySeparator/StrategySeparator'; import { ConstraintAccordionView } from '../../../../../common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView'; +import { styled } from '@mui/material'; interface PlaygroundResultConstraintExecutionProps { constraints?: PlaygroundFeatureStrategyConstraintResult[]; } +export const PlaygroundResultConstraintExecutionWrapper = styled('div')( + ({ theme }) => ({ + width: '100%', + display: 'flex', + flexDirection: 'column', + }) +); + export const PlaygroundResultConstraintExecution = ({ constraints, }: PlaygroundResultConstraintExecutionProps) => { + // const context = usePlaygroundContext(); + const context: SdkContextSchema = { + appName: 'MyApp', + environment: '', + }; + if (!constraints) return null; return ( - <> + {constraints?.map((constraint, index) => ( ))} - + ); }; diff --git a/frontend/src/hooks/api/actions/usePlayground/playground.model.ts b/frontend/src/hooks/api/actions/usePlayground/playground.model.ts index eff504cda2..fba4ce9432 100644 --- a/frontend/src/hooks/api/actions/usePlayground/playground.model.ts +++ b/frontend/src/hooks/api/actions/usePlayground/playground.model.ts @@ -264,6 +264,7 @@ export interface PlaygroundFeatureStrategySegmentResult { result: boolean; constraints?: PlaygroundFeatureStrategyConstraintResult[]; } +6; export interface PlaygroundFeatureStrategyResult { id: string;