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

Commit d0dd00e

Browse files
committed
fix: RadioTables are not replayable
Fixes #5599
1 parent f7f6918 commit d0dd00e

File tree

12 files changed

+42
-34
lines changed

12 files changed

+42
-34
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export {
238238
isRadioTable,
239239
RadioTableRow,
240240
RadioTableCell,
241+
Selectable,
241242
radioTableHintsAsCss,
242243
radioTableCellToString,
243244
radioTableAddHint,

packages/core/src/models/RadioTable.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export interface RadioTableRow {
3434
}
3535

3636
export interface Selectable {
37-
onSelect: () => void | Promise<void>
37+
/**
38+
* Handler for change of selection. This will be interpreted as a
39+
* Kui command line to be executed when the user clicks on the
40+
* corresponding row in the UI.
41+
*
42+
*/
43+
onSelect: string
3844
}
3945

4046
export function radioTableHintsAsCss(cell: RadioTableCell) {

plugins/plugin-client-common/src/components/Content/KuiContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class KuiMMRContent extends React.Component<KuiMMRProps, State> {
118118
// so we have to re-assign mode.content to work around this typescript compile error
119119
return (
120120
<KuiContext.Consumer>
121-
{config => <RadioTableSpi table={radioTable} title={!config.disableTableTitle} />}
121+
{config => <RadioTableSpi table={radioTable} title={!config.disableTableTitle} repl={tab.REPL} />}
122122
</KuiContext.Consumer>
123123
)
124124
} else if (isTable(mode.content)) {

plugins/plugin-client-common/src/components/Content/Scalar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export default class Scalar extends React.PureComponent<Props, State> {
104104
} else if (isRadioTable(response)) {
105105
return (
106106
<KuiContext.Consumer>
107-
{config => <RadioTableSpi table={response} title={!config.disableTableTitle} />}
107+
{config => <RadioTableSpi table={response} title={!config.disableTableTitle} repl={tab.REPL} />}
108108
</KuiContext.Consumer>
109109
)
110110
} else if (isTable(response)) {

plugins/plugin-client-common/src/components/spi/RadioTable/impl/Carbon.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { v4 as uuid } from 'uuid'
1919
import {
2020
Breadcrumb,
2121
RadioTableRow,
22+
Selectable,
2223
radioTableHintsAsCss,
2324
radioTableCellToString,
2425
cellShouldHaveBadge,
@@ -63,15 +64,17 @@ export default class CarbonRadioTable extends React.PureComponent<Props, State>
6364
}
6465
}
6566

66-
private async onChange(selectedIdx: number, onSelect: () => void) {
67+
private async onChange(selectedIdx: number, onSelect: Selectable['onSelect']) {
6768
// wow, carbon components isn't so great; we have to manage unchecking ourselves??
6869
const currentSelection = document.getElementById(this.id(this.props.selectedIdx)) as HTMLInputElement
6970
if (currentSelection) {
7071
currentSelection.checked = false
7172
}
7273

73-
if (onSelect) {
74-
await onSelect()
74+
try {
75+
await this.props.repl.qexec(onSelect)
76+
} catch (err) {
77+
console.error('Error changing selection in RadioTable', err)
7578
}
7679

7780
this.props.onChange(selectedIdx + this.props.offset)
@@ -101,7 +104,7 @@ export default class CarbonRadioTable extends React.PureComponent<Props, State>
101104
return <Toolbar className="kui--data-table-toolbar-top" breadcrumbs={breadcrumbs.length > 0 && breadcrumbs} />
102105
}
103106

104-
private row(row: RadioTableRow, ridx: number, head = false, onSelect?: () => void) {
107+
private row(row: RadioTableRow, ridx: number, head = false, onSelect?: Selectable['onSelect']) {
105108
const isSelected = !head && ridx === this.props.selectedIdx - this.props.offset
106109
const name = this.id(ridx)
107110

plugins/plugin-client-common/src/components/spi/RadioTable/model.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { RadioTable } from '@kui-shell/core'
17+
import { RadioTable, REPL } from '@kui-shell/core'
1818

1919
interface Props {
20+
/** The model to be rendered */
2021
table: RadioTable
22+
2123
/**
2224
* paginate: true -> always paginate
2325
* paginate: false -> never paginate
@@ -27,6 +29,9 @@ interface Props {
2729

2830
/** display table title? */
2931
title: boolean
32+
33+
/** REPL Controller */
34+
repl: REPL
3035
}
3136

3237
export default Props

plugins/plugin-core-support/src/lib/cmds/theme.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ const list = async ({ REPL }: Arguments): Promise<RadioTable> => {
101101
{ value: plugin, hints: [CellShould.HideWithSidecar, CellShould.BeGrayish] }
102102
],
103103

104-
onSelect: async () => {
105-
await REPL.qexec(`theme set ${REPL.encodeComponent(theme.name)}`)
106-
}
104+
onSelect: `theme set ${REPL.encodeComponent(theme.name)}`
107105
}))
108106
)
109107
)

plugins/plugin-git/src/controller/git/branch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ async function doListBranches(args: Arguments<GitBranchOptions>): Promise<RadioT
8181
return {
8282
nameIdx: 0,
8383
cells: [branchName],
84-
onSelect: async () => {
85-
args.REPL.pexec(`git checkout ${branchName}`)
86-
}
84+
onSelect: `git checkout ${branchName}`
8785
}
8886
})
8987

plugins/plugin-kubectl/oc/src/controller/oc/get/projects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727

2828
/** Actuate a project switch by using `oc project set` */
2929
function doSwitchViaOc(ns: string, args: Arguments<KubeOptions>) {
30-
return args.REPL.pexec(`oc project ${args.REPL.encodeComponent(ns)}`)
30+
return `oc project ${args.REPL.encodeComponent(ns)}`
3131
}
3232

3333
// we use the fetcher from 'kubectl get', and the viewTransformer from 'kubectl get namespaces'

plugins/plugin-kubectl/src/controller/kubectl/contexts.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,13 @@ const asRadioTable = (args: Arguments, { header, body }: Table): RadioTable => {
117117
header: rtRowsFor(header, wide),
118118
body: body
119119
.map(row => rtRowsFor(row, wide))
120-
.map(rtRow =>
121-
Object.assign(rtRow, {
122-
onSelect: async () => {
123-
const context = radioTableCellToString(rtRow.cells[0], true) // true: use title if we have it
124-
await args.REPL.qexec(`kubectl config use-context ${context}`)
125-
}
120+
.map(rtRow => {
121+
const context = radioTableCellToString(rtRow.cells[0], true) // true: use title if we have it
122+
123+
return Object.assign(rtRow, {
124+
onSelect: `kubectl config use-context ${context}`
126125
})
127-
)
126+
})
128127
}
129128
}
130129

0 commit comments

Comments
 (0)