From fe1e3566ee03b857ee55673495514af029df2b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Mon, 13 Mar 2023 10:25:48 +0000 Subject: [PATCH] fix: assume undefined instead of null on segment project (#3304) Assume `undefined` instead of `null` for project in terms of interfacing with segments: If the `project` field is not present, that means that it is not set, which means we're dealing with a "global" segment. If we want to unset `project` and make a segment global, we simply don't send the `project` property on our PUT method. --- frontend/src/component/segments/SegmentForm.tsx | 4 ++-- frontend/src/component/segments/SegmentFormStepOne.tsx | 6 +++--- frontend/src/component/segments/hooks/useSegmentForm.ts | 4 ++-- frontend/src/interfaces/segment.ts | 2 +- src/lib/db/segment-store.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/src/component/segments/SegmentForm.tsx b/frontend/src/component/segments/SegmentForm.tsx index 40bed15338..c0924bd400 100644 --- a/frontend/src/component/segments/SegmentForm.tsx +++ b/frontend/src/component/segments/SegmentForm.tsx @@ -12,11 +12,11 @@ export type SegmentFormMode = 'create' | 'edit'; interface ISegmentProps { name: string; description: string; - project: string | null; + project?: string; constraints: IConstraint[]; setName: React.Dispatch>; setDescription: React.Dispatch>; - setProject: React.Dispatch>; + setProject: React.Dispatch>; setConstraints: React.Dispatch>; handleSubmit: (e: any) => void; errors: { [key: string]: string }; diff --git a/frontend/src/component/segments/SegmentFormStepOne.tsx b/frontend/src/component/segments/SegmentFormStepOne.tsx index 398e1edbfe..a5fd0507e3 100644 --- a/frontend/src/component/segments/SegmentFormStepOne.tsx +++ b/frontend/src/component/segments/SegmentFormStepOne.tsx @@ -15,10 +15,10 @@ import useProjects from 'hooks/api/getters/useProjects/useProjects'; interface ISegmentFormPartOneProps { name: string; description: string; - project: string | null; + project?: string; setName: React.Dispatch>; setDescription: React.Dispatch>; - setProject: React.Dispatch>; + setProject: React.Dispatch>; errors: { [key: string]: string }; clearErrors: () => void; setCurrentStep: React.Dispatch>; @@ -115,7 +115,7 @@ export const SegmentFormStepOne: React.FC = ({ size="small" value={selectedProject} onChange={(_, newValue) => { - setProject(newValue?.id ?? null); + setProject(newValue?.id); }} options={projects} getOptionLabel={option => option.name} diff --git a/frontend/src/component/segments/hooks/useSegmentForm.ts b/frontend/src/component/segments/hooks/useSegmentForm.ts index cc8cf53113..782f86b1d2 100644 --- a/frontend/src/component/segments/hooks/useSegmentForm.ts +++ b/frontend/src/component/segments/hooks/useSegmentForm.ts @@ -5,12 +5,12 @@ import { useSegmentValidation } from 'hooks/api/getters/useSegmentValidation/use export const useSegmentForm = ( initialName = '', initialDescription = '', - initialProject: string | null = null, + initialProject?: string, initialConstraints: IConstraint[] = [] ) => { const [name, setName] = useState(initialName); const [description, setDescription] = useState(initialDescription); - const [project, setProject] = useState(initialProject); + const [project, setProject] = useState(initialProject); const [constraints, setConstraints] = useState(initialConstraints); const [errors, setErrors] = useState({}); diff --git a/frontend/src/interfaces/segment.ts b/frontend/src/interfaces/segment.ts index c0cffecfcb..b10f12fb50 100644 --- a/frontend/src/interfaces/segment.ts +++ b/frontend/src/interfaces/segment.ts @@ -4,7 +4,7 @@ export interface ISegment { id: number; name: string; description: string; - project: string | null; + project?: string; createdAt: string; createdBy: string; constraints: IConstraint[]; diff --git a/src/lib/db/segment-store.ts b/src/lib/db/segment-store.ts index 18085b6420..28899f1ca0 100644 --- a/src/lib/db/segment-store.ts +++ b/src/lib/db/segment-store.ts @@ -203,7 +203,7 @@ export default class SegmentStore implements ISegmentStore { id: row.id, name: row.name, description: row.description, - project: row.segment_project_id, + project: row.segment_project_id || undefined, constraints: row.constraints, createdBy: row.created_by, createdAt: row.created_at,