@evenicanpm/portal-types-schemas 1.5.0 → 1.6.0
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/package.json +4 -3
- package/src/index.ts +2 -0
- package/src/table-param.ts +51 -0
- package/src/view-config.ts +113 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evenicanpm/portal-types-schemas",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
".": "./src/index.ts"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src"
|
|
19
20
|
],
|
|
20
21
|
"types": "./dist/index.d.ts",
|
|
21
22
|
"devDependencies": {
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"typescript": "^5.6.3"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "9b18fe6294cc0e57332ec8703825a609ac7b73b2"
|
|
31
32
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const TableViewParamsSchema = z.object({
|
|
4
|
+
pageSize: z.number().default(5),
|
|
5
|
+
page: z.number().default(0),
|
|
6
|
+
filters: z.record(z.string(), z.unknown()).optional(),
|
|
7
|
+
searchTerm: z.string().optional().default(""),
|
|
8
|
+
searchColumn: z.string().default("all"),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// Extract the TypeScript interface from the schema
|
|
12
|
+
export type TableViewParams = z.infer<typeof TableViewParamsSchema>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* convert the table state into url params.
|
|
16
|
+
* @param params Filters and params stored from table state
|
|
17
|
+
* @returns Url params.
|
|
18
|
+
*/
|
|
19
|
+
export const tableStateToQuery = (params: TableViewParams): URLSearchParams => {
|
|
20
|
+
const { page, pageSize, searchTerm, searchColumn, filters } = params;
|
|
21
|
+
const searchParams = new URLSearchParams();
|
|
22
|
+
searchParams.set("page", String(page));
|
|
23
|
+
searchParams.set("pageSize", String(pageSize));
|
|
24
|
+
|
|
25
|
+
if (searchTerm && searchColumn) {
|
|
26
|
+
searchParams.set("searchTerm", searchTerm);
|
|
27
|
+
searchParams.set("searchColumn", searchColumn);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (filters) searchParams.set("filters", JSON.stringify(filters));
|
|
31
|
+
return searchParams;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Pre-processes url params into portal format to be
|
|
36
|
+
* inserted into one of the DMS URL builders
|
|
37
|
+
*
|
|
38
|
+
* @param searchParams url params from next endpoint
|
|
39
|
+
* @returns table view params formatted filters/pagination
|
|
40
|
+
*/
|
|
41
|
+
export const queryToTableState = (
|
|
42
|
+
searchParams: URLSearchParams,
|
|
43
|
+
): TableViewParams => {
|
|
44
|
+
const page = Number(searchParams.get("page") ?? 0);
|
|
45
|
+
const pageSize = Number(searchParams.get("pageSize") ?? 5);
|
|
46
|
+
const searchTerm = searchParams.get("searchTerm") ?? "";
|
|
47
|
+
const searchColumn = searchParams.get("searchColumn") ?? "";
|
|
48
|
+
const filtersValue = searchParams.get("filters");
|
|
49
|
+
const filters = filtersValue && JSON.parse(filtersValue);
|
|
50
|
+
return { page, pageSize, searchColumn, searchTerm, filters };
|
|
51
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* ColumnDataType
|
|
4
|
+
*/
|
|
5
|
+
export const ColumnDataTypeSchema = z.enum([
|
|
6
|
+
"String",
|
|
7
|
+
"int",
|
|
8
|
+
"numeric",
|
|
9
|
+
"date",
|
|
10
|
+
"datetime",
|
|
11
|
+
"url",
|
|
12
|
+
]);
|
|
13
|
+
export type ColumnDataType = z.infer<typeof ColumnDataTypeSchema>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* DataMaskFormat
|
|
17
|
+
*/
|
|
18
|
+
export const DataMaskFormatSchema = z.enum([
|
|
19
|
+
"MM/DD/YYYY",
|
|
20
|
+
"MM-DD-YYYY",
|
|
21
|
+
"DD/MM/YYYY",
|
|
22
|
+
"DD-MM-YYYY",
|
|
23
|
+
"YYYY/MM/DD",
|
|
24
|
+
"YYYY-MM-DD HH:MI:SS",
|
|
25
|
+
"$0.00",
|
|
26
|
+
"0,00€",
|
|
27
|
+
]);
|
|
28
|
+
export type DataMaskFormat = z.infer<typeof DataMaskFormatSchema>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* FilterOperation
|
|
32
|
+
*/
|
|
33
|
+
export const FilterOperationSchema = z.enum([
|
|
34
|
+
"eq",
|
|
35
|
+
"gt",
|
|
36
|
+
"lt",
|
|
37
|
+
"gte",
|
|
38
|
+
"lte",
|
|
39
|
+
"in",
|
|
40
|
+
]);
|
|
41
|
+
export type FilterOperation = z.infer<typeof FilterOperationSchema>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* FilterOption
|
|
45
|
+
*/
|
|
46
|
+
export const FilterOptionSchema = z.object({
|
|
47
|
+
value: z.union([z.string(), z.number()]),
|
|
48
|
+
label: z.string(),
|
|
49
|
+
});
|
|
50
|
+
export type FilterOption = z.infer<typeof FilterOptionSchema>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* FilterConfig
|
|
54
|
+
*/
|
|
55
|
+
export const FilterConfigSchema = z.object({
|
|
56
|
+
FilterOptions: z.array(FilterOptionSchema),
|
|
57
|
+
FilterType: z.string(),
|
|
58
|
+
FilterOperation: FilterOperationSchema,
|
|
59
|
+
});
|
|
60
|
+
export type FilterConfig = z.infer<typeof FilterConfigSchema>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Filter (from table metadata response)
|
|
64
|
+
*/
|
|
65
|
+
export const FilterSchema = z.object({
|
|
66
|
+
Operation: FilterOperationSchema,
|
|
67
|
+
Data: z.string(),
|
|
68
|
+
Value: z.union([z.string(), z.array(z.string()), z.number()]),
|
|
69
|
+
});
|
|
70
|
+
export type Filter = z.infer<typeof FilterSchema>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Column (recursive)
|
|
74
|
+
*/
|
|
75
|
+
export const ColumnSchema = z.object({
|
|
76
|
+
Label: z.string(),
|
|
77
|
+
Data: z.string(),
|
|
78
|
+
DataType: z.string(),
|
|
79
|
+
DataMask: z.string().optional(),
|
|
80
|
+
ColumnOrder: z.number().nullable().optional(),
|
|
81
|
+
IsSearchable: z.boolean().optional(),
|
|
82
|
+
IsFilterable: z.boolean().optional(),
|
|
83
|
+
Filters: z.array(FilterConfigSchema).optional(),
|
|
84
|
+
IsVisible: z.boolean().optional(),
|
|
85
|
+
IsSortable: z.boolean().optional(),
|
|
86
|
+
DisplayOrder: z.number().optional(),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export type Action = {
|
|
90
|
+
Name: string;
|
|
91
|
+
Type: string;
|
|
92
|
+
IdField?: string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export interface Column {
|
|
96
|
+
Label: string;
|
|
97
|
+
Data: string;
|
|
98
|
+
DataType: string;
|
|
99
|
+
ColumnOrder: number | undefined | null;
|
|
100
|
+
DataMask?: string;
|
|
101
|
+
IsSearchable?: boolean;
|
|
102
|
+
IsFilterable?: boolean;
|
|
103
|
+
Filters?: FilterConfig[];
|
|
104
|
+
IsVisible?: boolean;
|
|
105
|
+
IsSortable?: boolean;
|
|
106
|
+
DisplayOrder?: number;
|
|
107
|
+
Children: Column[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type ViewConfig = {
|
|
111
|
+
Columns: Column[];
|
|
112
|
+
Actions?: Action[];
|
|
113
|
+
};
|