Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update link resolver #11190

Merged
merged 27 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
347cd33
use uid instead of id in linkResolver
gestchild Sep 18, 2024
1d4b0ed
use linkResolver to create links
gestchild Sep 18, 2024
3d20b27
pass in required props
gestchild Sep 18, 2024
a391a7a
also check uid to find related visual stories
gestchild Sep 18, 2024
04e0854
pass in uid
gestchild Sep 18, 2024
b0e0055
try fetching by uid first
gestchild Sep 18, 2024
8cd2411
pass in uid to linkResolver
gestchild Sep 18, 2024
36f4970
update tests
gestchild Sep 18, 2024
02bfe1b
Merge remote-tracking branch 'origin/main' into update-linkResolver
gestchild Oct 8, 2024
d0baa89
update TODO with issue number
gestchild Oct 8, 2024
1f7854a
use linkResolver for EventPromo
gestchild Oct 8, 2024
7fe604b
use linkResolver and uid for guide links
gestchild Oct 8, 2024
be38e9a
use linkResolver for EG type urls
gestchild Oct 8, 2024
f304ad8
making more use of linkResolver
gestchild Oct 8, 2024
9ae6210
use linkResolver to construct links
gestchild Oct 8, 2024
f19d6a0
fetch the correct guide based on the type specified in the url
gestchild Oct 8, 2024
72192c3
specify types
gestchild Oct 8, 2024
c2417e8
use linkResolver to create stop links
gestchild Oct 8, 2024
c6aaa8c
use linkResolver to create links on stops page
gestchild Oct 8, 2024
20b31e9
use linkResolver for partOf in breadcrumb
gestchild Oct 9, 2024
14387fc
use linkResolver for tryTeseToo promos
gestchild Oct 9, 2024
1f56eec
update exhibition guides tests to use uids
gestchild Oct 9, 2024
8812ccc
update visual stories test to use uid
gestchild Oct 9, 2024
5e48079
rename variable
gestchild Oct 9, 2024
526ef19
Update content/webapp/components/ExhibitionGuideLinks/ExhibitionGuide…
gestchild Oct 9, 2024
a23e9d8
revert mistaken change
gestchild Oct 9, 2024
8846f11
second go at updating const name
gestchild Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions common/services/prismic/link-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import linkResolver from './link-resolver';
*/
describe('webcomic edge case', () => {
test.each([
{ doc: { type: 'webcomics', id: '1' }, path: '/articles/1' },
{ doc: { type: 'webcomic-series', id: '1' }, path: '/series/1' },
{ doc: { type: 'webcomics', uid: '1' }, path: '/articles/1' },
{ doc: { type: 'webcomic-series', uid: '1' }, path: '/series/1' },
])('$doc resolves to $path', ({ doc, path }) => {
expect(linkResolver(doc)).toBe(path);
});
});

it('resolves exhibition guides to /guides/exhibitions/{id}', () => {
const doc = { type: 'exhibition-guides', id: '1' };
const doc = { type: 'exhibition-guides', uid: '1' };
expect(linkResolver(doc)).toBe('/guides/exhibitions/1');
});

test.each([
{ doc: { type: 'articles', id: '1' }, path: '/articles/1' },
{ doc: { type: 'pages', id: '1' }, path: '/pages/1' },
{ doc: { type: 'not a thing', id: '1' }, path: '/' },
{ doc: { type: 'articles', uid: '1' }, path: '/articles/1' },
{ doc: { type: 'pages', uid: '1' }, path: '/pages/1' },
{ doc: { type: 'not a thing', uid: '1' }, path: '/' },
])('$doc resolves to $path', ({ doc, path }) => {
expect(linkResolver(doc)).toBe(path);
});
Expand Down
25 changes: 13 additions & 12 deletions common/services/prismic/link-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import { isContentType } from './content-types';

