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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user