shirkasoft-ui-components 1.3.15 → 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,10 +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 | ((row: any) => boolean); // with validateRequired: flags rows where it's empty (function = conditional)
410
- missingMessage?: string; // text in the empty cell (default "Falta <header>")
411
- missingSeverity?: 'error' | 'warning'; // mandatory (red) or informative (amber); default: table's missingAsError
412
- isMissing?: (row: any) => boolean; // custom rule (default: null/undefined/blank/[])
413
409
  format?: (row: any) => string;
414
410
  tagValue?: (row: any) => string;
415
411
  tagSeverity?: (row: any) => 'success' | 'danger' | 'warn' | 'info' | undefined;
@@ -484,8 +480,7 @@ interface FilterChangeEvent {
484
480
  | `searchPlaceholder` | `string` | `''` |
485
481
  | `globalFilterFields` | `string[]` (dot paths) | `[]` (all primitive values) |
486
482
  | `showGridlines` | `boolean` | `false` |
487
- | `validateRequired` | `boolean` | `false` |
488
- | `missingAsError` | `boolean` (with `validateRequired`) | `true` |
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,32 +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` (or a per-row condition). Each row is checked field by field: the empty cell shows "Falta <header>" (or `missingMessage`) and the whole row is highlighted — red when a field with severity `'error'` is missing, amber when only `'warning'` fields are missing (error wins). Empty means `null`, `undefined`, blank text or empty array; `0` and `false` are valid. 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
- // conditional: mandatory only when the row/payload meets the condition
542
- { field: 'rfc', header: 'RFC', required: (row) => row.tipo === 'empresa' },
543
- ];
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
+ };
544
543
  ```
545
544
 
546
- `required` can be a function evaluated per row (and per payload in `validateRow`): when it returns `false` the field is optional for that row; when `true`, it's checked like a regular required field.
547
545
  ```html
548
- <shk-table [data]="users" [columns]="cols" [validateRequired]="true" />
546
+ <shk-table [data]="items" [columns]="cols" [rowValidations]="rowValidations" />
549
547
  ```
550
548
 
551
- Each column sets the severity of its missing value with `missingSeverity`: `'error'` (red, mandatory) or `'warning'` (amber, informative), so mandatory and informative fields can live in the same `columns` array. Columns without it use the table's `missingAsError` (errors by default; `false` = warnings).
552
-
553
- ```typescript
554
- cols: Column[] = [
555
- { field: 'email', header: 'Email', required: true }, // error
556
- { field: 'phone', header: 'Teléfono', required: true, missingSeverity: 'warning' }, // informative
557
- ];
558
- ```
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`.
559
550
 
560
- **Validating a modal payload.** `validateRow(obj)` returns the `required` columns the object is missing (`[{ field, header, severity }]`, 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:
561
552
 
562
553
  ```typescript
563
554
  table = viewChild.required(TableComponent);
@@ -566,14 +557,14 @@ this.modalSrv.open({
566
557
  title: 'Nuevo usuario',
567
558
  component: NewUserFormComponent, // submitSuccess.emit(this.form.getRawValue())
568
559
  onAccept: (payload) => {
569
- const missing = this.table().validateRow(payload);
570
- this.users.update((u) => [...u, payload]); // the row is flagged by validateRequired
571
- 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');
572
563
  },
573
564
  });
574
565
  ```
575
566
 
576
- i18n: `table.missing.cell` (Spanish fallback).
567
+ i18n: none — the messages belong to the app (`message` key of each rule).
577
568
 
578
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.
579
570