From 29f43b25e743fc33b62457924df419ebd1b536ab Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 15:19:24 -0600 Subject: [PATCH] Keep a thread's settings when its data is saved, and show choices by title Saving the Datasets step deleted every parameter value in the thread, so the settings a runner had chosen were lost whenever data was assigned again. The values do not depend on the data; the step still clears what the data replaces (model inputs, runs and their summaries). The read-only settings view now shows a choice's title (Longest term wins) instead of its stored value (longest_match). --- ui-react/src/graphql/generated/modeling.ts | 7 ++----- ui-react/src/lib/__tests__/flow-settings.test.ts | 13 +++++++++++++ ui-react/src/lib/__tests__/thread-datasets.test.ts | 12 ++++++++++++ ui-react/src/lib/flow-settings.ts | 9 +++++++++ .../src/pages/modeling/thread/MintParameters.tsx | 7 ++++++- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ui-react/src/graphql/generated/modeling.ts b/ui-react/src/graphql/generated/modeling.ts index c62b6a59..ca090fca 100644 --- a/ui-react/src/graphql/generated/modeling.ts +++ b/ui-react/src/graphql/generated/modeling.ts @@ -1212,11 +1212,8 @@ export const UpdateThreadDataDocument = gql` ) { affected_rows } - delete_thread_model_parameter( - where: { thread_model: { thread_id: { _eq: $threadId } } } - ) { - affected_rows - } + # The models' parameter values are kept: they do not depend on which data is + # bound, and dropping them lost every setting the runner had chosen. delete_dataslice_resource( where: { dataslice: { thread_data: { thread_id: { _eq: $threadId } } } } ) { diff --git a/ui-react/src/lib/__tests__/flow-settings.test.ts b/ui-react/src/lib/__tests__/flow-settings.test.ts index 0036c0eb..c78ece35 100644 --- a/ui-react/src/lib/__tests__/flow-settings.test.ts +++ b/ui-react/src/lib/__tests__/flow-settings.test.ts @@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import { choiceLabel, + choiceText, fetchFlowSettings, settingText, settingTitle, @@ -32,6 +33,18 @@ describe('naming and showing a setting', () => { expect(choiceLabel({ value: 5 })).toBe('5'); }); + it('reads a value as its choice title, else as itself', () => { + const details = { + choices: [ + { value: 'auto', title: 'Prototype counting' }, + { value: 'longest_match', title: 'Longest term wins' }, + ], + }; + expect(choiceText(details, 'longest_match')).toBe('Longest term wins'); + expect(choiceText(details, 'other')).toBe('other'); + expect(choiceText(undefined, '4')).toBe('4'); + }); + it('writes a value as the text an input shows', () => { expect(settingText('x')).toBe('x'); expect(settingText(25)).toBe('25'); diff --git a/ui-react/src/lib/__tests__/thread-datasets.test.ts b/ui-react/src/lib/__tests__/thread-datasets.test.ts index cabef318..8d81cb6d 100644 --- a/ui-react/src/lib/__tests__/thread-datasets.test.ts +++ b/ui-react/src/lib/__tests__/thread-datasets.test.ts @@ -119,3 +119,15 @@ describe('datasliceRegionId', () => { expect(datasliceRegionId({ region_id: null, task: null })).toBeNull(); }); }); + +describe('UpdateThreadData', () => { + it('keeps the models parameter values when the data is saved', async () => { + const { print } = await import('graphql'); + const { UpdateThreadDataDocument } = await import('@/graphql/generated/modeling'); + const text = print(UpdateThreadDataDocument); + expect(text).not.toContain('delete_thread_model_parameter'); + // What the data replaces is still cleared. + expect(text).toContain('delete_thread_model_io'); + expect(text).toContain('delete_thread_model_execution'); + }); +}); diff --git a/ui-react/src/lib/flow-settings.ts b/ui-react/src/lib/flow-settings.ts index 4d14fc12..2bb79572 100644 --- a/ui-react/src/lib/flow-settings.ts +++ b/ui-react/src/lib/flow-settings.ts @@ -70,6 +70,15 @@ export function settingTitle(name: string, details?: Pick choice.title ?? String(choice.value); +/** A value as a person reads it: the title of the choice it is, else the value itself. */ +export function choiceText( + details: Pick | undefined, + value: string, +): string { + const choice = details?.choices?.find((c) => String(c.value) === value); + return choice ? choiceLabel(choice) : value; +} + /** The value a setting starts from, as the text an input shows. */ export function settingText(value: unknown): string { if (value === undefined || value === null) return ''; diff --git a/ui-react/src/pages/modeling/thread/MintParameters.tsx b/ui-react/src/pages/modeling/thread/MintParameters.tsx index 015464c3..41fb083b 100644 --- a/ui-react/src/pages/modeling/thread/MintParameters.tsx +++ b/ui-react/src/pages/modeling/thread/MintParameters.tsx @@ -35,6 +35,7 @@ import { SettingInput } from '@/components/common/SettingInput'; import { useFlowSettings } from '@/hooks/useFlowSettings'; import { settingText, + choiceText, settingTitle, type FlowSettings, type SettingDetails, @@ -607,7 +608,11 @@ export function MintParameters({ {!editMode ? ( - {displayValue || view?.defaultText || '—'} + + {(view ? choiceText(view.details, displayValue || view.defaultText) : '') || + displayValue || + '—'} + ) : isRegionGeoJson ? ( Region GeoJSON ) : (