Extract duplicate API path logic into helper function in allMapData store

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 21:22:19 +08:00
parent ec0035a182
commit f4fbae8a5c

View File

@@ -16,6 +16,19 @@ import apiClient from "@/api/client.js";
import apiError from '@/module/apiError.js'; import apiError from '@/module/apiError.js';
import { Decimal } from 'decimal.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. */ /** Pinia store for Discover Map page data and filter management. */
export const useAllMapDataStore = defineStore('allMapDataStore', { export const useAllMapDataStore = defineStore('allMapDataStore', {
state: () => ({ state: () => ({
@@ -139,16 +152,7 @@ export const useAllMapDataStore = defineStore('allMapDataStore', {
* fetch discover api, include '/process-map, /bpmn, /stats, /insights'. * fetch discover api, include '/process-map, /bpmn, /stats, /insights'.
*/ */
async getAllMapData() { async getAllMapData() {
const logId = this.logId; const api = `${getMapApiBase(this)}/discover`;
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`;
try { try {
const response = await apiClient.get(api); const response = await apiClient.get(api);
this.allProcessMap = response.data.process_map; this.allProcessMap = response.data.process_map;
@@ -163,18 +167,9 @@ export const useAllMapDataStore = defineStore('allMapDataStore', {
* fetch trace api. * fetch trace api.
*/ */
async getAllTrace() { async getAllTrace() {
const logId = this.logId;
const tempFilterId = this.tempFilterId;
const createFilterId = this.createFilterId;
const baseLogId = this.baseLogId; const baseLogId = this.baseLogId;
const baseApi = `/api/logs/${baseLogId}/traces`; const baseApi = `/api/logs/${baseLogId}/traces`;
let api = ''; const api = `${getMapApiBase(this)}/traces`;
// 先判斷暫存 再判斷 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`;
try { try {
let baseResponse; let baseResponse;
const response = await apiClient.get(api); const response = await apiClient.get(api);
@@ -191,18 +186,9 @@ export const useAllMapDataStore = defineStore('allMapDataStore', {
* fetch trace detail api. * fetch trace detail api.
*/ */
async getTraceDetail() { async getTraceDetail() {
const logId = this.logId;
const traceId = this.traceId; const traceId = this.traceId;
const tempFilterId = this.tempFilterId;
const createFilterId = this.createFilterId;
const start = this.infiniteStart; const start = this.infiniteStart;
let api = ''; const api = `${getMapApiBase(this)}/traces/${traceId}?start=${start}&page_size=20`;
// 先判斷暫存 再判斷 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`;
try { try {
const response = await apiClient.get(api); const response = await apiClient.get(api);
this.allTraceTaskSeq = response.data.task_seq; this.allTraceTaskSeq = response.data.task_seq;