integration layer; merge work on indicators from forks with existing ingestion pipeline
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
@let f = flow();
|
||||
@if (f.validating()) {
|
||||
<mat-progress-bar mode="indeterminate" aria-label="Validando"></mat-progress-bar>
|
||||
}
|
||||
|
||||
@if (f.validation(); as validation) {
|
||||
<div class="tiles">
|
||||
<div class="tile">
|
||||
<span class="tile__value">{{ validation.total_rows | number }}</span>
|
||||
<span class="tile__label">filas leídas</span>
|
||||
</div>
|
||||
<div class="tile tile--ok">
|
||||
<span class="tile__value">{{ validation.valid_count | number }}</span>
|
||||
<span class="tile__label">válidas · {{ validPercent() }}%</span>
|
||||
</div>
|
||||
<div class="tile" [class.tile--warn]="validation.error_count > 0">
|
||||
<span class="tile__value">{{ validation.error_count | number }}</span>
|
||||
<span class="tile__label">con errores (se omiten)</span>
|
||||
</div>
|
||||
@if (f.result(); as result) {
|
||||
<div class="tile tile--ok">
|
||||
<span class="tile__value">{{ result.created | number }} / {{ result.updated | number }}</span>
|
||||
<span class="tile__label">insertadas / actualizadas</span>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (errors().length > 0) {
|
||||
<div class="filters">
|
||||
<mat-chip-listbox multiple [value]="categories()" (change)="onCategories($event.value)" aria-label="Filtrar por tipo de error">
|
||||
@for (item of countsByCategory(); track item.category) {
|
||||
<mat-chip-option [value]="item.category">{{ categoryLabels[item.category] }} · {{ item.count }}</mat-chip-option>
|
||||
}
|
||||
</mat-chip-listbox>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="filters__field">
|
||||
<mat-label>Campo</mat-label>
|
||||
<mat-select [value]="field()" (selectionChange)="onField($event.value)">
|
||||
<mat-option [value]="null">Todos</mat-option>
|
||||
@for (name of fieldsWithErrors(); track name) {
|
||||
<mat-option [value]="name">{{ name }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table mat-table [dataSource]="pageRows()" class="errors">
|
||||
<ng-container matColumnDef="row">
|
||||
<th mat-header-cell *matHeaderCellDef>Fila</th>
|
||||
<td mat-cell *matCellDef="let error">{{ error.row_index + 1 }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="field">
|
||||
<th mat-header-cell *matHeaderCellDef>Campo</th>
|
||||
<td mat-cell *matCellDef="let error" class="errors__field">{{ error.field }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="category">
|
||||
<th mat-header-cell *matHeaderCellDef>Tipo</th>
|
||||
<td mat-cell *matCellDef="let error">
|
||||
<span class="category" [attr.data-category]="error.category">{{ categoryLabel(error.category) }}</span>
|
||||
</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="value">
|
||||
<th mat-header-cell *matHeaderCellDef>Valor</th>
|
||||
<td mat-cell *matCellDef="let error" class="errors__value">{{ display(error.raw_value) }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="message">
|
||||
<th mat-header-cell *matHeaderCellDef>Detalle</th>
|
||||
<td mat-cell *matCellDef="let error">{{ error.message }}</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="columns; sticky: true"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: columns"></tr>
|
||||
</table>
|
||||
</div>
|
||||
<mat-paginator
|
||||
[length]="filtered().length"
|
||||
[pageIndex]="page().index"
|
||||
[pageSize]="page().size"
|
||||
[pageSizeOptions]="[25, 50, 100]"
|
||||
(page)="onPage($event)"
|
||||
aria-label="Paginación de errores"
|
||||
></mat-paginator>
|
||||
} @else {
|
||||
<p class="all-good"><mat-icon aria-hidden="true">verified</mat-icon>Todas las filas pasan la validación.</p>
|
||||
}
|
||||
} @else if (!f.validating()) {
|
||||
<div class="empty">
|
||||
<mat-icon aria-hidden="true">fact_check</mat-icon>
|
||||
<p>
|
||||
La validación revisa <strong>todas</strong> las filas de la fuente contra las reglas de la tabla destino
|
||||
(obligatorios, catálogos, formatos) sin escribir nada en la base.
|
||||
</p>
|
||||
<button mat-flat-button type="button" [disabled]="!f.canSubmit" (click)="validate.emit()">
|
||||
<mat-icon aria-hidden="true">play_arrow</mat-icon>Validar ahora
|
||||
</button>
|
||||
@if (!f.canSubmit) {
|
||||
<p class="empty__hint">Completa primero los campos obligatorios en «Mapeo».</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.tiles {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
.tile {
|
||||
background: var(--mat-sys-surface-container-low);
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--space-3) var(--space-4);
|
||||
}
|
||||
|
||||
.tile__value {
|
||||
font: var(--mat-sys-headline-small);
|
||||
}
|
||||
|
||||
.tile__label {
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
|
||||
.tile--ok .tile__value {
|
||||
color: var(--mat-sys-primary);
|
||||
}
|
||||
|
||||
.tile--warn .tile__value {
|
||||
color: #9a5b00;
|
||||
}
|
||||
|
||||
.filters {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
margin-bottom: var(--space-3);
|
||||
}
|
||||
|
||||
.filters__field {
|
||||
width: 240px;
|
||||
}
|
||||
|
||||
.table-scroll {
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: var(--mat-sys-corner-medium);
|
||||
max-height: 50vh;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.errors {
|
||||
--mat-table-row-item-container-height: 40px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.errors__field,
|
||||
.errors__value {
|
||||
font-family: 'Roboto Mono', ui-monospace, monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.category {
|
||||
border-radius: 999px;
|
||||
font: var(--mat-sys-label-small);
|
||||
padding: 2px 8px;
|
||||
white-space: nowrap;
|
||||
background: var(--mat-sys-surface-container-high);
|
||||
}
|
||||
|
||||
.category[data-category='missing'],
|
||||
.category[data-category='conflict'] {
|
||||
background: var(--mat-sys-error-container);
|
||||
color: var(--mat-sys-on-error-container);
|
||||
}
|
||||
|
||||
.category[data-category='out_of_catalog'],
|
||||
.category[data-category='type_invalid'] {
|
||||
background: #fff1d6;
|
||||
color: #7a4b00;
|
||||
}
|
||||
|
||||
.all-good,
|
||||
.empty {
|
||||
align-items: center;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.all-good mat-icon {
|
||||
color: var(--mat-sys-primary);
|
||||
}
|
||||
|
||||
.empty {
|
||||
flex-direction: column;
|
||||
padding: var(--space-6);
|
||||
text-align: center;
|
||||
|
||||
> mat-icon {
|
||||
color: var(--mat-sys-primary);
|
||||
font-size: 36px;
|
||||
height: 36px;
|
||||
width: 36px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
max-width: 520px;
|
||||
}
|
||||
}
|
||||
|
||||
.empty__hint {
|
||||
font: var(--mat-sys-body-small);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, computed, input, output, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { ErrorCategory, RowError } from '../../api/api.types';
|
||||
import { ImportFlow } from '../../domain/import-flow';
|
||||
|
||||
export const CATEGORY_LABELS: Record<ErrorCategory, string> = {
|
||||
missing: 'Falta dato obligatorio',
|
||||
out_of_catalog: 'Fuera de catálogo',
|
||||
type_invalid: 'Formato inválido',
|
||||
conflict: 'Ya existe (clave duplicada)',
|
||||
merge_conflict: 'Difiere de otra fuente (se conservó la primera)',
|
||||
unknown: 'Otro',
|
||||
};
|
||||
|
||||
/** Validation outcome of one flow: totals, then every row error, filterable by category and field. */
|
||||
@Component({
|
||||
selector: 'app-validation-report',
|
||||
imports: [
|
||||
DecimalPipe,
|
||||
MatButtonModule,
|
||||
MatChipsModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressBarModule,
|
||||
MatSelectModule,
|
||||
MatTableModule,
|
||||
],
|
||||
templateUrl: './validation-report.html',
|
||||
styleUrl: './validation-report.scss',
|
||||
})
|
||||
export class ValidationReport {
|
||||
readonly flow = input.required<ImportFlow>();
|
||||
readonly validate = output<void>();
|
||||
|
||||
readonly categoryLabels = CATEGORY_LABELS;
|
||||
readonly columns = ['row', 'field', 'category', 'value', 'message'];
|
||||
|
||||
readonly categories = signal<ErrorCategory[]>([]);
|
||||
readonly field = signal<string | null>(null);
|
||||
readonly page = signal({ index: 0, size: 25 });
|
||||
|
||||
readonly errors = computed<RowError[]>(() => this.flow().validation()?.errors ?? []);
|
||||
|
||||
readonly countsByCategory = computed(() => {
|
||||
const counts = new Map<ErrorCategory, number>();
|
||||
for (const error of this.errors()) counts.set(error.category, (counts.get(error.category) ?? 0) + 1);
|
||||
return [...counts.entries()].map(([category, count]) => ({ category, count }));
|
||||
});
|
||||
|
||||
readonly fieldsWithErrors = computed(() => [...new Set(this.errors().map((error) => error.field))].sort());
|
||||
|
||||
readonly filtered = computed(() => {
|
||||
const categories = this.categories();
|
||||
const field = this.field();
|
||||
return this.errors().filter(
|
||||
(error) => (categories.length === 0 || categories.includes(error.category)) && (!field || error.field === field),
|
||||
);
|
||||
});
|
||||
|
||||
readonly pageRows = computed(() => {
|
||||
const { index, size } = this.page();
|
||||
return this.filtered().slice(index * size, (index + 1) * size);
|
||||
});
|
||||
|
||||
readonly validPercent = computed(() => {
|
||||
const validation = this.flow().validation();
|
||||
return validation && validation.total_rows ? Math.round((validation.valid_count / validation.total_rows) * 100) : 0;
|
||||
});
|
||||
|
||||
onCategories(value: ErrorCategory[]): void {
|
||||
this.categories.set(value);
|
||||
this.page.update((page) => ({ ...page, index: 0 }));
|
||||
}
|
||||
|
||||
onField(value: string | null): void {
|
||||
this.field.set(value);
|
||||
this.page.update((page) => ({ ...page, index: 0 }));
|
||||
}
|
||||
|
||||
onPage(event: PageEvent): void {
|
||||
this.page.set({ index: event.pageIndex, size: event.pageSize });
|
||||
}
|
||||
|
||||
categoryLabel(category: ErrorCategory): string {
|
||||
return CATEGORY_LABELS[category] ?? category;
|
||||
}
|
||||
|
||||
display(value: unknown): string {
|
||||
return value === null || value === undefined || value === '' ? '(vacío)' : String(value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user