Skip to content

Commit

Permalink
fix(plugins/plugin-client-common): when rerunning blocks, output alwa…
Browse files Browse the repository at this point in the history
…ys scrolls to bottom

part of kubernetes-sigs#7527
  • Loading branch information
starpit authored and k8s-ci-robot committed Jun 4, 2021
1 parent 207fe96 commit 4e360a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export function hasOriginalUUID(block: BlockModel | WithOriginalExecUUID): block
return typeof (block as WithOriginalExecUUID).originalExecUUID === 'string'
}

export function hasBeenRerun(block: BlockModel): boolean {
return hasOriginalUUID(block)
}

/** Transform to Processing */
export function Processing(
block: BlockModel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
FinishedBlock,
hasUUID,
hasCommand,
hasBeenRerun,
isBeingRerun,
isFinished,
isProcessing,
Expand Down Expand Up @@ -171,7 +172,8 @@ export default class Output extends React.PureComponent<Props, State> {
}

private onRender(assertHasContent: boolean): void {
if (this.props.onRender) {
if (this.props.onRender && !this.props.isBeingRerun && !hasBeenRerun(this.props.model)) {
// we don't want reruns to trigger any scrolling behavior
this.props.onRender()
}
this.setState({ assertHasContent })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type ScrollbackState = ScrollbackOptions & {
onFocus: (evt: React.FocusEvent) => void
onOutputRender: () => void
navigateTo: (dir: 'first' | 'last' | 'previous' | 'next') => void
setActiveBlock: (c: Block) => void
willFocusBlock: (evt: React.SyntheticEvent) => void
willRemoveBlock: (evt: React.SyntheticEvent, idx?: number) => void
willUpdateCommand: (idx: number, command: string) => void
Expand Down Expand Up @@ -403,6 +404,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
onFocus: undefined,
onOutputRender: undefined,
navigateTo: undefined,
setActiveBlock: undefined,
willFocusBlock: undefined,
willRemoveBlock: undefined,
willUpdateCommand: undefined
Expand Down Expand Up @@ -462,6 +464,13 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
})
}

/** Update the active block */
state.setActiveBlock = (c: Block) => {
if (c && c.props && c.props.model && isActive(c.props.model)) {
state._activeBlock = c
}
}

/**
* User clicked to focus a block.
*
Expand Down Expand Up @@ -1327,7 +1336,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
isWidthConstrained={isWidthConstrained}
onOutputRender={scrollback.onOutputRender}
navigateTo={scrollback.navigateTo}
ref={idx !== this.findActiveBlock(scrollback) ? undefined : c => (scrollback._activeBlock = c)}
ref={scrollback.setActiveBlock}
/>
)
})
Expand Down

0 comments on commit 4e360a9

Please sign in to comment.