Skip to content

Commit 1bfa2e3

Browse files
authored
Don't fail to render Jira embed if configuration is incomplete (#617)
* Don't fail to render Jira embed if configuration is incomplete * Rendering "Integration misconfigured" for title when missing values * Add missing version to jira * Push changeset
1 parent 1ab61f6 commit 1bfa2e3

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.changeset/cold-weeks-notice.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-jira': minor
3+
---
4+
5+
Prevent Jira embed render to fail when its configuration is incomplete

integrations/jira/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "@gitbook/integration-jira",
3+
"version": "0.1.0",
34
"private": true,
45
"scripts": {
56
"typecheck": "tsc --noEmit",

integrations/jira/src/index.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ interface Site {
2323
}
2424

2525
type JiraConfiguration = {
26-
sites: Site[];
27-
oauth_credentials: OAuthConfiguration;
26+
sites?: Site[];
27+
oauth_credentials?: OAuthConfiguration;
2828
};
2929

3030
type IntegrationEnvironment = RuntimeEnvironment<JiraConfiguration>;
@@ -58,6 +58,17 @@ const embedBlock = createComponent<Props, {}, void, IntegrationContext>({
5858
element.setCache({ maxAge: 0 });
5959

6060
const { url: rawUrl } = element.props;
61+
const { environment } = context;
62+
const configuration = environment.installation?.configuration as JiraConfiguration;
63+
if (!configuration.oauth_credentials || !configuration.sites) {
64+
return (
65+
<block>
66+
<card title="Integration misconfigured">
67+
<text>{rawUrl ?? ''}</text>
68+
</card>
69+
</block>
70+
);
71+
}
6172

6273
const url = rawUrl ? new URL(rawUrl) : null;
6374
const parts = url?.pathname.split('/');
@@ -73,10 +84,7 @@ const embedBlock = createComponent<Props, {}, void, IntegrationContext>({
7384
);
7485
}
7586

76-
const { environment } = context;
77-
const configuration = environment.installation?.configuration as JiraConfiguration;
7887
const site = configuration.sites.find((site) => url.toString().startsWith(site.url));
79-
8088
if (!site) {
8189
// JIRA site not part of this installation
8290
return (

0 commit comments

Comments
 (0)