mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-01 13:47:27 +02:00
adapt wrapper logic
This commit is contained in:
parent
941b5dc236
commit
10e5554de3
@ -14,7 +14,7 @@ export interface IEditableConstraintsListRef {
|
||||
|
||||
export interface IEditableConstraintsListProps {
|
||||
constraints: IConstraint[];
|
||||
setConstraints?: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
||||
setConstraints: React.Dispatch<React.SetStateAction<IConstraint[]>>;
|
||||
}
|
||||
|
||||
const StyledContainer = styled('div')({
|
||||
@ -29,29 +29,16 @@ export const EditableConstraintsList = forwardRef<
|
||||
>(({ constraints, setConstraints }, ref) => {
|
||||
const { context } = useUnleashContext();
|
||||
|
||||
const onRemove =
|
||||
setConstraints &&
|
||||
((index: number) => {
|
||||
setConstraints(
|
||||
produce((draft) => {
|
||||
draft.splice(index, 1);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
const onSave =
|
||||
setConstraints &&
|
||||
((index: number, constraint: IConstraint) => {
|
||||
setConstraints(
|
||||
produce((draft) => {
|
||||
draft[index] = constraint;
|
||||
}),
|
||||
);
|
||||
});
|
||||
const onDelete = (index: number) => {
|
||||
setConstraints(
|
||||
produce((draft) => {
|
||||
draft.splice(index, 1);
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const onAutoSave =
|
||||
setConstraints &&
|
||||
((id: string | undefined) => (constraint: IConstraint) => {
|
||||
(id: string | undefined) => (constraint: IConstraint) => {
|
||||
setConstraints(
|
||||
produce((draft) => {
|
||||
return draft.map((oldConstraint) => {
|
||||
@ -62,7 +49,7 @@ export const EditableConstraintsList = forwardRef<
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
if (context.length === 0) {
|
||||
return null;
|
||||
@ -75,9 +62,8 @@ export const EditableConstraintsList = forwardRef<
|
||||
<EditableConstraintWrapper
|
||||
key={constraint[constraintId]}
|
||||
constraint={constraint}
|
||||
onDelete={onRemove?.bind(null, index)}
|
||||
onSave={onSave!.bind(null, index)}
|
||||
onAutoSave={onAutoSave?.(constraint[constraintId])}
|
||||
onDelete={() => onDelete(index)}
|
||||
onAutoSave={onAutoSave(constraint[constraintId])}
|
||||
/>
|
||||
))}
|
||||
</ConstraintsList>
|
||||
|
@ -147,12 +147,15 @@ export const NewConstraintAccordionList = forwardRef<
|
||||
<ConstraintsList>
|
||||
{constraints.map((constraint, index) =>
|
||||
addEditStrategy ? (
|
||||
state.get(constraint)?.editing ? (
|
||||
state.get(constraint)?.editing &&
|
||||
Boolean(setConstraints) ? (
|
||||
<EditableConstraintWrapper
|
||||
key={constraint[constraintId]}
|
||||
constraint={constraint}
|
||||
onCancel={onCancel?.bind(null, index)}
|
||||
onDelete={onRemove?.bind(null, index)}
|
||||
// @ts-ignore todo: find a better way to do this
|
||||
onDelete={() => onRemove(index)}
|
||||
// @ts-ignore
|
||||
onAutoSave={onAutoSave(constraintId)}
|
||||
/>
|
||||
) : (
|
||||
<ConstraintAccordionView
|
||||
|
@ -94,7 +94,10 @@ export const FeatureStrategyConstraintAccordionList = forwardRef<
|
||||
/>
|
||||
</StyledHelpIconBox>
|
||||
<ConditionallyRender
|
||||
condition={Boolean(addEditStrategy)}
|
||||
condition={
|
||||
Boolean(addEditStrategy) &&
|
||||
Boolean(setConstraints)
|
||||
}
|
||||
show={
|
||||
<EditableConstraintsList
|
||||
ref={ref}
|
||||
|
Loading…
Reference in New Issue
Block a user