Skip to content

Commit 75e1ec8

Browse files
committed
fix: regression in user updates to form inputs
user typed updates would not register
1 parent 3b9a4d3 commit 75e1ec8

File tree

1 file changed

+18
-3
lines changed
  • plugins/plugin-codeflare/src/components

1 file changed

+18
-3
lines changed

Diff for: plugins/plugin-codeflare/src/components/Ask.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ export default class AskUI extends React.PureComponent<Props, State> {
101101
}
102102

103103
public static getDerivedStateFromProps(props: Props, state: State) {
104+
console.error(
105+
"!!!!!!!!",
106+
state.form,
107+
state.form && state.form.ask === props.ask,
108+
state.form && state.form.ask,
109+
props.ask
110+
)
104111
if (state.userSelection && props.ask.prompt.choices.find((_) => _.name === state.userSelection)) {
112+
console.error("!!!!!!!A")
105113
return state
106114
} else if (state.form && state.form.ask === props.ask) {
107115
// there has been an update to the form, nothing to do here
116+
console.error("!!!!!!!B", state.form)
108117
return state
109118
} else {
110119
const suggested = props.ask.prompt.choices.find((_) => (_ as any)["isSuggested"])
@@ -115,6 +124,7 @@ export default class AskUI extends React.PureComponent<Props, State> {
115124
M[_.name] = (_ as any)["initial"]
116125
return M
117126
}, {} as Record<string, string>)
127+
console.error("!!!!!!!C", state)
118128
return {
119129
form: { ask: props.ask, state },
120130
userSelection: !suggested ? undefined : suggested.name,
@@ -349,9 +359,14 @@ export default class AskUI extends React.PureComponent<Props, State> {
349359
private readonly _onFormChange = (value: string, evt: React.FormEvent<HTMLInputElement>) => {
350360
const name = evt.currentTarget.getAttribute("data-name")
351361
if (name && this.state.form) {
352-
this.setState((curState) =>
353-
!curState.form ? null : { form: Object.assign({}, curState.form, { [name]: value }) }
354-
)
362+
this.setState((curState) => {
363+
if (curState.form) {
364+
curState.form.state[name] = value
365+
return { form: Object.assign({}, curState.form) }
366+
} else {
367+
return null
368+
}
369+
})
355370
}
356371
}
357372

0 commit comments

Comments
 (0)