diff --git a/src/hooks/useDashboardsSession.ts b/src/hooks/useDashboardsSession.ts index e7c332b8..027e27e0 100644 --- a/src/hooks/useDashboardsSession.ts +++ b/src/hooks/useDashboardsSession.ts @@ -14,24 +14,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; -export default function getDashboard(param: { +import { LayoutConfig } from "@/types/dashboard"; + +export default function getDashboard(param?: { name: string; layer: string; entity: string; }) { const dashboardStore = useDashboardStore(); + const opt = param || dashboardStore.currentDashboard; const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]"); const dashboard = list.find( (d: { name: string; layer: string; entity: string }) => - d.name === param.name && - d.entity === param.entity && - d.layer === param.layer + d.name === opt.name && d.entity === opt.entity && d.layer === opt.layer ); const all = dashboardStore.layout; - const widgets = []; + const widgets: LayoutConfig[] = []; for (const item of all) { if (item.type === "Tab") { + widgets.push(item); if (item.children && item.children.length) { for (const child of item.children) { if (child.children && child.children.length) { @@ -43,5 +46,36 @@ export default function getDashboard(param: { widgets.push(item); } } - return { dashboard, widgets }; + function associationWidget(sourceId: string, filters: unknown, type: string) { + const widget = widgets.find((d: { type: string }) => d.type === type); + if (!widget) { + return ElMessage.info(`There has no a ${type} widget in the dashboard`); + } + const item = { + ...widget, + filters, + }; + dashboardStore.setWidget(item); + const targetTabIndex = (widget.id || "").split("-"); + const sourceTabindex = (sourceId || "").split("-") || []; + let container: Nullable; + + if (targetTabIndex[1] === undefined) { + container = document.querySelector(".ds-main"); + } else { + const w = widgets.find((d: any) => d.id === targetTabIndex[0]); + container = document.querySelector(".tab-layout"); + const layout: Nullable = document.querySelector(".ds-main"); + if (w && layout) { + layout.scrollTop = w.y * 10 + w.h * 5; + } + } + if (targetTabIndex[1] && targetTabIndex[1] !== sourceTabindex[1]) { + dashboardStore.setActiveTabIndex(Number(targetTabIndex[1])); + } + if (container && widget) { + container.scrollTop = widget.y * 10 + widget.h * 5; + } + } + return { dashboard, widgets, associationWidget }; } diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 9809221f..450c2373 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -39,6 +39,7 @@ interface DashboardState { dashboards: DashboardItem[]; currentDashboard: Nullable; editMode: boolean; + currentTabIndex: number; } export const dashboardStore = defineStore({ @@ -56,6 +57,7 @@ export const dashboardStore = defineStore({ dashboards: [], currentDashboard: null, editMode: false, + currentTabIndex: 0, }), actions: { setLayout(data: LayoutConfig[]) { @@ -189,6 +191,7 @@ export const dashboardStore = defineStore({ this.activedGridItem = index; }, setActiveTabIndex(index: number, target?: number) { + this.currentTabIndex = index; const m = target || this.activedGridItem; const idx = this.layout.findIndex((d: LayoutConfig) => d.i === m); if (idx < 0) { diff --git a/src/store/modules/trace.ts b/src/store/modules/trace.ts index 4e337351..16aa422b 100644 --- a/src/store/modules/trace.ts +++ b/src/store/modules/trace.ts @@ -63,6 +63,14 @@ export const traceStore = defineStore({ setTraceSpans(spans: Span) { this.traceSpans = spans; }, + resetCondition() { + this.conditions = { + queryDuration: useAppStoreWithOut().durationTime, + paging: { pageNum: 1, pageSize: 20 }, + traceState: "ALL", + queryOrder: "BY_START_TIME", + }; + }, async getServices(layer: string) { const res: AxiosResponse = await graphql.query("queryServices").params({ layer, diff --git a/src/types/dashboard.d.ts b/src/types/dashboard.d.ts index 1f3ecac9..e8cd4b11 100644 --- a/src/types/dashboard.d.ts +++ b/src/types/dashboard.d.ts @@ -47,6 +47,9 @@ export interface LayoutConfig { startTime: string; endTime: string; }; + traceId?: string; + spanId?: string; + segmentId?: string; }; } diff --git a/src/views/components/ConditionTags.vue b/src/views/components/ConditionTags.vue index f7e2ae60..d1f56ff6 100644 --- a/src/views/components/ConditionTags.vue +++ b/src/views/components/ConditionTags.vue @@ -15,11 +15,7 @@ limitations under the License. -->