Skip to content

Commit

Permalink
feat(plugins/plugin-client-common): support client option for hero na…
Browse files Browse the repository at this point in the history
…mes in sidecar

Fixes #4909
  • Loading branch information
myan9 authored and starpit committed Jun 18, 2020
1 parent f763d94 commit 6b930d9
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 37 deletions.
11 changes: 6 additions & 5 deletions packages/test/src/api/mmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export class TestMMR {
nameHash?: string
prettyName?: string
onclick?: {
name: ClickExpect
name?: ClickExpect
nameHash?: ClickExpect
}
heroName?: boolean
}) {
const { command, testName, metadata } = this.param
const testClickResult = this.testClickResult
Expand All @@ -73,7 +74,7 @@ export class TestMMR {
before(Common.before(this))
after(Common.after(this))

const { nameHash, prettyName, onclick } = opt
const { nameHash, prettyName, onclick, heroName } = opt

let cmdIdx = 0 // keep track of the command execution number

Expand All @@ -86,11 +87,11 @@ export class TestMMR {
})
.then(ReplExpect.ok)
.then(SidecarExpect.open)
.then(SidecarExpect.name(showName))
.then(heroName ? SidecarExpect.heroName(showName) : SidecarExpect.name(showName))
.then(app => (nameHash ? SidecarExpect.namehash(nameHash) : app))
.catch(Common.oops(this, true)))

