Skip to content

Commit

Permalink
fix: terminal component does not restart if given different extraEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Oct 14, 2022
1 parent b51bfc4 commit e4cc00a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/plugin-codeflare/src/controller/terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type State = Partial<Pick<BaseProps, "cmdline" | "env">> & {
/** Use this guidebook in the terminal execution */
guidebook?: string

/** Any extra env vars to add to the guidebook execution. These will be pre-joined with the default env. */
extraEnv?: BaseProps["env"]

/** Run guidebook in non-interactive mode? */
noninteractive?: boolean

Expand Down Expand Up @@ -131,7 +134,7 @@ export class TaskTerminal extends React.PureComponent<Props, State> {
this.setState((curState) => ({
cmdline,
initCount: curState.initCount + 1,
env: Object.assign({}, env, { MWCLEAR_INITIAL: "true" }, this.props.extraEnv),
env: Object.assign({}, env, { MWCLEAR_INITIAL: "true" }, this.state.extraEnv),
}))
} catch (error) {
console.error("Error initializing command line", error)
Expand All @@ -156,13 +159,16 @@ export class TaskTerminal extends React.PureComponent<Props, State> {
this.setState({ guidebook, ifor: true, noninteractive: false })

public static getDerivedStateFromProps(props: Props, state: State) {
if (props.defaultGuidebook && state.guidebook !== props.defaultGuidebook) {
if ((props.defaultGuidebook && state.guidebook !== props.defaultGuidebook) || props.extraEnv !== state.extraEnv) {
// different guidebook or different env vars to be passed to that guidebook
return {
ifor: false,
extraEnv: props.extraEnv,
guidebook: props.defaultGuidebook,
noninteractive: props.defaultNoninteractive,
}
} else if (props.defaultNoninteractive !== state.noninteractive) {
// different interactivity
return {
ifor: false,
noninteractive: props.defaultNoninteractive,
Expand Down

0 comments on commit e4cc00a

Please sign in to comment.