Skip to content

Commit 92bb016

Browse files
authored
Show additional context when linking to a page group & a page in another space (#2381)
1 parent c8810ea commit 92bb016

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/components/DocumentView/BlockContentRef.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export async function BlockContentRef(props: BlockProps<DocumentBlockContentRef>
1818
return null;
1919
}
2020

21+
const isContentInOtherSpace =
22+
context.contentRefContext?.space &&
23+
'space' in block.data.ref &&
24+
context.contentRefContext.space.id !== block.data.ref.space;
2125
const kind = block?.data?.ref?.kind;
22-
if (resolved.active && kind === 'space') {
26+
if ((resolved.active && kind === 'space') || isContentInOtherSpace) {
2327
return <SpaceRefCard {...props} resolved={resolved} />;
2428
}
2529

@@ -61,6 +65,7 @@ async function SpaceRefCard(
6165
}
6266
href={resolved.href}
6367
title={resolved.text}
68+
postTitle={resolved.subText}
6469
style={style}
6570
/>
6671
);

src/lib/references.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { getPagePath, resolvePageId } from './pages';
1818
export interface ResolvedContentRef {
1919
/** Text to render in the content ref */
2020
text: string;
21+
/** Additional sub text to render in the content ref */
22+
subText?: string;
2123
/** Emoji associated with the reference */
2224
emoji?: string;
2325
/** URL to open for the content ref */
@@ -103,10 +105,14 @@ export async function resolveContentRef(
103105
return resolveContentRefInSpace(contentRef.space, contentRef);
104106
}
105107

106-
const page =
108+
const resolvePageResult =
107109
!contentRef.page || contentRef.page === activePage?.id
108110
? activePage
109-
: resolvePageId(pages, contentRef.page)?.page;
111+
? { page: activePage, ancestors: [] }
112+
: undefined
113+
: resolvePageId(pages, contentRef.page);
114+
115+
const page = resolvePageResult?.page;
110116
if (!page) {
111117
return null;
112118
}
@@ -134,7 +140,13 @@ export async function resolveContentRef(
134140
}
135141
}
136142
} else {
137-
text = page.title;
143+
const parentPage = (resolvePageResult?.ancestors || []).slice(-1).pop();
144+
// When the looked up ref was a page group we use the page group title as resolved ref text.
145+
// Otherwise use the resolved page title.
146+
text =
147+
parentPage && contentRef.page === parentPage.id && parentPage.type === 'group'
148+
? parentPage.title
149+
: page.title;
138150
emoji = isCurrentPage ? undefined : page.emoji;
139151
}
140152

@@ -245,12 +257,21 @@ async function resolveContentRefInSpace(spaceId: string, contentRef: ContentRef)
245257
baseUrl += '/';
246258
}
247259

248-
return resolveContentRef(contentRef, {
260+
const resolved = await resolveContentRef(contentRef, {
249261
space,
250262
revisionId: space.revision,
251263
pages,
252264
baseUrl,
253265
});
266+
267+
if (!resolved) {
268+
return null;
269+
}
270+
271+
return {
272+
...resolved,
273+
subText: space.title,
274+
};
254275
}
255276

256277
export function resolveContentRefWithFiles(

0 commit comments

Comments
 (0)