Skip to content

Commit

Permalink
fix(web): Use || instead of ?? for JSON.parse fallback (#16360)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
RunarVestmann and kodiakhq[bot] authored Oct 10, 2024
1 parent 8e82475 commit 0c4b341
Show file tree
Hide file tree
Showing 30 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const OrganizationIslandFooter = () => {
})

const namespace = useMemo(
() => JSON.parse(data?.getNamespace?.fields ?? '{}'),
() => JSON.parse(data?.getNamespace?.fields || '{}'),
[data?.getNamespace?.fields],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const FiskistofaHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FjarsyslaRikisinsHeader = ({
}: HeaderProps) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const GevHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const HeilbrigdisstofnunAusturlandsHeader: React.FC<
const { linkResolver } = useLinkResolver()

const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const HeilbrigdisstofnunNordurlandsHeader: React.FC<
> = ({ organizationPage, logoAltText }) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const HeilbrigdisstofnunSudurlandsHeader: React.FC<
const { linkResolver } = useLinkResolver()

const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const HmsHeader: React.FC<HeaderProps> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const HveHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const IcelandicNaturalDisasterInsuranceHeader: React.FC<HeaderProps> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const IcelandicNaturalDisasterInsuranceHeader: React.FC<HeaderProps> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const LandskjorstjornHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const LandlaeknirHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const RikislogmadurHeader = ({
}: HeaderProps) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const RikissaksoknariHeader = ({
}: HeaderProps) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SAkHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ShhHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
const { linkResolver } = useLinkResolver()

const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const SyslumennHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const TransportAuthorityHeader: React.FC<HeaderProps> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const UtlendingastofnunHeader: React.FC<
> = ({ organizationPage, logoAltText }) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const VinnueftilitidHeader: React.FC<React.PropsWithChildren<HeaderProps>> = ({
}) => {
const { linkResolver } = useLinkResolver()
const namespace = useMemo(
() => JSON.parse(organizationPage.organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organizationPage.organization?.namespace?.fields || '{}'),
[organizationPage.organization?.namespace?.fields],
)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const DirectorateOfHealthDashboardHeader: React.FC<
React.PropsWithChildren<DirectorateOfHealthDashboardHeaderProps>
> = ({ projectPage }) => {
const namespace = useMemo(() => {
return JSON.parse(projectPage?.namespace?.fields ?? '{}')
return JSON.parse(projectPage?.namespace?.fields || '{}')
}, [projectPage?.namespace?.fields])
const { activeLocale } = useI18n()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const FiskistofaDashboardHeader: React.FC<
React.PropsWithChildren<FiskistofaDashboardHeaderProps>
> = ({ projectPage }) => {
const namespace = useMemo(() => {
return JSON.parse(projectPage?.namespace?.fields ?? '{}')
return JSON.parse(projectPage?.namespace?.fields || '{}')
}, [projectPage?.namespace?.fields])

const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const SignLanguageButton = ({
)

const namespace = useMemo(
() => JSON.parse(data?.getNamespace?.fields ?? '{}'),
() => JSON.parse(data?.getNamespace?.fields || '{}'),
[data?.getNamespace?.fields],
)

Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/Article/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ ArticleScreen.getProps = async ({ apolloClient, query, locale }) => {
})
.then((content) => {
// map data here to reduce data processing in component
return JSON.parse(content?.data?.getNamespace?.fields ?? '{}')
return JSON.parse(content?.data?.getNamespace?.fields || '{}')
}),
])

Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/Category/Categories/Categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Categories.getProps = async ({ apolloClient, locale }) => {
},
},
})
.then((res) => JSON.parse(res?.data?.getNamespace?.fields ?? '{}')),
.then((res) => JSON.parse(res?.data?.getNamespace?.fields || '{}')),
])

return {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface HomeProps {
}

const Home: Screen<HomeProps> = ({ categories, news, page, locale }) => {
const namespace = JSON.parse(page?.namespace?.fields ?? '{}')
const namespace = JSON.parse(page?.namespace?.fields || '{}')
const { activeLocale } = useI18n()
const { globalNamespace } = useContext(GlobalContext)
const n = useNamespace(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ PublishedMaterial.getProps = async ({ apolloClient, locale, query }) => {
})
.then((variables) => {
// map data here to reduce data processing in component
return JSON.parse(variables?.data?.getNamespace?.fields ?? '{}')
return JSON.parse(variables?.data?.getNamespace?.fields || '{}')
}),
])

Expand Down
6 changes: 3 additions & 3 deletions apps/web/screens/ServiceWeb/Forms/Forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const ServiceWebFormsPage: Screen<ServiceWebFormsPageProps> = ({
useLocalLinkTypeResolver()

const organizationNamespace = useMemo(
() => JSON.parse(organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organization?.namespace?.fields || '{}'),
[organization?.namespace],
)
const o = useNamespace(organizationNamespace)
Expand Down Expand Up @@ -434,7 +434,7 @@ ServiceWebFormsPage.getProps = async ({ apolloClient, locale, query }) => {
})
.then(
(variables) =>
JSON.parse(variables?.data?.getNamespace?.fields ?? '{}')?.entities ??
JSON.parse(variables?.data?.getNamespace?.fields || '{}')?.entities ??
[],
),
apolloClient
Expand All @@ -448,7 +448,7 @@ ServiceWebFormsPage.getProps = async ({ apolloClient, locale, query }) => {
},
})
.then((variables) =>
JSON.parse(variables?.data?.getNamespace?.fields ?? '{}'),
JSON.parse(variables?.data?.getNamespace?.fields || '{}'),
),
apolloClient.query<Query, QueryGetServiceWebPageArgs>({
query: GET_SERVICE_WEB_PAGE_QUERY,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/screens/ServiceWeb/Search/ServiceSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ServiceSearch: Screen<ServiceSearchProps> = ({
})
const { linkResolver } = useLinkResolver()
const organizationNamespace = useMemo(
() => JSON.parse(organization?.namespace?.fields ?? '{}'),
() => JSON.parse(organization?.namespace?.fields || '{}'),
[organization?.namespace?.fields],
)
const o = useNamespace(organizationNamespace)
Expand Down Expand Up @@ -431,7 +431,7 @@ ServiceSearch.getProps = async ({ apolloClient, locale, query }) => {
})
.then((variables) => {
// map data here to reduce data processing in component
return JSON.parse(variables?.data?.getNamespace?.fields ?? '{}')
return JSON.parse(variables?.data?.getNamespace?.fields || '{}')
}),
apolloClient.query<Query, QueryGetServiceWebPageArgs>({
query: GET_SERVICE_WEB_PAGE_QUERY,
Expand Down

0 comments on commit 0c4b341

Please sign in to comment.