Skip to content

Commit 8ac0f8d

Browse files
authored
Fix GitHub & GitLab files embed hide/show action (#883)
* bun lock * Fix hide/show action on github files embed * Fix hide/show action on gitlab files embed * changeset
1 parent a8fd3c5 commit 8ac0f8d

File tree

4 files changed

+79
-44
lines changed

4 files changed

+79
-44
lines changed

.changeset/eager-impalas-watch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@gitbook/integration-github-files': patch
3+
'@gitbook/integration-gitlab-files': patch
4+
---
5+
6+
Fix GitHub & GitLab files embed hide/show action

bun.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"integrations/bucket": {
3030
"name": "@gitbook/integration-bucket",
31-
"version": "0.2.0",
31+
"version": "0.3.0",
3232
"dependencies": {
3333
"@gitbook/runtime": "*",
3434
"itty-router": "^5.0.18",
@@ -192,7 +192,7 @@
192192
},
193193
"integrations/googleanalytics": {
194194
"name": "@gitbook/integration-googleanalytics",
195-
"version": "0.6.2",
195+
"version": "0.7.0",
196196
"dependencies": {
197197
"@gitbook/api": "*",
198198
"@gitbook/runtime": "*",
@@ -289,7 +289,7 @@
289289
},
290290
"integrations/launchdarkly": {
291291
"name": "@gitbook/integration-launchdarkly",
292-
"version": "0.2.0",
292+
"version": "0.3.0",
293293
"dependencies": {
294294
"@gitbook/runtime": "*",
295295
"itty-router": "^5.0.18",
@@ -493,7 +493,7 @@
493493
},
494494
"integrations/slack": {
495495
"name": "@gitbook/integration-slack",
496-
"version": "2.0.3",
496+
"version": "2.0.4",
497497
"dependencies": {
498498
"@gitbook/api": "*",
499499
"@gitbook/runtime": "*",
@@ -520,7 +520,7 @@
520520
},
521521
"integrations/unify": {
522522
"name": "@gitbook/integration-unify",
523-
"version": "0.1.0",
523+
"version": "0.1.1",
524524
"dependencies": {
525525
"@gitbook/api": "*",
526526
"@gitbook/runtime": "*",
@@ -599,7 +599,7 @@
599599
},
600600
"packages/adaptive": {
601601
"name": "@gitbook/adaptive",
602-
"version": "0.1.0",
602+
"version": "0.1.1",
603603
"dependencies": {
604604
"js-cookie": "^3.0.5",
605605
},
@@ -614,7 +614,7 @@
614614
},
615615
"packages/api": {
616616
"name": "@gitbook/api",
617-
"version": "0.120.0",
617+
"version": "0.124.0",
618618
"dependencies": {
619619
"event-iterator": "^2.0.0",
620620
"eventsource-parser": "^3.0.0",
@@ -629,7 +629,7 @@
629629
},
630630
"packages/cli": {
631631
"name": "@gitbook/cli",
632-
"version": "0.24.0",
632+
"version": "0.25.0",
633633
"bin": {
634634
"gitbook": "./cli.js",
635635
},

integrations/github-files/src/index.tsx

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Router } from 'itty-router';
22

3-
import { RequestUpdateIntegrationInstallation } from '@gitbook/api';
3+
import { ContentKitIcon, RequestUpdateIntegrationInstallation } from '@gitbook/api';
44
import {
55
createIntegration,
66
createComponent,
@@ -14,18 +14,19 @@ import { GithubRuntimeContext } from './types';
1414
import { getFileExtension } from './utils';
1515

1616
const embedBlock = createComponent<
17-
{ url?: string },
17+
{ url?: string; visible?: boolean },
1818
{ visible: boolean },
1919
{
2020
action: 'show' | 'hide';
2121
},
2222
GithubRuntimeContext
2323
>({
2424
componentId: 'github-code-block',
25-
initialState: {
26-
visible: true,
25+
initialState: (props) => {
26+
return {
27+
visible: props.visible ?? true,
28+
};
2729
},
28-
2930
async action(element, action) {
3031
switch (action.action) {
3132
case '@link.unfurl': {
@@ -38,10 +39,21 @@ const embedBlock = createComponent<
3839
};
3940
}
4041
case 'show': {
41-
return { state: { visible: true } };
42+
return {
43+
...element,
44+
state: { visible: true },
45+
props: {
46+
...element.props,
47+
visible: true,
48+
},
49+
};
4250
}
4351
case 'hide': {
44-
return { state: { visible: false } };
52+
return {
53+
...element,
54+
state: { visible: false },
55+
props: { ...element.props, visible: false },
56+
};
4557
}
4658
}
4759

@@ -82,18 +94,21 @@ const embedBlock = createComponent<
8294
return (
8395
<block
8496
controls={[
85-
{
86-
label: 'Show title & link',
87-
onPress: {
88-
action: 'show',
89-
},
90-
},
91-
{
92-
label: 'Hide title & link',
93-
onPress: {
94-
action: 'hide',
95-
},
96-
},
97+
element.state.visible
98+
? {
99+
label: 'Hide title & link',
100+
icon: ContentKitIcon.EyeOff,
101+
onPress: {
102+
action: 'hide',
103+
},
104+
}
105+
: {
106+
label: 'Show title & link',
107+
icon: ContentKitIcon.Eye,
108+
onPress: {
109+
action: 'show',
110+
},
111+
},
97112
]}
98113
>
99114
<card

integrations/gitlab-files/src/index.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ import { createIntegration, createComponent, createOAuthHandler } from '@gitbook
33
import { getGitlabContent, GitlabProps } from './gitlab';
44
import { GitlabRuntimeContext } from './types';
55
import { getFileExtension } from './utils';
6+
import { ContentKitIcon } from '@gitbook/api';
67

78
const gitlabCodeBlock = createComponent<
8-
{ url?: string },
9+
{ url?: string; visible?: boolean },
910
{ visible: boolean },
1011
{
1112
action: 'show' | 'hide';
1213
},
1314
GitlabRuntimeContext
1415
>({
1516
componentId: 'gitlab-code-block',
16-
initialState: {
17-
visible: true,
17+
initialState: (props) => {
18+
return {
19+
visible: props.visible ?? true,
20+
};
1821
},
1922
async action(element, action) {
2023
switch (action.action) {
@@ -28,10 +31,18 @@ const gitlabCodeBlock = createComponent<
2831
};
2932
}
3033
case 'show': {
31-
return { state: { visible: true } };
34+
return {
35+
...element,
36+
state: { visible: true },
37+
props: { ...element.props, visible: true },
38+
};
3239
}
3340
case 'hide': {
34-
return { state: { visible: false } };
41+
return {
42+
...element,
43+
state: { visible: false },
44+
props: { ...element.props, visible: false },
45+
};
3546
}
3647
}
3748

@@ -71,18 +82,21 @@ const gitlabCodeBlock = createComponent<
7182
return (
7283
<block
7384
controls={[
74-
{
75-
label: 'Show title & link',
76-
onPress: {
77-
action: 'show',
78-
},
79-
},
80-
{
81-
label: 'Hide title & link',
82-
onPress: {
83-
action: 'hide',
84-
},
85-
},
85+
element.state.visible
86+
? {
87+
label: 'Hide title & link',
88+
icon: ContentKitIcon.EyeOff,
89+
onPress: {
90+
action: 'hide',
91+
},
92+
}
93+
: {
94+
label: 'Show title & link',
95+
icon: ContentKitIcon.Eye,
96+
onPress: {
97+
action: 'show',
98+
},
99+
},
86100
]}
87101
>
88102
<card

0 commit comments

Comments
 (0)