Skip to content

Commit

Permalink
feat: allow table drilldown to a new window
Browse files Browse the repository at this point in the history
  • Loading branch information
myan9 authored and k8s-ci-robot committed May 6, 2021
1 parent ef2e4b3 commit 96d1d0e
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 9 deletions.
11 changes: 10 additions & 1 deletion packages/core/src/main/spawn-electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,16 @@ export function createWindow(
app.quit()
break
case 'new-window':
createWindow(true, message.argv, undefined, { initialTabTitle: message.title }, true)
createWindow(
true,
message.argv,
undefined,
{
initialTabTitle: message.title,
quietExecCommand: message.quietExecCommand !== undefined ? message.quietExecCommand : false
},
true
)
break
case 'open-graphical-shell':
createWindow(true)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/models/SubwindowPrefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface SubwindowPrefs {
width?: number
height?: number
initialTabTitle?: string
quietExecCommand?: boolean
position?: () => Promise<{ x: number; y: number }>
bringYourOwnWindow?: () => void
}
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/webapp/bootstrap/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export function inBrowser() {
}

/** client-provided renderer of the main content */
type ClientRender = (root: Element, isPopup: boolean, commandLine?: string[], initialTabTitle?: string) => void
type ClientRender = (
root: Element,
isPopup: boolean,
commandLine?: string[],
initialTabTitle?: string,
quietExecCommand?: boolean
) => void

export default ClientRender
4 changes: 3 additions & 1 deletion packages/core/src/webapp/bootstrap/init-electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface KuiWindow extends BrowserWindow {
viewName?: string
title?: string
initialTabTitle?: string
quietExecCommand?: boolean
partialExec?: string
noEcho?: boolean
theme?: string
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function render(client: Client, root: Element) {
root,
!!prefs && prefs.fullscreen,
!fullShell ? maybeExecuteThis : undefined,
prefs ? prefs.initialTabTitle : undefined
prefs ? prefs.initialTabTitle : undefined,
prefs ? prefs.quietExecCommand : undefined
)
}
2 changes: 1 addition & 1 deletion packages/core/src/webapp/models/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class Table<RowType extends Row = Row> {
* `side-split`, unless the user chords the click with the Meta key
* (which is Command on macOS, and Option on Linux/Windows
*/
drilldownTo?: 'side-split' | 'this-split'
drilldownTo?: 'side-split' | 'this-split' | 'new-window'

/** Default presentation? */
defaultPresentation?: PresentationStyle
Expand Down
16 changes: 14 additions & 2 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ import Client from '@kui-shell/client'
* Format the body view
*
*/
function renderMain(container: Element, isPopup: boolean, commandLine?: string[], initialTabTitle?: string) {
function renderMain(
container: Element,
isPopup: boolean,
commandLine?: string[],
initialTabTitle?: string,
quietExecCommand?: boolean
) {
// re: noBootstrap; since we do the bootstrapping here, we don't
// need the Client to do anything more
ReactDomRender(
<Client noBootstrap isPopup={isPopup} commandLine={commandLine} initialTabTitle={initialTabTitle} />,
<Client
noBootstrap
isPopup={isPopup}
commandLine={commandLine}
initialTabTitle={initialTabTitle}
quietExecCommand={quietExecCommand}
/>,
container
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
* limitations under the License.
*/

import { Table } from '@kui-shell/core'

type FeatureFlags = {
/** [Optional] disable table title? */
disableTableTitle?: boolean

/** [Optional] when drilling down a table cell, open a new window to execute the comamnd? */
drilldownTo?: Table['drilldownTo']

/** [Optional] show sidecar name as breadcrumb or hero text, default: 'breadcrumb' */
sidecarName?: 'breadcrumb' | 'heroText'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import kuiHeaderFromBody from './kuiHeaderFromBody'
import Toolbar, { Props as ToolbarProps } from './Toolbar'
import Grid, { findGridableColumn } from './Grid'
import { BreadcrumbView } from '../../spi/Breadcrumb'
import KuiConfiguration from '../../Client/KuiConfiguration'

/** import the kui theme alignment */
import '../../../../web/scss/components/Table/PatternFly.scss'
Expand All @@ -54,6 +55,7 @@ interface PaginationConfiguration {
/** parameters to PaginatedTable component */
export type Props<T extends KuiTable = KuiTable> = PaginationConfiguration & {
tab: Tab
config: KuiConfiguration
repl: REPL
response: T

Expand Down Expand Up @@ -149,6 +151,9 @@ export default class PaginatedTable<P extends Props, S extends State> extends Re
try {
const { header = kuiHeaderFromBody(props.response.body), body, footer, defaultPresentation } = props.response
props.response.header = header
if (props.config && props.config.drilldownTo) {
props.response.drilldownTo = props.config.drilldownTo
}

const asGrid =
((!defaultPresentation || defaultPresentation === 'grid') &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export default class SequenceDiagram extends React.PureComponent<Props, State> {
: (gap >= 0 ? '+' : '') + prettyPrintDuration(gap)

// drilldown to underlying resource, e.g. Pod for Kubernetes Jobs
const onClick = onClickForCell(row, this.props.tab, this.props.repl, row.attributes[0])
const onClick = onClickForCell(row, this.props.tab, this.props.repl, row.attributes[0], this.props.response)

// rows that help to define the contents of the interval; e.g. jobName
const interGroupGapRow =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import React from 'react'
import prettyPrintDuration from 'pretty-ms'
import { Td } from '@patternfly/react-table'
import {
split,
Table as KuiTable,
Cell as KuiCell,
Row as KuiRow,
Tab,
REPL,
isPopup,
eventBus,
pexecInCurrentTab
pexecInCurrentTab,
isHeadless
} from '@kui-shell/core'

import Icons from '../../spi/Icons'
Expand Down Expand Up @@ -75,11 +77,20 @@ export function onClickForCell(
} else if (handler) {
const opts = { tab }
if (!row.onclickExec || row.onclickExec === 'pexec') {
return whenNothingIsSelected((evt: React.MouseEvent) => {
return whenNothingIsSelected(async (evt: React.MouseEvent) => {
evt.stopPropagation()
selectRow()
if (!isPopup() && drilldownTo === 'side-split' && !XOR(evt.metaKey, !!process.env.KUI_SPLIT_DRILLDOWN)) {
pexecInCurrentTab(`split --ifnot is-split --cmdline "${handler}"`, undefined, false, true)
} else if (!isHeadless() && drilldownTo === 'new-window') {
const { ipcRenderer } = await import('electron')
ipcRenderer.send(
'synchronous-message',
JSON.stringify({
operation: 'new-window',
argv: split(handler)
})
)
} else {
repl.pexec(handler, opts)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function renderTable(
<LivePaginatedTable
tab={tab}
repl={repl}
config={config}
response={response}
paginate={paginate}
title={!config.disableTableTitle}
Expand All @@ -62,6 +63,7 @@ export default function renderTable(
<PaginatedTable
tab={tab}
repl={repl}
config={config}
response={response}
paginate={paginate}
title={!config.disableTableTitle}
Expand Down

0 comments on commit 96d1d0e

Please sign in to comment.