From ffa6234a367a8cb7e4a8dab37afb657610b64eed Mon Sep 17 00:00:00 2001 From: busya Date: Fri, 29 May 2026 16:33:15 +0300 Subject: [PATCH] refactor: remove orphaned functions after tab extraction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove loadColumnsForDatasource, searchDatasources, selectDatasource, toggleContextColumn, toggleSourceKeyCol, updateTargetKeyCol, isVirtual from page — all moved to ConfigTabForm.svelte. Add on datasourceId in ConfigTabForm to auto-load columns when parent sets datasourceId (loadJob) or user selects a datasource. --- .../components/translate/ConfigTabForm.svelte | 13 ++++---- .../src/routes/translate/[id]/+page.svelte | 30 ++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/frontend/src/lib/components/translate/ConfigTabForm.svelte b/frontend/src/lib/components/translate/ConfigTabForm.svelte index facfe25b..92d10373 100644 --- a/frontend/src/lib/components/translate/ConfigTabForm.svelte +++ b/frontend/src/lib/components/translate/ConfigTabForm.svelte @@ -78,6 +78,13 @@ return (virtualColumns || []).includes(colName); } + // Auto-load columns when datasourceId changes (from parent loadJob or user selection) + $effect(() => { + if (datasourceId && environmentId) { + loadColumnsForDatasource(); + } + }); + // ---- Datasource search ---- let searchTimer = null; async function handleDatasourceSearch() { @@ -113,12 +120,6 @@ targetSourceLanguageColumn = ''; contextColumns = []; databaseDialect = ds.database_dialect || ''; - if (ds.database_id) { - // will be picked up by parent via bind:datasourceId - } - if (datasourceId && environmentId) { - loadColumnsForDatasource(); - } } async function loadColumnsForDatasource() { diff --git a/frontend/src/routes/translate/[id]/+page.svelte b/frontend/src/routes/translate/[id]/+page.svelte index 7ffabc51..cce5aaa1 100644 --- a/frontend/src/routes/translate/[id]/+page.svelte +++ b/frontend/src/routes/translate/[id]/+page.svelte @@ -73,8 +73,6 @@ fetchJobs, createJob, updateJob, - fetchDatasourceColumns, - fetchDatasources, } from '$lib/api/translate.js'; import MultiSelect from '$lib/components/ui/MultiSelect.svelte'; import TranslationPreview from '$lib/components/translate/TranslationPreview.svelte'; @@ -412,7 +410,6 @@ } else { datasourceSearch = `Dataset #${j.source_datasource_id}`; } - await loadColumnsForDatasource(); } uxState = 'configured'; @@ -424,13 +421,18 @@ } } - /** @returns {Promise} */ - async function loadColumnsForDatasource() { - if (!datasourceId || !environmentId) { - availableColumns = []; - virtualColumns = []; - return; - } + /** @param {Event} event */ + async function handleDatasourceChange(event) { + const val = event.target.value; + datasourceId = val; + availableColumns = []; + virtualColumns = []; + // Reset column selections when datasource changes + sourceKeyCols = []; + targetKeyCols = []; + translationColumn = ''; + contextColumns = []; + } isColumnsLoading = true; try { @@ -527,16 +529,10 @@ async function handleEnvChange(event) { const newEnv = event.target.value; environmentId = newEnv; - // Clear search state, but KEEP datasourceId if already loaded from job - // — just reload columns with the new environment - datasourceSearch = ''; - datasourceList = []; databaseDialect = ''; targetDatabaseId = ''; await loadDatabases(); - if (datasourceId) { - await loadColumnsForDatasource(); - } + } } /** @param {string} col */