@morscherlab/mld-sdk 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { ref, computed, reactive, watch, onScopeDispose } from "vue";
|
|
2
2
|
import { useApi } from "./useApi.js";
|
|
3
|
+
function getPlatformApiUrl() {
|
|
4
|
+
var _a;
|
|
5
|
+
if (typeof window === "undefined") return void 0;
|
|
6
|
+
return (_a = window.__MLD_PLATFORM__) == null ? void 0 : _a.platformApiUrl;
|
|
7
|
+
}
|
|
3
8
|
function useExperimentSelector(options = {}) {
|
|
4
9
|
const { limit = 100, immediate = false, experimentType, apiBaseUrl } = options;
|
|
5
|
-
const
|
|
10
|
+
const platformBase = apiBaseUrl ?? getPlatformApiUrl();
|
|
11
|
+
const api = useApi();
|
|
6
12
|
const experiments = ref([]);
|
|
7
13
|
const total = ref(0);
|
|
8
14
|
const selectedExperiment = ref(null);
|
|
@@ -22,7 +28,8 @@ function useExperimentSelector(options = {}) {
|
|
|
22
28
|
params.set("limit", String(limit));
|
|
23
29
|
params.set("skip", String(page.value * limit));
|
|
24
30
|
const query = params.toString();
|
|
25
|
-
const
|
|
31
|
+
const base = platformBase ?? "/api";
|
|
32
|
+
const url = `${base}/experiments${query ? `?${query}` : ""}`;
|
|
26
33
|
const data = await api.get(url);
|
|
27
34
|
if (page.value === 0) {
|
|
28
35
|
experiments.value = data.experiments;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExperimentSelector.js","sources":["../../src/composables/useExperimentSelector.ts"],"sourcesContent":["import { ref, reactive, computed, watch, onScopeDispose, type Ref, type ComputedRef } from 'vue'\nimport { useApi } from './useApi'\nimport type { ExperimentSummary, ExperimentListResponse, ExperimentFilters } from '../types'\n\nexport interface UseExperimentSelectorOptions {\n experimentType?: string\n apiBaseUrl?: string\n limit?: number\n immediate?: boolean\n}\n\nexport interface UseExperimentSelectorReturn {\n experiments: Ref<ExperimentSummary[]>\n total: Ref<number>\n selectedExperiment: Ref<ExperimentSummary | null>\n filters: ExperimentFilters\n isLoading: Ref<boolean>\n error: Ref<string | null>\n page: Ref<number>\n hasMore: ComputedRef<boolean>\n fetch: () => Promise<void>\n loadMore: () => Promise<void>\n reset: () => void\n select: (experiment: ExperimentSummary) => void\n clear: () => void\n}\n\nexport function useExperimentSelector(\n options: UseExperimentSelectorOptions = {},\n): UseExperimentSelectorReturn {\n const { limit = 100, immediate = false, experimentType, apiBaseUrl } = options\n const
|
|
1
|
+
{"version":3,"file":"useExperimentSelector.js","sources":["../../src/composables/useExperimentSelector.ts"],"sourcesContent":["import { ref, reactive, computed, watch, onScopeDispose, type Ref, type ComputedRef } from 'vue'\nimport { useApi } from './useApi'\nimport type { ExperimentSummary, ExperimentListResponse, ExperimentFilters, PlatformContext } from '../types'\n\nfunction getPlatformApiUrl(): string | undefined {\n if (typeof window === 'undefined') return undefined\n return (window as unknown as { __MLD_PLATFORM__?: PlatformContext }).__MLD_PLATFORM__?.platformApiUrl\n}\n\nexport interface UseExperimentSelectorOptions {\n experimentType?: string\n apiBaseUrl?: string\n limit?: number\n immediate?: boolean\n}\n\nexport interface UseExperimentSelectorReturn {\n experiments: Ref<ExperimentSummary[]>\n total: Ref<number>\n selectedExperiment: Ref<ExperimentSummary | null>\n filters: ExperimentFilters\n isLoading: Ref<boolean>\n error: Ref<string | null>\n page: Ref<number>\n hasMore: ComputedRef<boolean>\n fetch: () => Promise<void>\n loadMore: () => Promise<void>\n reset: () => void\n select: (experiment: ExperimentSummary) => void\n clear: () => void\n}\n\nexport function useExperimentSelector(\n options: UseExperimentSelectorOptions = {},\n): UseExperimentSelectorReturn {\n const { limit = 100, immediate = false, experimentType, apiBaseUrl } = options\n const platformBase = apiBaseUrl ?? getPlatformApiUrl()\n const api = useApi()\n\n const experiments = ref<ExperimentSummary[]>([])\n const total = ref(0)\n const selectedExperiment = ref<ExperimentSummary | null>(null)\n const isLoading = ref(false)\n const error = ref<string | null>(null)\n const page = ref(0)\n\n const hasMore = computed(() => experiments.value.length < total.value)\n\n async function fetchExperiments(): Promise<void> {\n isLoading.value = true\n error.value = null\n try {\n const params = new URLSearchParams()\n if (experimentType) params.set('experiment_type', experimentType)\n if (filters.status) params.set('status', filters.status)\n if (filters.search) params.set('search', filters.search)\n if (filters.project) params.set('project', filters.project)\n params.set('limit', String(limit))\n params.set('skip', String(page.value * limit))\n\n const query = params.toString()\n // Use absolute platform URL in integrated mode to bypass plugin's baseURL\n const base = platformBase ?? '/api'\n const url = `${base}/experiments${query ? `?${query}` : ''}`\n const data = await api.get<ExperimentListResponse>(url)\n\n if (page.value === 0) {\n experiments.value = data.experiments\n } else {\n experiments.value = [...experiments.value, ...data.experiments]\n }\n total.value = data.total\n } catch (e) {\n error.value = e instanceof Error ? e.message : 'Failed to fetch experiments'\n if (page.value === 0) {\n experiments.value = []\n total.value = 0\n }\n } finally {\n isLoading.value = false\n }\n }\n\n async function loadMore(): Promise<void> {\n if (!hasMore.value || isLoading.value) return\n page.value++\n await fetchExperiments()\n }\n\n function reset(): void {\n page.value = 0\n experiments.value = []\n total.value = 0\n fetchExperiments()\n }\n\n function select(experiment: ExperimentSummary): void {\n selectedExperiment.value = experiment\n }\n\n function clear(): void {\n selectedExperiment.value = null\n filters.search = undefined\n filters.status = undefined\n filters.project = undefined\n page.value = 0\n }\n\n const filters: ExperimentFilters = reactive({\n search: undefined,\n status: undefined,\n project: undefined,\n })\n\n // Debounced watch on search filter\n let debounceTimer: ReturnType<typeof setTimeout> | null = null\n watch(\n () => filters.search,\n () => {\n if (debounceTimer) clearTimeout(debounceTimer)\n debounceTimer = setTimeout(() => {\n page.value = 0\n fetchExperiments()\n }, 300)\n },\n )\n\n // Immediate watch on status/project filters (no debounce needed)\n watch(\n () => [filters.status, filters.project],\n () => {\n page.value = 0\n fetchExperiments()\n },\n )\n\n onScopeDispose(() => {\n if (debounceTimer) clearTimeout(debounceTimer)\n })\n\n if (immediate) {\n fetchExperiments()\n }\n\n return {\n experiments,\n total,\n selectedExperiment,\n filters,\n isLoading,\n error,\n page,\n hasMore,\n fetch: fetchExperiments,\n loadMore,\n reset,\n select,\n clear,\n }\n}\n"],"names":[],"mappings":";;AAIA,SAAS,oBAAwC;;AAC/C,MAAI,OAAO,WAAW,YAAa,QAAO;AAC1C,UAAQ,YAA6D,qBAA7D,mBAA+E;AACzF;AAyBO,SAAS,sBACd,UAAwC,IACX;AAC7B,QAAM,EAAE,QAAQ,KAAK,YAAY,OAAO,gBAAgB,eAAe;AACvE,QAAM,eAAe,cAAc,kBAAA;AACnC,QAAM,MAAM,OAAA;AAEZ,QAAM,cAAc,IAAyB,EAAE;AAC/C,QAAM,QAAQ,IAAI,CAAC;AACnB,QAAM,qBAAqB,IAA8B,IAAI;AAC7D,QAAM,YAAY,IAAI,KAAK;AAC3B,QAAM,QAAQ,IAAmB,IAAI;AACrC,QAAM,OAAO,IAAI,CAAC;AAElB,QAAM,UAAU,SAAS,MAAM,YAAY,MAAM,SAAS,MAAM,KAAK;AAErE,iBAAe,mBAAkC;AAC/C,cAAU,QAAQ;AAClB,UAAM,QAAQ;AACd,QAAI;AACF,YAAM,SAAS,IAAI,gBAAA;AACnB,UAAI,eAAgB,QAAO,IAAI,mBAAmB,cAAc;AAChE,UAAI,QAAQ,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AACvD,UAAI,QAAQ,OAAQ,QAAO,IAAI,UAAU,QAAQ,MAAM;AACvD,UAAI,QAAQ,QAAS,QAAO,IAAI,WAAW,QAAQ,OAAO;AAC1D,aAAO,IAAI,SAAS,OAAO,KAAK,CAAC;AACjC,aAAO,IAAI,QAAQ,OAAO,KAAK,QAAQ,KAAK,CAAC;AAE7C,YAAM,QAAQ,OAAO,SAAA;AAErB,YAAM,OAAO,gBAAgB;AAC7B,YAAM,MAAM,GAAG,IAAI,eAAe,QAAQ,IAAI,KAAK,KAAK,EAAE;AAC1D,YAAM,OAAO,MAAM,IA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AAGF,iBAAe,MAAM;AACnB,QAAI,4BAA4B,aAAa;AAAA,EAC/C,CAAC;AAED,MAAI,WAAW;AACb,qBAAA;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { ref, reactive, computed, watch, onScopeDispose, type Ref, type ComputedRef } from 'vue'
|
|
2
2
|
import { useApi } from './useApi'
|
|
3
|
-
import type { ExperimentSummary, ExperimentListResponse, ExperimentFilters } from '../types'
|
|
3
|
+
import type { ExperimentSummary, ExperimentListResponse, ExperimentFilters, PlatformContext } from '../types'
|
|
4
|
+
|
|
5
|
+
function getPlatformApiUrl(): string | undefined {
|
|
6
|
+
if (typeof window === 'undefined') return undefined
|
|
7
|
+
return (window as unknown as { __MLD_PLATFORM__?: PlatformContext }).__MLD_PLATFORM__?.platformApiUrl
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
export interface UseExperimentSelectorOptions {
|
|
6
11
|
experimentType?: string
|
|
@@ -29,7 +34,8 @@ export function useExperimentSelector(
|
|
|
29
34
|
options: UseExperimentSelectorOptions = {},
|
|
30
35
|
): UseExperimentSelectorReturn {
|
|
31
36
|
const { limit = 100, immediate = false, experimentType, apiBaseUrl } = options
|
|
32
|
-
const
|
|
37
|
+
const platformBase = apiBaseUrl ?? getPlatformApiUrl()
|
|
38
|
+
const api = useApi()
|
|
33
39
|
|
|
34
40
|
const experiments = ref<ExperimentSummary[]>([])
|
|
35
41
|
const total = ref(0)
|
|
@@ -53,7 +59,9 @@ export function useExperimentSelector(
|
|
|
53
59
|
params.set('skip', String(page.value * limit))
|
|
54
60
|
|
|
55
61
|
const query = params.toString()
|
|
56
|
-
|
|
62
|
+
// Use absolute platform URL in integrated mode to bypass plugin's baseURL
|
|
63
|
+
const base = platformBase ?? '/api'
|
|
64
|
+
const url = `${base}/experiments${query ? `?${query}` : ''}`
|
|
57
65
|
const data = await api.get<ExperimentListResponse>(url)
|
|
58
66
|
|
|
59
67
|
if (page.value === 0) {
|