Skip to content

Commit

Permalink
chore: add id to constraint
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps committed Feb 6, 2025
1 parent 27cb45d commit 611b53a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 196 deletions.
184 changes: 0 additions & 184 deletions ui/src/app/flags/rulesApi.ts

This file was deleted.

5 changes: 3 additions & 2 deletions ui/src/app/segments/segmentsApi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
import { createApi } from '@reduxjs/toolkit/query/react';
import { SortingState } from '@tanstack/react-table';
import { v4 as uuid } from 'uuid';

import { IConstraint } from '~/types/Constraint';
import { IResourceListResponse, IResourceResponse } from '~/types/Resource';
Expand Down Expand Up @@ -86,9 +87,9 @@ export const segmentsApi = createApi({
return {
...response.resource.payload,
constraints: response.resource.payload.constraints?.map(
(c: IConstraint, i: number) => ({
(c: IConstraint) => ({
...c,
rank: i
id: uuid()
})
)
};
Expand Down
11 changes: 5 additions & 6 deletions ui/src/components/flags/FlagFormContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FormikProps } from 'formik';
import React, { ReactNode, createContext } from 'react';
import { v4 as uuid } from 'uuid';

import { IFlag, IFlagBase } from '~/types/Flag';
import { IFlag } from '~/types/Flag';
import { IRollout } from '~/types/Rollout';
import { IRule } from '~/types/Rule';
import { IVariant } from '~/types/Variant';
Expand All @@ -11,7 +11,7 @@ interface FlagFormContextProps {
variants: IVariant[];
rules: IRule[];
rollouts: IRollout[];
updateFlag: (f: Partial<IFlagBase>) => void;
updateFlag: (f: Partial<IFlag>) => void;
setRules: (rules: IRule[]) => void;
createRule: (r: IRule) => void;
updateRule: (r: IRule) => void;
Expand Down Expand Up @@ -57,7 +57,7 @@ export const FlagFormProvider: React.FC<FlagFormProviderProps> = ({
}) => {
const { rules, variants, rollouts } = formik.values;

const updateFlag = (f: Partial<IFlagBase>) => {
const updateFlag = (f: Partial<IFlag>) => {
if ('name' in f) {
formik.setFieldValue('name', f.name);
}
Expand Down Expand Up @@ -104,14 +104,13 @@ export const FlagFormProvider: React.FC<FlagFormProviderProps> = ({
};

const createVariant = (v: IVariant) => {
v.id = uuid();
const newVariants = [...(variants || []), v];
formik.setFieldValue('variants', newVariants);
};

const updateVariant = (v: IVariant) => {
const newVariants = [...(variants || [])];
const index = newVariants.findIndex((variant) => variant.id === v.id);
const index = newVariants.findIndex((variant) => variant.key === v.key);
newVariants[index] = v;
formik.setFieldValue('variants', newVariants);
};
Expand All @@ -125,7 +124,7 @@ export const FlagFormProvider: React.FC<FlagFormProviderProps> = ({
});

const newVariants = [...(variants || [])];
const index = newVariants.findIndex((variant) => variant.id === v.id);
const index = newVariants.findIndex((variant) => variant.key === v.key);
newVariants.splice(index, 1);
formik.setFieldValue('variants', newVariants);
};
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/rules/SortableRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function SortableRule(props: SortableRuleProps) {
transform,
transition
} = useSortable({
id: rule.id
id: rule.id!
});

const style = transform
Expand Down
3 changes: 0 additions & 3 deletions ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { eventKey, eventSlice } from './app/events/eventSlice';
import { analyticsApi } from './app/flags/analyticsApi';
import { flagsApi, flagsTableSlice } from './app/flags/flagsApi';
import { rolloutsApi } from './app/flags/rolloutsApi';
import { rulesApi } from './app/flags/rulesApi';
import { metaSlice } from './app/meta/metaSlice';
import {
preferencesKey,
Expand Down Expand Up @@ -129,7 +128,6 @@ export const store = configureStore({
[namespaceApi.reducerPath]: namespaceApi.reducer,
[flagsApi.reducerPath]: flagsApi.reducer,
[segmentsApi.reducerPath]: segmentsApi.reducer,
[rulesApi.reducerPath]: rulesApi.reducer,
[rolloutsApi.reducerPath]: rolloutsApi.reducer,
[tokensApi.reducerPath]: tokensApi.reducer,
[authProvidersApi.reducerPath]: authProvidersApi.reducer,
Expand All @@ -143,7 +141,6 @@ export const store = configureStore({
namespaceApi.middleware,
flagsApi.middleware,
segmentsApi.middleware,
rulesApi.middleware,
rolloutsApi.middleware,
tokensApi.middleware,
authProvidersApi.middleware,
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/Constraint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface IConstraint {
id?: string;
property: string;
type: ConstraintType;
operator: string;
Expand Down

0 comments on commit 611b53a

Please sign in to comment.