From 9795904facbfe78f4cd8a9a5397feb4a6235aab4 Mon Sep 17 00:00:00 2001 From: M Fahru Date: Wed, 1 Feb 2023 09:31:13 -0700 Subject: [PATCH] Add nullcheck to tag name to avoid crashing the client (#11519) GitOrigin-RevId: 917fcffa672e2626203275ea5e62ce9388366f8e --- services/web/app/src/Features/Tags/types.d.ts | 2 +- .../components/dropdown/projects-dropdown.tsx | 2 +- .../project-list/components/modals/edit-tag-modal.tsx | 2 +- .../project-list/components/modals/rename-tag-modal.tsx | 2 +- .../project-list/components/sidebar/tags-list.tsx | 2 +- .../table/project-tools/buttons/tags-dropdown.tsx | 2 +- .../project-list/context/project-list-context.tsx | 9 ++++++++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/services/web/app/src/Features/Tags/types.d.ts b/services/web/app/src/Features/Tags/types.d.ts index 89d00e7487..3886cf0424 100644 --- a/services/web/app/src/Features/Tags/types.d.ts +++ b/services/web/app/src/Features/Tags/types.d.ts @@ -1,6 +1,6 @@ export type Tag = { _id: string user_id: string - name: string + name: string | null project_ids?: string[] } diff --git a/services/web/frontend/js/features/project-list/components/dropdown/projects-dropdown.tsx b/services/web/frontend/js/features/project-list/components/dropdown/projects-dropdown.tsx index 6b7d521b8c..59a51c10ad 100644 --- a/services/web/frontend/js/features/project-list/components/dropdown/projects-dropdown.tsx +++ b/services/web/frontend/js/features/project-list/components/dropdown/projects-dropdown.tsx @@ -66,7 +66,7 @@ function ProjectsDropdown() { const tag = tags.find(({ _id: id }) => id === selectedTagId) if (tag) { - setTitle(tag.name) + setTitle(tag.name ?? '') } } }, [filter, tags, selectedTagId, t]) diff --git a/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx b/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx index 745cbeae9f..957f870214 100644 --- a/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx +++ b/services/web/frontend/js/features/project-list/components/modals/edit-tag-modal.tsx @@ -86,7 +86,7 @@ export default function EditTagModal({ type="text" placeholder="Tag Name" name="new-tag-name" - value={newTagName === undefined ? tag.name : newTagName} + value={newTagName === undefined ? tag.name ?? '' : newTagName} required onChange={e => setNewTagName(e.target.value)} /> diff --git a/services/web/frontend/js/features/project-list/components/modals/rename-tag-modal.tsx b/services/web/frontend/js/features/project-list/components/modals/rename-tag-modal.tsx index 70110efb1a..3db7260daf 100644 --- a/services/web/frontend/js/features/project-list/components/modals/rename-tag-modal.tsx +++ b/services/web/frontend/js/features/project-list/components/modals/rename-tag-modal.tsx @@ -85,7 +85,7 @@ export default function RenameTagModal({ type="text" placeholder="Tag Name" name="new-tag-name" - value={newTagName === undefined ? tag.name : newTagName} + value={newTagName === undefined ? tag.name ?? '' : newTagName} required onChange={e => setNewTagName(e.target.value)} /> diff --git a/services/web/frontend/js/features/project-list/components/sidebar/tags-list.tsx b/services/web/frontend/js/features/project-list/components/sidebar/tags-list.tsx index c43dfb2dda..8cf9e18326 100644 --- a/services/web/frontend/js/features/project-list/components/sidebar/tags-list.tsx +++ b/services/web/frontend/js/features/project-list/components/sidebar/tags-list.tsx @@ -39,7 +39,7 @@ export default function TagsList() { {t('new_folder')} - {sortBy(tags, tag => tag.name.toLowerCase()).map(tag => { + {sortBy(tags, tag => tag.name?.toLowerCase()).map(tag => { return (
  • {t('add_to_folder')}
  • - {sortBy(tags, tag => tag.name.toLowerCase()).map(tag => { + {sortBy(tags, tag => tag.name?.toLowerCase()).map(tag => { return (