1
0
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:
Thomas Heartman 2025-06-17 15:38:42 +02:00 committed by GitHub
parent 0bad9101fc
commit 95049b8f9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -70,7 +70,7 @@ export const EditableConstraintsList = forwardRef<
<ConstraintsList>
{constraints.map((constraint, index) => (
<EditableConstraint
key={constraint[constraintId]}
key={constraint[constraintId] || index}
constraint={constraint}
onDelete={() => onDelete(index)}
onUpdate={onAutoSave(constraint[constraintId])}

View File

@ -24,15 +24,31 @@ import { useSegmentLimits } from 'hooks/api/getters/useSegmentLimits/useSegmentL
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
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 {
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) => {
const projectId = useOptionalPathParam('projectId');
const segmentId = useRequiredPathParam('segmentId');
const { segment } = useSegment(Number(segmentId));
const { segment: segmentWithoutConstraintIds } = useSegment(
Number(segmentId),
);
const segment = addIdSymbolToConstraints(segmentWithoutConstraintIds);
const { uiConfig } = useUiConfig();
const { setToastData, setToastApiError } = useToast();
const navigate = useNavigate();