shirkasoft-ui-components 1.3.14 → 1.13.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -406,9 +406,6 @@ interface Column {
406
406
  currency?: string; // template 'currency', default 'USD'
407
407
  image?: (row: any) => string | undefined; // avatar/flag before the text
408
408
  imageWidth?: number; // default 28
409
- required?: boolean; // with validateRequired: flags rows where it's empty
410
- missingMessage?: string; // text in the empty cell (default "Falta <header>")
411
- isMissing?: (row: any) => boolean; // custom rule (default: null/undefined/blank/[])
412
409
  format?: (row: any) => string;
413
410
  tagValue?: (row: any) => string;
414
411
  tagSeverity?: (row: any) => 'success' | 'danger' | 'warn' | 'info' | undefined;
@@ -483,9 +480,7 @@ interface FilterChangeEvent {
483
480
  | `searchPlaceholder` | `string` | `''` |
484
481
  | `globalFilterFields` | `string[]` (dot paths) | `[]` (all primitive values) |
485
482
  | `showGridlines` | `boolean` | `false` |
486
- | `validateRequired` | `boolean` | `false` |
487
- | `missingAsError` | `boolean` (with `validateRequired`) | `true` |
488
- | `requiredFields` | `(string \| RequiredField)[]` | `[]` |
483
+ | `rowValidations` | `Record<string, RowValidation>` | `{}` |
489
484
  | `resizableColumns` | `boolean` (only with `showGridlines`) | `true` |
490
485
  | `columnWidths` | `Record<string, number>` (two-way `[(columnWidths)]`) | `{}` |
491
486
  | `stateKey` | `string` (persists column widths) | `''` |
@@ -532,28 +527,28 @@ i18n keys used: `table.selected` (`{{count}}`), `table.selectAll`, `table.select
532
527
  - `boolean`: tri-state checkbox (any → yes → no), applied immediately.
533
528
  - `range`: two-thumb slider between `filterMin` and `filterMax`, applied on release.
534
529
 
535
- **Missing data validation.** Opt-in with `[validateRequired]="true"` and mark the mandatory columns with `required: true`. Rows where one of them is empty (`null`, `undefined`, blank text or empty array; `0` and `false` are valid) get a red (error) background and stripe, an error icon whose tooltip lists the missing fields, and the empty cell shows "Falta <header>" (or `missingMessage`). The caption shows how many rows are incomplete (whole dataset in client mode, current page in server mode). Use `isMissing: (row) => boolean` for custom rules.
530
+ **Row severity validation.** `[rowValidations]` takes one rule per payload field (the key is the field; dot paths like `'invoice.total'` work). Each rule applies a `condition(value, row)` and, when it returns `true`, paints the **whole row** with a tinted tone: `low` blue (informational), `moderate` amber (needs attention) or `critical` red (blocks). When a row has several issues the worst severity wins (`critical` > `moderate` > `low`). Nothing is written into the cells: they keep showing their real values. The rows that have issues also get a severity icon (info / triangle / octagon in the row color) at the beginning of the **actions column**, before the row actions; its tooltip lists every message, one per line, on hover or keyboard focus.
536
531
 
537
532
  ```typescript
538
- cols: Column[] = [
539
- { field: 'name', header: 'Nombre', required: true },
540
- { field: 'email', header: 'Email', required: true, missingMessage: 'Sin correo' },
541
- ];
542
- ```
543
- ```html
544
- <shk-table [data]="users" [columns]="cols" [validateRequired]="true" />
533
+ rowValidations: Record<string, RowValidation> = {
534
+ valor_factura: {
535
+ condition: (value, row) => !row.factura_id || value == null || Number(value) <= 0,
536
+ severity: 'critical',
537
+ message: 'items.validation.valorFactura', // i18n key (Transloco)
538
+ messageParams: (value, row) => ({ invoice: row.factura_id ?? '—' }),
539
+ },
540
+ documentos: { condition: (value) => !value?.trim(), severity: 'moderate', message: 'items.validation.documentos' },
541
+ peso_bruto: { condition: (value, row) => Number(value) > Number(row.peso_neto), severity: 'low' },
542
+ };
545
543
  ```
546
544
 
547
- Fields that aren't columns can be required too with `requiredFields`: a field name (`'phone'`) or `{ field, label?, isMissing? }`. They flag the row the same way and appear in the tooltip (there's no cell to write "Falta…" in), and `validateRow` checks them as well.
548
-
549
545
  ```html
550
- <shk-table [data]="users()" [columns]="cols" [validateRequired]="true"
551
- [requiredFields]="[{ field: 'phone', label: 'Teléfono' }, 'address.street']" />
546
+ <shk-table [data]="items" [columns]="cols" [rowValidations]="rowValidations" />
552
547
  ```
553
548
 
554
- Incomplete rows are shown as errors (red) by default; set `[missingAsError]="false"` to show them as warnings (amber) instead.
549
+ `message` is a translation key resolved with the table's Transloco service (`{{param}}` interpolation included); when the app doesn't register the key, the string is used as literal text. `rowSeverity(row)` returns `'low' | 'moderate' | 'critical' | null`. The actions column is rendered automatically when there are violations, even if the table has no `rowActions`.
555
550
 
556
- **Validating a modal payload.** `validateRow(obj)` returns the `required` columns and `requiredFields` the object is missing (`[{ field, header }]`, empty when complete); it works even with `validateRequired` off. Combined with the modal's optional `onAccept`, the data coming from a form can be added and flagged:
551
+ **Validating a modal payload.** `validateRow(obj)` returns the violations of any object (`[{ field, severity, message }]`, empty when clean) with the messages already translated. It doesn't need the row to be displayed, so it can be used before adding it:
557
552
 
558
553
  ```typescript
559
554
  table = viewChild.required(TableComponent);
@@ -562,14 +557,14 @@ this.modalSrv.open({
562
557
  title: 'Nuevo usuario',
563
558
  component: NewUserFormComponent, // submitSuccess.emit(this.form.getRawValue())
564
559
  onAccept: (payload) => {
565
- const missing = this.table().validateRow(payload);
566
- this.users.update((u) => [...u, payload]); // the row is flagged by validateRequired
567
- if (missing.length) this.notify('Faltan: ' + missing.map((m) => m.header).join(', '));
560
+ const issues = this.table().validateRow(payload); // [{ field, severity, message }]
561
+ this.users.update((u) => [...u, payload]); // the new row is painted by severity
562
+ if (issues.length) this.notify(issues.map((i) => i.message).join(' · '), 'warning');
568
563
  },
569
564
  });
570
565
  ```
571
566
 
572
- i18n: `table.missing.{summary, row, cell, column}` (Spanish fallbacks).
567
+ i18n: none — the messages belong to the app (`message` key of each rule).
573
568
 
574
569
  **Resizable columns.** With `[showGridlines]="true"` each header has a handle on its right border: drag it to widen/narrow the column (minimum 60px; the table scrolls horizontally when it no longer fits), use the arrow keys on it (Shift = 50px steps), or double click it to go back to the automatic width. Disable it with `[resizableColumns]="false"`. Every change emits `columnResize`. The row actions column can be resized too (its width is stored under the `actions` key); its automatic width fits the most actions visible in a row of the current page (honouring each action's `isVisible`), not every action defined.
575
570