Skip to content

Commit 7ff59a2

Browse files
committed
feat: support integrations inside reusable content blocks
1 parent f71ab84 commit 7ff59a2

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,34 @@ import { renderIntegrationUi } from './server-actions';
1212
export async function IntegrationBlock(props: BlockProps<DocumentBlockIntegration>) {
1313
const { block, context, style } = props;
1414

15-
if (!context.contentContext?.space) {
16-
throw new Error('integration block requires a content.spaceId');
15+
if (!context.contentContext?.space && !props.block.data.spaceId) {
16+
throw new Error('integration block requires a spaceId');
1717
}
1818

19+
// When the block originates from a cross-space reusable content, the server adds a spaceId so the integration is
20+
// looked up in the correct source space.
21+
const spaceId = props.block.data.spaceId ?? context.contentContext.space.id;
22+
1923
const initialInput: RenderIntegrationUI = {
2024
componentId: block.data.block,
2125
props: block.data.props,
2226
action: block.data.action,
2327
context: {
2428
type: 'document',
25-
spaceId: context.contentContext?.space.id,
29+
spaceId,
2630
editable: false,
2731
theme: 'light', // TODO: how to handle this without moving rendering to the client side?
2832
},
2933
};
3034

31-
const initialResponse = await fetchSafeIntegrationUI(context.contentContext, {
35+
const dataFetcher = block.meta?.token
36+
? context.contentContext.dataFetcher.withToken({ apiToken: block.meta.token })
37+
: context.contentContext.dataFetcher;
38+
39+
const initialResponse = await fetchSafeIntegrationUI({
40+
...context.contentContext,
41+
dataFetcher
42+
}, {
3243
integrationName: block.data.integration,
3344
request: initialInput,
3445
});

0 commit comments

Comments
 (0)