Skip to content

Commit

Permalink
fix: regression in user updates to form inputs
Browse files Browse the repository at this point in the history
user typed updates would not register
  • Loading branch information
starpit committed Nov 30, 2022
1 parent 3b9a4d3 commit 75e1ec8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugins/plugin-codeflare/src/components/Ask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ export default class AskUI extends React.PureComponent<Props, State> {
}

public static getDerivedStateFromProps(props: Props, state: State) {
console.error(
"!!!!!!!!",
state.form,
state.form && state.form.ask === props.ask,
state.form && state.form.ask,
props.ask
)
if (state.userSelection && props.ask.prompt.choices.find((_) => _.name === state.userSelection)) {
console.error("!!!!!!!A")
return state
} else if (state.form && state.form.ask === props.ask) {
// there has been an update to the form, nothing to do here
console.error("!!!!!!!B", state.form)
return state
} else {
const suggested = props.ask.prompt.choices.find((_) => (_ as any)["isSuggested"])
Expand All @@ -115,6 +124,7 @@ export default class AskUI extends React.PureComponent<Props, State> {
M[_.name] = (_ as any)["initial"]
return M
}, {} as Record<string, string>)
console.error("!!!!!!!C", state)
return {
form: { ask: props.ask, state },
userSelection: !suggested ? undefined : suggested.name,
Expand Down Expand Up @@ -349,9 +359,14 @@ export default class AskUI extends React.PureComponent<Props, State> {
private readonly _onFormChange = (value: string, evt: React.FormEvent<HTMLInputElement>) => {
const name = evt.currentTarget.getAttribute("data-name")
if (name && this.state.form) {
this.setState((curState) =>
!curState.form ? null : { form: Object.assign({}, curState.form, { [name]: value }) }
)
this.setState((curState) => {
if (curState.form) {
curState.form.state[name] = value
return { form: Object.assign({}, curState.form) }
} else {
return null
}
})
}
}

Expand Down

0 comments on commit 75e1ec8

Please sign in to comment.