Conectar: Configuración and Avanzado tabs, rows instead of JSON, field titles as keys, captions that fit their nodes
This commit is contained in:
@@ -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<Kind, string> = {
|
||||
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<Kind, string> = {
|
||||
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<string | undefined>(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<string, unknown> } };
|
||||
private readonly titles = effect(() => {
|
||||
const entities = (this.schema.value()?.['entities'] ?? {}) as Record<
|
||||
string,
|
||||
{ properties?: Record<string, { title?: string }> }
|
||||
>;
|
||||
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<string, unknown> = {};
|
||||
/** 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<string, unknown>;
|
||||
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<string, unknown>;
|
||||
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 (
|
||||
`<div class="node-caption" title="${kind} · ${name}">` +
|
||||
`<span class="kind">${kind}</span><span class="name">${name}</span></div>`
|
||||
);
|
||||
}
|
||||
|
||||
/** 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]!,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user