mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-04 13:48:56 +02:00
feat: recently used constraints have use this button now (#9871)
Also splitted actions, so we have edit view actions, and view actions. 
This commit is contained in:
parent
3ef32dca93
commit
3c6d797234
@ -22,7 +22,7 @@ import {
|
|||||||
} from 'utils/operatorsForContext';
|
} from 'utils/operatorsForContext';
|
||||||
import { InvertedOperatorButton } from '../StyledToggleButton/InvertedOperatorButton/InvertedOperatorButton';
|
import { InvertedOperatorButton } from '../StyledToggleButton/InvertedOperatorButton/InvertedOperatorButton';
|
||||||
import { CaseSensitiveButton } from '../StyledToggleButton/CaseSensitiveButton/CaseSensitiveButton';
|
import { CaseSensitiveButton } from '../StyledToggleButton/CaseSensitiveButton/CaseSensitiveButton';
|
||||||
import { ConstraintAccordionHeaderActions } from '../../ConstraintAccordionHeaderActions/ConstraintAccordionHeaderActions';
|
import { ConstraintAccordionEditActions } from '../../ConstraintAccordionEditActions/ConstraintAccordionEditActions';
|
||||||
import { styled } from '@mui/material';
|
import { styled } from '@mui/material';
|
||||||
|
|
||||||
interface IConstraintAccordionViewHeader {
|
interface IConstraintAccordionViewHeader {
|
||||||
@ -207,7 +207,7 @@ export const ConstraintAccordionEditHeader = ({
|
|||||||
</StyledHeaderText>
|
</StyledHeaderText>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<ConstraintAccordionHeaderActions
|
<ConstraintAccordionEditActions
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
onUndo={onUndo}
|
onUndo={onUndo}
|
||||||
constraintChanges={constraintChanges}
|
constraintChanges={constraintChanges}
|
||||||
|
@ -6,7 +6,7 @@ import Undo from '@mui/icons-material/Undo';
|
|||||||
import { ConditionallyRender } from '../../ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from '../../ConditionallyRender/ConditionallyRender';
|
||||||
import type { IConstraint } from 'interfaces/strategy';
|
import type { IConstraint } from 'interfaces/strategy';
|
||||||
|
|
||||||
interface ConstraintAccordionHeaderActionsProps {
|
interface ConstraintAccordionEditActionsProps {
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onEdit?: () => void;
|
onEdit?: () => void;
|
||||||
onUndo?: () => void;
|
onUndo?: () => void;
|
||||||
@ -23,14 +23,14 @@ const StyledHeaderActions = styled('div')(({ theme }) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const ConstraintAccordionHeaderActions = ({
|
export const ConstraintAccordionEditActions = ({
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
onUndo,
|
onUndo,
|
||||||
constraintChanges = [],
|
constraintChanges = [],
|
||||||
disableDelete = false,
|
disableDelete = false,
|
||||||
disableEdit = false,
|
disableEdit = false,
|
||||||
}: ConstraintAccordionHeaderActionsProps) => {
|
}: ConstraintAccordionEditActionsProps) => {
|
||||||
const onEditClick =
|
const onEditClick =
|
||||||
onEdit &&
|
onEdit &&
|
||||||
((event: React.SyntheticEvent) => {
|
((event: React.SyntheticEvent) => {
|
@ -21,6 +21,7 @@ interface IConstraintAccordionViewProps {
|
|||||||
constraint: IConstraint;
|
constraint: IConstraint;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onEdit?: () => void;
|
onEdit?: () => void;
|
||||||
|
onUse?: () => void;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
compact?: boolean;
|
compact?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@ -67,6 +68,7 @@ export const ConstraintAccordionView = ({
|
|||||||
constraint,
|
constraint,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
onUse,
|
||||||
sx = undefined,
|
sx = undefined,
|
||||||
compact = false,
|
compact = false,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
@ -103,6 +105,7 @@ export const ConstraintAccordionView = ({
|
|||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
|
onUse={onUse}
|
||||||
singleValue={singleValue}
|
singleValue={singleValue}
|
||||||
allowExpand={setExpandable}
|
allowExpand={setExpandable}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
@ -2,15 +2,17 @@ import { ConstraintIcon } from 'component/common/LegacyConstraintAccordion/Const
|
|||||||
import type { IConstraint } from 'interfaces/strategy';
|
import type { IConstraint } from 'interfaces/strategy';
|
||||||
import { ConstraintAccordionViewHeaderInfo } from './ConstraintAccordionViewHeaderInfo';
|
import { ConstraintAccordionViewHeaderInfo } from './ConstraintAccordionViewHeaderInfo';
|
||||||
import { ConstraintAccordionViewHeaderInfo as LegacyConstraintAccordionViewHeaderInfo } from './LegacyConstraintAccordionViewHeaderInfo';
|
import { ConstraintAccordionViewHeaderInfo as LegacyConstraintAccordionViewHeaderInfo } from './LegacyConstraintAccordionViewHeaderInfo';
|
||||||
import { ConstraintAccordionHeaderActions } from '../../ConstraintAccordionHeaderActions/ConstraintAccordionHeaderActions';
|
|
||||||
import { styled } from '@mui/system';
|
import { styled } from '@mui/system';
|
||||||
import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext';
|
import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext';
|
||||||
import { useUiFlag } from 'hooks/useUiFlag';
|
import { useUiFlag } from 'hooks/useUiFlag';
|
||||||
|
import { ConstraintAccordionViewActions } from '../../ConstraintAccordionViewActions/ConstraintAccordionViewActions';
|
||||||
|
import { ConstraintAccordionEditActions } from '../../ConstraintAccordionEditActions/ConstraintAccordionEditActions';
|
||||||
|
|
||||||
interface IConstraintAccordionViewHeaderProps {
|
interface IConstraintAccordionViewHeaderProps {
|
||||||
constraint: IConstraint;
|
constraint: IConstraint;
|
||||||
onDelete?: () => void;
|
onDelete?: () => void;
|
||||||
onEdit?: () => void;
|
onEdit?: () => void;
|
||||||
|
onUse?: () => void;
|
||||||
singleValue: boolean;
|
singleValue: boolean;
|
||||||
expanded: boolean;
|
expanded: boolean;
|
||||||
allowExpand: (shouldExpand: boolean) => void;
|
allowExpand: (shouldExpand: boolean) => void;
|
||||||
@ -33,6 +35,7 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
constraint,
|
constraint,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
onUse,
|
||||||
singleValue,
|
singleValue,
|
||||||
allowExpand,
|
allowExpand,
|
||||||
expanded,
|
expanded,
|
||||||
@ -68,11 +71,16 @@ export const ConstraintAccordionViewHeader = ({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<ConstraintAccordionHeaderActions
|
{onUse ? (
|
||||||
|
<ConstraintAccordionViewActions onUse={onUse} />
|
||||||
|
) : (
|
||||||
|
// @deprecated : remove onEdit and onDelete from current file together with NewConstraintAccordionList and addEditStrategy flag
|
||||||
|
<ConstraintAccordionEditActions
|
||||||
onEdit={onEdit}
|
onEdit={onEdit}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
disableEdit={disableEdit}
|
disableEdit={disableEdit}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</StyledContainer>
|
</StyledContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
import type React from 'react';
|
||||||
|
import { Button, styled, Tooltip } from '@mui/material';
|
||||||
|
import { ConditionallyRender } from '../../ConditionallyRender/ConditionallyRender';
|
||||||
|
|
||||||
|
interface ConstraintAccordionHeaderActionsProps {
|
||||||
|
onUse?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StyledHeaderActions = styled('div')(({ theme }) => ({
|
||||||
|
marginLeft: 'auto',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
[theme.breakpoints.down('sm')]: {
|
||||||
|
display: 'none',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const StyledButton = styled(Button)(({ theme }) => ({
|
||||||
|
fontSize: theme.typography.body2.fontSize,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const ConstraintAccordionViewActions = ({
|
||||||
|
onUse,
|
||||||
|
}: ConstraintAccordionHeaderActionsProps) => {
|
||||||
|
const onUseClick =
|
||||||
|
onUse &&
|
||||||
|
((event: React.SyntheticEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onUse();
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StyledHeaderActions>
|
||||||
|
<ConditionallyRender
|
||||||
|
condition={Boolean(onUseClick)}
|
||||||
|
show={
|
||||||
|
<Tooltip title='Use constraint' arrow>
|
||||||
|
<StyledButton
|
||||||
|
variant='text'
|
||||||
|
color='primary'
|
||||||
|
onClick={onUseClick}
|
||||||
|
data-testid='USE_CONSTRAINT_BUTTON'
|
||||||
|
>
|
||||||
|
Use this
|
||||||
|
</StyledButton>
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</StyledHeaderActions>
|
||||||
|
);
|
||||||
|
};
|
@ -166,8 +166,6 @@ export const NewConstraintAccordionList = forwardRef<
|
|||||||
<ConstraintAccordionView
|
<ConstraintAccordionView
|
||||||
key={constraint[constraintId]}
|
key={constraint[constraintId]}
|
||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
onEdit={onEdit?.bind(null, constraint)}
|
|
||||||
onDelete={onRemove?.bind(null, index)}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
|
@ -139,7 +139,11 @@ export const FeatureStrategyConstraintAccordionList = forwardRef<
|
|||||||
</Button>
|
</Button>
|
||||||
<ConditionallyRender
|
<ConditionallyRender
|
||||||
condition={Boolean(addEditStrategy)}
|
condition={Boolean(addEditStrategy)}
|
||||||
show={<RecentlyUsedConstraints />}
|
show={
|
||||||
|
<RecentlyUsedConstraints
|
||||||
|
setConstraints={setConstraints}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ import { styled, Typography } from '@mui/material';
|
|||||||
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
import { ConstraintAccordionView } from 'component/common/NewConstraintAccordion/ConstraintAccordionView/ConstraintAccordionView';
|
||||||
import { constraintId } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionList/createEmptyConstraint';
|
import { constraintId } from 'component/common/LegacyConstraintAccordion/ConstraintAccordionList/createEmptyConstraint';
|
||||||
import { useRecentlyUsedConstraints } from './useRecentlyUsedConstraints';
|
import { useRecentlyUsedConstraints } from './useRecentlyUsedConstraints';
|
||||||
|
import type { IConstraint } from 'interfaces/strategy';
|
||||||
|
|
||||||
type IRecentlyUsedConstraintsProps = {
|
type IRecentlyUsedConstraintsProps = {
|
||||||
temporary?: string;
|
setConstraints?: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledContainer = styled('div')(({ theme }) => ({
|
const StyledContainer = styled('div')(({ theme }) => ({
|
||||||
@ -24,11 +25,11 @@ const StyledConstraintsContainer = styled('div')(({ theme }) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const RecentlyUsedConstraints = ({
|
export const RecentlyUsedConstraints = ({
|
||||||
temporary,
|
setConstraints,
|
||||||
}: IRecentlyUsedConstraintsProps) => {
|
}: IRecentlyUsedConstraintsProps) => {
|
||||||
const { items: recentlyUsedConstraints } = useRecentlyUsedConstraints();
|
const { items: recentlyUsedConstraints } = useRecentlyUsedConstraints();
|
||||||
|
|
||||||
if (recentlyUsedConstraints.length === 0) {
|
if (recentlyUsedConstraints.length === 0 || !setConstraints) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +41,9 @@ export const RecentlyUsedConstraints = ({
|
|||||||
<ConstraintAccordionView
|
<ConstraintAccordionView
|
||||||
key={constraint[constraintId]}
|
key={constraint[constraintId]}
|
||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
|
onUse={() => {
|
||||||
|
setConstraints((prev) => [...prev, constraint]);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</StyledConstraintsContainer>
|
</StyledConstraintsContainer>
|
||||||
|
Loading…
Reference in New Issue
Block a user