From f4fbae8a5cc1a295780aac133425edca503b16d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 6 Mar 2026 21:22:19 +0800 Subject: [PATCH] Extract duplicate API path logic into helper function in allMapData store Co-Authored-By: Claude Opus 4.6 --- src/stores/allMapData.ts | 46 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/src/stores/allMapData.ts b/src/stores/allMapData.ts index a247009..e4ed2e7 100644 --- a/src/stores/allMapData.ts +++ b/src/stores/allMapData.ts @@ -16,6 +16,19 @@ import apiClient from "@/api/client.js"; import apiError from '@/module/apiError.js'; import { Decimal } from 'decimal.js'; +/** + * Returns the API base path for the current map data source, + * prioritizing temp filter over created filter over log. + * @param {object} state - The store state. + * @returns {string} The API base path. + */ +function getMapApiBase(state) { + const { tempFilterId, createFilterId, logId } = state; + if (tempFilterId !== null) return `/api/temp-filters/${tempFilterId}`; + if (createFilterId !== null) return `/api/filters/${createFilterId}`; + return `/api/logs/${logId}`; +} + /** Pinia store for Discover Map page data and filter management. */ export const useAllMapDataStore = defineStore('allMapDataStore', { state: () => ({ @@ -139,16 +152,7 @@ export const useAllMapDataStore = defineStore('allMapDataStore', { * fetch discover api, include '/process-map, /bpmn, /stats, /insights'. */ async getAllMapData() { - const logId = this.logId; - const tempFilterId = this.tempFilterId; - const createFilterId = this.createFilterId - let api = ''; - - // 先判斷暫存 再判斷 filter 最後 log - if(tempFilterId !== null) api = `/api/temp-filters/${tempFilterId}/discover`; - else if(createFilterId!== null) api = `/api/filters/${createFilterId}/discover`; - else api = `/api/logs/${logId}/discover`; - + const api = `${getMapApiBase(this)}/discover`; try { const response = await apiClient.get(api); this.allProcessMap = response.data.process_map; @@ -163,18 +167,9 @@ export const useAllMapDataStore = defineStore('allMapDataStore', { * fetch trace api. */ async getAllTrace() { - const logId = this.logId; - const tempFilterId = this.tempFilterId; - const createFilterId = this.createFilterId; const baseLogId = this.baseLogId; const baseApi = `/api/logs/${baseLogId}/traces`; - let api = ''; - - // 先判斷暫存 再判斷 filter 最後 log - if(tempFilterId !== null) api = `/api/temp-filters/${tempFilterId}/traces`; - else if(createFilterId!== null) api = `/api/filters/${createFilterId}/traces`; - else api = `/api/logs/${logId}/traces`; - + const api = `${getMapApiBase(this)}/traces`; try { let baseResponse; const response = await apiClient.get(api); @@ -191,18 +186,9 @@ export const useAllMapDataStore = defineStore('allMapDataStore', { * fetch trace detail api. */ async getTraceDetail() { - const logId = this.logId; const traceId = this.traceId; - const tempFilterId = this.tempFilterId; - const createFilterId = this.createFilterId; const start = this.infiniteStart; - let api = ''; - - // 先判斷暫存 再判斷 filter 最後 log - if(tempFilterId !== null) api = `/api/temp-filters/${tempFilterId}/traces/${traceId}?start=${start}&page_size=20`; - else if(createFilterId!== null) api = `/api/filters/${createFilterId}/traces/${traceId}?start=${start}&page_size=20`; - else api = `/api/logs/${logId}/traces/${traceId}?start=${start}&page_size=20`; - + const api = `${getMapApiBase(this)}/traces/${traceId}?start=${start}&page_size=20`; try { const response = await apiClient.get(api); this.allTraceTaskSeq = response.data.task_seq;