mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-01 13:47:27 +02:00
remove legacy code usage
This commit is contained in:
parent
04074928ca
commit
c45d558352
@ -1,145 +0,0 @@
|
|||||||
import { useId, useMemo, useState, type FC } from 'react';
|
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import type { ISegment } from 'interfaces/segment';
|
|
||||||
import {
|
|
||||||
Accordion,
|
|
||||||
AccordionDetails,
|
|
||||||
AccordionSummary,
|
|
||||||
Button,
|
|
||||||
styled,
|
|
||||||
} from '@mui/material';
|
|
||||||
import { StrategyEvaluationItem } from 'component/common/ConstraintsList/StrategyEvaluationItem/StrategyEvaluationItem';
|
|
||||||
import { objectId } from 'utils/objectId';
|
|
||||||
import {
|
|
||||||
ConstraintListItem,
|
|
||||||
ConstraintsList,
|
|
||||||
} from 'component/common/ConstraintsList/ConstraintsList';
|
|
||||||
import { ConstraintAccordionView } from '../NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView.tsx';
|
|
||||||
|
|
||||||
type SegmentItemProps = {
|
|
||||||
segment: Partial<ISegment>;
|
|
||||||
isExpanded?: boolean;
|
|
||||||
disabled?: boolean | null;
|
|
||||||
constraintList?: JSX.Element;
|
|
||||||
headerContent?: JSX.Element;
|
|
||||||
};
|
|
||||||
|
|
||||||
const StyledConstraintListItem = styled(ConstraintListItem)(() => ({
|
|
||||||
padding: 0,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledAccordion = styled(Accordion)(() => ({
|
|
||||||
boxShadow: 'none',
|
|
||||||
margin: 0,
|
|
||||||
padding: 0,
|
|
||||||
'::before': {
|
|
||||||
// MUI separator between accordions
|
|
||||||
display: 'none',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({
|
|
||||||
fontSize: theme.typography.body2.fontSize,
|
|
||||||
minHeight: 'unset',
|
|
||||||
':focus-within': {
|
|
||||||
backgroundColor: 'inherit',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledAccordionDetails = styled(AccordionDetails)(({ theme }) => ({
|
|
||||||
padding: theme.spacing(0.5, 3, 2.5),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledLink = styled(Link)(({ theme }) => ({
|
|
||||||
textDecoration: 'none',
|
|
||||||
paddingRight: theme.spacing(0.5),
|
|
||||||
'&:hover': {
|
|
||||||
textDecoration: 'underline',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledActionsContainer = styled('div')(({ theme }) => ({
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
marginLeft: 'auto',
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledButton = styled(Button)(({ theme }) => ({
|
|
||||||
fontSize: theme.typography.body2.fontSize,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const StyledNoConstraintsText = styled('p')(({ theme }) => ({
|
|
||||||
fontSize: theme.typography.body2.fontSize,
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const SegmentItem: FC<SegmentItemProps> = ({
|
|
||||||
segment,
|
|
||||||
isExpanded,
|
|
||||||
headerContent,
|
|
||||||
constraintList,
|
|
||||||
}) => {
|
|
||||||
const [isOpen, setIsOpen] = useState(isExpanded || false);
|
|
||||||
const segmentDetailsId = useId();
|
|
||||||
|
|
||||||
const constraints = useMemo(() => {
|
|
||||||
if (constraintList) {
|
|
||||||
return constraintList;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (segment.constraints?.length) {
|
|
||||||
return (
|
|
||||||
<ConstraintsList>
|
|
||||||
{segment.constraints.map((constraint, index) => (
|
|
||||||
<ConstraintAccordionView
|
|
||||||
key={`${objectId(constraint)}-${index}`}
|
|
||||||
constraint={constraint}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ConstraintsList>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StyledNoConstraintsText>
|
|
||||||
This segment has no constraints.
|
|
||||||
</StyledNoConstraintsText>
|
|
||||||
);
|
|
||||||
}, [constraintList, segment.constraints]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<StyledConstraintListItem>
|
|
||||||
<StyledAccordion
|
|
||||||
expanded={isOpen}
|
|
||||||
disableGutters
|
|
||||||
TransitionProps={{ mountOnEnter: true, unmountOnExit: true }}
|
|
||||||
>
|
|
||||||
<StyledAccordionSummary
|
|
||||||
id={`segment-accordion-${segment.id}`}
|
|
||||||
tabIndex={-1}
|
|
||||||
aria-controls={segmentDetailsId}
|
|
||||||
>
|
|
||||||
<StrategyEvaluationItem type='Segment'>
|
|
||||||
<StyledLink to={`/segments/edit/${segment.id}`}>
|
|
||||||
{segment.name}
|
|
||||||
</StyledLink>
|
|
||||||
</StrategyEvaluationItem>
|
|
||||||
{headerContent ? headerContent : null}
|
|
||||||
{!isExpanded ? (
|
|
||||||
<StyledActionsContainer>
|
|
||||||
<StyledButton
|
|
||||||
aria-controls={segmentDetailsId}
|
|
||||||
size='small'
|
|
||||||
variant='outlined'
|
|
||||||
onClick={() => setIsOpen((value) => !value)}
|
|
||||||
>
|
|
||||||
{isOpen ? 'Close preview' : 'Preview'}
|
|
||||||
</StyledButton>
|
|
||||||
</StyledActionsContainer>
|
|
||||||
) : null}
|
|
||||||
</StyledAccordionSummary>
|
|
||||||
<StyledAccordionDetails>{constraints}</StyledAccordionDetails>
|
|
||||||
</StyledAccordion>
|
|
||||||
</StyledConstraintListItem>
|
|
||||||
);
|
|
||||||
};
|
|
@ -3,8 +3,8 @@ import { Fragment, useState } from 'react';
|
|||||||
import type { ISegment } from 'interfaces/segment';
|
import type { ISegment } from 'interfaces/segment';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { FeatureStrategySegmentChip } from 'component/feature/FeatureStrategy/FeatureStrategySegment/FeatureStrategySegmentChip';
|
import { FeatureStrategySegmentChip } from 'component/feature/FeatureStrategy/FeatureStrategySegment/FeatureStrategySegmentChip';
|
||||||
import { SegmentItem } from 'component/common/SegmentItem/LegacySegmentItem';
|
|
||||||
import { styled } from '@mui/material';
|
import { styled } from '@mui/material';
|
||||||
|
import { SegmentItem } from 'component/common/SegmentItem/SegmentItem';
|
||||||
|
|
||||||
interface IFeatureStrategySegmentListProps {
|
interface IFeatureStrategySegmentListProps {
|
||||||
segments: ISegment[];
|
segments: ISegment[];
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { StrategySeparator } from 'component/common/StrategySeparator/LegacyStrategySeparator';
|
|
||||||
import { SegmentItem } from 'component/common/SegmentItem/LegacySegmentItem';
|
|
||||||
import type { ISegment } from 'interfaces/segment';
|
import type { ISegment } from 'interfaces/segment';
|
||||||
|
import { SegmentItem } from 'component/common/SegmentItem/SegmentItem';
|
||||||
|
import { ConstraintSeparator } from 'component/common/ConstraintsList/ConstraintSeparator/ConstraintSeparator';
|
||||||
|
|
||||||
interface IFeatureOverviewSegmentProps {
|
interface IFeatureOverviewSegmentProps {
|
||||||
segments?: ISegment[];
|
segments?: ISegment[];
|
||||||
@ -23,7 +23,7 @@ export const FeatureOverviewSegment = ({
|
|||||||
<Fragment key={segment.id}>
|
<Fragment key={segment.id}>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={index > 0}
|
condition={index > 0}
|
||||||
show={<StrategySeparator text='AND' />}
|
show={<ConstraintSeparator />}
|
||||||
/>
|
/>
|
||||||
<SegmentItem segment={segment} disabled={disabled} />
|
<SegmentItem segment={segment} disabled={disabled} />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Fragment, type VFC } from 'react';
|
import { type FC, Fragment } from 'react';
|
||||||
import type { PlaygroundConstraintSchema } from 'openapi';
|
import type { PlaygroundConstraintSchema } from 'openapi';
|
||||||
import { objectId } from 'utils/objectId';
|
import { objectId } from 'utils/objectId';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { StrategySeparator } from 'component/common/StrategySeparator/LegacyStrategySeparator';
|
|
||||||
import { styled } from '@mui/material';
|
import { styled } from '@mui/material';
|
||||||
import { ConstraintAccordionView } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
||||||
|
import { ConstraintSeparator } from 'component/common/ConstraintsList/ConstraintSeparator/ConstraintSeparator';
|
||||||
|
|
||||||
interface IConstraintExecutionWithoutResultsProps {
|
interface IConstraintExecutionWithoutResultsProps {
|
||||||
constraints?: PlaygroundConstraintSchema[];
|
constraints?: PlaygroundConstraintSchema[];
|
||||||
@ -16,7 +16,7 @@ export const ConstraintExecutionWrapper = styled('div')(() => ({
|
|||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const ConstraintExecutionWithoutResults: VFC<
|
export const ConstraintExecutionWithoutResults: FC<
|
||||||
IConstraintExecutionWithoutResultsProps
|
IConstraintExecutionWithoutResultsProps
|
||||||
> = ({ constraints }) => {
|
> = ({ constraints }) => {
|
||||||
if (!constraints) return null;
|
if (!constraints) return null;
|
||||||
@ -27,13 +27,9 @@ export const ConstraintExecutionWithoutResults: VFC<
|
|||||||
<Fragment key={objectId(constraint)}>
|
<Fragment key={objectId(constraint)}>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={index > 0}
|
condition={index > 0}
|
||||||
show={<StrategySeparator text='AND' />}
|
show={<ConstraintSeparator />}
|
||||||
/>
|
|
||||||
<ConstraintAccordionView
|
|
||||||
constraint={constraint}
|
|
||||||
compact
|
|
||||||
disabled
|
|
||||||
/>
|
/>
|
||||||
|
<ConstraintAccordionView constraint={constraint} disabled />
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</ConstraintExecutionWrapper>
|
</ConstraintExecutionWrapper>
|
||||||
|
@ -2,8 +2,8 @@ import { Fragment, type VFC } from 'react';
|
|||||||
import type { PlaygroundSegmentSchema } from 'openapi';
|
import type { PlaygroundSegmentSchema } from 'openapi';
|
||||||
import { StrategySeparator } from 'component/common/StrategySeparator/LegacyStrategySeparator';
|
import { StrategySeparator } from 'component/common/StrategySeparator/LegacyStrategySeparator';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { SegmentItem } from 'component/common/SegmentItem/LegacySegmentItem';
|
|
||||||
import { ConstraintExecutionWithoutResults } from '../ConstraintExecution/ConstraintExecutionWithoutResults.tsx';
|
import { ConstraintExecutionWithoutResults } from '../ConstraintExecution/ConstraintExecutionWithoutResults.tsx';
|
||||||
|
import { SegmentItem } from 'component/common/SegmentItem/SegmentItem.tsx';
|
||||||
|
|
||||||
interface ISegmentExecutionWithoutResultProps {
|
interface ISegmentExecutionWithoutResultProps {
|
||||||
segments?: PlaygroundSegmentSchema[];
|
segments?: PlaygroundSegmentSchema[];
|
||||||
|
@ -2,8 +2,8 @@ import { Fragment, useState } from 'react';
|
|||||||
import type { ISegment } from 'interfaces/segment';
|
import type { ISegment } from 'interfaces/segment';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
import { FeatureStrategySegmentChip } from 'component/feature/FeatureStrategy/FeatureStrategySegment/FeatureStrategySegmentChip';
|
import { FeatureStrategySegmentChip } from 'component/feature/FeatureStrategy/FeatureStrategySegment/FeatureStrategySegmentChip';
|
||||||
import { SegmentItem } from 'component/common/SegmentItem/LegacySegmentItem';
|
|
||||||
import { styled } from '@mui/material';
|
import { styled } from '@mui/material';
|
||||||
|
import { SegmentItem } from 'component/common/SegmentItem/SegmentItem';
|
||||||
|
|
||||||
const StyledList = styled('div')(({ theme }) => ({
|
const StyledList = styled('div')(({ theme }) => ({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
Loading…
Reference in New Issue
Block a user