type Props = {
id: string;
uid?: string;
type: string;
};
type DataProps = {
id: string;
uid?: string;
type: string;
data: {
relatedDocument?: {
id: string;
uid: string;
type: string;
};
};
};
function linkResolver(doc: Props | DataProps): string {
const { id, type } = doc;

if (type === 'webcomics') return `/articles/${id}`;
if (type === 'webcomic-series') return `/series/${id}`;
function linkResolver(doc: Props | DataProps): string {
const { uid, type } = doc;
if (!uid) return '/';
if (type === 'webcomics') return `/articles/${uid}`;
if (type === 'webcomic-series') return `/series/${uid}`;
if (
type === 'exhibition-guides' ||
type === 'exhibition-texts' ||
type === 'exhibition-highlight-tours'
)
return `/guides/exhibitions/${id}`;
return `/guides/exhibitions/${uid}`;
gestchild marked this conversation as resolved.
Show resolved Hide resolved

if (type === 'visual-stories') {
if ('data' in doc) {
const {
data: { relatedDocument },
} = doc;
if (relatedDocument?.id) {
return `/${relatedDocument.type}/${relatedDocument.id}/visual-stories`;
if (relatedDocument?.uid) {
return `/${relatedDocument.type}/${relatedDocument.uid}/visual-stories`;
} else {
return `/visual-stories/${id}`;
return `/visual-stories/${uid}`;
}
}
}

if (isContentType(type)) {
return `/${type}/${id}`;
return `/${type}/${uid}`;
}

return '/';
Expand Down
4 changes: 2 additions & 2 deletions common/services/prismic/transformers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ describe('transformLink', () => {
const result = transformLink({
id: 'YoedaBEAACMAXnil',
type: 'projects',
slug: 'ellen-reid-soundwalk-at-regents-park',
uid: 'ellen-reid-soundwalk-at-regents-park',
link_type: 'Document',
isBroken: false,
});

expect(result).toBe('/projects/YoedaBEAACMAXnil');
expect(result).toBe('/projects/ellen-reid-soundwalk-at-regents-park');
});
});
2 changes: 1 addition & 1 deletion content/webapp/components/BannerCard/BannerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const BannerCard: FunctionComponent<Props> = ({
},
link:
(item.promo && item.promo.link) ||
linkResolver({ id: item.id, type: item.type }),
linkResolver({ uid: item.uid, type: item.type }),
};
return (
<CardOuter href={link} $background={background}>
Expand Down
5 changes: 3 additions & 2 deletions content/webapp/components/BookPromo/BookPromo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BookBasic } from '@weco/content/types/books';
import Space from '@weco/common/views/components/styled/Space';
import LabelsList from '@weco/common/views/components/LabelsList/LabelsList';
import BookImage from '@weco/content/components/BookImage/BookImage';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type LinkSpaceAttrs = {
$url: string;
Expand Down Expand Up @@ -56,9 +57,9 @@ type Props = {
};

const BookPromo: FunctionComponent<Props> = ({ book }) => {
const { id, title, subtitle, promo, cover } = book;
const { title, subtitle, promo, cover } = book;
return (
<LinkSpace $url={`/books/${id}`}>
<LinkSpace $url={linkResolver(book)}>
<Space $v={{ size: 'l', properties: ['margin-bottom'] }}>
<BookImage
image={{
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/EventCard/EventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { font } from '@weco/common/utils/classnames';
import { getCrop } from '@weco/common/model/image';
import Space from '@weco/common/views/components/styled/Space';
import WatchLabel from '@weco/content/components/WatchLabel/WatchLabel';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
event: EventBasic;
Expand Down Expand Up @@ -70,7 +71,7 @@ const EventCard: FunctionComponent<Props> = ({ event, xOfY }) => {

return (
<CompactCard
url={`/events/${event.id}`}
url={linkResolver(event)}
title={event.title}
primaryLabels={event.primaryLabels}
secondaryLabels={event.secondaryLabels}
Expand Down
2 changes: 1 addition & 1 deletion content/webapp/components/EventsSearchResults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const EventsSearchResults: FunctionComponent<Props> = ({ events }: Props) => {
return (
<CardOuter
key={event.id}
href={linkResolver({ id: event.id, type: 'events' })}
href={linkResolver({ uid: event.uid, type: 'events' })}
>
<CardImageWrapper>
{croppedImage && (
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/Exhibition/Exhibition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
ResourceLink,
ResourceLinkIconWrapper,
} from '@weco/content/components/styled/AccessResources';
import linkResolver from '@weco/common/services/prismic/link-resolver';

function getBorderColor({
type,
Expand Down Expand Up @@ -223,7 +224,7 @@ const Exhibition: FunctionComponent<Props> = ({
text: 'Exhibitions',
},
{
url: `/exhibitions/${exhibition.id}`,
url: linkResolver(exhibition),
text: exhibition.title,
isHidden: true,
},
Expand Down
2 changes: 1 addition & 1 deletion content/webapp/components/FeaturedCard/FeaturedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function convertItemToFeaturedCardProps(
},
labels: item.labels,
link: {
url: linkResolver({ id: item.id, type: item.type }),
url: linkResolver({ uid: item.uid, type: item.type }),
text: item.title,
},
};
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/components/Installation/Installation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ContentPage from '@weco/content/components/ContentPage/ContentPage';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import { fetchExhibitExhibition } from '@weco/content/services/prismic/fetch/exhibitions';
import { createScreenreaderLabel } from '@weco/common/utils/telephone-numbers';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
installation: InstallationType;
Expand Down Expand Up @@ -46,7 +47,7 @@ const Installation: FunctionComponent<Props> = ({ installation }) => {
}
: undefined,
{
url: `/exhibitions/${installation.id}`,
url: linkResolver(installation),
text: installation.title,
isHidden: true,
},
Expand Down
12 changes: 6 additions & 6 deletions content/webapp/components/SearchResults/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ArticleCard from '@weco/content/components/ArticleCard/ArticleCard';
import { getCrop } from '@weco/common/model/image';
import { Card } from '@weco/content/types/card';
import PlainList from '@weco/common/views/components/styled/PlainList';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const Result = styled.li`
border-top: 1px solid ${props => props.theme.color('warmNeutral.400')};
Expand Down Expand Up @@ -43,7 +44,6 @@ const SearchResults: FunctionComponent<Props> = ({
{summary && (
<Space $v={{ size: 'l', properties: ['margin-bottom'] }}>{summary}</Space>
)}

{items.length > 0 && (
<PlainList>
{items.map((item, index) => (
Expand Down Expand Up @@ -81,7 +81,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'pages' && (
<CompactCard
url={`/pages/${item.id}`}
url={linkResolver(item)}
title={item.title || ''}
primaryLabels={[]}
secondaryLabels={[]}
Expand Down Expand Up @@ -114,7 +114,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'event-series' && (
<CompactCard
url={`/event-series/${item.id}`}
url={linkResolver(item)}
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -147,7 +147,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'books' && (
<CompactCard
url={`/books/${item.id}`}
url={linkResolver(item)}
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -187,7 +187,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'series' && (
<CompactCard
url={`/series/${item.id}`}
url={linkResolver(item)}
title={item.title || ''}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down Expand Up @@ -226,7 +226,7 @@ const SearchResults: FunctionComponent<Props> = ({
)}
{item.type === 'exhibitions' && (
<CompactCard
url={`/exhibitions/${item.id}`}
url={linkResolver(item)}
title={item.title}
primaryLabels={item.labels}
secondaryLabels={[]}
Expand Down
2 changes: 1 addition & 1 deletion content/webapp/components/StoriesGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const StoriesGrid: FunctionComponent<Props> = ({
<StoryWrapper
key={article.id}
as="a"
href={linkResolver({ id: article.id, type: 'articles' })}
href={linkResolver({ uid: article.uid, type: 'articles' })}
$isDetailed={isDetailed}
data-testid="story-search-result"
>
Expand Down
15 changes: 9 additions & 6 deletions content/webapp/pages/articles/[articleId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { createPrismicLink } from '@weco/common/views/components/ApiToolbar';
import { setCacheControl } from '@weco/content/utils/setCacheControl';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import Standfirst from '@weco/common/views/slices/Standfirst';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const ContentTypeWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -202,13 +203,15 @@ const ArticlePage: FunctionComponent<Props> = ({ article, jsonLd }) => {
// GOTCHA: we only take the first of the series list as the data is being
// used a little bit badly, but we don't have capacity to implement a
// better solution
...article.series.slice(0, 1).map(series => ({
url: `/series/${series.id}`,
text: series.title || '',
prefix: 'Part of',
})),
...article.series.slice(0, 1).map(series => {
return {
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
};
}),
{
url: `/articles/${article.id}`,
url: linkResolver(article),
text: article.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/books/[bookId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Pageview } from '@weco/common/services/conversion/track';
import { createPrismicLink } from '@weco/common/views/components/ApiToolbar';
import { setCacheControl } from '@weco/content/utils/setCacheControl';
import { isNotUndefined } from '@weco/common/utils/type-guards';
import linkResolver from '@weco/common/services/prismic/link-resolver';

const MetadataWrapper = styled.div`
border-top: 1px solid ${props => props.theme.color('neutral.300')};
Expand Down Expand Up @@ -139,7 +140,7 @@ const BookPage: FunctionComponent<Props> = props => {
url: '/books',
},
{
url: `/books/${book.id}`,
url: linkResolver(book),
text: book.title,
isHidden: true,
},
Expand Down
3 changes: 2 additions & 1 deletion content/webapp/pages/event-series/[eventSeriesId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { PaginatedResults } from '@weco/common/services/prismic/types';
import PaginationWrapper from '@weco/common/views/components/styled/PaginationWrapper';
import Pagination from '@weco/content/components/Pagination/Pagination';
import { getPage } from '@weco/content/utils/query-params';
import linkResolver from '@weco/common/services/prismic/link-resolver';

type Props = {
series: EventSeries;
Expand Down Expand Up @@ -130,7 +131,7 @@ const EventSeriesPage: FunctionComponent<Props> = ({
text: 'Events',
},
{
url: `/events-series/${series.id}`,
url: linkResolver(series),
text: series.title,
isHidden: true,
},
Expand Down
17 changes: 10 additions & 7 deletions content/webapp/pages/events/[eventId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,23 @@ const EventPage: NextPage<EventProps> = ({
url: '/events',
text: 'Events',
},
...event.series.map(series => ({
url: `/event-series/${series.id}`,
text: series.title || '',
prefix: 'Part of',
})),
...event.series.map(series => {
console.log(series);
return {
url: linkResolver(series),
text: series.title || '',
prefix: 'Part of',
};
}),
scheduledIn
? {
url: `/events/${scheduledIn.id}`,
url: linkResolver(scheduledIn),
text: scheduledIn.title || '',
prefix: 'Part of',
}
: undefined,
{
url: `/events/${event.id}`,
url: linkResolver(event),
text: event.title,
isHidden: true,
},
Expand Down
4 changes: 3 additions & 1 deletion content/webapp/pages/events/[eventId]/visual-stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const getServerSideProps = async context => {

const visualStoryDocument = visualStoriesQuery.results.find(result => {
return (
// TODO once redirects are in place we should only compare with uid
gestchild marked this conversation as resolved.
Show resolved Hide resolved
isFilledLinkToDocument(result.data.relatedDocument) &&
result.data.relatedDocument.id === context.query.eventId
(result.data.relatedDocument.uid === context.query.eventId ||
result.data.relatedDocument.id === context.query.eventId)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const getServerSideProps = async context => {

const visualStoryDocument = visualStoriesQuery.results.find(result => {
return (
// TODO once redirects are in place we should only compare with uid
gestchild marked this conversation as resolved.
Show resolved Hide resolved
isFilledLinkToDocument(result.data.relatedDocument) &&
result.data.relatedDocument.id === context.query.exhibitionId
(result.data.relatedDocument.uid === context.query.exhibitionId ||
result.data.relatedDocument.id === context.query.exhibitionId)
);
});

Expand Down
Loading
Loading