T3: training form edits the training source; kind and mains as selects

This commit is contained in:
2026-12-01 00:53:30 -06:00
parent d3c04a5fcf
commit 61aeed35ff
2 changed files with 28 additions and 15 deletions
+16 -9
View File
@@ -1,24 +1,27 @@
import { trainingForm } from './training';
describe('training form', () => {
it('removes execution and resolves the TEA reference fields with their defaults', () => {
it('removes execution and resolves the TEA training source with its defaults', () => {
const { schema, model } = trainingForm({
name: 'all',
domain: 'tea',
defaults: { execution: { mode: 'local', scheduler: null }, reference: { line_hz: 50 } },
defaults: {
execution: { mode: 'local', scheduler: null },
source: { kind: 'site', line_hz: 50 },
},
json_schema: {
type: 'object',
properties: {
execution: { type: 'object' },
as_of: { anyOf: [{ type: 'string', format: 'date' }, { type: 'null' }] },
reference: { anyOf: [{ $ref: '#/$defs/Reference' }, { type: 'null' }] },
source: { anyOf: [{ $ref: '#/$defs/TrainingSource' }, { type: 'null' }] },
},
$defs: {
Reference: {
TrainingSource: {
type: 'object',
required: ['name'],
properties: {
name: { type: 'string' },
kind: { type: 'string', enum: ['site', 'folder'], default: 'site' },
folder: { anyOf: [{ type: 'string' }, { type: 'null' }] },
line_hz: { type: 'integer', enum: [50, 60], default: 50 },
},
},
@@ -31,10 +34,14 @@ describe('training form', () => {
type: ['string', 'null'],
format: 'date',
});
expect(schema.properties?.['reference']).toMatchObject({
expect(schema.properties?.['source']).toMatchObject({
type: ['object', 'null'],
properties: { name: { type: 'string' }, line_hz: { enum: [50, 60] } },
properties: {
kind: { enum: ['site', 'folder'] },
folder: { type: ['string', 'null'] },
line_hz: { enum: [50, 60] },
},
});
expect(model).toEqual({ reference: { line_hz: 50 } });
expect(model).toEqual({ source: { kind: 'site', line_hz: 50 } });
});
});
+12 -6
View File
@@ -53,10 +53,7 @@ export function trainingForm(config: TrainingConfig) {
}
return schema;
};
const schema = normalize(raw);
const reference = schema.properties?.['reference'] as Schema | undefined;
if (reference) reference.required = reference.required?.filter((key) => key !== 'name');
return { schema, model };
return { schema: normalize(raw), model };
}
function allowedFile(file: File, allowed: string[]): boolean {
@@ -148,6 +145,16 @@ export class Training {
if (source.format === 'date') {
field.props = { ...field.props, type: 'date' };
}
if (field.key === 'kind') {
field.type = 'select';
field.props = {
...field.props,
options: [
{ value: 'site', label: 'Niños del sitio sin el diagnóstico' },
{ value: 'folder', label: 'Carpeta de EDF con edades' },
],
};
}
if (field.key === 'line_hz') {
field.type = 'select';
field.props = {
@@ -189,13 +196,12 @@ export class Training {
const domain = this.domain();
const name = this.name();
const autoPromote = domain === 'tea' && this.autoPromote();
const reference = model['reference'];
try {
const { run_id } = await this.api.invoke(train, {
domain,
body: {
as_of: model['as_of'] || undefined,
reference: reference?.name ? reference : undefined,
source: model['source'] ?? undefined,
execution: this.execution(),
...(name === 'all' ? {} : { models: [name] }),
},