feat: add CKYC management tab, checker inbox views, and maker-checker diff utilities
This commit is contained in:
+4
-60
@@ -18,6 +18,7 @@ import {
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
|
||||
import { humanizeKey, sameValue, toIsoDate } from 'app/tasks/command-diff.util';
|
||||
|
||||
interface DiffRow {
|
||||
label: string;
|
||||
@@ -106,9 +107,9 @@ export class ProductEditDiffDialogComponent implements OnInit {
|
||||
this.rows = Object.keys(proposed)
|
||||
.filter((key) => !ProductEditDiffDialogComponent.IGNORED_KEYS.has(key))
|
||||
.map((key) => ({ key, originalValue: this.originalValueFor(key, original) }))
|
||||
.filter(({ key, originalValue }) => !this.sameValue(originalValue, proposed[key]))
|
||||
.filter(({ key, originalValue }) => !sameValue(originalValue, proposed[key]))
|
||||
.map(({ key, originalValue }) => ({
|
||||
label: this.humanizeKey(key),
|
||||
label: humanizeKey(key),
|
||||
original: this.displayValue(originalValue, key, original),
|
||||
proposed: this.displayValue(proposed[key], key, original)
|
||||
}))
|
||||
@@ -173,58 +174,11 @@ export class ProductEditDiffDialogComponent implements OnInit {
|
||||
* carries just the id, so a raw comparison reports every such field as changed. Comparing on the id
|
||||
* (and coercing numeric strings) keeps the list to fields whose value genuinely moved.
|
||||
*/
|
||||
private sameValue(a: any, b: any): boolean {
|
||||
return JSON.stringify(this.normalize(a)) === JSON.stringify(this.normalize(b));
|
||||
}
|
||||
|
||||
private normalize(value: any): any {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return null;
|
||||
}
|
||||
// Dates come back from the product as [yyyy, m, d] but are submitted as "yyyy-MM-dd"; without
|
||||
// folding both to one form every date field reads as changed on every edit.
|
||||
const asDate = this.toIsoDate(value);
|
||||
if (asDate !== null) {
|
||||
return asDate;
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
// An empty array and an absent value mean the same thing here.
|
||||
return value.length === 0 ? null : value.map((item) => this.normalize(item));
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
if (value.id !== undefined) {
|
||||
return this.normalize(value.id);
|
||||
}
|
||||
return Object.keys(value).length === 0 ? null : JSON.stringify(value);
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
const asNumber = Number(value);
|
||||
return Number.isNaN(asNumber) ? value : asNumber;
|
||||
}
|
||||
|
||||
/** Recognises both date shapes the API uses and returns "yyyy-MM-dd", or null if not a date. */
|
||||
private toIsoDate(value: any): string | null {
|
||||
if (Array.isArray(value) && value.length === 3 && value.every((part) => typeof part === 'number')) {
|
||||
const [
|
||||
year,
|
||||
month,
|
||||
day
|
||||
] = value;
|
||||
return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
||||
}
|
||||
if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private displayValue(value: any, fieldKey: string, template: any): string {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return '—';
|
||||
}
|
||||
const asDate = this.toIsoDate(value);
|
||||
const asDate = toIsoDate(value);
|
||||
if (asDate !== null) {
|
||||
return asDate;
|
||||
}
|
||||
@@ -248,14 +202,4 @@ export class ProductEditDiffDialogComponent implements OnInit {
|
||||
// A bare id that names an option -- show the option's label, not the number.
|
||||
return this.resolveOptionLabel(fieldKey, value, template) ?? String(value);
|
||||
}
|
||||
|
||||
/** camelCase / PascalCase field name to a spaced, capitalised label. */
|
||||
private humanizeKey(key: string): string {
|
||||
const spaced = key
|
||||
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
||||
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
||||
.replace(/[_-]+/g, ' ')
|
||||
.trim();
|
||||
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user