@etsoo/react 1.8.9 → 1.8.11
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.
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DataTypes } from "@etsoo/shared";
|
|
2
|
+
import {
|
|
3
|
+
GridDataGetData,
|
|
4
|
+
GridTemplateType
|
|
5
|
+
} from "../src/components/GridLoader";
|
|
6
|
+
|
|
7
|
+
const template = {
|
|
8
|
+
keyword: "string",
|
|
9
|
+
deviceId: "number",
|
|
10
|
+
creationStart: "date",
|
|
11
|
+
creationEnd: "date"
|
|
12
|
+
} as const satisfies DataTypes.BasicTemplate;
|
|
13
|
+
|
|
14
|
+
test("Tests for GridTemplateType", () => {
|
|
15
|
+
const data: GridTemplateType<typeof template> = {
|
|
16
|
+
keyword: "test",
|
|
17
|
+
deviceId: 1,
|
|
18
|
+
creationStart: new Date()
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
expect(data.keyword).toBe("test");
|
|
22
|
+
expect(data.deviceId).toBe(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("Tests for GridDataGetData with keeping source", () => {
|
|
26
|
+
const data = {
|
|
27
|
+
keyword: "test",
|
|
28
|
+
deviceId: 1,
|
|
29
|
+
creationStart: "2024/12/06",
|
|
30
|
+
other: false
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const result = GridDataGetData(data, template, true);
|
|
34
|
+
|
|
35
|
+
expect(result.keyword).toBe("test");
|
|
36
|
+
expect(result.deviceId).toBe(1);
|
|
37
|
+
expect(result.creationStart).toBeInstanceOf(Date);
|
|
38
|
+
expect((result as any).other).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("Tests for GridDataGetData without keeping source", () => {
|
|
42
|
+
const data = {
|
|
43
|
+
keyword: "test",
|
|
44
|
+
deviceId: 1,
|
|
45
|
+
creationStart: "2024/12/06",
|
|
46
|
+
other: false
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const result = GridDataGetData(data, template, false);
|
|
50
|
+
|
|
51
|
+
expect(result.keyword).toBe("test");
|
|
52
|
+
expect(result.deviceId).toBe(1);
|
|
53
|
+
expect(result.creationStart).toBeInstanceOf(Date);
|
|
54
|
+
expect((result as any).other).toBeUndefined();
|
|
55
|
+
});
|
|
@@ -14,18 +14,28 @@ export declare const GridSizeGet: (size: GridSize, input: number) => number;
|
|
|
14
14
|
* Grid data type
|
|
15
15
|
*/
|
|
16
16
|
export type GridData = FormData | DataTypes.StringRecord;
|
|
17
|
+
/**
|
|
18
|
+
* Grid template type
|
|
19
|
+
*/
|
|
20
|
+
export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
|
|
21
|
+
[k in keyof T]: T[k] extends "date" ? "date" | "string" : T[k] extends DataTypes.BasicNames ? T[k] : never;
|
|
22
|
+
}>;
|
|
17
23
|
/**
|
|
18
24
|
* Grid data get with format
|
|
19
25
|
* @param data Data
|
|
26
|
+
* @param template Template
|
|
27
|
+
* @param keepSource Keep source data
|
|
20
28
|
* @returns Json data
|
|
21
29
|
*/
|
|
22
|
-
export declare function GridDataGet<
|
|
30
|
+
export declare function GridDataGet<const T>(props: GridLoadDataProps, template?: T, keepSource?: boolean): GridJsonData & GridTemplateType<T>;
|
|
23
31
|
/**
|
|
24
32
|
* Grid data get with format
|
|
25
33
|
* @param data Data
|
|
34
|
+
* @param template Template
|
|
35
|
+
* @param keepSource Keep source data
|
|
26
36
|
* @returns Json data
|
|
27
37
|
*/
|
|
28
|
-
export declare function GridDataGetData<
|
|
38
|
+
export declare function GridDataGetData<const T>(data?: GridData, template?: T, keepSource?: boolean): GridTemplateType<T>;
|
|
29
39
|
/**
|
|
30
40
|
* Grid Json data
|
|
31
41
|
*/
|
|
@@ -12,25 +12,32 @@ export const GridSizeGet = (size, input) => {
|
|
|
12
12
|
/**
|
|
13
13
|
* Grid data get with format
|
|
14
14
|
* @param data Data
|
|
15
|
+
* @param template Template
|
|
16
|
+
* @param keepSource Keep source data
|
|
15
17
|
* @returns Json data
|
|
16
18
|
*/
|
|
17
|
-
export function GridDataGet(props, template) {
|
|
19
|
+
export function GridDataGet(props, template, keepSource) {
|
|
18
20
|
// Destruct
|
|
19
21
|
const { data, ...rest } = props;
|
|
20
22
|
// DomUtils.dataAs(data, template);
|
|
21
|
-
return { ...GridDataGetData(data, template), ...rest };
|
|
23
|
+
return { ...GridDataGetData(data, template, keepSource), ...rest };
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Grid data get with format
|
|
25
27
|
* @param data Data
|
|
28
|
+
* @param template Template
|
|
29
|
+
* @param keepSource Keep source data
|
|
26
30
|
* @returns Json data
|
|
27
31
|
*/
|
|
28
|
-
export function GridDataGetData(data, template) {
|
|
32
|
+
export function GridDataGetData(data, template, keepSource) {
|
|
29
33
|
// Clear form empty value
|
|
30
34
|
if (data instanceof FormData) {
|
|
31
35
|
DomUtils.clearFormData(data);
|
|
32
36
|
}
|
|
33
37
|
// Conditions
|
|
34
|
-
|
|
38
|
+
// Set keepSource to true to hold form data, even they are invisible from the conditions
|
|
39
|
+
const conditions = data == null
|
|
40
|
+
? {}
|
|
41
|
+
: DomUtils.dataAs(data, template, keepSource);
|
|
35
42
|
return conditions;
|
|
36
43
|
}
|
package/package.json
CHANGED
|
@@ -21,41 +21,61 @@ export const GridSizeGet = (size: GridSize, input: number) => {
|
|
|
21
21
|
*/
|
|
22
22
|
export type GridData = FormData | DataTypes.StringRecord;
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Grid template type
|
|
26
|
+
*/
|
|
27
|
+
export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
|
|
28
|
+
[k in keyof T]: T[k] extends "date"
|
|
29
|
+
? "date" | "string"
|
|
30
|
+
: T[k] extends DataTypes.BasicNames
|
|
31
|
+
? T[k]
|
|
32
|
+
: never;
|
|
33
|
+
}>;
|
|
34
|
+
|
|
24
35
|
/**
|
|
25
36
|
* Grid data get with format
|
|
26
37
|
* @param data Data
|
|
38
|
+
* @param template Template
|
|
39
|
+
* @param keepSource Keep source data
|
|
27
40
|
* @returns Json data
|
|
28
41
|
*/
|
|
29
|
-
export function GridDataGet<
|
|
42
|
+
export function GridDataGet<const T>(
|
|
30
43
|
props: GridLoadDataProps,
|
|
31
|
-
template?:
|
|
32
|
-
|
|
44
|
+
template?: T,
|
|
45
|
+
keepSource?: boolean
|
|
46
|
+
): GridJsonData & GridTemplateType<T> {
|
|
33
47
|
// Destruct
|
|
34
48
|
const { data, ...rest } = props;
|
|
35
49
|
|
|
36
50
|
// DomUtils.dataAs(data, template);
|
|
37
|
-
return { ...GridDataGetData(data, template), ...rest };
|
|
51
|
+
return { ...GridDataGetData<T>(data, template, keepSource), ...rest };
|
|
38
52
|
}
|
|
39
53
|
|
|
40
54
|
/**
|
|
41
55
|
* Grid data get with format
|
|
42
56
|
* @param data Data
|
|
57
|
+
* @param template Template
|
|
58
|
+
* @param keepSource Keep source data
|
|
43
59
|
* @returns Json data
|
|
44
60
|
*/
|
|
45
|
-
export function GridDataGetData<
|
|
61
|
+
export function GridDataGetData<const T>(
|
|
46
62
|
data?: GridData,
|
|
47
|
-
template?:
|
|
48
|
-
|
|
63
|
+
template?: T,
|
|
64
|
+
keepSource?: boolean
|
|
65
|
+
): GridTemplateType<T> {
|
|
49
66
|
// Clear form empty value
|
|
50
67
|
if (data instanceof FormData) {
|
|
51
68
|
DomUtils.clearFormData(data);
|
|
52
69
|
}
|
|
53
70
|
|
|
54
71
|
// Conditions
|
|
55
|
-
|
|
56
|
-
|
|
72
|
+
// Set keepSource to true to hold form data, even they are invisible from the conditions
|
|
73
|
+
const conditions =
|
|
74
|
+
data == null
|
|
75
|
+
? {}
|
|
76
|
+
: DomUtils.dataAs(data, template as DataTypes.BasicTemplate, keepSource);
|
|
57
77
|
|
|
58
|
-
return conditions;
|
|
78
|
+
return conditions as any;
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
/**
|