From 5b0aa27f2bb3e9570241500132b9e09f9dd1f5a3 Mon Sep 17 00:00:00 2001 From: Erik Ritter Date: Mon, 20 Dec 2021 15:53:48 -0800 Subject: [PATCH] feat: Persist SQL Lab autocomplete setting across tabs and visits (#17708) --- .../src/SqlLab/components/SqlEditor/index.jsx | 22 +++++++++++++++---- .../src/utils/localStorageHelpers.ts | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx index 6197256666361..e06d89832716b 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx @@ -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'; @@ -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: '', }; @@ -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() { diff --git a/superset-frontend/src/utils/localStorageHelpers.ts b/superset-frontend/src/utils/localStorageHelpers.ts index 75c18226ef8cc..b530f27b910c4 100644 --- a/superset-frontend/src/utils/localStorageHelpers.ts +++ b/superset-frontend/src/utils/localStorageHelpers.ts @@ -48,6 +48,7 @@ export enum LocalStorageKeys { * Example: * sqllab__is_autocomplete_enabled */ + sqllab__is_autocomplete_enabled = 'sqllab__is_autocomplete_enabled', } export type LocalStorageValues = { @@ -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(