Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(explore): Reset values in TextControl only when datasource changes #13211

Merged
merged 2 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export default class SelectControl extends React.PureComponent {
isMulti &&
optionsRemaining &&
Array.isArray(this.state.value) &&
Array.isArray(value) &&
!!value.length
) {
assistiveText = optionRemaingText;
Expand Down
16 changes: 10 additions & 6 deletions superset-frontend/src/explore/components/controls/TextControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface TextControlProps {

interface TextControlState {
controlId: string;
currentDatasource?: string;
value?: string | number;
}

Expand All @@ -55,8 +56,14 @@ export default class TextControl extends React.Component<
props: TextControlProps,
state: TextControlState,
) {
if (props.value !== state.value) {
return { value: props.value };
// reset value when datasource changes
// props.datasource and props.value don't update in the same re-render,
// so we need to synchronize them to update the state with correct values
if (
props.value !== state.value &&
props.datasource !== state.currentDatasource
) {
return { value: props.value, currentDatasource: props.datasource };
}
return null;
}
Expand All @@ -69,13 +76,10 @@ export default class TextControl extends React.Component<
this.state = {
controlId: generateControlId(props.controlId),
value: props.value,
currentDatasource: props.datasource,
};
}

defaultInput = () => {
this.setState({ value: '' });
};

onChange = (inputValue: string) => {
let parsedValue: string | number = inputValue;
// Validation & casting
Expand Down