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