Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: first attempt to pinia (#980)

Liu Ji602f572db973
diff --git a/frontend/package.json b/frontend/package.json
index 5a7490ad60..fa7b7a15cd 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -25,6 +25,7 @@
"naive-ui": "^2.26.4",
"node-sql-parser": "^4.0.8",
"papaparse": "^5.3.1",
+ "pinia": "^2.0.12",
"slug": "^4.0.2",
"splitpanes": "^3.0.6",
"sql-formatter": "^4.0.2",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index a1fe8a6ef7..db1d50e563 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -36,6 +36,7 @@ specifiers:
naive-ui: ^2.26.4
node-sql-parser: ^4.0.8
papaparse: ^5.3.1
+ pinia: ^2.0.12
postcss: ^8.4.12
prettier: ^2.4.1
slug: ^4.0.2
@@ -72,6 +73,7 @@ dependencies:
node-sql-parser: 4.1.1
papaparse: 5.3.1
slug: 4.1.0
splitpanes: 3.1.1
sql-formatter: 4.0.2
@@ -298,8 +300,8 @@ packages:
vue-i18n:
optional: true
dependencies:
- '@intlify/message-compiler': 9.2.0-beta.32
- '@intlify/shared': 9.2.0-beta.32
+ '@intlify/message-compiler': 9.2.0-beta.33
+ '@intlify/shared': 9.2.0-beta.33
jsonc-eslint-parser: 1.4.1
source-map: 0.6.1
@@ -329,10 +331,25 @@ packages:
dependencies:
'@intlify/shared': 9.2.0-beta.32
source-map: 0.6.1
+ dev: false
+
+ /@intlify/message-compiler/9.2.0-beta.33:
+ resolution: {integrity: sha512-+SICjFlnHSbRLZT+sNdBvOAQfcNX+fESyMmgPxC8HHWu4GLN2CoVQS4ACXb3QBZDKLVJBFhFGMnl+UXyJrno6g==}
+ engines: {node: '>= 12'}
+ dependencies:
+ '@intlify/shared': 9.2.0-beta.33
+ source-map: 0.6.1
+ dev: true
/@intlify/shared/9.2.0-beta.32:
resolution: {integrity: sha512-lVaHnKFNg16eWlfDLzDFLapurrf0WK7xLWEkz8DMYNIXJshRQOZCkH7sQaqtONPoOT0LqjyPo1+sV0Wq85/HRQ==}
engines: {node: '>= 12'}
+ dev: false
+
+ /@intlify/shared/9.2.0-beta.33:
+ resolution: {integrity: sha512-HldlkV66vMt1vQsuUz4zjQ202C5KW6aHeIQhx7RxBO11i3E8V84dp5MG9epr9GZXVsrCAR56Ekj0HaTqksIRJA==}
+ engines: {node: '>= 12'}
+ dev: true
/@intlify/vite-plugin-vue-i18n/3.3.1_ee51299bfed31ad0f4705239faf2563e:
resolution: {integrity: sha512-b9HIUANzL4/LmrA5RqeiPabZl2/RiWNAJ90TVZ8kSi3APRZ4BbmwUAclKe8ip+1jCDhqaGO/qfAI7SbQ0Y76Uw==}
@@ -348,7 +365,7 @@ packages:
optional: true
dependencies:
'@intlify/bundle-utils': [email protected]
- '@intlify/shared': 9.2.0-beta.32
+ '@intlify/shared': 9.2.0-beta.33
'@rollup/pluginutils': 4.2.0
debug: 4.3.3
fast-glob: 3.2.11
@@ -2463,6 +2480,24 @@ packages:
engines: {node: '>=8.6'}
dev: true
+ resolution: {integrity: sha512-tUeuYGFrLU5irmGyRAIxp35q1OTcZ8sKpGT4XkPeVcG35W4R6cfXDbCGexzmVqH5lTQJJTXXbNGutIu9yS5yew==}
+ peerDependencies:
+ '@vue/composition-api': ^1.4.0
+ typescript: '>=4.4.4'
+ vue: ^2.6.14 || ^3.2.0
+ peerDependenciesMeta:
+ '@vue/composition-api':
+ optional: true
+ typescript:
+ optional: true
+ dependencies:
+ '@vue/devtools-api': 6.1.0
+ typescript: 4.6.2
+ vue: 3.2.31
+ vue-demi: [email protected]
+ dev: false
+
/postcss-js/[email protected]:
resolution: {integrity: sha512-77QESFBwgX4irogGVPgQ5s07vLvFqWr228qZY+w6lW599cRlK/HmnlivnnVUxkjHnCu4J16PDMHcH+e+2HbvTQ==}
engines: {node: ^12 || ^14 || >= 16}
@@ -3088,7 +3123,7 @@ packages:
diff2html: 3.4.16
highlight.js: 10.7.3
vue: 3.2.31
- vue-demi: [email protected]
+ vue-demi: [email protected]
dev: false
/v8-compile-cache/2.3.0:
@@ -3324,6 +3359,21 @@ packages:
vue: 3.2.31
dev: false
+ /vue-demi/[email protected]:
+ resolution: {integrity: sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==}
+ engines: {node: '>=12'}
+ hasBin: true
+ requiresBuild: true
+ peerDependencies:
+ '@vue/composition-api': ^1.0.0-rc.1
+ vue: ^3.0.0-0 || ^2.6.0
+ peerDependenciesMeta:
+ '@vue/composition-api':
+ optional: true
+ dependencies:
+ vue: 3.2.31
+ dev: false
+
/vue-eslint-parser/[email protected]:
resolution: {integrity: sha512-dzHGG3+sYwSf6zFBa0Gi9ZDshD7+ad14DGOdTLjruRVgZXe2J+DcZ9iUhyR48z5g1PqRa20yt3Njna/veLJL/g==}
engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0}
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index 9f10758b8a..c2215fb1f8 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -121,28 +121,30 @@
</template>
<script lang="ts">
-import { computed, ref } from "vue";
+import { computed, defineComponent, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import PrincipalAvatar from "./PrincipalAvatar.vue";
import { ServerInfo } from "../types";
import { useLanguage } from "../composables/useLanguage";
+import { useActuatorStore, useDebugStore } from "@/store";
+import { storeToRefs } from "pinia";
-export default {
+export default defineComponent({
name: "ProfileDropdown",
components: { PrincipalAvatar },
props: {},
setup() {
const store = useStore();
+ const actuatorStore = useActuatorStore();
+ const debugStore = useDebugStore();
const router = useRouter();
const { setLocale, locale } = useLanguage();
const languageMenu = ref();
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const showQuickstart = computed(() => {
- return !store.getters["actuator/isDemo"]();
- });
+ const showQuickstart = computed(() => !actuatorStore.isDemo);
const logout = () => {
store.dispatch("auth/logout").then(() => {
@@ -238,14 +240,16 @@ export default {
});
};
- const isDebug = computed(() => store.getters["debug/isDebug"]());
+ const { isDebug } = storeToRefs(debugStore);
const switchDebug = () => {
- store.dispatch("debug/patchDebug", { isDebug: !isDebug.value });
+ debugStore.patchDebug({
+ isDebug: !isDebug.value,
+ });
};
const ping = () => {
- store.dispatch("actuator/fetchInfo").then((info: ServerInfo) => {
+ actuatorStore.fetchInfo().then((info: ServerInfo) => {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
@@ -275,5 +279,5 @@ export default {
locale,
};
},
-};
+});
</script>
diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vue
index 075895b0d7..1f1d0b3950 100644
--- a/frontend/src/layouts/BodyLayout.vue
+++ b/frontend/src/layouts/BodyLayout.vue
@@ -138,7 +138,7 @@
</template>
<script lang="ts">
-import { computed, reactive } from "vue";
+import { computed, defineComponent, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import Breadcrumb from "../components/Breadcrumb.vue";
@@ -148,12 +148,13 @@ import QuickActionPanel from "../components/QuickActionPanel.vue";
import { QuickActionType } from "../types";
import { isDBA, isDeveloper, isOwner } from "../utils";
import { PlanType } from "../types";
+import { useActuatorStore } from "@/store";
interface LocalState {
showMobileOverlay: boolean;
}
-export default {
+export default defineComponent({
name: "BodyLayout",
components: {
Breadcrumb,
@@ -163,6 +164,7 @@ export default {
},
setup() {
const store = useStore();
+ const actuatorStore = useActuatorStore();
const router = useRouter();
const state = reactive<LocalState>({
@@ -226,13 +228,13 @@ export default {
const showQuickstart = computed(() => {
// Do not show quickstart in demo mode since we don't expect user to alter the data
return (
- !store.getters["actuator/isDemo"]() &&
+ !actuatorStore.isDemo &&
!store.getters["uistate/introStateByKey"]("hidden")
);
});
const version = computed(() => {
- const v = store.getters["actuator/version"]();
+ const v = actuatorStore.version;
if (v.split(".").length == 3) {
return `v${v}`;
}
@@ -267,5 +269,5 @@ export default {
isFreePlan,
};
},
-};
+});
</script>
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index a5b38b7f04..b1e6ce0d71 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -48,9 +48,11 @@ import DashboardHeader from "../views/DashboardHeader.vue";
import BannerDemo from "../views/BannerDemo.vue";
import BannerTrial from "../views/BannerTrial.vue";
import { ServerInfo } from "../types";
-import { computed } from "vue";
+import { computed, defineComponent } from "vue";
+import { useActuatorStore } from "@/store";
+import { storeToRefs } from "pinia";
-export default {
+export default defineComponent({
name: "DashboardLayout",
components: {
ProvideDashboardContext,
@@ -60,9 +62,10 @@ export default {
},
setup() {
const store = useStore();
+ const actuatorStore = useActuatorStore();
const ping = () => {
- store.dispatch("actuator/fetchInfo").then((info: ServerInfo) => {
+ actuatorStore.fetchInfo().then((info: ServerInfo) => {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
@@ -71,13 +74,11 @@ export default {
});
};
- const isDemo = computed(() => store.getters["actuator/isDemo"]());
+ const { isDemo, isReadonly } = storeToRefs(actuatorStore);
const isNearTrialExpireTime = computed(() =>
store.getters["subscription/isNearTrialExpireTime"]()
);
- const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
-
return {
ping,
isDemo,
@@ -85,5 +86,5 @@ export default {
isNearTrialExpireTime,
};
},
-};
+});
</script>
diff --git a/frontend/src/layouts/SqlEditorLayout.vue b/frontend/src/layouts/SqlEditorLayout.vue
index aa69254665..b4d05dad5f 100644
--- a/frontend/src/layouts/SqlEditorLayout.vue
+++ b/frontend/src/layouts/SqlEditorLayout.vue
@@ -43,11 +43,14 @@ import EditorHeader from "@/views/SqlEditor/EditorHeader.vue";
import BannerDemo from "@/views/BannerDemo.vue";
import BannerTrial from "@/views/BannerTrial.vue";
import { ServerInfo } from "../types";
+import { useActuatorStore } from "@/store";
+import { storeToRefs } from "pinia";
const store = useStore();
+const actuatorStore = useActuatorStore();
const ping = () => {
- store.dispatch("actuator/fetchInfo").then((info: ServerInfo) => {
+ actuatorStore.fetchInfo().then((info: ServerInfo) => {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
@@ -56,11 +59,9 @@ const ping = () => {
});
};
-const isDemo = computed(() => store.getters["actuator/isDemo"]());
+const { isDemo, isReadonly } = storeToRefs(actuatorStore);
const isNearTrialExpireTime = computed(() =>
store.getters["subscription/isNearTrialExpireTime"]()
);
-
-const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
</script>
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index ff8df076d1..1abf7b9874 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -15,7 +15,7 @@ import dataSourceType from "./directives/data-source-type";
// @ts-ignore
import highlight from "./directives/highlight";
import { router } from "./router";
-import { store } from "./store";
+import { store, pinia, useActuatorStore } from "./store";
import {
databaseSlug,
dataSourceSlug,
@@ -73,8 +73,8 @@ axios.interceptors.response.use(
// We could receive 401 when calling external service such as VCS provider,
// in such case, we shouldn't logout.
if (error.response.status == 401) {
- const host = store.getters["actuator/info"]().host;
- if (error.response.request.responseURL.startsWith(host))
+ const host = useActuatorStore().info?.host;
+ if (host && error.response.request.responseURL.startsWith(host))
try {
await store.dispatch("auth/logout");
} finally {
@@ -104,51 +104,51 @@ axios.interceptors.response.use(
throw error;
}
);
+const app = createApp(App);
+// Allow template to access various function
+app.config.globalProperties.window = window;
+app.config.globalProperties.console = console;
+app.config.globalProperties.dayjs = dayjs;
+app.config.globalProperties.humanizeTs = humanizeTs;
+app.config.globalProperties.isDev = isDev();
+app.config.globalProperties.isRelease = isRelease();
+app.config.globalProperties.sizeToFit = sizeToFit;
+app.config.globalProperties.urlfy = urlfy;
+app.config.globalProperties.isEmpty = isEmpty;
+app.config.globalProperties.environmentName = environmentName;
+app.config.globalProperties.environmentSlug = environmentSlug;
+app.config.globalProperties.projectName = projectName;
+app.config.globalProperties.projectSlug = projectSlug;
+app.config.globalProperties.instanceName = instanceName;
+app.config.globalProperties.instanceSlug = instanceSlug;
+app.config.globalProperties.databaseSlug = databaseSlug;
+app.config.globalProperties.dataSourceSlug = dataSourceSlug;
+app.config.globalProperties.connectionSlug = connectionSlug;
-// A global hook to collect errors to a central service
-// app.config.errorHandler = function (err, vm, info) {
-// };
+app
+ // Need to use a directive on the element.
+ // The normal hljs.initHighlightingOnLoad() won't work because router change would cause vue
+ // to re-render the page and remove the event listener required for
+ .directive("highlight", highlight)
+ .directive("data-source-type", dataSourceType)
+ .use(store)
+ .use(pinia)
+ .use(router)
+ .use(i18n)
+ .use(splitpanes)
+ .use(NaiveUI);
// We need to restore the basic info in order to perform route authentication.
// Even using the <suspense>, it's still too late, thus we do the fetch here.
// We use finally because we always want to mount the app regardless of the error.
+const initActuator = () => {
+ const actuatorStore = useActuatorStore();
+ return actuatorStore.fetchInfo();
+};
Promise.all([
- store.dispatch("actuator/fetchInfo"),
+ initActuator(),
store.dispatch("subscription/fetchSubscription"),
store.dispatch("auth/restoreUser"),
]).finally(() => {
- const app = createApp(App);
-
- // Allow template to access various function
- app.config.globalProperties.window = window;
- app.config.globalProperties.console = console;
- app.config.globalProperties.dayjs = dayjs;
- app.config.globalProperties.humanizeTs = humanizeTs;
- app.config.globalProperties.isDev = isDev();
- app.config.globalProperties.isRelease = isRelease();
- app.config.globalProperties.sizeToFit = sizeToFit;
- app.config.globalProperties.urlfy = urlfy;
- app.config.globalProperties.isEmpty = isEmpty;
- app.config.globalProperties.environmentName = environmentName;
- app.config.globalProperties.environmentSlug = environmentSlug;
- app.config.globalProperties.projectName = projectName;
- app.config.globalProperties.projectSlug = projectSlug;
- app.config.globalProperties.instanceName = instanceName;
- app.config.globalProperties.instanceSlug = instanceSlug;
- app.config.globalProperties.databaseSlug = databaseSlug;
- app.config.globalProperties.dataSourceSlug = dataSourceSlug;
- app.config.globalProperties.connectionSlug = connectionSlug;
-
- app
- // Need to use a directive on the element.
- // The normal hljs.initHighlightingOnLoad() won't work because router change would cause vue
- // to re-render the page and remove the event listener required for
- .directive("highlight", highlight)
- .directive("data-source-type", dataSourceType)
- .use(store)
- .use(router)
- .use(i18n)
- .use(splitpanes)
- .use(NaiveUI)
- .mount("#app");
+ app.mount("#app");
});
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 9c1fa05407..be3e47d035 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -21,3 +21,5 @@ export const store: Store<any> = createStore({
modules,
strict: !isProd,
});
+
+export * from "./pinia";
diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.ts
deleted file mode 100644
index c9bc09f6c6..0000000000
--- a/frontend/src/store/modules/actuator.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import axios from "axios";
-import { ActuatorState, ServerInfo } from "../../types";
-
-const state: () => ActuatorState = () => ({
- serverInfo: undefined,
-});
-
-const getters = {
- info: (state: ActuatorState) => (): ServerInfo | undefined => {
- return state.serverInfo;
- },
- version: (state: ActuatorState) => (): string => {
- return state.serverInfo?.version || "";
- },
- isDemo: (state: ActuatorState) => (): boolean => {
- return state.serverInfo?.demo || false;
- },
- isReadonly: (state: ActuatorState) => (): boolean => {
- return state.serverInfo?.readonly || false;
- },
- needAdminSetup: (state: ActuatorState) => (): boolean => {
- return state.serverInfo?.needAdminSetup || false;
- },
-};
-
-const actions = {
- async fetchInfo({ commit }: any): Promise<ServerInfo> {
- const serverInfo = (await axios.get(`/api/actuator/info`)).data;
-
- commit("setInfo", serverInfo);
-
- return serverInfo;
- },
-};
-
-const mutations = {
- setInfo(state: ActuatorState, serverInfo: ServerInfo) {
- state.serverInfo = serverInfo;
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/debug.ts b/frontend/src/store/modules/debug.ts
deleted file mode 100644
index 880bd49834..0000000000
--- a/frontend/src/store/modules/debug.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import axios from "axios";
-import { DebugState, ResourceObject } from "../../types";
-import { Debug, DebugPatch } from "../../types/debug";
-
-function convert(debug: ResourceObject): Debug {
- return { ...(debug.attributes as Omit<Debug, "">) };
-}
-
-const state: () => DebugState = () => ({
- isDebug: false,
-});
-
-const getters = {
- isDebug: (state: DebugState) => () => {
- return state.isDebug;
- },
-};
-
-const actions = {
- async fetchDebug() {
- const data = (await axios.get("/api/debug")).data;
- return convert(data);
- },
- async patchDebug({ commit }: any, debugPatch: DebugPatch) {
- const debugState: Debug = convert(
- (
- await axios.patch("/api/debug", {
- data: {
- type: "debugPatch",
- attributes: { isDebug: debugPatch.isDebug },
- },
- })
- ).data.data
- );
- commit("setDebug", debugState);
- },
-};
-
-const mutations = {
- setDebug(state: DebugState, debug: Debug) {
- state.isDebug = debug.isDebug;
- },
-};
-
-export default { namespaced: true, state, getters, actions, mutations };
diff --git a/frontend/src/store/pinia-modules/actuator.ts b/frontend/src/store/pinia-modules/actuator.ts
new file mode 100644
index 0000000000..d6a6df3182
--- /dev/null
+++ b/frontend/src/store/pinia-modules/actuator.ts
@@ -0,0 +1,43 @@
+import axios from "axios";
+import { ActuatorState, ServerInfo } from "@/types";
+import { acceptHMRUpdate, defineStore } from "pinia";
+
+export const useActuatorStore = defineStore("actuator", {
+ state: (): ActuatorState => ({
+ serverInfo: undefined,
+ }),
+ getters: {
+ info: (state) => {
+ return state.serverInfo;
+ },
+ version: (state) => {
+ return state.serverInfo?.version || "";
+ },
+ isDemo: (state) => {
+ return state.serverInfo?.demo || false;
+ },
+ isReadonly: (state) => {
+ return state.serverInfo?.readonly || false;
+ },
+ needAdminSetup: (state) => {
+ return state.serverInfo?.needAdminSetup || false;
+ },
+ },
+ actions: {
+ async fetchInfo() {
+ const serverInfo = (await axios.get(`/api/actuator/info`))
+ .data as ServerInfo;
+
+ this.setInfo(serverInfo);
+
+ return serverInfo;
+ },
+ setInfo(serverInfo: ServerInfo) {
+ this.serverInfo = serverInfo;
+ },
+ },
+});
+
+if (import.meta.hot) {
+ import.meta.hot.accept(acceptHMRUpdate(useActuatorStore, import.meta.hot));
+}
diff --git a/frontend/src/store/pinia-modules/debug.ts b/frontend/src/store/pinia-modules/debug.ts
new file mode 100644
index 0000000000..8a7970657c
--- /dev/null
+++ b/frontend/src/store/pinia-modules/debug.ts
@@ -0,0 +1,38 @@
+import axios from "axios";
+import type { DebugState, ResourceObject } from "@/types";
+import type { Debug, DebugPatch } from "@/types/debug";
+import { defineStore } from "pinia";
+
+function convert(debug: ResourceObject): Debug {
+ return { ...(debug.attributes as Omit<Debug, "">) };
+}
+
+export const useDebugStore = defineStore("debug", {
+ state: (): DebugState => ({
+ isDebug: false,
+ }),
+ actions: {
+ setDebug(debug: Debug) {
+ this.isDebug = debug.isDebug;
+ },
+ async fetchDebug() {
+ const data = (await axios.get("/api/debug")).data;
+ const debug = convert(data);
+ this.setDebug(debug);
+ return debug;
+ },
+ async patchDebug(debugPatch: DebugPatch) {
+ const debugState = convert(
+ (
+ await axios.patch("/api/debug", {
+ data: {
+ type: "debugPatch",
+ attributes: { isDebug: debugPatch.isDebug },
+ },
+ })
+ ).data.data
+ );
+ this.setDebug(debugState);
+ },
+ },
+});
diff --git a/frontend/src/store/pinia-modules/index.ts b/frontend/src/store/pinia-modules/index.ts
new file mode 100644
index 0000000000..e3803b788b
--- /dev/null
+++ b/frontend/src/store/pinia-modules/index.ts
@@ -0,0 +1,2 @@
+export * from "./actuator";
+export * from "./debug";
diff --git a/frontend/src/store/pinia.ts b/frontend/src/store/pinia.ts
new file mode 100644
index 0000000000..0d4348a4ec
--- /dev/null
+++ b/frontend/src/store/pinia.ts
@@ -0,0 +1,5 @@
+import { createPinia } from "pinia";
+
+export const pinia = createPinia();
+
+export * from "./pinia-modules";
diff --git a/frontend/src/views/BannerDemo.vue b/frontend/src/views/BannerDemo.vue
index 290e0443d1..17970ed326 100644
--- a/frontend/src/views/BannerDemo.vue
+++ b/frontend/src/views/BannerDemo.vue
@@ -38,18 +38,19 @@
</template>
<script lang="ts">
-import { computed, ref } from "vue";
-import { useStore } from "vuex";
+import { useActuatorStore } from "@/store";
+import { storeToRefs } from "pinia";
+import { defineComponent, ref } from "vue";
-export default {
+export default defineComponent({
name: "BannerDemo",
setup() {
- const store = useStore();
+ const actuatorStore = useActuatorStore();
const show = ref(true);
- const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
+ const { isReadonly } = storeToRefs(actuatorStore);
return { show, isReadonly };
},
-};
+});
</script>
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index bd68c36579..1e60f1c7a5 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -54,6 +54,7 @@ import {
TemplateType,
} from "../plugins";
import { NSpin } from "naive-ui";
+import { useActuatorStore } from "@/store";
interface LocalState {
// Needs to maintain this state and set it to false manually after creating the issue.
@@ -378,7 +379,8 @@ class IssueCreateHelper {
}
async prepare(): Promise<IssueCreate> {
- const { template, currentUser, store, route } = this.context;
+ const { template, currentUser, route } = this.context;
+ const actuatorStore = useActuatorStore();
const baseTemplate = template.value.buildIssue({
environmentList: [],
approvalPolicyList: [],
@@ -404,7 +406,7 @@ class IssueCreateHelper {
};
// For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.
- if (store.getters["actuator/isDemo"]()) {
+ if (actuatorStore.isDemo) {
issueCreate.assigneeId = currentUser.value.id;
}
if (route.query.name) {
diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vue
index cf4874931c..6a94b1f568 100644
--- a/frontend/src/views/auth/Signin.vue
+++ b/frontend/src/views/auth/Signin.vue
@@ -158,7 +158,13 @@
</template>
<script lang="ts">
-import { computed, onMounted, onUnmounted, reactive } from "vue";
+import {
+ computed,
+ defineComponent,
+ onMounted,
+ onUnmounted,
+ reactive,
+} from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import {
@@ -174,6 +180,8 @@ import {
} from "../../types";
import { isDev, isValidEmail } from "../../utils";
import AuthFooter from "./AuthFooter.vue";
+import { useActuatorStore } from "@/store";
+import { storeToRefs } from "pinia";
interface LocalState {
email: string;
@@ -181,11 +189,12 @@ interface LocalState {
activeAuthProvider: AuthProvider;
}
-export default {
+export default defineComponent({
name: "SigninPage",
components: { AuthFooter },
setup() {
const store = useStore();
+ const actuatorStore = useActuatorStore();
const router = useRouter();
const state = reactive<LocalState>({
@@ -193,8 +202,7 @@ export default {
password: "",
activeAuthProvider: EmptyAuthProvider,
});
-
- const isDemo = computed(() => store.getters["actuator/isDemo"]());
+ const { isDemo } = storeToRefs(actuatorStore);
onMounted(() => {
state.email = isDev() || isDemo.value ? "[email protected]" : "";
@@ -202,7 +210,7 @@ export default {
// Navigate to signup if needs admin setup.
// Unable to achieve it in router.beforeEach because actuator/info is fetched async and returns
// after router has already made the decision on first page load.
- if (store.getters["actuator/needAdminSetup"]()) {
+ if (actuatorStore.needAdminSetup) {
router.push({ name: "auth.signup", replace: true });
}
@@ -310,5 +318,5 @@ export default {
has3rdPartyLoginFeature,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vue
index 2298465ae8..f93016f849 100644
--- a/frontend/src/views/auth/Signup.vue
+++ b/frontend/src/views/auth/Signup.vue
@@ -150,12 +150,14 @@
</template>
<script lang="ts">
-import { computed, onUnmounted, reactive } from "vue";
+import { computed, defineComponent, onUnmounted, reactive } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { SignupInfo, TEXT_VALIDATION_DELAY } from "../../types";
import { isValidEmail } from "../../utils";
import AuthFooter from "./AuthFooter.vue";
+import { useActuatorStore } from "@/store";
+import { storeToRefs } from "pinia";
interface LocalState {
email: string;
@@ -167,11 +169,12 @@ interface LocalState {
nameManuallyEdited: boolean;
}
-export default {
+export default defineComponent({
name: "SignupPage",
components: { AuthFooter },
setup() {
const store = useStore();
+ const actuatorStore = useActuatorStore();
const router = useRouter();
const state = reactive<LocalState>({
@@ -189,9 +192,7 @@ export default {
}
});
- const needAdminSetup = computed(() => {
- return store.getters["actuator/needAdminSetup"]();
- });
+ const { needAdminSetup } = storeToRefs(actuatorStore);
const allowSignup = computed(() => {
return (
@@ -277,7 +278,7 @@ export default {
// we need to update the server info after setting up the first admin account so that the splash screen
// won't display the UI for registering the first admin account again.
if (needAdminSetup.value) {
- await store.dispatch("actuator/fetchInfo");
+ await actuatorStore.fetchInfo();
}
router.push("/");
});
@@ -295,5 +296,5 @@ export default {
trySignup,
};
},
-};
+});
</script>