Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: local storage with user (#13195)
ecmadao3452c3f42318
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vueindex 1a8b0618ad..a572f504c7 100644--- a/frontend/src/components/ProvideDashboardContext.vue+++ b/frontend/src/components/ProvideDashboardContext.vue@@ -86,7 +86,7 @@ onMounted(async () => {useEnvironmentV1Store().fetchEnvironments(),useProjectV1Store().fetchProjectList(true /* showDeleted */),]);- await Promise.all([useUIStateStore().restoreState()]);+ useUIStateStore().restoreState();await fetchInstancesAndDatabases(route.params.projectId as string);isInitializing.value = false;diff --git a/frontend/src/router/useRecentVisit.ts b/frontend/src/router/useRecentVisit.tsindex 9e76657814..15100ed1a1 100644--- a/frontend/src/router/useRecentVisit.ts+++ b/frontend/src/router/useRecentVisit.ts@@ -1,7 +1,8 @@-import { useLocalStorage, useDebounce } from "@vueuse/core";+import { useDebounce } from "@vueuse/core";import { computed, ref, watch, nextTick } from "vue";import { useRoute } from "vue-router";-import { useAuthStore } from "@/store";+import { useCurrentUserV1 } from "@/store";+import { useDynamicLocalStorage } from "@/utils";import { WORKSPACE_ROOT_MODULE } from "./dashboard/workspaceRoutes";type RecentVisit = {@@ -14,10 +15,11 @@ const MAX_HISTORY = 3;export function useRecentVisit() {const route = useRoute();- const authStore = useAuthStore();- const recentVisit = useLocalStorage(- `${STORAGE_KEY}.${authStore.currentUserId ?? 0}`,- [] as RecentVisit[]+ const currentUser = useCurrentUserV1();++ const recentVisit = useDynamicLocalStorage<RecentVisit[]>(+ computed(() => `${STORAGE_KEY}.${currentUser.value.name}`),+ []);const lastVisit = computed(() => {diff --git a/frontend/src/store/modules/uistate.ts b/frontend/src/store/modules/uistate.tsindex 170ff19aea..c07860a4fe 100644--- a/frontend/src/store/modules/uistate.ts+++ b/frontend/src/store/modules/uistate.ts@@ -1,101 +1,100 @@import { useLocalStorage } from "@vueuse/core";import { isUndefined } from "lodash-es";import { defineStore } from "pinia";--const COLLAPSE_MODULE = "ui.list.collapse";-const INTRO_MODULE = "ui.intro";--// default to false-const editorFormatStatementOnSave = useLocalStorage(- "ui.state.editor.format-statement-on-save",- false-);+import { computed, reactive } from "vue";+import { useCurrentUserV1 } from "@/store";export interface UIState {collapseStateByKey: Map<string, boolean>;introStateByKey: Map<string, boolean>;}-export const useUIStateStore = defineStore("uistate", {- state: (): UIState => ({+export const useUIStateStore = defineStore("uistate", () => {+ const state = reactive<UIState>({collapseStateByKey: new Map(),introStateByKey: new Map(),- }),- getters: {- editorFormatStatementOnSave: () => {- return editorFormatStatementOnSave.value;- },- },- actions: {- getCollapseStateByKey(key: string): boolean {- return stateByKey(this.collapseStateByKey, COLLAPSE_MODULE, key);- },- getIntroStateByKey(key: string): boolean {- return stateByKey(this.introStateByKey, INTRO_MODULE, key);- },- setCollapseState(fullState: any) {- const newMap = new Map();- for (const key in fullState) {- newMap.set(key, fullState[key]);- }- this.collapseStateByKey = newMap;- },- setCollapseStateByKey({- key,- collapse,- }: {- key: string;- collapse: boolean;- }) {- this.collapseStateByKey.set(key, collapse);- },- setIntroState(fullState: any) {- const newMap = new Map();- for (const key in fullState) {- newMap.set(key, fullState[key]);- }- this.introStateByKey = newMap;- },- setIntroStateByKey({ key, newState }: { key: string; newState: boolean }) {- this.introStateByKey.set(key, newState);- },- setEditorFormatStatementOnSave(value: boolean) {- editorFormatStatementOnSave.value = value;- },- async restoreState() {- const storedCollapseState = localStorage.getItem(COLLAPSE_MODULE);- const collapseState = storedCollapseState- ? JSON.parse(storedCollapseState)- : {};- this.setCollapseState(collapseState);+ });+ const currentUser = useCurrentUserV1();++ const COLLAPSE_MODULE_KEY = computed(+ () => `ui.list.collapse.${currentUser.value.name}`+ );+ const INTRO_MODULE_KEY = computed(() => `ui.intro.${currentUser.value.name}`);+ const EDITOR_FORMAT_MODULE_KEY = computed(+ () => `ui.state.editor.format-statement-on-save.${currentUser.value.name}`+ );++ // default to false+ const editorFormatStatementOnSave = useLocalStorage(+ EDITOR_FORMAT_MODULE_KEY.value,+ false+ );++ const getIntroStateByKey = (key: string): boolean => {+ return stateByKey(state.introStateByKey, INTRO_MODULE_KEY.value, key);+ };++ const setCollapseState = (fullState: any) => {+ const newMap = new Map();+ for (const key in fullState) {+ newMap.set(key, fullState[key]);+ }+ state.collapseStateByKey = newMap;+ };++ const setIntroState = (fullState: any) => {+ const newMap = new Map();+ for (const key in fullState) {+ newMap.set(key, fullState[key]);+ }+ state.introStateByKey = newMap;+ };++ const setIntroStateByKey = ({+ key,+ newState,+ }: {+ key: string;+ newState: boolean;+ }) => {+ state.introStateByKey.set(key, newState);+ };++ const setEditorFormatStatementOnSave = (value: boolean) => {+ editorFormatStatementOnSave.value = value;+ };++ const restoreState = () => {+ const storedCollapseState = localStorage.getItem(COLLAPSE_MODULE_KEY.value);+ const collapseState = storedCollapseState+ ? JSON.parse(storedCollapseState)+ : {};+ setCollapseState(collapseState);++ const storedIntroState = localStorage.getItem(INTRO_MODULE_KEY.value);+ const introState = storedIntroState ? JSON.parse(storedIntroState) : {};+ setIntroState(introState);+ };++ const saveIntroStateByKey = async ({+ key,+ newState,+ }: {+ key: string;+ newState: boolean;+ }) => {+ const state = saveStateByKey(INTRO_MODULE_KEY.value, key, newState);+ setIntroStateByKey({ key, newState });+ return state;+ };- const storedIntroState = localStorage.getItem(INTRO_MODULE);- const introState = storedIntroState ? JSON.parse(storedIntroState) : {};- this.setIntroState(introState);- },- async saveCollapseStateByKey({- key,- collapse,- }: {- key: string;- collapse: boolean;- }) {- const state = saveStateByKey(COLLAPSE_MODULE, key, collapse);- this.setCollapseStateByKey({ key, collapse: state });- return state;- },- async saveIntroStateByKey({- key,- newState,- }: {- key: string;- newState: boolean;- }) {- const state = saveStateByKey(INTRO_MODULE, key, newState);- this.setIntroStateByKey({ key, newState });- return state;- },- },+ return {+ saveIntroStateByKey,+ restoreState,+ setEditorFormatStatementOnSave,+ getIntroStateByKey,+ editorFormatStatementOnSave,+ };});const stateByKey = function (