Skip to content

Commit

Permalink
feat: Persist SQL Lab autocomplete setting across tabs and visits
Browse files Browse the repository at this point in the history
  • Loading branch information
erik_ritter committed Dec 20, 2021
1 parent 6edc183 commit 24c3d9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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 {
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

0 comments on commit 24c3d9a

Please sign in to comment.