rapida-partner 8.0.0 → 8.1.1
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/index.ts +2 -1
- package/package.json +1 -1
- package/src/interfaces/choice-display.interface.ts +4 -0
- package/src/interfaces/form-array.interface.ts +3 -0
- package/src/interfaces/form-checkbox.interface.ts +6 -0
- package/src/interfaces/form-datepicker.interface.ts +4 -0
- package/src/interfaces/form-file.interface.ts +1 -0
- package/src/interfaces/form-radio.interface.ts +4 -0
- package/src/interfaces/form-switch.interface.ts +6 -0
- package/src/interfaces/list.interface.ts +32 -1
- package/src/schemas/choice-display.ref.json +6 -0
- package/src/schemas/form-array.ref.json +3 -0
- package/src/schemas/form-checkbox.ref.json +6 -0
- package/src/schemas/form-datepicker.ref.json +3 -0
- package/src/schemas/form-radio.ref.json +6 -0
- package/src/schemas/form-switch.ref.json +3 -0
- package/src/schemas/list.ref.json +68 -0
- package/src/utils/form-elements.ts +48 -0
- package/src/utils/form-references.test.ts +54 -0
- package/src/utils/form-references.ts +59 -0
- package/src/utils/list-references.ts +73 -25
package/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { tsProjectToJsonProject } from "./src/controllers/ts_project_to_json_project";
|
|
4
4
|
import { validateProjectJson } from "./src/utils/json";
|
|
5
5
|
import { checkListReferences } from "./src/utils/list-references";
|
|
6
|
+
import { checkFormReferences } from "./src/utils/form-references";
|
|
6
7
|
import type { IProject } from "./src/interfaces/project.interface";
|
|
7
8
|
import * as fs from "fs";
|
|
8
9
|
import * as path from "path";
|
|
@@ -78,7 +79,7 @@ async function main() {
|
|
|
78
79
|
process.exit(1);
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
for (const warning of checkListReferences(project)) {
|
|
82
|
+
for (const warning of [...checkListReferences(project), ...checkFormReferences(project)]) {
|
|
82
83
|
console.warn("Aviso: " + warning);
|
|
83
84
|
}
|
|
84
85
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Como as opções de checkbox e radio aparecem. "list" (padrão): uma por linha. "chips": botões
|
|
2
|
+
// lado a lado, para opções curtas (dias da semana, durações). "cards": cartões com a description
|
|
3
|
+
// de cada opção, para escolhas que mudam o resto do formulário.
|
|
4
|
+
export type TChoiceDisplay = "list" | "chips" | "cards";
|
|
@@ -14,4 +14,7 @@ export interface IFormArray {
|
|
|
14
14
|
businessRules?: IBusinessRule[];
|
|
15
15
|
elementDescription?: string;
|
|
16
16
|
isRequired?: boolean;
|
|
17
|
+
// Nome de um item, no singular ("dependente"), para "Adicionar dependente",
|
|
18
|
+
// "Dependente 2" e "Remover dependente 2". Sem ele, a tela usa "item".
|
|
19
|
+
itemLabel?: TTranslatable;
|
|
17
20
|
}
|
|
@@ -2,6 +2,7 @@ import type { TTranslatable } from "./translatable.interface";
|
|
|
2
2
|
// MODIFICATION BASED ON: src/interfaces/form-checkbox.interface.ts
|
|
3
3
|
import type { IFormCondition } from "./condition.interface";
|
|
4
4
|
import type { IBusinessRule } from "./project.interface";
|
|
5
|
+
import type { TChoiceDisplay } from "./choice-display.interface";
|
|
5
6
|
|
|
6
7
|
export interface IFormCheckbox {
|
|
7
8
|
type: "checkbox";
|
|
@@ -18,11 +19,16 @@ export interface IFormCheckbox {
|
|
|
18
19
|
businessRules?: IBusinessRule[];
|
|
19
20
|
elementDescription?: string;
|
|
20
21
|
space?: 1 | 2 | 3 | 4;
|
|
22
|
+
display?: TChoiceDisplay; // ver choice-display.interface.ts
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
export type { TChoiceDisplay } from "./choice-display.interface";
|
|
26
|
+
|
|
23
27
|
export interface ICheckboxOption {
|
|
24
28
|
label: TTranslatable;
|
|
25
29
|
value: string | number | boolean;
|
|
26
30
|
isDisabled?: boolean;
|
|
27
31
|
isSelected?: boolean;
|
|
32
|
+
// Texto de apoio da opção, mostrado só com display "cards".
|
|
33
|
+
description?: TTranslatable;
|
|
28
34
|
}
|
|
@@ -19,4 +19,8 @@ export interface IFormDatePicker {
|
|
|
19
19
|
businessRules?: IBusinessRule[];
|
|
20
20
|
elementDescription?: string;
|
|
21
21
|
space?: 1 | 2 | 3 | 4;
|
|
22
|
+
// Só em listFilters: vira um filtro de período, com "De" e "Até" e atalhos (hoje, esta
|
|
23
|
+
// semana, este mês, mês passado). Busca os registros com a data dentro do período.
|
|
24
|
+
// Em formulários é ignorado.
|
|
25
|
+
range?: boolean;
|
|
22
26
|
}
|
|
@@ -19,6 +19,7 @@ export interface IFormFile {
|
|
|
19
19
|
accept?: Record<string, string[]>;
|
|
20
20
|
isMultiple?: boolean;
|
|
21
21
|
isProfilePicture?: boolean;
|
|
22
|
+
// Tamanho máximo de cada arquivo, em bytes (5 MB = 5242880).
|
|
22
23
|
maxSize?: number;
|
|
23
24
|
isDisabled?: boolean;
|
|
24
25
|
isDisabledOnUpdate?: boolean;
|
|
@@ -2,6 +2,7 @@ import type { TTranslatable } from "./translatable.interface";
|
|
|
2
2
|
// MODIFICATION BASED ON: src/interfaces/form-radio.interface.ts
|
|
3
3
|
import type { IFormCondition } from "./condition.interface";
|
|
4
4
|
import type { IBusinessRule } from "./project.interface";
|
|
5
|
+
import type { TChoiceDisplay } from "./choice-display.interface";
|
|
5
6
|
|
|
6
7
|
export interface IFormRadio {
|
|
7
8
|
type: "radio";
|
|
@@ -18,6 +19,7 @@ export interface IFormRadio {
|
|
|
18
19
|
businessRules?: IBusinessRule[];
|
|
19
20
|
elementDescription?: string;
|
|
20
21
|
space?: 1 | 2 | 3 | 4;
|
|
22
|
+
display?: TChoiceDisplay; // ver choice-display.interface.ts
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export interface IRadioOption {
|
|
@@ -25,4 +27,6 @@ export interface IRadioOption {
|
|
|
25
27
|
value: string | number | boolean;
|
|
26
28
|
isDisabled?: boolean;
|
|
27
29
|
isSelected?: boolean;
|
|
30
|
+
// Texto de apoio da opção, mostrado só com display "cards".
|
|
31
|
+
description?: TTranslatable;
|
|
28
32
|
}
|
|
@@ -16,4 +16,10 @@ export interface IFormSwitch {
|
|
|
16
16
|
businessRules?: IBusinessRule[];
|
|
17
17
|
elementDescription?: string;
|
|
18
18
|
space?: 1 | 2 | 3 | 4;
|
|
19
|
+
// Consentimento: guarda o último aceite e a última revogação, não um histórico completo. Ao
|
|
20
|
+
// ligar, o backend grava a data e o usuário em <name>At e <name>By; ao desligar, grava a
|
|
21
|
+
// revogação em <name>RevokedAt e <name>RevokedBy, sem apagar o aceite. Ligar de novo troca o
|
|
22
|
+
// aceite e limpa a revogação. Evite names que gerem campos já existentes (e.g.: "created"
|
|
23
|
+
// vira createdAt).
|
|
24
|
+
recordTimestamp?: boolean;
|
|
19
25
|
}
|
|
@@ -43,6 +43,7 @@ export interface IList {
|
|
|
43
43
|
tones?: Record<string, TTone>; // só em type "badge" (nos outros tipos é ignorado): tom de cada valor. e.g.: { "paid": "success", "overdue": "danger" }
|
|
44
44
|
mobilePriority?: 1 | 2 | 3; // 1 e 2 aparecem no card do celular; 3 só no desktop
|
|
45
45
|
relativeDate?: "plain" | "deadline"; // data com texto relativo abaixo ("há 3 dias"); "deadline" pinta o passado de vermelho e os próximos 7 dias de âmbar
|
|
46
|
+
columnGroup?: TTranslatable; // grupo da coluna (e.g.: "Valores"), escrito acima do nome e usado no seletor de colunas; colunas do mesmo grupo devem ficar juntas
|
|
46
47
|
conditions?: IFormCondition;
|
|
47
48
|
businessRules?: IBusinessRule[];
|
|
48
49
|
todo?: string;
|
|
@@ -50,6 +51,10 @@ export interface IList {
|
|
|
50
51
|
listFilters?: IFormElement[]; // filters to be applied on dataSource
|
|
51
52
|
quickFilters?: string[]; // até 2 `name` de listFilters que ficam ao lado da busca; os demais vão para a área "Mais filtros". Sem isso, todos ficam na área "Filtros"
|
|
52
53
|
tabs?: IListTabs; // abas com contador acima da tabela, uma por valor de `property`, mais "Todos"
|
|
54
|
+
kpis?: IListKpi[]; // até 4 números-resumo acima da tabela; clicar num deles filtra a lista
|
|
55
|
+
columnViews?: IListColumnView[]; // visualizações de colunas (e.g.: Resumo, Fiscal, Completo); com elas aparece o seletor de colunas e a escolha fica salva por pessoa e por tela
|
|
56
|
+
stickyStart?: boolean; // em tabelas largas, a coluna de identificação (title) fica fixa à esquerda e as ações à direita enquanto o meio rola
|
|
57
|
+
views?: TListView[]; // modos de ver a lista; o primeiro é o padrão. Com os dois, aparece o seletor Tabela/Lista e a escolha fica salva por pessoa e por tela
|
|
53
58
|
listActions?: IFormElement[]; // actions that can be performed on the list
|
|
54
59
|
cardAsALink?: {
|
|
55
60
|
link: string; // e.g.: "/user"
|
|
@@ -114,4 +119,30 @@ export interface IListPagination {
|
|
|
114
119
|
pageSize: number;
|
|
115
120
|
pageSizeOptions?: number[];
|
|
116
121
|
position?: "top" | "bottom" | "both";
|
|
117
|
-
}
|
|
122
|
+
}
|
|
123
|
+
// Número-resumo acima da tabela. Sem sumOf, conta os registros que passam no filtro;
|
|
124
|
+
// com sumOf, soma esse campo numérico. Clicar aplica o filtro na lista.
|
|
125
|
+
export interface IListKpi {
|
|
126
|
+
label: TTranslatable;
|
|
127
|
+
description?: TTranslatable; // contexto abaixo do valor, e.g.: "contas vencidas"
|
|
128
|
+
filter?: IListKpiCondition[]; // condições que o registro precisa cumprir (todas), e.g.: [{ field: "dueDate", op: "lt", value: "$today" }]
|
|
129
|
+
sumOf?: string; // campo numérico do form do módulo, e.g.: "accountAmount"
|
|
130
|
+
tone?: TTone | "brand"; // "brand" no número principal (no máximo 1), "danger" para atraso, "warning" para hoje
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// "table": tabela com colunas, para comparar e ordenar. "list": um card largo por registro, com
|
|
134
|
+
// avatar, título, situação e até 4 campos, para entender e agir em cada um.
|
|
135
|
+
export type TListView = "table" | "list";
|
|
136
|
+
|
|
137
|
+
export interface IListColumnView {
|
|
138
|
+
label: TTranslatable; // e.g.: "Resumo"
|
|
139
|
+
columns: string[]; // property de cada listItem visível nesta visualização; a coluna title aparece sempre
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type TListKpiOperator = "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in";
|
|
143
|
+
|
|
144
|
+
export interface IListKpiCondition {
|
|
145
|
+
field: string; // name de um campo do form do módulo
|
|
146
|
+
op: TListKpiOperator;
|
|
147
|
+
value: string | number | boolean | (string | number)[]; // "$today" e "$tomorrow" viram as datas do dia; com "in", uma lista
|
|
148
|
+
}
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"isSelected": {
|
|
34
34
|
"type": "boolean"
|
|
35
|
+
},
|
|
36
|
+
"description": {
|
|
37
|
+
"$ref": "translatable.ref.json"
|
|
35
38
|
}
|
|
36
39
|
},
|
|
37
40
|
"required": ["label", "value"]
|
|
@@ -67,6 +70,9 @@
|
|
|
67
70
|
"space": {
|
|
68
71
|
"type": "number",
|
|
69
72
|
"enum": [1, 2, 3, 4]
|
|
73
|
+
},
|
|
74
|
+
"display": {
|
|
75
|
+
"$ref": "choice-display.ref.json"
|
|
70
76
|
}
|
|
71
77
|
},
|
|
72
78
|
"required": ["type", "name", "label", "options"]
|
|
@@ -32,6 +32,9 @@
|
|
|
32
32
|
},
|
|
33
33
|
"isSelected": {
|
|
34
34
|
"type": "boolean"
|
|
35
|
+
},
|
|
36
|
+
"description": {
|
|
37
|
+
"$ref": "translatable.ref.json"
|
|
35
38
|
}
|
|
36
39
|
},
|
|
37
40
|
"required": ["label", "value"]
|
|
@@ -67,6 +70,9 @@
|
|
|
67
70
|
"space": {
|
|
68
71
|
"type": "number",
|
|
69
72
|
"enum": [1, 2, 3, 4]
|
|
73
|
+
},
|
|
74
|
+
"display": {
|
|
75
|
+
"$ref": "choice-display.ref.json"
|
|
70
76
|
}
|
|
71
77
|
},
|
|
72
78
|
"required": ["type", "name", "label", "options"]
|
|
@@ -81,6 +81,10 @@
|
|
|
81
81
|
"enum": [1, 2, 3],
|
|
82
82
|
"description": "1 e 2 aparecem no card do celular; 3 só no desktop."
|
|
83
83
|
},
|
|
84
|
+
"columnGroup": {
|
|
85
|
+
"$ref": "translatable.ref.json",
|
|
86
|
+
"description": "Grupo da coluna, escrito acima do nome e usado no seletor de colunas."
|
|
87
|
+
},
|
|
84
88
|
"relativeDate": {
|
|
85
89
|
"type": "string",
|
|
86
90
|
"enum": ["plain", "deadline"],
|
|
@@ -275,6 +279,70 @@
|
|
|
275
279
|
"items": { "type": "string" },
|
|
276
280
|
"description": "Até 2 `name` de listFilters que ficam ao lado da busca; os demais vão para a área 'Mais filtros'. Sem isso, todos ficam na área 'Filtros'."
|
|
277
281
|
},
|
|
282
|
+
"columnViews": {
|
|
283
|
+
"type": "array",
|
|
284
|
+
"description": "Visualizações de colunas; com elas aparece o seletor de colunas.",
|
|
285
|
+
"items": {
|
|
286
|
+
"type": "object",
|
|
287
|
+
"properties": {
|
|
288
|
+
"label": { "$ref": "translatable.ref.json" },
|
|
289
|
+
"columns": { "type": "array", "minItems": 1, "items": { "type": "string" } }
|
|
290
|
+
},
|
|
291
|
+
"required": ["label", "columns"],
|
|
292
|
+
"additionalProperties": false
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
"stickyStart": {
|
|
296
|
+
"type": "boolean",
|
|
297
|
+
"description": "Em tabelas largas, a identificação fica fixa à esquerda e as ações à direita."
|
|
298
|
+
},
|
|
299
|
+
"views": {
|
|
300
|
+
"type": "array",
|
|
301
|
+
"minItems": 1,
|
|
302
|
+
"maxItems": 2,
|
|
303
|
+
"uniqueItems": true,
|
|
304
|
+
"items": { "type": "string", "enum": ["table", "list"] },
|
|
305
|
+
"description": "Modos de ver a lista; o primeiro é o padrão. Com os dois, aparece o seletor Tabela/Lista."
|
|
306
|
+
},
|
|
307
|
+
"kpis": {
|
|
308
|
+
"type": "array",
|
|
309
|
+
"maxItems": 4,
|
|
310
|
+
"description": "Até 4 números-resumo acima da tabela; clicar num deles filtra a lista.",
|
|
311
|
+
"items": {
|
|
312
|
+
"type": "object",
|
|
313
|
+
"properties": {
|
|
314
|
+
"label": { "$ref": "translatable.ref.json" },
|
|
315
|
+
"description": { "$ref": "translatable.ref.json" },
|
|
316
|
+
"filter": {
|
|
317
|
+
"type": "array",
|
|
318
|
+
"items": {
|
|
319
|
+
"type": "object",
|
|
320
|
+
"properties": {
|
|
321
|
+
"field": { "type": "string" },
|
|
322
|
+
"op": { "type": "string", "enum": ["eq", "ne", "lt", "lte", "gt", "gte", "in"] },
|
|
323
|
+
"value": {
|
|
324
|
+
"oneOf": [
|
|
325
|
+
{ "type": "string" },
|
|
326
|
+
{ "type": "number" },
|
|
327
|
+
{ "type": "boolean" },
|
|
328
|
+
{ "type": "array", "items": { "type": ["string", "number"] } }
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
"required": ["field", "op", "value"],
|
|
333
|
+
"additionalProperties": false,
|
|
334
|
+
"if": { "properties": { "op": { "const": "in" } } },
|
|
335
|
+
"then": { "properties": { "value": { "type": "array", "minItems": 1 } } },
|
|
336
|
+
"else": { "properties": { "value": { "not": { "type": "array" } } } }
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
"sumOf": { "type": "string" },
|
|
340
|
+
"tone": { "oneOf": [{ "$ref": "tone.ref.json" }, { "const": "brand" }] }
|
|
341
|
+
},
|
|
342
|
+
"required": ["label"],
|
|
343
|
+
"additionalProperties": false
|
|
344
|
+
}
|
|
345
|
+
},
|
|
278
346
|
"tabs": {
|
|
279
347
|
"type": "object",
|
|
280
348
|
"description": "Abas com contador acima da tabela, uma por valor de `property`, mais 'Todos'.",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { EDataType } from "../enums/form.enum";
|
|
2
|
+
|
|
3
|
+
export interface IFlatElement {
|
|
4
|
+
name?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
dataType?: string;
|
|
7
|
+
range?: boolean;
|
|
8
|
+
recordTimestamp?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface INode extends IFlatElement {
|
|
12
|
+
elements?: unknown[];
|
|
13
|
+
tabs?: { elements?: unknown[] }[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const nodeOf = (element: unknown): INode => (element ?? {}) as INode;
|
|
17
|
+
|
|
18
|
+
const childrenOf = (node: INode): unknown[] =>
|
|
19
|
+
node.type === "tab" ? (node.tabs ?? []).flatMap((tab) => tab.elements ?? []) : (node.elements ?? []);
|
|
20
|
+
|
|
21
|
+
const isContainer = (node: INode): boolean => node.type === "tab" || node.type === "fieldset";
|
|
22
|
+
|
|
23
|
+
// Campos de um mesmo nível: entra em tabs e fieldsets; o array conta como um campo, sem os de dentro.
|
|
24
|
+
export const flattenElements = (elements: unknown[] | undefined): IFlatElement[] =>
|
|
25
|
+
(elements ?? []).map(nodeOf).flatMap((node: INode): IFlatElement[] => (isContainer(node) ? flattenElements(childrenOf(node)) : [node]));
|
|
26
|
+
|
|
27
|
+
// Cada nível de campos separado: o form e, depois, o item de cada array (também os aninhados).
|
|
28
|
+
export const fieldScopes = (elements: unknown[] | undefined): IFlatElement[][] => {
|
|
29
|
+
const fields: IFlatElement[] = flattenElements(elements);
|
|
30
|
+
const nested: IFlatElement[][] = fields
|
|
31
|
+
.filter((field: IFlatElement) => field.type === "array")
|
|
32
|
+
.flatMap((field: IFlatElement) => fieldScopes(nodeOf(field).elements));
|
|
33
|
+
return [fields, ...nested];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Todos os campos, inclusive os de dentro dos arrays.
|
|
37
|
+
export const allFields = (elements: unknown[] | undefined): IFlatElement[] => fieldScopes(elements).flat();
|
|
38
|
+
|
|
39
|
+
export const NUMERIC_DATA_TYPES: string[] = [
|
|
40
|
+
EDataType.NUMBER,
|
|
41
|
+
EDataType.INTEGER,
|
|
42
|
+
EDataType.DECIMAL,
|
|
43
|
+
EDataType.NUMERIC,
|
|
44
|
+
EDataType.FLOAT,
|
|
45
|
+
EDataType.DOUBLE,
|
|
46
|
+
EDataType.REAL,
|
|
47
|
+
EDataType.CURRENCY,
|
|
48
|
+
];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { checkFormReferences } from "./form-references";
|
|
4
|
+
|
|
5
|
+
const consent = (name: string): Record<string, unknown> => ({ type: "switch", name, label: name, recordTimestamp: true });
|
|
6
|
+
const input = (name: string): Record<string, unknown> => ({ type: "input", name, label: name, dataType: "text" });
|
|
7
|
+
const form = (id: string, elements: unknown[]): Record<string, unknown> => ({ componentType: "form", id, elements });
|
|
8
|
+
const projectWith = (components: unknown[], profiles?: Record<string, unknown>): IProject =>
|
|
9
|
+
({ id: "p", modules: [{ id: "m", components }], ...(profiles ? { flows: { profiles } } : {}) }) as unknown as IProject;
|
|
10
|
+
|
|
11
|
+
describe("recordTimestamp", () => {
|
|
12
|
+
test("no nível de cima do primeiro form, sem colisão, não avisa", () => {
|
|
13
|
+
expect(checkFormReferences(projectWith([form("f", [consent("terms"), input("name")])]))).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("avisa colisão com campo reservado e com campo do form", () => {
|
|
17
|
+
const warnings = checkFormReferences(projectWith([form("f", [consent("created"), consent("terms"), input("termsAt")])]));
|
|
18
|
+
expect(warnings).toContain("f: recordTimestamp em \"created\" gera o campo \"createdAt\", que já existe");
|
|
19
|
+
expect(warnings).toContain("f: recordTimestamp em \"terms\" gera o campo \"termsAt\", que já existe");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("compara o nome como o gerador grava no backend", () => {
|
|
23
|
+
const warnings = checkFormReferences(projectWith([form("f", [consent("accepted-terms"), input("accepted_termsAt")])]));
|
|
24
|
+
expect(warnings).toEqual(["f: recordTimestamp em \"accepted-terms\" gera o campo \"accepted_termsAt\", que já existe"]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("dentro de array avisa que o aceite não é registrado, em vez de conferir colisão", () => {
|
|
28
|
+
const warnings = checkFormReferences(projectWith([form("f", [{ type: "array", name: "deps", elements: [consent("terms"), input("termsAt")] }])]));
|
|
29
|
+
expect(warnings).toEqual(["f: recordTimestamp em \"terms\" está dentro de um array; só vale no nível de cima do form, e o aceite não é registrado"]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("num segundo form do módulo avisa que o aceite não é registrado", () => {
|
|
33
|
+
const warnings = checkFormReferences(projectWith([form("first", [input("name")]), form("second", [consent("terms")])]));
|
|
34
|
+
expect(warnings).toEqual(["second: recordTimestamp em \"terms\" só vale no primeiro form do módulo; neste o aceite não é registrado"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("forms de perfil (pessoa e empresa) também gravam, e a colisão é conferida", () => {
|
|
38
|
+
const profiles = { personProfile: { id: "person", elements: [consent("terms")] }, companyProfile: { id: "company", elements: [consent("updated")] } };
|
|
39
|
+
expect(checkFormReferences(projectWith([], profiles))).toEqual([
|
|
40
|
+
"company: recordTimestamp em \"updated\" gera o campo \"updatedAt\", que já existe",
|
|
41
|
+
"company: recordTimestamp em \"updated\" gera o campo \"updatedBy\", que já existe",
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("range", () => {
|
|
47
|
+
test("avisa range em form, inclusive dentro de array", () => {
|
|
48
|
+
const warnings = checkFormReferences(projectWith([form("f", [{ type: "datepicker", name: "due", range: true }, { type: "array", name: "deps", elements: [{ type: "datepicker", name: "born", range: true }] }])]));
|
|
49
|
+
expect(warnings).toEqual([
|
|
50
|
+
"f: \"due\" tem range, que só vale em listFilters; no form vira uma data simples",
|
|
51
|
+
"f: \"born\" tem range, que só vale em listFilters; no form vira uma data simples",
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { IForm } from "../interfaces/form.interface";
|
|
2
|
+
import type { IComponent, IModule, IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { fieldScopes, type IFlatElement } from "./form-elements";
|
|
4
|
+
|
|
5
|
+
const RESERVED_FIELDS: string[] = ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "workspaceId"];
|
|
6
|
+
const CONSENT_SUFFIXES: string[] = ["At", "By", "RevokedAt", "RevokedBy"];
|
|
7
|
+
|
|
8
|
+
interface IFormToCheck {
|
|
9
|
+
id: string;
|
|
10
|
+
elements: unknown[] | undefined;
|
|
11
|
+
recordsConsent: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Mesma regra do sanitizeFieldName do gerador: "accepted-terms" vira "accepted_terms".
|
|
15
|
+
const backendName = (name: string): string => name.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
16
|
+
|
|
17
|
+
const consentWarnings = (form: IFormToCheck, fields: IFlatElement[], isRoot: boolean): string[] => {
|
|
18
|
+
const switches: IFlatElement[] = fields.filter((field: IFlatElement) => field.type === "switch" && field.recordTimestamp === true && field.name);
|
|
19
|
+
if (!isRoot) {
|
|
20
|
+
return switches.map((field: IFlatElement) => form.id + ": recordTimestamp em \"" + field.name + "\" está dentro de um array; só vale no nível de cima do form, e o aceite não é registrado");
|
|
21
|
+
}
|
|
22
|
+
if (!form.recordsConsent) {
|
|
23
|
+
return switches.map((field: IFlatElement) => form.id + ": recordTimestamp em \"" + field.name + "\" só vale no primeiro form do módulo; neste o aceite não é registrado");
|
|
24
|
+
}
|
|
25
|
+
const names = new Set(fields.flatMap((field: IFlatElement): string[] => (field.name ? [backendName(field.name)] : [])));
|
|
26
|
+
return switches.flatMap((field: IFlatElement): string[] =>
|
|
27
|
+
CONSENT_SUFFIXES.map((suffix: string) => backendName(field.name ?? "") + suffix)
|
|
28
|
+
.filter((generated: string) => RESERVED_FIELDS.includes(generated) || names.has(generated))
|
|
29
|
+
.map((generated: string) => form.id + ": recordTimestamp em \"" + field.name + "\" gera o campo \"" + generated + "\", que já existe"),
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const rangeWarnings = (form: IFormToCheck, fields: IFlatElement[]): string[] =>
|
|
34
|
+
fields
|
|
35
|
+
.filter((field: IFlatElement) => field.type === "datepicker" && field.range === true)
|
|
36
|
+
.map((field: IFlatElement) => form.id + ": \"" + field.name + "\" tem range, que só vale em listFilters; no form vira uma data simples");
|
|
37
|
+
|
|
38
|
+
const formWarnings = (form: IFormToCheck): string[] =>
|
|
39
|
+
fieldScopes(form.elements).flatMap((fields: IFlatElement[], index: number) => [
|
|
40
|
+
...rangeWarnings(form, fields),
|
|
41
|
+
...consentWarnings(form, fields, index === 0),
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
// O backend gerado grava o consentimento só no primeiro form de cada módulo; os forms de perfil viram uma
|
|
45
|
+
// collection só, então os dois gravam.
|
|
46
|
+
const formsOf = (project: IProject): IFormToCheck[] => [
|
|
47
|
+
...(project.modules ?? []).flatMap((module: IModule): IFormToCheck[] =>
|
|
48
|
+
module.components
|
|
49
|
+
.filter((component: IComponent) => component.componentType === "form")
|
|
50
|
+
.map((component: IComponent, index: number) => ({ id: component.id, elements: "elements" in component ? component.elements : undefined, recordsConsent: index === 0 })),
|
|
51
|
+
),
|
|
52
|
+
...[project.flows?.profiles?.personProfile, project.flows?.profiles?.companyProfile]
|
|
53
|
+
.filter((form: IForm | undefined): form is IForm => !!form)
|
|
54
|
+
.map((form: IForm) => ({ id: form.id, elements: form.elements, recordsConsent: true })),
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// Regras de formulário que o schema não consegue conferir (range fora de filtro e recordTimestamp:
|
|
58
|
+
// lugar onde o gerador grava e colisão com campos existentes).
|
|
59
|
+
export const checkFormReferences = (project: IProject): string[] => formsOf(project).flatMap(formWarnings);
|
|
@@ -1,51 +1,99 @@
|
|
|
1
1
|
import type { IList } from "../interfaces/list.interface";
|
|
2
2
|
import type { IComponent, IModule, IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { allFields, fieldScopes, NUMERIC_DATA_TYPES, type IFlatElement } from "./form-elements";
|
|
3
4
|
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tabs?: { elements?: unknown[] }[];
|
|
5
|
+
interface IModuleFields {
|
|
6
|
+
names: Set<string>;
|
|
7
|
+
fields: Map<string, IFlatElement>;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const namesOf = (elements: unknown[] | undefined): string
|
|
11
|
-
(elements
|
|
12
|
-
const node = (element ?? {}) as INamedNode;
|
|
13
|
-
return [
|
|
14
|
-
...(node.name ? [node.name] : []),
|
|
15
|
-
...namesOf(node.elements),
|
|
16
|
-
...namesOf((node.tabs ?? []).flatMap((tab) => tab.elements ?? [])),
|
|
17
|
-
];
|
|
18
|
-
});
|
|
10
|
+
const namesOf = (elements: unknown[] | undefined): Set<string> =>
|
|
11
|
+
new Set(allFields(elements).flatMap((field: IFlatElement): string[] => (field.name ? [field.name] : [])));
|
|
19
12
|
|
|
20
13
|
const isList = (component: IComponent): component is IList => component.componentType === "list";
|
|
21
14
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const namedFields = (fields: IFlatElement[]): [string, IFlatElement][] =>
|
|
16
|
+
fields.flatMap((field: IFlatElement): [string, IFlatElement][] => (field.name ? [[field.name, field]] : []));
|
|
17
|
+
|
|
18
|
+
// names: todos os campos, inclusive de arrays (tabs.property). fields: só o nível de cima de cada form,
|
|
19
|
+
// que é o que o registro tem e o que os KPIs conseguem contar e somar.
|
|
20
|
+
const moduleFieldsOf = (module: IModule): IModuleFields => {
|
|
21
|
+
const elementsOf = (component: IComponent): unknown[] | undefined =>
|
|
22
|
+
component.componentType === "form" ? component.elements : undefined;
|
|
23
|
+
const forms: IComponent[] = module.components.filter((component: IComponent) => component.componentType === "form");
|
|
24
|
+
return {
|
|
25
|
+
names: new Set(namedFields(forms.flatMap((form: IComponent) => allFields(elementsOf(form)))).map(([name]) => name)),
|
|
26
|
+
fields: new Map(namedFields(forms.flatMap((form: IComponent) => fieldScopes(elementsOf(form))[0]))),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const columnViewWarnings = (list: IList): string[] => {
|
|
31
|
+
const properties = new Set(list.listItems.map((item) => item.property).filter(Boolean));
|
|
32
|
+
return (list.columnViews ?? []).flatMap((view) =>
|
|
33
|
+
view.columns
|
|
34
|
+
.filter((column: string) => !properties.has(column))
|
|
35
|
+
.map((column: string) => list.id + ": columnViews cita a coluna \"" + column + "\", que não está em listItems"),
|
|
27
36
|
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const columnGroupWarnings = (list: IList): string[] => {
|
|
40
|
+
const groups: string[] = list.listItems.filter((item) => item.columnGroup).map((item) => JSON.stringify(item.columnGroup));
|
|
41
|
+
const seen: string[] = [];
|
|
42
|
+
const warnings: string[] = [];
|
|
43
|
+
groups.forEach((group: string, index: number) => {
|
|
44
|
+
if (index > 0 && group !== groups[index - 1] && seen.includes(group)) {
|
|
45
|
+
warnings.push(list.id + ": o columnGroup " + group + " aparece separado; deixe as colunas do mesmo grupo juntas");
|
|
46
|
+
}
|
|
47
|
+
if (!seen.includes(group)) seen.push(group);
|
|
48
|
+
});
|
|
49
|
+
return warnings;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const kpiWarnings = (list: IList, fields: Map<string, IFlatElement>): string[] => {
|
|
53
|
+
const kpis = list.kpis ?? [];
|
|
54
|
+
const warnings: string[] = [];
|
|
55
|
+
if (kpis.filter((kpi) => kpi.tone === "brand").length > 1) {
|
|
56
|
+
warnings.push(list.id + ": mais de um KPI com tone \"brand\"; use no máximo um");
|
|
57
|
+
}
|
|
58
|
+
for (const kpi of kpis) {
|
|
59
|
+
if (kpi.sumOf) {
|
|
60
|
+
const field = fields.get(kpi.sumOf);
|
|
61
|
+
if (!field) warnings.push(list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não existe no nível de cima de nenhum form do módulo (campos de array não valem)");
|
|
62
|
+
else if (!NUMERIC_DATA_TYPES.includes((field.dataType ?? "").toLowerCase())) {
|
|
63
|
+
warnings.push(list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não é um campo numérico");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const condition of Array.isArray(kpi.filter) ? kpi.filter : []) {
|
|
67
|
+
if (!fields.has(condition.field)) {
|
|
68
|
+
warnings.push(list.id + ": kpis.filter cita o campo \"" + condition.field + "\", que não existe no nível de cima de nenhum form do módulo (campos de array não valem)");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return warnings;
|
|
73
|
+
};
|
|
28
74
|
|
|
29
|
-
const listWarnings = (list: IList,
|
|
75
|
+
const listWarnings = (list: IList, moduleFields: IModuleFields): string[] => {
|
|
30
76
|
const warnings: string[] = [];
|
|
31
|
-
const filterNames =
|
|
77
|
+
const filterNames: Set<string> = namesOf(list.listFilters);
|
|
32
78
|
for (const name of list.quickFilters ?? []) {
|
|
33
79
|
if (!filterNames.has(name)) {
|
|
34
80
|
warnings.push(list.id + ": quickFilters cita \"" + name + "\", que não está em listFilters");
|
|
35
81
|
}
|
|
36
82
|
}
|
|
37
83
|
const tabs = list.tabs;
|
|
38
|
-
if (tabs && !tabs.options?.length && !
|
|
84
|
+
if (tabs && !tabs.options?.length && !moduleFields.names.has(tabs.property)) {
|
|
39
85
|
warnings.push(
|
|
40
86
|
list.id + ": tabs.property \"" + tabs.property + "\" não existe em nenhum form do módulo e tabs.options está vazio",
|
|
41
87
|
);
|
|
42
88
|
}
|
|
43
|
-
return warnings;
|
|
89
|
+
return [...warnings, ...columnViewWarnings(list), ...columnGroupWarnings(list), ...kpiWarnings(list, moduleFields.fields)];
|
|
44
90
|
};
|
|
45
91
|
|
|
46
|
-
// Nomes citados por texto (quickFilters
|
|
92
|
+
// Nomes citados por texto (quickFilters, tabs.property, columnViews, kpis) que o schema não consegue conferir.
|
|
47
93
|
export const checkListReferences = (project: IProject): string[] =>
|
|
48
94
|
(project.modules ?? []).flatMap((module: IModule): string[] => {
|
|
49
|
-
const
|
|
50
|
-
|
|
95
|
+
const lists: IList[] = module.components.filter(isList);
|
|
96
|
+
if (lists.length === 0) return [];
|
|
97
|
+
const moduleFields: IModuleFields = moduleFieldsOf(module);
|
|
98
|
+
return lists.flatMap((list: IList) => listWarnings(list, moduleFields));
|
|
51
99
|
});
|