1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

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.
This commit is contained in:
Nuno Góis 2023-03-13 10:25:48 +00:00 committed by GitHub
parent 9e8094f97c
commit fe1e3566ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -12,11 +12,11 @@ export type SegmentFormMode = 'create' | 'edit';
interface ISegmentProps { interface ISegmentProps {
name: string; name: string;
description: string; description: string;
project: string | null; project?: string;
constraints: IConstraint[]; 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 | null>>; setProject: React.Dispatch<React.SetStateAction<string | undefined>>;
setConstraints: React.Dispatch<React.SetStateAction<IConstraint[]>>; setConstraints: React.Dispatch<React.SetStateAction<IConstraint[]>>;
handleSubmit: (e: any) => void; handleSubmit: (e: any) => void;
errors: { [key: string]: string }; errors: { [key: string]: string };

View File

@ -15,10 +15,10 @@ import useProjects from 'hooks/api/getters/useProjects/useProjects';
interface ISegmentFormPartOneProps { interface ISegmentFormPartOneProps {
name: string; name: string;
description: string; description: string;
project: string | null; project?: string;
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 | null>>; setProject: React.Dispatch<React.SetStateAction<string | undefined>>;
errors: { [key: string]: string }; errors: { [key: string]: string };
clearErrors: () => void; clearErrors: () => void;
setCurrentStep: React.Dispatch<React.SetStateAction<SegmentFormStep>>; setCurrentStep: React.Dispatch<React.SetStateAction<SegmentFormStep>>;
@ -115,7 +115,7 @@ export const SegmentFormStepOne: React.FC<ISegmentFormPartOneProps> = ({
size="small" size="small"
value={selectedProject} value={selectedProject}
onChange={(_, newValue) => { onChange={(_, newValue) => {
setProject(newValue?.id ?? null); setProject(newValue?.id);
}} }}
options={projects} options={projects}
getOptionLabel={option => option.name} getOptionLabel={option => option.name}

View File

@ -5,12 +5,12 @@ import { useSegmentValidation } from 'hooks/api/getters/useSegmentValidation/use
export const useSegmentForm = ( export const useSegmentForm = (
initialName = '', initialName = '',
initialDescription = '', initialDescription = '',
initialProject: string | null = null, initialProject?: string,
initialConstraints: IConstraint[] = [] initialConstraints: IConstraint[] = []
) => { ) => {
const [name, setName] = useState(initialName); const [name, setName] = useState(initialName);
const [description, setDescription] = useState(initialDescription); const [description, setDescription] = useState(initialDescription);
const [project, setProject] = useState<string | null>(initialProject); const [project, setProject] = useState<string | undefined>(initialProject);
const [constraints, setConstraints] = const [constraints, setConstraints] =
useState<IConstraint[]>(initialConstraints); useState<IConstraint[]>(initialConstraints);
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});

View File

@ -4,7 +4,7 @@ export interface ISegment {
id: number; id: number;
name: string; name: string;
description: string; description: string;
project: string | null; project?: string;
createdAt: string; createdAt: string;
createdBy: string; createdBy: string;
constraints: IConstraint[]; constraints: IConstraint[];

View File

@ -203,7 +203,7 @@ export default class SegmentStore implements ISegmentStore {
id: row.id, id: row.id,
name: row.name, name: row.name,
description: row.description, description: row.description,
project: row.segment_project_id, project: row.segment_project_id || undefined,
constraints: row.constraints, constraints: row.constraints,
createdBy: row.created_by, createdBy: row.created_by,
createdAt: row.created_at, createdAt: row.created_at,