mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-18 13:48:58 +02:00
Fix/constraint editing is broken in segment form (#10152)
This adds constraint ids to segment constraints used in editing segments. Without them, there was a bug where when you went to edit the segment, all constraints would be invisibly set to the same constraint.
This commit is contained in:
parent
0bad9101fc
commit
95049b8f9f
@ -70,7 +70,7 @@ export const EditableConstraintsList = forwardRef<
|
|||||||
<ConstraintsList>
|
<ConstraintsList>
|
||||||
{constraints.map((constraint, index) => (
|
{constraints.map((constraint, index) => (
|
||||||
<EditableConstraint
|
<EditableConstraint
|
||||||
key={constraint[constraintId]}
|
key={constraint[constraintId] || index}
|
||||||
constraint={constraint}
|
constraint={constraint}
|
||||||
onDelete={() => onDelete(index)}
|
onDelete={() => onDelete(index)}
|
||||||
onUpdate={onAutoSave(constraint[constraintId])}
|
onUpdate={onAutoSave(constraint[constraintId])}
|
||||||
|
@ -24,15 +24,31 @@ import { useSegmentLimits } from 'hooks/api/getters/useSegmentLimits/useSegmentL
|
|||||||
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
|
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
|
||||||
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
||||||
import { useHighestPermissionChangeRequestEnvironment } from 'hooks/useHighestPermissionChangeRequestEnvironment';
|
import { useHighestPermissionChangeRequestEnvironment } from 'hooks/useHighestPermissionChangeRequestEnvironment';
|
||||||
|
import type { ISegment } from 'interfaces/segment.ts';
|
||||||
|
import { constraintId } from 'constants/constraintId.ts';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
interface IEditSegmentProps {
|
interface IEditSegmentProps {
|
||||||
modal?: boolean;
|
modal?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addIdSymbolToConstraints = (segment?: ISegment): ISegment | undefined => {
|
||||||
|
if (!segment) return;
|
||||||
|
|
||||||
|
const constraints = segment.constraints.map((constraint) => {
|
||||||
|
return { ...constraint, [constraintId]: uuidv4() };
|
||||||
|
});
|
||||||
|
|
||||||
|
return { ...segment, constraints };
|
||||||
|
};
|
||||||
|
|
||||||
export const EditSegment = ({ modal }: IEditSegmentProps) => {
|
export const EditSegment = ({ modal }: IEditSegmentProps) => {
|
||||||
const projectId = useOptionalPathParam('projectId');
|
const projectId = useOptionalPathParam('projectId');
|
||||||
const segmentId = useRequiredPathParam('segmentId');
|
const segmentId = useRequiredPathParam('segmentId');
|
||||||
const { segment } = useSegment(Number(segmentId));
|
const { segment: segmentWithoutConstraintIds } = useSegment(
|
||||||
|
Number(segmentId),
|
||||||
|
);
|
||||||
|
const segment = addIdSymbolToConstraints(segmentWithoutConstraintIds);
|
||||||
const { uiConfig } = useUiConfig();
|
const { uiConfig } = useUiConfig();
|
||||||
const { setToastData, setToastApiError } = useToast();
|
const { setToastData, setToastApiError } = useToast();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
Loading…
Reference in New Issue
Block a user