Skip to content
Closed
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
124 changes: 97 additions & 27 deletions ui-react/src/pages/modeling/thread/MintRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,87 @@ interface MintRunsProps {

const PAGE_SIZE = 100;

interface RunParam {
id?: string | null;
name?: string | null;
default?: string | null;
}

function humanizeName(name?: string | null): string {
return (name ?? '').replace(/[-_]/g, ' ');
}

/** The value a run shows for a parameter: its binding, else the default. */
function runParamValue(param: RunParam, execution: Execution): string {
let value = execution.bindings[param.id ?? ''] as unknown;
if (value == null) value = param.default ?? null;
if (typeof value === 'string' && value.startsWith('__region_geojson')) {
return 'Region GeoJSON';
}
if (value == null || value === '') return '—';
return String(value);
}

/**
* Split parameters into those that tell the listed runs apart (they get a
* column) and those every run shares (they are summarised above the table).
*/
function splitRunParams<P extends RunParam>(
params: P[],
executions: Execution[],
): { varying: P[]; common: Array<{ param: P; value: string }> } {
const varying: P[] = [];
const common: Array<{ param: P; value: string }> = [];
for (const param of params) {
const values = new Set(executions.map((e) => runParamValue(param, e)));
if (values.size > 1) {
varying.push(param);
} else {
const value = executions[0] ? runParamValue(param, executions[0]) : '—';
if (value !== '—') common.push({ param, value });
}
}
return { varying, common };
}

const SAME_FOR_EVERY_RUN_LIMIT = 6;

function SameForEveryRun({
items,
testId,
}: {
items: Array<{ param: RunParam; value: string }>;
testId: string;
}) {
const [showAll, setShowAll] = useState(false);
if (items.length === 0) return null;
const truncated = items.length > SAME_FOR_EVERY_RUN_LIMIT && !showAll;
const shown = truncated ? items.slice(0, SAME_FOR_EVERY_RUN_LIMIT) : items;
return (
<p className="break-words text-xs text-gray-600" data-testid={testId}>
<span className="font-medium">Same for every run:</span>{' '}
{shown.map(({ param, value }, i) => (
<span key={param.id ?? i}>
{i > 0 && ' · '}
{humanizeName(param.name)} <span className="text-gray-900">{value}</span>
</span>
))}
{items.length > SAME_FOR_EVERY_RUN_LIMIT && (
<>
{' '}
<button
type="button"
onClick={() => setShowAll((v) => !v)}
className="text-blue-600 hover:underline"
>
{showAll ? 'show fewer' : `show all ${items.length}`}
</button>
</>
)}
</p>
);
}

export function MintRuns({
threadId,
threadData,
Expand Down Expand Up @@ -1351,7 +1432,11 @@ export function MintRuns({

// ── adjustable inputs / params for column headers ─────────────
const adjustableInputs = model.input_files.filter((f) => !f.value);
const adjustableParams = userParameters(model).filter((p) => !p.value);
const settableParams = userParameters(model).filter((p) => !p.value);
const { varying: adjustableParams, common: sameParams } = splitRunParams(
settableParams,
grouped.executions,
);

return (
<li key={mid}>
Expand Down Expand Up @@ -1568,8 +1653,10 @@ export function MintRuns({
</div>
</div>

{/* Runs table */}
<div className="max-h-96 overflow-auto border border-gray-200">
{/* Runs table: paged, so it grows with the step pane instead of
adding a scroll box of its own. */}
<SameForEveryRun items={sameParams} testId={`same-for-every-run-${mid}`} />
<div className="overflow-x-auto border border-gray-200">
{grouped.loading ? (
<div className="flex items-center justify-center py-8">
<span className="h-6 w-6 animate-spin rounded-full border-2 border-blue-600 border-t-transparent" />
Expand All @@ -1579,7 +1666,7 @@ export function MintRuns({
className="w-full border-collapse text-xs"
data-testid={`runs-table-${mid}`}
>
<thead className="sticky top-0 bg-gray-100">
<thead className="bg-gray-100">
<tr>
<th colSpan={5} className="px-2 py-1 text-left font-semibold">
Run
Expand Down Expand Up @@ -1617,7 +1704,7 @@ export function MintRuns({
))}
{adjustableParams.map((p) => (
<th key={p.id} className="px-2 py-1 font-medium">
{(p.name ?? '').replace(/[-_]/g, ' ')}
{humanizeName(p.name)}
</th>
))}
</tr>
Expand All @@ -1643,10 +1730,6 @@ export function MintRuns({
</tr>
) : (
grouped.executions.map((execution: Execution) => {
const paramDefaults: Record<string, string | null | undefined> = {};
userParameters(model).forEach(
(p) => (paramDefaults[p.id ?? ''] = p.default ?? null),
);
return (
<tr key={execution.id} className="odd:bg-white even:bg-gray-50">
<td className="px-2 py-1">
Expand Down Expand Up @@ -1713,24 +1796,11 @@ export function MintRuns({
</td>
);
})}
{adjustableParams.map((param) => {
let pval = execution.bindings[param.id ?? ''] as
| string
| null
| undefined;
if (pval == null) pval = paramDefaults[param.id ?? ''];
if (
typeof pval === 'string' &&
pval.startsWith('__region_geojson')
) {
pval = 'Region GeoJSON';
}
return (
<td key={param.id} className="px-2 py-1">
{pval ?? '—'}
</td>
);
})}
{adjustableParams.map((param) => (
<td key={param.id} className="px-2 py-1">
{runParamValue(param, execution)}
</td>
))}
</tr>
);
})
Expand Down
80 changes: 79 additions & 1 deletion ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for MintRuns — execution lifecycle step.
*/
import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest';
import { screen, fireEvent, waitFor } from '@testing-library/react';
import { screen, fireEvent, waitFor, within } from '@testing-library/react';
import { renderWithProviders } from '@/test/utils/render';
import { storeTokens } from '@/lib/auth/token-store';
import { MintRuns } from '../MintRuns';
Expand Down Expand Up @@ -943,3 +943,81 @@ describe('MintRuns archived files', () => {
);
});
});

// A flow can expose a dozen settings; only the ones that tell runs apart earn
// a column, the rest are summarised once above the table.
describe('MintRuns runs table columns', () => {
const model = {
...mockModel,
input_parameters: [
{ id: 'p-depth', name: 'flood_depth', type: 'float', default: '10' },
{ id: 'p-mode', name: 'match_mode', type: 'string', default: 'longest_match' },
{ id: 'p-max', name: 'max_files', type: 'int', default: '200' },
],
};
const thread: ThreadExecutionData = {
...mockThreadDataSubmitted,
models: { 'model-1': model },
model_ensembles: {
'model-1': {
id: 'ens-1',
bindings: { 'p-depth': ['15', '25'], 'p-mode': ['longest_match'], 'p-max': ['200'] },
},
},
};
const run = (id: string, bindings: Record<string, unknown>) => ({
id,
modelid: 'model-1',
status: 'SUCCESS',
run_progress: 1,
bindings,
results: {},
});

function renderRuns(runs: ReturnType<typeof run>[]) {
return renderWithProviders(
<MintRuns
threadData={thread}
executions={{ 'model-1': { loading: false, executions: runs } } as ModelExecutionsMap}
canWrite
canExecute
ensembleManagerApi="http://ensemble"
onContinue={vi.fn()}
onFetchRuns={vi.fn()}
onSubmitRuns={vi.fn()}
/>,
);
}

it('shows no parameter columns for one run and lists every value as shared', () => {
renderRuns([run('exec-1', { 'p-depth': '15' })]);
const table = screen.getByTestId('runs-table-model-1');
expect(within(table).queryByText('Parameters')).not.toBeInTheDocument();
expect(within(table).queryByText('flood depth')).not.toBeInTheDocument();
const line = screen.getByTestId('same-for-every-run-model-1');
expect(line).toHaveTextContent('Same for every run:');
expect(line).toHaveTextContent('flood depth 15');
expect(line).toHaveTextContent('match mode longest_match');
expect(line).toHaveTextContent('max files 200');
});

it('gives only the parameter that differs a column', () => {
renderRuns([run('exec-1', { 'p-depth': '15' }), run('exec-2', { 'p-depth': '25' })]);
const table = screen.getByTestId('runs-table-model-1');
expect(within(table).getByText('flood depth')).toBeInTheDocument();
expect(within(table).queryByText('match mode')).not.toBeInTheDocument();
expect(within(table).queryByText('max files')).not.toBeInTheDocument();
expect(within(table).getByText('15')).toBeInTheDocument();
expect(within(table).getByText('25')).toBeInTheDocument();
const line = screen.getByTestId('same-for-every-run-model-1');
expect(line).toHaveTextContent('match mode longest_match');
expect(line).not.toHaveTextContent('flood depth');
});

it('does not wrap the table in a vertically scrolling box', () => {
renderRuns([run('exec-1', {}), run('exec-2', {})]);
const wrapper = screen.getByTestId('runs-table-model-1').parentElement;
expect(wrapper?.className).not.toContain('max-h-96');
expect(wrapper?.className).not.toMatch(/\boverflow-(auto|y-)/);
});
});
Loading