Skip to content

Commit

Permalink
ui/cluster-ui: prevent returning new obj from session storage every time
Browse files Browse the repository at this point in the history
When we retrieve from localSettings in db-console, we retrieve
in the following order: `localSettings ?? sessionStorage ?? defaultValue`
The value from the session storage is retrieved via parsing a JSON
string and returning a new object. In the active execution pages, we
update the URL search string every time the filters object changes to
reflect any filters selected. Due to the local settings behaviour,
we could end up in an infinite update loop if we continously read from
session storage since a new object was being returned each time
(e.g. on a hard refresh). To prevent this, when retrieving a stored
value, if it exists in session storage but not local storage, we can
set the local setting to be parsed object from session storage.

Release note (bug fix): active execution pages will no longer crash
if there are no filters set in local settings.

Release justification: bug fix
  • Loading branch information
xinhaoz committed Aug 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4561f22 commit fff9cce
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/ui/workspaces/db-console/src/redux/localsettings.ts
Original file line number Diff line number Diff line change
@@ -157,6 +157,9 @@ export class LocalSetting<S, T> {
innerSelector,
() => getValueFromSessionStorage(this.key),
(uiSettings, cachedValue) => {
if (cachedValue != null && uiSettings[this.key] == null) {
uiSettings[this.key] = cachedValue;
}
return uiSettings[this.key] ?? cachedValue ?? defaultValue;
},
);
Original file line number Diff line number Diff line change
@@ -27,13 +27,15 @@ const selectedColumnsLocalSetting = new LocalSetting<
null,
);

const defaultActiveFilters = { app: defaultFilters.app };

const filtersLocalSetting = new LocalSetting<
AdminUIState,
ActiveStatementFilters
>(
"filters/ActiveStatementsPage",
(state: AdminUIState) => state.localSettings,
{ app: defaultFilters.app },
defaultActiveFilters,
);

const sortSettingLocalSetting = new LocalSetting<AdminUIState, SortSetting>(
Original file line number Diff line number Diff line change
@@ -28,13 +28,15 @@ const transactionsColumnsLocalSetting = new LocalSetting<
null,
);

const defaultActiveTxnFilters = { app: defaultFilters.app };

const filtersLocalSetting = new LocalSetting<
AdminUIState,
ActiveTransactionFilters
>(
"filters/ActiveTransactionsPage",
(state: AdminUIState) => state.localSettings,
{ app: defaultFilters.app },
defaultActiveTxnFilters,
);

const sortSettingLocalSetting = new LocalSetting<AdminUIState, SortSetting>(

0 comments on commit fff9cce

Please sign in to comment.