Add nullcheck to tag name to avoid crashing the client (#11519)

GitOrigin-RevId: 917fcffa672e2626203275ea5e62ce9388366f8e
This commit is contained in:
M Fahru 2023-02-01 09:31:13 -07:00 committed by Copybot
parent e5f8b991ba
commit 9795904fac
7 changed files with 14 additions and 7 deletions

View file

@ -1,6 +1,6 @@
export type Tag = {
_id: string
user_id: string
name: string
name: string | null
project_ids?: string[]
}

View file

@ -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])

View file

@ -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)}
/>

View file

@ -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)}
/>

View file

@ -39,7 +39,7 @@ export default function TagsList() {
<span className="name">{t('new_folder')}</span>
</Button>
</li>
{sortBy(tags, tag => tag.name.toLowerCase()).map(tag => {
{sortBy(tags, tag => tag.name?.toLowerCase()).map(tag => {
return (
<li
className={`tag ${selectedTagId === tag._id ? 'active' : ''}`}

View file

@ -95,7 +95,7 @@ function TagsDropdown() {
<li className="dropdown-header" role="heading" aria-level={3}>
{t('add_to_folder')}
</li>
{sortBy(tags, tag => tag.name.toLowerCase()).map(tag => {
{sortBy(tags, tag => tag.name?.toLowerCase()).map(tag => {
return (
<li key={tag._id}>
<Button

View file

@ -138,7 +138,14 @@ export function ProjectListProvider({ children }: ProjectListProviderProps) {
const [selectedTagId, setSelectedTagId] = usePersistedState<
string | undefined
>('project-list-selected-tag-id', undefined)
const [tags, setTags] = useState<Tag[]>(getMeta('ol-tags', []) as Tag[])
const olTags: Tag[] = getMeta('ol-tags', [])
const [tags, setTags] = useState<Tag[]>(() =>
// `tag.name` data may be null for some old users
olTags.map(tag => ({ ...tag, name: tag.name ?? '' }))
)
const [searchText, setSearchText] = useState('')
const {