From c394800a1981e24e99344298c99a1d25635e1f31 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 18 Jul 2025 13:23:18 +0200 Subject: [PATCH] Remove IConstraintWithId type. The next move is to make id required on IConstraint. --- frontend/src/component/segments/SegmentForm.tsx | 4 ++-- frontend/src/component/segments/SegmentFormStepTwo.test.tsx | 4 ++-- frontend/src/component/segments/SegmentFormStepTwo.tsx | 4 ++-- frontend/src/component/segments/hooks/useSegmentForm.ts | 4 ++-- frontend/src/interfaces/strategy.ts | 4 ---- frontend/src/utils/createEmptyConstraint.ts | 6 ++---- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/frontend/src/component/segments/SegmentForm.tsx b/frontend/src/component/segments/SegmentForm.tsx index 0d3cfcee14..8a1c38c7ad 100644 --- a/frontend/src/component/segments/SegmentForm.tsx +++ b/frontend/src/component/segments/SegmentForm.tsx @@ -1,4 +1,4 @@ -import type { IConstraint, IConstraintWithId } from 'interfaces/strategy'; +import type { IConstraint } from 'interfaces/strategy'; import { SegmentFormStepOne } from './SegmentFormStepOne.tsx'; import { SegmentFormStepTwo } from './SegmentFormStepTwo.tsx'; import type React from 'react'; @@ -14,7 +14,7 @@ interface ISegmentProps { name: string; description: string; project?: string; - constraints: IConstraintWithId[]; + constraints: IConstraint[]; setName: React.Dispatch>; setDescription: React.Dispatch>; setProject: React.Dispatch>; diff --git a/frontend/src/component/segments/SegmentFormStepTwo.test.tsx b/frontend/src/component/segments/SegmentFormStepTwo.test.tsx index 6a8efec383..3c8160d348 100644 --- a/frontend/src/component/segments/SegmentFormStepTwo.test.tsx +++ b/frontend/src/component/segments/SegmentFormStepTwo.test.tsx @@ -8,7 +8,7 @@ import { CREATE_SEGMENT, UPDATE_PROJECT_SEGMENT, } from 'component/providers/AccessProvider/permissions'; -import type { IConstraintWithId } from 'interfaces/strategy.ts'; +import type { IConstraint } from 'interfaces/strategy.ts'; const server = testServerSetup(); @@ -26,7 +26,7 @@ const setupRoutes = () => { const defaultProps = { project: undefined, - constraints: [] as IConstraintWithId[], + constraints: [] as IConstraint[], setConstraints: vi.fn(), setCurrentStep: vi.fn(), mode: 'create' as const, diff --git a/frontend/src/component/segments/SegmentFormStepTwo.tsx b/frontend/src/component/segments/SegmentFormStepTwo.tsx index abea3aeb9e..ddb84cf021 100644 --- a/frontend/src/component/segments/SegmentFormStepTwo.tsx +++ b/frontend/src/component/segments/SegmentFormStepTwo.tsx @@ -13,7 +13,7 @@ import { UPDATE_SEGMENT, } from 'component/providers/AccessProvider/permissions'; import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext'; -import type { IConstraint, IConstraintWithId } from 'interfaces/strategy'; +import type { IConstraint } from 'interfaces/strategy'; import { useNavigate } from 'react-router-dom'; import { EditableConstraintsList } from 'component/common/NewConstraintAccordion/ConstraintsList/EditableConstraintsList'; import type { IEditableConstraintsListRef } from 'component/common/NewConstraintAccordion/ConstraintsList/EditableConstraintsList'; @@ -33,7 +33,7 @@ import { GO_BACK } from 'constants/navigate'; interface ISegmentFormPartTwoProps { project?: string; - constraints: IConstraintWithId[]; + constraints: IConstraint[]; setConstraints: React.Dispatch>; setCurrentStep: React.Dispatch>; mode: SegmentFormMode; diff --git a/frontend/src/component/segments/hooks/useSegmentForm.ts b/frontend/src/component/segments/hooks/useSegmentForm.ts index 951619715d..e8e0d79992 100644 --- a/frontend/src/component/segments/hooks/useSegmentForm.ts +++ b/frontend/src/component/segments/hooks/useSegmentForm.ts @@ -1,4 +1,4 @@ -import type { IConstraint, IConstraintWithId } from 'interfaces/strategy'; +import type { IConstraint } from 'interfaces/strategy'; import { useEffect, useState } from 'react'; import { useSegmentValidation } from 'hooks/api/getters/useSegmentValidation/useSegmentValidation'; import { v4 as uuidv4 } from 'uuid'; @@ -17,7 +17,7 @@ export const useSegmentForm = ( [constraintId]: uuidv4(), ...constraint, })); - const [constraints, setConstraints] = useState( + const [constraints, setConstraints] = useState( initialConstraintsWithId, ); const [errors, setErrors] = useState({}); diff --git a/frontend/src/interfaces/strategy.ts b/frontend/src/interfaces/strategy.ts index 0f46621f79..b2aa226009 100644 --- a/frontend/src/interfaces/strategy.ts +++ b/frontend/src/interfaces/strategy.ts @@ -68,10 +68,6 @@ export interface IConstraint { [constraintId]?: string; } -export interface IConstraintWithId extends IConstraint { - [constraintId]: string; -} - export interface IFeatureStrategySortOrder { id: string; sortOrder: number; diff --git a/frontend/src/utils/createEmptyConstraint.ts b/frontend/src/utils/createEmptyConstraint.ts index 49e2887cbf..f05b19f1df 100644 --- a/frontend/src/utils/createEmptyConstraint.ts +++ b/frontend/src/utils/createEmptyConstraint.ts @@ -1,12 +1,10 @@ import { constraintId } from 'constants/constraintId'; import { isDateOperator } from 'constants/operators'; -import type { IConstraintWithId } from 'interfaces/strategy'; +import type { IConstraint } from 'interfaces/strategy'; import { operatorsForContext } from 'utils/operatorsForContext'; import { v4 as uuidv4 } from 'uuid'; -export const createEmptyConstraint = ( - contextName: string, -): IConstraintWithId => { +export const createEmptyConstraint = (contextName: string): IConstraint => { const operator = operatorsForContext(contextName)[0]; const value = isDateOperator(operator) ? new Date().toISOString() : '';