From bdcaba8828476fbc066789fd0255ded0415d6919 Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Wed, 16 Mar 2022 11:49:05 +0800 Subject: [PATCH] set root dashboards --- src/locales/lang/en.ts | 2 + src/locales/lang/zh.ts | 4 +- src/store/modules/dashboard.ts | 56 +++++--------- src/views/dashboard/List.vue | 134 ++++++++++++++++++++++++++++++--- 4 files changed, 147 insertions(+), 49 deletions(-) diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index e764c8fd..3c7740d1 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -98,6 +98,8 @@ const msg = { editTab: "Enable editing tab names", label: "Name", id: "ID", + setRoot: "Set this to root", + setNormal: "Set this to normal", hourTip: "Select Hour", minuteTip: "Select Minute", secondTip: "Select Second", diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index ab3e8a0e..9f950a96 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -97,7 +97,9 @@ const msg = { sampledTraces: "采样的追踪", editTab: "开启编辑Tab的名称", label: "名称", - id: "ID", + id: "编号", + setRoot: "设置成为根", + setNormal: "设置成为普通", hourTip: "选择小时", minuteTip: "选择分钟", secondTip: "选择秒数", diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index be2cd255..15d48295 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -74,6 +74,18 @@ export const dashboardStore = defineStore({ setLayout(data: LayoutConfig[]) { this.layout = data; }, + resetDashboards( + list: { + name: string; + layer: string; + entity: string; + id: string; + isRoot: boolean; + }[] + ) { + this.dashboards = list; + sessionStorage.setItem("dashboards", JSON.stringify(list)); + }, setCurrentDashboard(item: { name: string; layer: string; @@ -349,23 +361,7 @@ export const dashboardStore = defineStore({ sessionStorage.getItem("dashboards") || "[]" ); }, - async updateDashboard(param: { name: string }) { - const key = [ - this.currentDashboard.layer, - this.currentDashboard.entity, - this.currentDashboard.name.split(" ").join("-"), - ].join("_"); - const layout = sessionStorage.getItem(key); - const c = { - isRoot: false, - children: layout, - ...this.currentDashboard, - name: param.name, - }; - const setting = { - id: this.currentDashboard.id, - configuration: JSON.stringify(c), - }; + async updateDashboard(setting: { id: string; configuration: string }) { const res: AxiosResponse = await graphql.query("updateTemplate").params({ setting, }); @@ -376,24 +372,10 @@ export const dashboardStore = defineStore({ const json = res.data.data.changeTemplate; if (!json.status) { ElMessage.error(json.message); - return; + return res.data; } ElMessage.success("Saved successfully"); - this.currentDashboard.name = param.name; - this.dashboards = this.dashboards.map((d: any) => { - if (d.id === this.currentDashboard.id) { - d = this.currentDashboard; - } - return d; - }); - sessionStorage.setItem("dashboards", JSON.stringify(this.dashboards)); - sessionStorage.removeItem(key); - const str = [ - this.currentDashboard.layer, - this.currentDashboard.entity, - param.name.split(" ").join("-"), - ].join("_"); - sessionStorage.setItem(str, JSON.stringify(setting)); + return res.data; }, async saveDashboard() { if (!this.currentDashboard.name) { @@ -405,17 +387,17 @@ export const dashboardStore = defineStore({ children: this.layout, ...this.currentDashboard, }; - let res: AxiosResponse; + let res: any; let json; if (this.currentDashboard.id) { - res = await graphql.query("updateTemplate").params({ + res = await this.updateDashboard({ setting: { id: this.currentDashboard.id, configuration: JSON.stringify(c), }, }); - json = res.data.data.changeTemplate; + json = res.data.changeTemplate; } else { const index = this.dashboards.findIndex( (d: { name: string; entity: string; layer: string; id: string }) => @@ -433,7 +415,7 @@ export const dashboardStore = defineStore({ json = res.data.data.addTemplate; } - if (res.data.errors) { + if (res.data.errors || res.errors) { ElMessage.error(res.data.errors); return res.data; } diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index eede0f39..e06372bf 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -47,15 +47,25 @@ limitations under the License. -->