1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-01 13:47:27 +02:00

Remove IConstraintWithId type.

The next move is to make id required on IConstraint.
This commit is contained in:
Thomas Heartman 2025-07-18 13:23:18 +02:00
parent 4c358c88df
commit c394800a19
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78
6 changed files with 10 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import type { IConstraint, IConstraintWithId } from 'interfaces/strategy'; import type { IConstraint } from 'interfaces/strategy';
import { SegmentFormStepOne } from './SegmentFormStepOne.tsx'; import { SegmentFormStepOne } from './SegmentFormStepOne.tsx';
import { SegmentFormStepTwo } from './SegmentFormStepTwo.tsx'; import { SegmentFormStepTwo } from './SegmentFormStepTwo.tsx';
import type React from 'react'; import type React from 'react';
@ -14,7 +14,7 @@ interface ISegmentProps {
name: string; name: string;
description: string; description: string;
project?: string; project?: string;
constraints: IConstraintWithId[]; constraints: IConstraint[];
setName: React.Dispatch<React.SetStateAction<string>>; setName: React.Dispatch<React.SetStateAction<string>>;
setDescription: React.Dispatch<React.SetStateAction<string>>; setDescription: React.Dispatch<React.SetStateAction<string>>;
setProject: React.Dispatch<React.SetStateAction<string | undefined>>; setProject: React.Dispatch<React.SetStateAction<string | undefined>>;

View File

@ -8,7 +8,7 @@ import {
CREATE_SEGMENT, CREATE_SEGMENT,
UPDATE_PROJECT_SEGMENT, UPDATE_PROJECT_SEGMENT,
} from 'component/providers/AccessProvider/permissions'; } from 'component/providers/AccessProvider/permissions';
import type { IConstraintWithId } from 'interfaces/strategy.ts'; import type { IConstraint } from 'interfaces/strategy.ts';
const server = testServerSetup(); const server = testServerSetup();
@ -26,7 +26,7 @@ const setupRoutes = () => {
const defaultProps = { const defaultProps = {
project: undefined, project: undefined,
constraints: [] as IConstraintWithId[], constraints: [] as IConstraint[],
setConstraints: vi.fn(), setConstraints: vi.fn(),
setCurrentStep: vi.fn(), setCurrentStep: vi.fn(),
mode: 'create' as const, mode: 'create' as const,

View File

@ -13,7 +13,7 @@ import {
UPDATE_SEGMENT, UPDATE_SEGMENT,
} from 'component/providers/AccessProvider/permissions'; } from 'component/providers/AccessProvider/permissions';
import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashContext'; 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 { useNavigate } from 'react-router-dom';
import { EditableConstraintsList } from 'component/common/NewConstraintAccordion/ConstraintsList/EditableConstraintsList'; import { EditableConstraintsList } from 'component/common/NewConstraintAccordion/ConstraintsList/EditableConstraintsList';
import type { IEditableConstraintsListRef } 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 { interface ISegmentFormPartTwoProps {
project?: string; project?: string;
constraints: IConstraintWithId[]; constraints: IConstraint[];
setConstraints: React.Dispatch<React.SetStateAction<IConstraint[]>>; setConstraints: React.Dispatch<React.SetStateAction<IConstraint[]>>;
setCurrentStep: React.Dispatch<React.SetStateAction<SegmentFormStep>>; setCurrentStep: React.Dispatch<React.SetStateAction<SegmentFormStep>>;
mode: SegmentFormMode; mode: SegmentFormMode;

View File

@ -1,4 +1,4 @@
import type { IConstraint, IConstraintWithId } from 'interfaces/strategy'; import type { IConstraint } from 'interfaces/strategy';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { useSegmentValidation } from 'hooks/api/getters/useSegmentValidation/useSegmentValidation'; import { useSegmentValidation } from 'hooks/api/getters/useSegmentValidation/useSegmentValidation';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
@ -17,7 +17,7 @@ export const useSegmentForm = (
[constraintId]: uuidv4(), [constraintId]: uuidv4(),
...constraint, ...constraint,
})); }));
const [constraints, setConstraints] = useState<IConstraintWithId[]>( const [constraints, setConstraints] = useState<IConstraint[]>(
initialConstraintsWithId, initialConstraintsWithId,
); );
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});

View File

@ -68,10 +68,6 @@ export interface IConstraint {
[constraintId]?: string; [constraintId]?: string;
} }
export interface IConstraintWithId extends IConstraint {
[constraintId]: string;
}
export interface IFeatureStrategySortOrder { export interface IFeatureStrategySortOrder {
id: string; id: string;
sortOrder: number; sortOrder: number;

View File

@ -1,12 +1,10 @@
import { constraintId } from 'constants/constraintId'; import { constraintId } from 'constants/constraintId';
import { isDateOperator } from 'constants/operators'; import { isDateOperator } from 'constants/operators';
import type { IConstraintWithId } from 'interfaces/strategy'; import type { IConstraint } from 'interfaces/strategy';
import { operatorsForContext } from 'utils/operatorsForContext'; import { operatorsForContext } from 'utils/operatorsForContext';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
export const createEmptyConstraint = ( export const createEmptyConstraint = (contextName: string): IConstraint => {
contextName: string,
): IConstraintWithId => {
const operator = operatorsForContext(contextName)[0]; const operator = operatorsForContext(contextName)[0];
const value = isDateOperator(operator) ? new Date().toISOString() : ''; const value = isDateOperator(operator) ? new Date().toISOString() : '';