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

feat: Persist SQL Lab autocomplete setting across tabs and visits #17708

Merged
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
22 changes: 18 additions & 4 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ import {
SQL_EDITOR_GUTTER_MARGIN,
SQL_TOOLBAR_HEIGHT,
} from 'src/SqlLab/constants';
import {
getItem,
LocalStorageKeys,
setItem,
} from 'src/utils/localStorageHelpers';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import TemplateParamsEditor from '../TemplateParamsEditor';
import ConnectedSouthPane from '../SouthPane/state';
Expand Down Expand Up @@ -171,7 +176,10 @@ class SqlEditor extends React.PureComponent {
northPercent: props.queryEditor.northPercent || INITIAL_NORTH_PERCENT,
southPercent: props.queryEditor.southPercent || INITIAL_SOUTH_PERCENT,
sql: props.queryEditor.sql,
autocompleteEnabled: true,
autocompleteEnabled: getItem(
LocalStorageKeys.sqllab__is_autocomplete_enabled,
true,
),
showCreateAsModal: false,
createAs: '',
};
Expand Down Expand Up @@ -365,9 +373,15 @@ class SqlEditor extends React.PureComponent {
}

handleToggleAutocompleteEnabled = () => {
this.setState(prevState => ({
autocompleteEnabled: !prevState.autocompleteEnabled,
}));
this.setState(prevState => {
setItem(
LocalStorageKeys.sqllab__is_autocomplete_enabled,
!prevState.autocompleteEnabled,
);
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a return necessary when it wasn’t previously?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does previously. An arrow function with just expression will use the value of that expression as the return value.

autocompleteEnabled: !prevState.autocompleteEnabled,
};
});
};

handleWindowResize() {
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/utils/localStorageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum LocalStorageKeys {
* Example:
* sqllab__is_autocomplete_enabled
*/
sqllab__is_autocomplete_enabled = 'sqllab__is_autocomplete_enabled',
}

export type LocalStorageValues = {
Expand All @@ -60,6 +61,7 @@ export type LocalStorageValues = {
homepage_dashboard_filter: TableTabTypes;
homepage_collapse_state: string[];
homepage_activity_filter: SetTabType | null;
sqllab__is_autocomplete_enabled: boolean;
};

export function getItem<K extends LocalStorageKeys>(
Expand Down