Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions ui-react/src/graphql/generated/modeling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } } }
) {
Expand Down
13 changes: 13 additions & 0 deletions ui-react/src/lib/__tests__/flow-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';

import {
choiceLabel,
choiceText,
fetchFlowSettings,
settingText,
settingTitle,
Expand Down Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions ui-react/src/lib/__tests__/thread-datasets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
9 changes: 9 additions & 0 deletions ui-react/src/lib/flow-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ export function settingTitle(name: string, details?: Pick<SettingDetails, 'title

export const choiceLabel = (choice: SettingChoice): string => 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<SettingDetails, 'choices'> | 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 '';
Expand Down
7 changes: 6 additions & 1 deletion ui-react/src/pages/modeling/thread/MintParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { SettingInput } from '@/components/common/SettingInput';
import { useFlowSettings } from '@/hooks/useFlowSettings';
import {
settingText,
choiceText,
settingTitle,
type FlowSettings,
type SettingDetails,
Expand Down Expand Up @@ -607,7 +608,11 @@ export function MintParameters({
</td>
<td className="px-2 py-1">
{!editMode ? (
<span>{displayValue || view?.defaultText || '—'}</span>
<span>
{(view ? choiceText(view.details, displayValue || view.defaultText) : '') ||
displayValue ||
'—'}
</span>
) : isRegionGeoJson ? (
<span className="text-gray-500">Region GeoJSON</span>
) : (
Expand Down
Loading