if (onclick.name) {
if (onclick && onclick.name) {
it('should click the name part of sidecar and expect the command shows in repl', async () => {
try {
await this.app.client.click(Selectors.SIDECAR_TITLE)
Expand All @@ -101,7 +102,7 @@ export class TestMMR {
})
}

if (onclick.nameHash) {
if (onclick && onclick.nameHash) {
it('should click the namehash part of sidecar and expect the command shows in repl', async () => {
try {
await this.app.client.click(Selectors.SIDECAR_ACTIVATION_TITLE)
Expand Down
2 changes: 2 additions & 0 deletions packages/test/src/api/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export const SIDECAR = `${SIDECAR_BASE}.visible:not(.minimized)`
export const SIDECAR_WITH_FAILURE = `${SIDECAR_BASE}.visible.activation-success-false`
export const SIDECAR_ACTIVATION_TITLE = `${SIDECAR} .kui--sidecar-entity-name-hash .bx--link`
export const SIDECAR_TITLE = `${SIDECAR} .kui--sidecar-entity-name .bx--link`
export const SIDECAR_HERO_TITLE = `${SIDECAR} .sidecar-header .sidecar-header-name`
export const SIDECAR_LEFTNAV_TITLE = `${SIDECAR} .sidecar-header-name-content .bx--side-nav__submenu-title`
export const SIDECAR_HEADER_NAVIGATION = `${SIDECAR} .kui--sidecar--titlebar-navigation`
export const SIDECAR_BREADCRUMBS = `${SIDECAR_HEADER_NAVIGATION} .bx--breadcrumb .bx--breadcrumb-item .bx--link`
export const SIDECAR_PACKAGE_NAME_TITLE = `${SIDECAR} .kui--sidecar-entity-namespace .bx--link`
export const SIDECAR_POPUP_TITLE = SIDECAR_TITLE
export const SIDECAR_POPUP_HERO_TITLE = SIDECAR_HERO_TITLE
export const SIDECAR_KIND = `${SIDECAR} .kui--sidecar-kind .bx--link`
export const SIDECAR_CONTENT = `${SIDECAR} .sidecar-content`
export const SIDECAR_WEB_ACTION_URL = `${SIDECAR} .sidecar-header .entity-web-export-url.has-url`
Expand Down
4 changes: 3 additions & 1 deletion packages/test/src/api/sidecar-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ const show = (expected: string, selector: string) => async (app: Application) =>

export const name = (expectedName: string) => show(expectedName, Selectors.SIDECAR_TITLE)

export const heroName = (expectedName: string) => show(expectedName, Selectors.SIDECAR_HERO_TITLE)

export const namehash = (expectedNameHash: string) => show(expectedNameHash, Selectors.SIDECAR_ACTIVATION_TITLE)

export const namespace = (expectedNamespace: string) => show(expectedNamespace, Selectors.SIDECAR_PACKAGE_NAME_TITLE)
Expand Down Expand Up @@ -241,7 +243,7 @@ export const yaml = (content: object) => async (app: Application) => {

export async function popupTitle(app: Application, expectedTitle: string) {
return app.client.waitUntil(async () => {
const actualTitle = await app.client.getText(Selectors.SIDECAR_POPUP_TITLE)
const actualTitle = await app.client.getText(Selectors.SIDECAR_POPUP_HERO_TITLE)
return actualTitle === expectedTitle
}, waitTimeout)
}
Expand Down
16 changes: 12 additions & 4 deletions plugins/plugin-client-common/src/components/Client/Kui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Kui extends React.PureComponent<Props, State> {
}

try {
this.state = Object.assign({}, this.defaultSessionBehavior(), props, {
this.state = Object.assign({}, this.defaultSessionBehavior(), this.defaultFeatureFlag(), props, {
isBootstrapped: !!props.noBootstrap
})
debug('initial state', this.state)
Expand All @@ -113,6 +113,12 @@ export class Kui extends React.PureComponent<Props, State> {
}
}

private defaultFeatureFlag() {
return {
sidecarName: 'breadcrumb'
}
}

/**
* For browser-based clients, this defines the default UI for
* session initialization.
Expand Down Expand Up @@ -161,9 +167,11 @@ export class Kui extends React.PureComponent<Props, State> {

if (this.props.isPopup && this.props.commandLine) {
return (
<React.Suspense fallback={<div />}>
<Popup commandLine={this.props.commandLine}>{this.props.children}</Popup>
</React.Suspense>
<KuiContext.Provider value={this.state}>
<React.Suspense fallback={<div />}>
<Popup commandLine={this.props.commandLine}>{this.props.children}</Popup>
</React.Suspense>
</KuiContext.Provider>
)
} else {
const bottom = !!this.props.bottomInput && <InputStripe>{this.props.bottomInput}</InputStripe>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type FeatureFlags = {
/** [Optional] disable table title? */
disableTableTitle?: boolean

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

/** [Optional] Enable Split Terminals? */
splitTerminals?: boolean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Badge from './Badge'
import ToolbarContainer from './ToolbarContainer'
import { BreadcrumbView } from '../../spi/Breadcrumb'
import { BaseSidecar, Props, SidecarHistoryEntry, cwd } from './BaseSidecar'
import KuiContext from '../../Client/context'

import '../../../../web/css/static/ToolbarButton.scss'

Expand Down Expand Up @@ -130,6 +131,8 @@ export function getStateFromMMR(
*
*/
export default class TopNavSidecar extends BaseSidecar<MultiModalResponse, HistoryEntry> {
public static contextType = KuiContext

public constructor(props: Props) {
super(props)

Expand Down Expand Up @@ -178,16 +181,29 @@ export default class TopNavSidecar extends BaseSidecar<MultiModalResponse, Histo
return { 'flex-direction': 'column' }
}

private namePart() {
/** return the name from the response */
private name(): string {
return (
<div className="header-left-bits">
<div className="sidecar-header-text">
<div className="sidecar-header-name" data-base-class="sidecar-header-name">
<div className="sidecar-header-name-content" data-base-class="sidecar-header-name-content"></div>
this.current.response &&
(this.current.response.prettyName ||
(this.current.response.metadata ? this.current.response.metadata.name : undefined))
)
}

private namePart() {
if (this.context.sidecarName === 'heroText') {
return (
<div className="header-left-bits">
<div className="sidecar-header-text">
<div className="sidecar-header-name" data-base-class="sidecar-header-name">
<div className="sidecar-header-name-content" data-base-class="sidecar-header-name-content">
{this.name()}
</div>
</div>
</div>
</div>
</div>
)
)
}
}

/** Tell the world that we have changed the focused mode */
Expand Down Expand Up @@ -326,18 +342,17 @@ export default class TopNavSidecar extends BaseSidecar<MultiModalResponse, Histo
return { label: kind, command: onclick && onclick.kind, className: 'kui--sidecar-kind' }
}

/** show name as breadcrumb when not showing context as hero text in sidecar header */
private nameBreadcrumb(): BreadcrumbView {
const name =
this.current.response &&
(this.current.response.prettyName ||
(this.current.response.metadata ? this.current.response.metadata.name : undefined))
const { onclick } = this.current.response

return {
label: name,
command: onclick && onclick.name,
isCurrentPage: true,
className: 'kui--sidecar-entity-name'
if (this.context.sidecarName === 'breadcrumb') {
const { onclick } = this.current.response

return {
label: this.name(),
command: onclick && onclick.name,
isCurrentPage: true,
className: 'kui--sidecar-entity-name'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
}

private allocateUUIDForScrollback() {
if (this.props.config.splitTerminals) {
if (this.props.config.splitTerminals && !isPopup()) {
return `${this.props.uuid}_${uuid()}`
} else {
return this.props.uuid
Expand Down Expand Up @@ -391,7 +391,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
eventChannelUnsafe.off(`/terminal/clear/${state.uuid}`, clear)
})

if (this.props.config.splitTerminals) {
if (this.props.config.splitTerminals && !isPopup()) {
const split = this.onSplit.bind(this)
onSplit(state.uuid, split)
state.cleaners.push(() => offSplit(state.uuid, split))
Expand Down
5 changes: 5 additions & 0 deletions plugins/plugin-client-common/web/css/static/sidecar-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
margin: 0.75em 0 0;
}

.sidecar-header-text {
margin: 0 0 0.75em 0;
font-size: 22px;
}

.kui--sidecar-overflow {
font-size: 1em;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-client-test/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import '../web/css/static/test.scss'
*/
export default function TestClient(props: KuiProps) {
return (
<Kui {...props} disableTableTitle>
<Kui {...props} disableTableTitle sidecarName="heroText">
<ContextWidgets>
<CounterWidget idx={0} />
</ContextWidgets>
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-client-test/src/test/response/mmr-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ testReact.toolbarText({
text: 'hello this is iter',
exact: false
})
testDefault.name({ onclick: { name: { command: 'test string', expect: 'hello world' } } })
testDefault.name({ heroName: true })
testDefault.modes(expectModes, expectModes[0], { testWindowButtons: true })
testDefault2.modes(expectModes2, expectModes2[0])
testDefault3.modes(expectModes3, expectModes3[0])
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugin-client-test/src/test/response/mmr-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ const testPrettyName = new TestMMR({

testMetadataName.name({
nameHash: 'this is the namehash part',
heroName: true,
onclick: {
name: { command: 'test string', expect: 'hello world' },
nameHash: { command: 'test string --grumble 1', expect: 'hello world 1' }
}
})

testPrettyName.name({
nameHash: 'this is the namehash part',
prettyName: 'this is the prettyName part',
heroName: true,
onclick: {
name: { command: 'test string', expect: 'hello world' },
nameHash: { command: 'test string --grumble 1', expect: 'hello world 1' }
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const test = new TestMMR({

test.name({
nameHash: 'this is the namehash part',
heroName: true,
onclick: {
name: { command: 'test string --grumble 1', expect: 'hello world 1' },
nameHash: { command: 'test string --grumble 3', expect: 'hello world 3' }
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('TopNavSidecar back button', function(this: Common.ISuite) {
return CLI.command(firstCmd, this.app)
.then(ReplExpect.justOK)
.then(SidecarExpect.open)
.then(SidecarExpect.showingTopNav('this is the name part'))
.then(SidecarExpect.heroName('this is the name part'))
.then(
() =>
!startOfBuffer
Expand All @@ -143,7 +143,7 @@ describe('TopNavSidecar back button', function(this: Common.ISuite) {
return CLI.command(secondCmd, this.app)
.then(ReplExpect.justOK)
.then(SidecarExpect.open)
.then(SidecarExpect.showingTopNav('this is the name part'))
.then(SidecarExpect.heroName('this is the name part'))
.then(SidecarExpect.badge('badge1'))
.then(SidecarExpect.button({ mode: 'button1', label: 'button1 label' }))
.then(() => this.app.client.waitForVisible(Selectors.SIDECAR_BACK_BUTTON)) // back button IS visible
Expand Down

0 comments on commit 6b930d9

Please sign in to comment.