From 61aeed35ffc5f3cbc958ebd784de39b18b87b692 Mon Sep 17 00:00:00 2001 From: alberto Date: Tue, 1 Dec 2026 00:53:30 -0600 Subject: [PATCH] T3: training form edits the training source; kind and mains as selects --- src/app/gobernanza/training.spec.ts | 25 ++++++++++++++++--------- src/app/gobernanza/training.ts | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/app/gobernanza/training.spec.ts b/src/app/gobernanza/training.spec.ts index 9a316e1..bde7605 100644 --- a/src/app/gobernanza/training.spec.ts +++ b/src/app/gobernanza/training.spec.ts @@ -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 } }); }); }); diff --git a/src/app/gobernanza/training.ts b/src/app/gobernanza/training.ts index dc71c1b..836d350 100644 --- a/src/app/gobernanza/training.ts +++ b/src/app/gobernanza/training.ts @@ -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] }), },