Skip to content

Commit

Permalink
fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gestchild committed Jan 31, 2025
1 parent 08fc481 commit 5be2880
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
20 changes: 10 additions & 10 deletions common/services/prismic/link-resolver.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import linkResolver from './link-resolver';
import linkResolver, { HighlightTourType } from './link-resolver';

// We want to be able to pass in either Prismic or Content API content types
test.each([
Expand Down Expand Up @@ -26,23 +26,23 @@ test.each([
doc: {
type: 'Exhibition highlight tour',
uid: '1',
highlightTourType: 'text',
highlightTourType: 'text' as HighlightTourType,
},
path: '/guides/exhibitions/1/captions-and-transcripts',
},
{
doc: {
type: 'Exhibition highlight tour',
uid: '1',
highlightTourType: 'audio',
highlightTourType: 'audio' as HighlightTourType,
},
path: '/guides/exhibitions/1/audio-without-descriptions',
},
{
doc: {
type: 'Exhibition highlight tour',
uid: '1',
highlightTourType: 'bsl',
highlightTourType: 'bsl' as HighlightTourType,
},
path: '/guides/exhibitions/1/bsl',
},
Expand All @@ -63,23 +63,23 @@ test.each([
doc: {
type: 'exhibition-guides-links',
uid: '1',
highlightTourType: 'text',
highlightTourType: 'text' as HighlightTourType,
},
path: '/guides/exhibitions/1/captions-and-transcripts',
},
{
doc: {
type: 'exhibition-guides-links',
uid: '1',
highlightTourType: 'audio',
highlightTourType: 'audio' as HighlightTourType,
},
path: '/guides/exhibitions/1/audio-without-descriptions',
},
{
doc: {
type: 'exhibition-guides-links',
uid: '1',
highlightTourType: 'bsl',
highlightTourType: 'bsl' as HighlightTourType,
},
path: '/guides/exhibitions/1/bsl',
},
Expand All @@ -92,23 +92,23 @@ test.each([
doc: {
type: 'exhibition-guides',
uid: '1',
highlightTourType: 'text',
highlightTourType: 'text' as HighlightTourType,
},
path: '/guides/exhibitions/1/captions-and-transcripts',
},
{
doc: {
type: 'exhibition-guides',
uid: '1',
highlightTourType: 'audio',
highlightTourType: 'audio' as HighlightTourType,
},
path: '/guides/exhibitions/1/audio-without-descriptions',
},
{
doc: {
type: 'exhibition-guides',
uid: '1',
highlightTourType: 'bsl',
highlightTourType: 'bsl' as HighlightTourType,
},
path: '/guides/exhibitions/1/bsl',
},
Expand Down
15 changes: 7 additions & 8 deletions common/services/prismic/link-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import {
isContentType,
} from './content-types';

export type HighlightTourType = 'audio' | 'bsl' | 'text';
type Props = {
uid?: string;
type: string;
highlightTourType?: 'audio' | 'bsl' | 'text';
highlightTourType?: HighlightTourType;
siteSection?: SiteSection;
};

// Untransformed data
type DataProps = {
uid?: string;
type: string;
highlightTourType?: 'audio' | 'bsl' | 'text';
tags: string[];
data: {
highlightTourType?: HighlightTourType;
tags?: string[];
data?: {
relatedDocument?: {
uid: string;
type: string;
Expand Down Expand Up @@ -73,9 +74,7 @@ function linkResolver(doc: Props | DataProps): string {
}
case 'visual-stories':
if ('data' in doc) {
const {
data: { relatedDocument },
} = doc;
const { data: { relatedDocument } = {} } = doc;
if (relatedDocument?.uid) {
return `/${relatedDocument.type}/${relatedDocument.uid}/visual-stories`;
} else {
Expand All @@ -90,7 +89,7 @@ function linkResolver(doc: Props | DataProps): string {

// Prismic previews come through here.
if ('tags' in doc) {
siteSection = doc.tags.find(t => isSiteSection(t));
siteSection = doc.tags?.find(t => isSiteSection(t));
}

return siteSection === uid || !siteSection // if it is a landing page or doesn't have a siteSection
Expand Down

0 comments on commit 5be2880

Please sign in to comment.