Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit f5f7072

Browse files
myan9k8s-ci-robot
authored andcommitted
feat: add readonly and executable client options for replaying notebooks
1 parent f93301f commit f5f7072

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

packages/core/src/api/client.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,47 @@ const debug = Debug('core/api/client')
2020
/** Is the current client running in offline/disconnected mode? */
2121
export function isOfflineClient(): boolean {
2222
try {
23-
const { offline } = require('@kui-shell/client/config.d/client.json')
24-
return offline
23+
const { offline, readonly, executable } = require('@kui-shell/client/config.d/client.json')
24+
25+
if (offline === undefined && readonly !== undefined && executable !== undefined) {
26+
return readonly && !executable
27+
} else {
28+
return offline
29+
}
2530
} catch (err) {
2631
debug('Client did not define an offline status, assuming not offline')
2732
return false
2833
}
2934
}
35+
36+
/** Is the current client running in readonly mode? */
37+
export function isReadOnlyClient(): boolean {
38+
try {
39+
const { offline, readonly } = require('@kui-shell/client/config.d/client.json')
40+
41+
if (offline) {
42+
return true
43+
} else {
44+
return readonly
45+
}
46+
} catch (err) {
47+
debug('Client did not define a readonly status, assuming not readonly')
48+
return false
49+
}
50+
}
51+
52+
/** Is the current client running in an executable mode? */
53+
export function isExecutableClient(): boolean {
54+
try {
55+
const { offline, executable } = require('@kui-shell/client/config.d/client.json')
56+
57+
if (offline) {
58+
return false
59+
} else {
60+
return executable === undefined ? true : executable
61+
}
62+
} catch (err) {
63+
debug('Client did not define an executable status, assuming executable')
64+
return true
65+
}
66+
}

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,6 @@ export {
306306
export { default as teeToFile } from './util/tee'
307307

308308
// Client API
309-
export { isOfflineClient } from './api/client'
309+
export { isOfflineClient, isReadOnlyClient, isExecutableClient } from './api/client'
310310

311311
export * from './api/window-events'

plugins/plugin-client-common/src/components/Views/Terminal/Block/Actions.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import React from 'react'
18-
import { Tab, i18n, isOfflineClient } from '@kui-shell/core'
18+
import { Tab, i18n, isOfflineClient, isReadOnlyClient, isExecutableClient } from '@kui-shell/core'
1919

2020
import { InputOptions } from './Input'
2121
import { SupportedIcon } from '../../../spi/Icons'
@@ -123,10 +123,10 @@ export default class Actions extends React.PureComponent<Props> {
123123
!isOfflineClient() && (
124124
<div className="kui--block-actions-buttons kui--inverted-color-context">
125125
<div className="kui-block-actions-others">
126-
{this.copyAction()}
127-
{this.rerunAction()}
126+
{!isReadOnlyClient() && this.copyAction()}
127+
{isExecutableClient() && this.rerunAction()}
128128
</div>
129-
{this.removeAction()}
129+
{!isReadOnlyClient() && this.removeAction()}
130130
</div>
131131
)
132132
)

plugins/plugin-client-common/src/components/Views/Terminal/SplitHeader.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import React from 'react'
18-
import { i18n } from '@kui-shell/core'
18+
import { i18n, isReadOnlyClient } from '@kui-shell/core'
1919

2020
import Icons from '../../spi/Icons'
2121
import Tooltip from '../../spi/Tooltip'
@@ -59,11 +59,13 @@ export default class SplitHeader extends React.PureComponent<Props> {
5959

6060
public render() {
6161
return (
62-
<div className="kui--split-header flex-layout kui--inverted-color-context">
63-
<div className="flex-fill" />
64-
{this.clearButton()}
65-
{this.closeButton()}
66-
</div>
62+
!isReadOnlyClient() && (
63+
<div className="kui--split-header flex-layout kui--inverted-color-context">
64+
<div className="flex-fill" />
65+
{this.clearButton()}
66+
{this.closeButton()}
67+
</div>
68+
)
6769
)
6870
}
6971
}

0 commit comments

Comments
 (0)