From 04b01eadb5e9ed768c3193c880c9c1dabef67666 Mon Sep 17 00:00:00 2001 From: busya Date: Wed, 25 Feb 2026 20:59:24 +0300 Subject: [PATCH] fix(ui): use global environment context on datasets page --- frontend/src/routes/datasets/+page.svelte | 60 ++++++++++------------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/frontend/src/routes/datasets/+page.svelte b/frontend/src/routes/datasets/+page.svelte index 08bc90e..497b055 100644 --- a/frontend/src/routes/datasets/+page.svelte +++ b/frontend/src/routes/datasets/+page.svelte @@ -24,6 +24,12 @@ import { openDrawerForTask } from '$lib/stores/taskDrawer.js'; import { api } from '$lib/api.js'; import { debounce } from '$lib/utils/debounce.js'; + import { + environmentContextStore, + initializeEnvironmentContext, + setSelectedEnvironment, + selectedEnvironmentStore + } from '$lib/stores/environmentContext.js'; // State let selectedEnv = null; @@ -66,30 +72,13 @@ // Load environments and datasets on mount onMount(async () => { - await loadEnvironments(); + await initializeEnvironmentContext(); + if (!selectedEnv && $environmentContextStore?.selectedEnvId) { + selectedEnv = $environmentContextStore.selectedEnvId; + } await loadDatasets(); }); - // Load environments from API - async function loadEnvironments() { - try { - const response = await api.getEnvironments(); - environments = response; - // Set first environment as default if no selection - if (environments.length > 0 && !selectedEnv) { - selectedEnv = environments[0].id; - } - } catch (err) { - console.error('[DatasetHub][Coherence:Failed] Failed to load environments:', err); - // Use fallback environments if API fails - environments = [ - { id: 'development', name: 'Development' }, - { id: 'staging', name: 'Staging' }, - { id: 'production', name: 'Production' } - ]; - } - } - // Load datasets from API async function loadDatasets() { if (!selectedEnv) return; @@ -142,14 +131,6 @@ } } - // Handle environment change - function handleEnvChange(event) { - selectedEnv = event.target.value; - currentPage = 1; - selectedIds.clear(); - loadDatasets(); - } - // Handle search input function handleSearch(event) { debouncedSearch(event.target.value); @@ -361,6 +342,19 @@ return 'bg-blue-400'; } } + + $: environments = $environmentContextStore?.environments || []; + $: activeEnvironment = $selectedEnvironmentStore; + $: if ( + $environmentContextStore?.selectedEnvId && + selectedEnv !== $environmentContextStore.selectedEnvId + ) { + selectedEnv = $environmentContextStore.selectedEnvId; + setSelectedEnvironment(selectedEnv); + currentPage = 1; + selectedIds.clear(); + loadDatasets(); + } @@ -370,11 +364,9 @@

{$t.nav?.datasets}

- + + {$t.dashboard?.environment}: {activeEnvironment?.name || selectedEnv || '-'} +