From bb506c3926777502a5cc840b5bb60abb516c73e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Sun, 29 Nov 2026 15:24:24 -0600 Subject: [PATCH] =?UTF-8?q?Conectar:=20Configuraci=C3=B3n=20and=20Avanzado?= =?UTF-8?q?=20tabs,=20rows=20instead=20of=20JSON,=20field=20titles=20as=20?= =?UTF-8?q?keys,=20captions=20that=20fit=20their=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/pages.spec.ts | 22 ++- src/app/conectar/conectar.html | 97 +++++++---- src/app/conectar/conectar.scss | 52 ++++++ src/app/conectar/conectar.ts | 101 ++++++++++-- src/app/conectar/schema-form.spec.ts | 18 +- src/app/conectar/schema-form.ts | 238 ++++++++++++++++++++++++++- src/app/conectar/source-dialog.html | 21 ++- src/app/conectar/source-dialog.ts | 10 ++ 8 files changed, 498 insertions(+), 61 deletions(-) diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 96e8da3..f024b4f 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -102,12 +102,18 @@ test('conectar: open the hospital pipeline, preview a source, run it to success' await page.goto('/conectar'); await page.getByText('cacu', { exact: true }).click(); await expect(page.locator('vflow')).toBeVisible(); - await page.getByText('Fuente de datos · Patients').click(); - await expect(page.locator('formly-form')).toBeVisible(); // drawn by hand: its raw form + // a node's caption: its kind, then its name + await page.locator('.node-caption', { hasText: 'Pacientes' }).click(); + // drawn from a fixture, read back as a guided SQLite source: the dialog edits it + await expect(page.getByRole('button', { name: 'Editar conexión' })).toBeVisible(); await page.getByRole('button', { name: 'Vista previa' }).click(); await expect(page.locator('.preview tr[mat-row]').first()).toBeVisible(); // A map node shows the site's codes in platform terms (its ConceptMap), editable as rows. - await page.getByText('Traducir códigos · cytology', { exact: true }).click(); + await page; + await page + .locator('.node-caption', { hasText: 'Traducir códigos' }) + .filter({ has: page.locator('.name', { hasText: /^Citología$/ }) }) + .click(); await expect(page.getByRole('heading', { name: /^Códigos del sitio/ })).toBeVisible(); await expect .poll(() => @@ -146,7 +152,7 @@ test('gobernanza: a version with its reports, its curves, and promotion refused await version.getByRole('button', { name: 'Ver gráficas' }).click(); await expect(page.locator('app-plot .plot svg').first()).toBeVisible(); await version.getByRole('button', { name: 'Promover' }).click(); - await expect(page.getByText('No se promovió')).toContainText('clinical_validation'); + await expect(page.getByText('No se promovió')).toContainText('Validación clínica'); expect(problems.filter((p) => !p.includes('409'))).toEqual([]); }); @@ -172,7 +178,7 @@ test('conectar: someone who knows nothing of databases connects the SQL Server w await expect(page.getByText(/(Las primeras \d+ filas|La primera fila):/)).toBeVisible(); await page.getByLabel('Nombre de esta fuente').fill('Resultados'); await page.getByRole('button', { name: 'Guardar', exact: true }).last().click(); - await expect(page.getByText('Fuente de datos · Resultados')).toBeVisible(); + await expect(page.locator('.node-caption', { hasText: 'Resultados' })).toBeVisible(); // A wrong password says so in words, not a stack trace. await page.getByRole('button', { name: 'Editar conexión' }).click(); await page.locator('[data-field="password"]').fill('not-it'); @@ -323,6 +329,12 @@ for (const width of [1440, 820]) { } await page.goto('/conectar'); await check('conectar'); + // a pipeline open, a node chosen, in both of its panel's tabs + await page.locator('.pipelines [mat-list-item]').first().click(); + await page.locator('.node-caption').first().dispatchEvent('click'); // the canvas may draw it off-screen + await check('conectar node'); + await page.getByRole('tab', { name: 'Avanzado' }).click(); + await check('conectar node, advanced'); await page.goto('/revision'); const tabs = page.locator('.mdc-tab'); for (let i = 0; i < (await tabs.count()); i++) { diff --git a/src/app/conectar/conectar.html b/src/app/conectar/conectar.html index 876c82c..a7fec54 100644 --- a/src/app/conectar/conectar.html +++ b/src/app/conectar/conectar.html @@ -73,10 +73,6 @@

{{ help[d.kind ?? 'source'] }}

- - Id - - @if (d.inputs?.length) {
Entradas: @@ -87,40 +83,71 @@ }
} @else if (d.kind !== 'source') { -

Una flecha desde otro nodo le da su entrada.

+

Conecte una flecha desde otro nodo para darle entrada.

} - @if (guided(d); as g) { -
-

- check_circle - {{ d.label || d.id }} + + + @if (d.kind === 'source') { + @if (guided(d)) { +

+

+ check_circle + {{ d.label || d.id }} +

+ +
+ } @else { +

+ Esta fuente no corresponde a ningún tipo del asistente. Edítela en «Avanzado» o + vuelva a conectarla con el asistente. +

+ + } + } + + @if (conceptMap(d); as cm) { + + } + + +

+ Para personal técnico: el nodo completo como lo guarda la plataforma. + @if (guided(d)) { + Si cambia su fuente aquí, deja de editarse con el asistente. + }

- -
- - Avanzado (para personal técnico) - - } @else if (d.kind === 'source') { - - } - @if (!guided(d) || advanced()) { - @if (guided(d)) { -

Si cambia algo aquí, la fuente deja de editarse con ayuda.

- } - - } - @if (conceptMap(d); as cm) { - - } + + @if (preview(); as rows) {
diff --git a/src/app/conectar/conectar.scss b/src/app/conectar/conectar.scss index 83c9ff4..b0e74e4 100644 --- a/src/app/conectar/conectar.scss +++ b/src/app/conectar/conectar.scss @@ -140,3 +140,55 @@ h2 { color: var(--color-success, #2e7d32); } } + +// The canvas's nodes: the kind small on top, the name below in two lines at most. +:host ::ng-deep default-node { + box-sizing: border-box; + overflow: hidden; + padding: 4px 10px; + display: flex; + align-items: center; +} +:host ::ng-deep .node-caption { + min-width: 0; + width: 100%; + line-height: 1.2; +} +:host ::ng-deep .node-caption .kind { + display: block; + font-size: 10px; + color: var(--color-text-secondary); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +:host ::ng-deep .node-caption .name { + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + font-size: 12px; + font-weight: 500; + overflow-wrap: anywhere; +} +.panel-tabs { + margin-top: var(--space-2); +} +.panel-tabs .hint { + color: var(--color-text-secondary); + font-size: 12px; + margin: var(--space-3) 0; +} +.raw textarea { + font-family: monospace; + font-size: 12px; +} +.error { + color: var(--mat-sys-error); + font-size: 13px; +} + +// Fields in the panel keep their hints clear of the next field's label. +:host ::ng-deep .panel mat-form-field { + margin-bottom: var(--space-3); +} diff --git a/src/app/conectar/conectar.ts b/src/app/conectar/conectar.ts index 3b6f5db..d63e95f 100644 --- a/src/app/conectar/conectar.ts +++ b/src/app/conectar/conectar.ts @@ -1,5 +1,13 @@ import { HttpErrorResponse } from '@angular/common/http'; -import { Component, computed, inject, resource, signal, WritableSignal } from '@angular/core'; +import { + Component, + computed, + effect, + inject, + resource, + signal, + WritableSignal, +} from '@angular/core'; import { FormsModule, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; @@ -7,7 +15,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { MatListModule } from '@angular/material/list'; import { MatDialog } from '@angular/material/dialog'; -import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { MatTabsModule } from '@angular/material/tabs'; import { MatTableModule } from '@angular/material/table'; import { MatTooltipModule } from '@angular/material/tooltip'; import { FormlyFieldConfig, FormlyForm, provideFormlyCore } from '@ngx-formly/core'; @@ -57,21 +65,21 @@ export const KINDS: Record = { read: 'Leer documentos', route: 'Separar por tipo', map: 'Traducir códigos', - extract: 'Sacar datos', + extract: 'Extraer datos', fhir: 'Leer FHIR', - join: 'Juntar', + join: 'Unir', link: 'Identificar a la persona', target: 'Guardar en la plataforma', }; export const HELP: Record = { source: 'De dónde vienen los datos: una base de datos, una carpeta, la nube o una API.', - read: 'Saca el texto de cada documento (PDF, Word, escaneos con OCR).', + read: 'Extrae el texto de cada documento (PDF, Word, escaneos con OCR).', route: 'Deja pasar solo los documentos o filas que cumplen una condición; por ejemplo, las citologías.', map: 'Cambia los códigos del hospital por los de la plataforma, con una tabla de equivalencias.', - extract: 'Toma de cada documento los datos de un estudio: fechas, resultados, nombres.', - fhir: 'Lee paquetes FHIR que un sistema envió y saca de ellos los estudios.', - join: 'Junta dos entradas que hablan de lo mismo; por ejemplo, un resultado con su orden.', + extract: 'Extrae de cada documento los datos de un estudio: fechas, resultados, nombres.', + fhir: 'Lee los paquetes FHIR que envía un sistema y extrae sus estudios.', + join: 'Une dos entradas que se refieren al mismo registro; por ejemplo, un resultado con su orden.', link: 'Reconoce a qué paciente pertenece cada registro, aunque su nombre venga escrito distinto.', target: 'Guarda los estudios ya revisados en la plataforma.', }; @@ -90,7 +98,7 @@ const ID = /^[a-z][a-z0-9_]*$/; MatIconModule, MatInputModule, MatListModule, - MatSlideToggleModule, + MatTabsModule, MatTableModule, MatTooltipModule, Vflow, @@ -107,8 +115,9 @@ export class Conectar { private readonly dialog = inject(MatDialog); protected readonly kinds = Object.entries(KINDS) as [Kind, string][]; protected readonly help = HELP; - /** The raw form of a source drawn with the dialog ("Avanzado"). */ - protected readonly advanced = signal(false); + /** "Avanzado": the selected node as JSON, as edited and not applied yet. */ + protected readonly rawDraft = signal(undefined); + protected readonly rawError = signal(''); protected readonly list = resource({ loader: () => this.api.invoke(pipelines) }); private readonly schema = resource({ loader: () => this.api.invoke(schema) }); @@ -132,6 +141,20 @@ export class Conectar { return !!run && !['SUCCESS', 'FAILURE', 'CANCELED'].includes(run.status); }); + /** What the node forms share: each entity's fields by their titles (the catalog's). */ + protected readonly formOptions = { formState: { fields: {} as Record } }; + private readonly titles = effect(() => { + const entities = (this.schema.value()?.['entities'] ?? {}) as Record< + string, + { properties?: Record } + >; + this.formOptions.formState.fields = Object.fromEntries( + Object.entries(entities).map(([e, s]) => [ + e, + Object.fromEntries(Object.entries(s.properties ?? {}).map(([f, p]) => [f, p.title ?? f])), + ]), + ); + }); protected form = new UntypedFormGroup({}); protected model: Record = {}; /** The selected node's form, generated from its kind's JSON Schema. */ @@ -264,7 +287,8 @@ export class Conectar { ); this.form = new UntypedFormGroup({}); this.preview.set(undefined); - this.advanced.set(false); + this.rawDraft.set(undefined); + this.rawError.set(''); } /** A source the dialog drew (its answers make its dlt fields). */ @@ -279,13 +303,46 @@ export class Conectar { const values = Object.fromEntries( Object.entries(model).filter(([, v]) => v !== undefined && v !== null), ); - if (this.advanced()) delete values['guided']; // drawn by hand from here on this.update( id, (d) => ({ ...values, id: d.id, kind: d.kind, inputs: d.inputs }) as unknown as Doc, ); } + /** The node as the platform keeps it (its place on the canvas aside). */ + protected raw(d: Doc): string { + const { position, ...rest } = d as Doc & { position?: unknown }; + return JSON.stringify(rest, null, 2); + } + + /** "Aplicar": the edited JSON becomes the node. Its kind stays; its id changes with the + * Id field (so the arrows follow). A source whose dlt fields change is drawn by hand from + * then on (unless a catalog type makes it exactly: the platform reads it back). */ + protected applyRaw(): void { + const d = this.doc(); + const text = this.rawDraft(); + if (!d || text === undefined) return; + let parsed: Record; + try { + parsed = JSON.parse(text); + } catch { + this.rawError.set('El texto no es JSON válido.'); + return; + } + if (parsed['kind'] !== d.kind) { + this.rawError.set(`El tipo del nodo es «${d.kind}» y no cambia aquí.`); + return; + } + if (d.kind === 'source') { + const dlt = ['source', 'args', 'resource', 'then'] as const; + const before = d as unknown as Record; + if (dlt.some((k) => JSON.stringify(parsed[k]) !== JSON.stringify(before[k]))) + delete parsed['guided']; + } + this.update(d.id, () => ({ ...parsed, id: d.id, kind: d.kind }) as unknown as Doc); + this.select(d.id); + } + protected rename(to: string): void { const from = this.selected(); if (!from || from === to || !ID.test(to) || this.docs().some((d) => d.id === to)) return; @@ -363,7 +420,7 @@ export class Conectar { ? await this.api.invoke(sourcePreview, { limit: 20, body: doc as Source }) : await this.api.invoke(nodeRows, { pipeline_id: id, node_id: doc.id, limit: 50 }); this.preview.set(rows); - this.message.set(rows.length ? '' : 'Sin filas todavía: ejecute la canalización.'); + this.message.set(rows.length ? '' : 'Sin filas: ejecute la canalización.'); } catch (e) { this.message.set(problem(e)); } @@ -389,7 +446,14 @@ export class Conectar { } function text(d: Doc): string { - return `${KINDS[d.kind ?? 'source']} · ${d.label || d.id}`; + // ngx-vflow draws a node's text as HTML: the kind above, the name below (two lines at + // most; the whole of it on hover). The name is the operator's text, so it is escaped. + const kind = KINDS[d.kind ?? 'source']; + const name = escape(d.label || d.id); + return ( + `
` + + `${kind}${name}
` + ); } /** Each node's distance from the sources: its column when it has no saved position. */ @@ -416,3 +480,10 @@ function problem(e: unknown): string { } return String(e); } + +function escape(text: string): string { + return text.replace( + /[&<>"']/g, + (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]!, + ); +} diff --git a/src/app/conectar/schema-form.spec.ts b/src/app/conectar/schema-form.spec.ts index da73b01..04bc403 100644 --- a/src/app/conectar/schema-form.spec.ts +++ b/src/app/conectar/schema-form.spec.ts @@ -16,6 +16,12 @@ const PIPELINE = { when: { type: 'array', items: { $ref: '#/$defs/Condition' } }, resource: { anyOf: [{ type: 'string' }, { type: 'null' }], title: 'Resource' }, values: { type: 'object', additionalProperties: { type: 'string' }, title: 'Values' }, + on: { + type: 'array', + items: { type: 'array', prefixItems: [{ type: 'string' }, { type: 'string' }] }, + }, + extra: { type: 'object', title: 'Extra' }, + source: { type: 'string', advanced: true }, }, }, }, @@ -25,7 +31,7 @@ describe('node forms from the pipeline schema', () => { const schema = nodeSchema(PIPELINE, 'route') as any; it('leaves out what the canvas edits', () => { - expect(Object.keys(schema.properties)).toEqual(['when', 'resource', 'values']); + expect(Object.keys(schema.properties)).toEqual(['when', 'resource', 'values', 'on']); expect(schema.required).toEqual(['when']); }); @@ -34,7 +40,13 @@ describe('node forms from the pipeline schema', () => { expect(schema.properties.resource.type).toBe('string'); }); - it('edits maps as JSON', () => { - expect(schema.properties.values.widget.formlyConfig.type).toBe('json'); + it('edits maps of texts and pairs as rows', () => { + expect(schema.properties.values.widget.formlyConfig.type).toBe('map'); + expect(schema.properties.on.widget.formlyConfig.type).toBe('pairs'); + }); + + it('leaves JSON-only values and advanced fields to the "Avanzado" tab', () => { + expect(schema.properties.extra).toBeUndefined(); + expect(schema.properties.source).toBeUndefined(); }); }); diff --git a/src/app/conectar/schema-form.ts b/src/app/conectar/schema-form.ts index c0599db..10e5328 100644 --- a/src/app/conectar/schema-form.ts +++ b/src/app/conectar/schema-form.ts @@ -3,6 +3,7 @@ import { MatButtonModule } from '@angular/material/button'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; +import { MatSelectModule } from '@angular/material/select'; import { ReactiveFormsModule } from '@angular/forms'; import { ConfigOption, @@ -27,11 +28,29 @@ export function nodeSchema(pipeline: Schema, kind: string): Schema { )!; const node = structuredClone(defs[name]); for (const field of CANVAS_FIELDS) delete node.properties?.[field]; - node.required = (node.required ?? []).filter((f) => !CANVAS_FIELDS.includes(f)); + // The panel says what the kind does (in Spanish); the class's own docstring is for code. + delete node.title; + delete node.description; + // What a guided dialog fills, or what only JSON can say, is for the "Avanzado" tab. + for (const [field, value] of Object.entries(node.properties ?? {})) { + const simple = simplify(value as Schema, defs) as Schema & { widget?: unknown }; + if ((value as { advanced?: boolean }).advanced || isJson(simple)) + delete node.properties![field]; + } + node.required = (node.required ?? []).filter( + (f) => !CANVAS_FIELDS.includes(f) && f in (node.properties ?? {}), + ); delete node.additionalProperties; return simplify(node, defs); } +function isJson(schema: Schema): boolean { + return ( + (schema as { widget?: { formlyConfig?: { type?: string } } }).widget?.formlyConfig?.type === + 'json' + ); +} + function simplify(schema: Schema, defs: Record): Schema { if (schema.$ref) { const { $ref, ...rest } = schema; @@ -45,6 +64,34 @@ function simplify(schema: Schema, defs: Record): Schema { return simplify({ ...kept[0], ...rest }, defs); } } + const values = schema.additionalProperties as Schema | boolean | undefined; + if ( + schema.type === 'object' && + !schema.properties && + typeof values === 'object' && + values.type === 'string' + ) { + const byField = (schema as { keys?: string }).keys === 'field'; + return { + title: schema.title, + description: schema.description, + default: schema.default, + widget: { formlyConfig: { type: 'map', props: { fieldKeys: byField } } }, + } as Schema; + } + const pair = schema.items as Schema | undefined; + if ( + schema.type === 'array' && + (pair?.prefixItems as Schema[] | undefined)?.length === 2 && + (pair!.prefixItems as Schema[]).every((p) => p.type === 'string') + ) { + return { + title: schema.title, + description: schema.description, + default: schema.default, + widget: { formlyConfig: { type: 'pairs' } }, + } as Schema; + } const isMap = schema.type === 'object' && !schema.properties; const isTuple = schema.type === 'array' && @@ -117,7 +164,7 @@ export class ArrayType extends FieldArrayType {} imports: [MatFormFieldModule, MatInputModule, ReactiveFormsModule], template: ` - {{ props.label }} (JSON) + {{ props.label }}