mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-23 13:46:45 +02:00
Playground context value
This commit is contained in:
parent
9e38cf3ff9
commit
a0a7c83366
@ -16,11 +16,17 @@ import {
|
|||||||
semVerOperators,
|
semVerOperators,
|
||||||
} from 'constants/operators';
|
} from 'constants/operators';
|
||||||
import { useStyles } from '../ConstraintAccordion.styles';
|
import { useStyles } from '../ConstraintAccordion.styles';
|
||||||
|
import {
|
||||||
|
PlaygroundFeatureStrategyConstraintResult,
|
||||||
|
SdkContextSchema,
|
||||||
|
} from '../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
|
||||||
interface IConstraintAccordionViewProps {
|
interface IConstraintAccordionViewProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onEdit?: () => void;
|
onEdit?: () => void;
|
||||||
|
playgroundContext?: SdkContextSchema;
|
||||||
|
maxLength?: number;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +35,8 @@ export const ConstraintAccordionView = ({
|
|||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
sx = undefined,
|
sx = undefined,
|
||||||
|
maxLength,
|
||||||
|
playgroundContext,
|
||||||
}: IConstraintAccordionViewProps) => {
|
}: IConstraintAccordionViewProps) => {
|
||||||
const { classes: styles } = useStyles();
|
const { classes: styles } = useStyles();
|
||||||
const [expandable, setExpandable] = useState(true);
|
const [expandable, setExpandable] = useState(true);
|
||||||
@ -70,6 +78,8 @@ export const ConstraintAccordionView = ({
|
|||||||
singleValue={singleValue}
|
singleValue={singleValue}
|
||||||
allowExpand={setExpandable}
|
allowExpand={setExpandable}
|
||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
|
maxLength={maxLength ?? 112}
|
||||||
|
playgroundContext={playgroundContext}
|
||||||
/>
|
/>
|
||||||
</AccordionSummary>
|
</AccordionSummary>
|
||||||
|
|
||||||
|
@ -3,14 +3,20 @@ import { IConstraint } from 'interfaces/strategy';
|
|||||||
import { ConstraintAccordionViewHeaderInfo } from './ConstraintAccordionViewHeaderInfo/ConstraintAccordionViewHeaderInfo';
|
import { ConstraintAccordionViewHeaderInfo } from './ConstraintAccordionViewHeaderInfo/ConstraintAccordionViewHeaderInfo';
|
||||||
import { ConstraintAccordionHeaderActions } from '../../ConstraintAccordionHeaderActions/ConstraintAccordionHeaderActions';
|
import { ConstraintAccordionHeaderActions } from '../../ConstraintAccordionHeaderActions/ConstraintAccordionHeaderActions';
|
||||||
import { useStyles } from 'component/common/ConstraintAccordion/ConstraintAccordion.styles';
|
import { useStyles } from 'component/common/ConstraintAccordion/ConstraintAccordion.styles';
|
||||||
|
import {
|
||||||
|
PlaygroundFeatureStrategyConstraintResult,
|
||||||
|
SdkContextSchema,
|
||||||
|
} from '../../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
|
||||||
interface IConstraintAccordionViewHeaderProps {
|
interface IConstraintAccordionViewHeaderProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onEdit?: () => void;
|
onEdit?: () => void;
|
||||||
singleValue: boolean;
|
singleValue: boolean;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
allowExpand: (shouldExpand: boolean) => void;
|
allowExpand: (shouldExpand: boolean) => void;
|
||||||
|
playgroundContext?: SdkContextSchema;
|
||||||
|
maxLength?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConstraintAccordionViewHeader = ({
|
export const ConstraintAccordionViewHeader = ({
|
||||||
@ -20,6 +26,8 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
singleValue,
|
singleValue,
|
||||||
allowExpand,
|
allowExpand,
|
||||||
expanded,
|
expanded,
|
||||||
|
maxLength,
|
||||||
|
playgroundContext,
|
||||||
}: IConstraintAccordionViewHeaderProps) => {
|
}: IConstraintAccordionViewHeaderProps) => {
|
||||||
const { classes: styles } = useStyles();
|
const { classes: styles } = useStyles();
|
||||||
|
|
||||||
@ -31,6 +39,9 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
singleValue={singleValue}
|
singleValue={singleValue}
|
||||||
allowExpand={allowExpand}
|
allowExpand={allowExpand}
|
||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
|
result={'result' in constraint ? constraint.result : undefined}
|
||||||
|
maxLength={maxLength}
|
||||||
|
playgroundContext={playgroundContext}
|
||||||
/>
|
/>
|
||||||
<ConstraintAccordionHeaderActions
|
<ConstraintAccordionHeaderActions
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { styled, Tooltip } from '@mui/material';
|
import { styled, Tooltip, Typography, useTheme } from '@mui/material';
|
||||||
import { ConstraintViewHeaderOperator } from '../ConstraintViewHeaderOperator/ConstraintViewHeaderOperator';
|
import { ConstraintViewHeaderOperator } from '../ConstraintViewHeaderOperator/ConstraintViewHeaderOperator';
|
||||||
import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender';
|
||||||
import { ConstraintAccordionViewHeaderSingleValue } from '../ContraintAccordionViewHeaderSingleValue/ConstraintAccordionViewHeaderSingleValue';
|
import { ConstraintAccordionViewHeaderSingleValue } from '../ContraintAccordionViewHeaderSingleValue/ConstraintAccordionViewHeaderSingleValue';
|
||||||
@ -6,6 +6,8 @@ import { ConstraintAccordionViewHeaderMultipleValues } from '../ContraintAccordi
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { IConstraint } from '../../../../../../interfaces/strategy';
|
import { IConstraint } from '../../../../../../interfaces/strategy';
|
||||||
import { useStyles } from '../../../ConstraintAccordion.styles';
|
import { useStyles } from '../../../ConstraintAccordion.styles';
|
||||||
|
import { CancelOutlined } from '@mui/icons-material';
|
||||||
|
import { SdkContextSchema } from '../../../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
|
||||||
const StyledHeaderText = styled('span')(({ theme }) => ({
|
const StyledHeaderText = styled('span')(({ theme }) => ({
|
||||||
display: '-webkit-box',
|
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 {
|
interface ConstraintAccordionViewHeaderMetaInfoProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint;
|
||||||
singleValue: boolean;
|
singleValue: boolean;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
allowExpand: (shouldExpand: boolean) => void;
|
allowExpand: (shouldExpand: boolean) => void;
|
||||||
|
result?: boolean;
|
||||||
|
maxLength?: number;
|
||||||
|
playgroundContext?: SdkContextSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ConstraintAccordionViewHeaderInfo = ({
|
export const ConstraintAccordionViewHeaderInfo = ({
|
||||||
@ -39,12 +51,46 @@ export const ConstraintAccordionViewHeaderInfo = ({
|
|||||||
singleValue,
|
singleValue,
|
||||||
allowExpand,
|
allowExpand,
|
||||||
expanded,
|
expanded,
|
||||||
|
result,
|
||||||
|
maxLength = 112,
|
||||||
|
playgroundContext,
|
||||||
}: ConstraintAccordionViewHeaderMetaInfoProps) => {
|
}: ConstraintAccordionViewHeaderMetaInfoProps) => {
|
||||||
const { classes: styles } = useStyles();
|
const { classes: styles } = useStyles();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<StyledHeaderWrapper>
|
||||||
<div className={styles.headerMetaInfo}>
|
<div className={styles.headerMetaInfo}>
|
||||||
<Tooltip title={constraint.contextName} arrow>
|
<Tooltip title={constraint.contextName} arrow>
|
||||||
<StyledHeaderText>{constraint.contextName}</StyledHeaderText>
|
<StyledHeaderText>
|
||||||
|
{constraint.contextName}
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={
|
||||||
|
result !== undefined &&
|
||||||
|
!Boolean(result) &&
|
||||||
|
Boolean(playgroundContext)
|
||||||
|
}
|
||||||
|
show={
|
||||||
|
<Typography
|
||||||
|
variant={'body1'}
|
||||||
|
color={
|
||||||
|
Boolean(
|
||||||
|
playgroundContext![
|
||||||
|
constraint.contextName
|
||||||
|
]
|
||||||
|
)
|
||||||
|
? theme.palette.neutral
|
||||||
|
.dark
|
||||||
|
: theme.palette.error.main
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{playgroundContext![
|
||||||
|
constraint.contextName
|
||||||
|
] || 'no value'}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</StyledHeaderText>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<ConstraintViewHeaderOperator constraint={constraint} />
|
<ConstraintViewHeaderOperator constraint={constraint} />
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
@ -60,10 +106,15 @@ export const ConstraintAccordionViewHeaderInfo = ({
|
|||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
expanded={expanded}
|
expanded={expanded}
|
||||||
allowExpand={allowExpand}
|
allowExpand={allowExpand}
|
||||||
maxLength={112}
|
maxLength={maxLength}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={result !== undefined && !Boolean(result)}
|
||||||
|
show={<CancelOutlined color="error" sx={{ mt: 1 }} />}
|
||||||
|
/>
|
||||||
|
</StyledHeaderWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender';
|
||||||
import { styled } from '@mui/material';
|
import { styled, Typography } from '@mui/material';
|
||||||
import React, { useEffect, useMemo, useState } from 'react';
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { IConstraint } from '../../../../../../interfaces/strategy';
|
import { IConstraint } from '../../../../../../interfaces/strategy';
|
||||||
import { useStyles } from '../../../ConstraintAccordion.styles';
|
import { useStyles } from '../../../ConstraintAccordion.styles';
|
||||||
|
import { PlaygroundFeatureStrategyConstraintResult } from '../../../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
|
||||||
const StyledValuesSpan = styled('span')(({ theme }) => ({
|
const StyledValuesSpan = styled('span')(({ theme }) => ({
|
||||||
display: '-webkit-box',
|
display: '-webkit-box',
|
||||||
@ -20,7 +21,7 @@ const StyledValuesSpan = styled('span')(({ theme }) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
interface ConstraintSingleValueProps {
|
interface ConstraintSingleValueProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
maxLength: number;
|
maxLength: number;
|
||||||
allowExpand: (shouldExpand: boolean) => void;
|
allowExpand: (shouldExpand: boolean) => void;
|
||||||
@ -50,6 +51,21 @@ export const ConstraintAccordionViewHeaderMultipleValues = ({
|
|||||||
return (
|
return (
|
||||||
<div className={styles.headerValuesContainerWrapper}>
|
<div className={styles.headerValuesContainerWrapper}>
|
||||||
<div className={styles.headerValuesContainer}>
|
<div className={styles.headerValuesContainer}>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={
|
||||||
|
'result' in constraint && !Boolean(constraint.result)
|
||||||
|
}
|
||||||
|
show={
|
||||||
|
<Typography
|
||||||
|
variant={'body2'}
|
||||||
|
color={'error'}
|
||||||
|
noWrap={true}
|
||||||
|
sx={{ mr: 1 }}
|
||||||
|
>
|
||||||
|
does not match any values{' '}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<StyledValuesSpan>{text}</StyledValuesSpan>
|
<StyledValuesSpan>{text}</StyledValuesSpan>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={expandable}
|
condition={expandable}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { Chip, styled } from '@mui/material';
|
import { Chip, styled, Typography } from '@mui/material';
|
||||||
import { formatConstraintValue } from '../../../../../../utils/formatConstraintValue';
|
import { formatConstraintValue } from '../../../../../../utils/formatConstraintValue';
|
||||||
import { useStyles } from '../../../ConstraintAccordion.styles';
|
import { useStyles } from '../../../ConstraintAccordion.styles';
|
||||||
import { IConstraint } from '../../../../../../interfaces/strategy';
|
import { IConstraint } from '../../../../../../interfaces/strategy';
|
||||||
import { useLocationSettings } from '../../../../../../hooks/useLocationSettings';
|
import { useLocationSettings } from '../../../../../../hooks/useLocationSettings';
|
||||||
|
import { PlaygroundFeatureStrategyConstraintResult } from '../../../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
import { ConditionallyRender } from '../../../../ConditionallyRender/ConditionallyRender';
|
||||||
|
|
||||||
const StyledSingleValueChip = styled(Chip)(({ theme }) => ({
|
const StyledSingleValueChip = styled(Chip)(({ theme }) => ({
|
||||||
margin: 'auto 0',
|
margin: 'auto 0',
|
||||||
@ -13,7 +15,7 @@ const StyledSingleValueChip = styled(Chip)(({ theme }) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
interface ConstraintSingleValueProps {
|
interface ConstraintSingleValueProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint | PlaygroundFeatureStrategyConstraintResult;
|
||||||
allowExpand: (shouldExpand: boolean) => void;
|
allowExpand: (shouldExpand: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +32,16 @@ export const ConstraintAccordionViewHeaderSingleValue = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.headerValuesContainerWrapper}>
|
<div className={styles.headerValuesContainerWrapper}>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={
|
||||||
|
'result' in constraint && !Boolean(constraint.result)
|
||||||
|
}
|
||||||
|
show={
|
||||||
|
<Typography variant={'body1'} color={'error'}>
|
||||||
|
does not match any values{' '}
|
||||||
|
</Typography>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<StyledSingleValueChip
|
<StyledSingleValueChip
|
||||||
label={formatConstraintValue(constraint, locationSettings)}
|
label={formatConstraintValue(constraint, locationSettings)}
|
||||||
/>
|
/>
|
||||||
|
@ -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 React, { Fragment } from 'react';
|
||||||
import { objectId } from '../../../../../../utils/objectId';
|
import { objectId } from '../../../../../../utils/objectId';
|
||||||
import { ConditionallyRender } from '../../../../../common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../../../../common/ConditionallyRender/ConditionallyRender';
|
||||||
import { StrategySeparator } from '../../../../../common/StrategySeparator/StrategySeparator';
|
import { StrategySeparator } from '../../../../../common/StrategySeparator/StrategySeparator';
|
||||||
import { ConstraintAccordionView } from '../../../../../common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
import { ConstraintAccordionView } from '../../../../../common/ConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
||||||
|
import { styled } from '@mui/material';
|
||||||
|
|
||||||
interface PlaygroundResultConstraintExecutionProps {
|
interface PlaygroundResultConstraintExecutionProps {
|
||||||
constraints?: PlaygroundFeatureStrategyConstraintResult[];
|
constraints?: PlaygroundFeatureStrategyConstraintResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const PlaygroundResultConstraintExecutionWrapper = styled('div')(
|
||||||
|
({ theme }) => ({
|
||||||
|
width: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
export const PlaygroundResultConstraintExecution = ({
|
export const PlaygroundResultConstraintExecution = ({
|
||||||
constraints,
|
constraints,
|
||||||
}: PlaygroundResultConstraintExecutionProps) => {
|
}: PlaygroundResultConstraintExecutionProps) => {
|
||||||
|
// const context = usePlaygroundContext();
|
||||||
|
const context: SdkContextSchema = {
|
||||||
|
appName: 'MyApp',
|
||||||
|
environment: '',
|
||||||
|
};
|
||||||
|
|
||||||
if (!constraints) return null;
|
if (!constraints) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<PlaygroundResultConstraintExecutionWrapper>
|
||||||
{constraints?.map((constraint, index) => (
|
{constraints?.map((constraint, index) => (
|
||||||
<Fragment key={objectId(constraint)}>
|
<Fragment key={objectId(constraint)}>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
@ -24,12 +42,14 @@ export const PlaygroundResultConstraintExecution = ({
|
|||||||
/>
|
/>
|
||||||
<ConstraintAccordionView
|
<ConstraintAccordionView
|
||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
|
playgroundContext={context}
|
||||||
|
maxLength={80}
|
||||||
sx={{
|
sx={{
|
||||||
backgroundColor: 'transparent!important',
|
backgroundColor: 'transparent!important',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</>
|
</PlaygroundResultConstraintExecutionWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -264,6 +264,7 @@ export interface PlaygroundFeatureStrategySegmentResult {
|
|||||||
result: boolean;
|
result: boolean;
|
||||||
constraints?: PlaygroundFeatureStrategyConstraintResult[];
|
constraints?: PlaygroundFeatureStrategyConstraintResult[];
|
||||||
}
|
}
|
||||||
|
6;
|
||||||
|
|
||||||
export interface PlaygroundFeatureStrategyResult {
|
export interface PlaygroundFeatureStrategyResult {
|
||||||
id: string;
|
id: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user