From ca59c90b1de8169e6c09691ab5e9ca92e57b2003 Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 12:59:43 -0600 Subject: [PATCH] Upload page: Use in a thread starts guided model setup with the dataset and recommended models The wizard shows models that take the uploaded variable first, close matches as a second tier, and prefills the question, period and region (editable). --- ui-react/src/lib/datasets/upload-preview.ts | 33 ++++++++ .../src/pages/datasets/DatasetUploadPage.tsx | 21 +++++- .../__tests__/DatasetUploadPage.test.tsx | 29 ++++++- .../src/pages/modeling/GuidedModelSetup.tsx | 75 +++++++++++++++++-- .../__tests__/GuidedModelSetup.test.tsx | 65 ++++++++++++++++ 5 files changed, 211 insertions(+), 12 deletions(-) diff --git a/ui-react/src/lib/datasets/upload-preview.ts b/ui-react/src/lib/datasets/upload-preview.ts index ace22e0b..283a91b1 100644 --- a/ui-react/src/lib/datasets/upload-preview.ts +++ b/ui-react/src/lib/datasets/upload-preview.ts @@ -103,3 +103,36 @@ export function closeConsumers( } return found; } + +export interface GuidedSetupLinkInput { + datasetId: string; + variable: { label: string } | null; + exact: UploadConsumer[]; + close: CloseConsumer[]; + title: string; + startDate: string; + endDate: string; + /** Only set when the user picked a catalog region; a drawn box is derived from the dataset instead. */ + regionId?: string; +} + +/** + * The guided model setup URL for a just-uploaded dataset. The exact consumers + * travel as `modelIds` (recommended), the close matches as `closeModelIds`, and + * `modelNames` maps ids to readable names. Nothing here confirms anything: the + * wizard still asks the user to frame the question. + */ +export function guidedSetupLink(input: GuidedSetupLinkInput): string { + const params = new URLSearchParams({ datasetId: input.datasetId }); + if (input.exact.length) params.set('modelIds', input.exact.map((c) => c.id).join(',')); + if (input.close.length) params.set('closeModelIds', input.close.map((c) => c.id).join(',')); + const names: Record = {}; + for (const c of [...input.exact, ...input.close]) names[c.id] = c.name; + if (Object.keys(names).length) params.set('modelNames', JSON.stringify(names)); + if (input.variable) params.set('variable', input.variable.label); + if (input.title.trim()) params.set('goal', input.title.trim()); + if (input.startDate) params.set('startDate', input.startDate); + if (input.endDate) params.set('endDate', input.endDate); + if (input.regionId) params.set('regionId', input.regionId); + return `/modeling/problem-statements/start?${params.toString()}`; +} diff --git a/ui-react/src/pages/datasets/DatasetUploadPage.tsx b/ui-react/src/pages/datasets/DatasetUploadPage.tsx index 4c2a8bc7..5ed8dfc7 100644 --- a/ui-react/src/pages/datasets/DatasetUploadPage.tsx +++ b/ui-react/src/pages/datasets/DatasetUploadPage.tsx @@ -35,7 +35,11 @@ import { } from '@/lib/ckan-upload'; import { useDebouncedValue } from '@/hooks/useDebouncedValue'; import { useSemanticSearch, useSimilarVariables } from '@/hooks/useSemanticSearch'; -import { closeConsumers, consumersOfVariable } from '@/lib/datasets/upload-preview'; +import { + closeConsumers, + consumersOfVariable, + guidedSetupLink, +} from '@/lib/datasets/upload-preview'; import { unionBoundingBox, type BoundingBox } from '@/lib/geo/bbox'; import { standardVariableName } from '@/lib/standard-variable-display'; import { useAuth } from '@/lib/auth/useAuth'; @@ -304,7 +308,20 @@ export function DatasetUploadPage() {