@etsoo/react 1.8.10 → 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
|
+
});
|
|
@@ -17,8 +17,8 @@ export type GridData = FormData | DataTypes.StringRecord;
|
|
|
17
17
|
/**
|
|
18
18
|
* Grid template type
|
|
19
19
|
*/
|
|
20
|
-
export type GridTemplateType<
|
|
21
|
-
[k in keyof
|
|
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
22
|
}>;
|
|
23
23
|
/**
|
|
24
24
|
* Grid data get with format
|
|
@@ -27,7 +27,7 @@ export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
|
|
|
27
27
|
* @param keepSource Keep source data
|
|
28
28
|
* @returns Json data
|
|
29
29
|
*/
|
|
30
|
-
export declare function GridDataGet(props: GridLoadDataProps, template?:
|
|
30
|
+
export declare function GridDataGet<const T>(props: GridLoadDataProps, template?: T, keepSource?: boolean): GridJsonData & GridTemplateType<T>;
|
|
31
31
|
/**
|
|
32
32
|
* Grid data get with format
|
|
33
33
|
* @param data Data
|
|
@@ -35,7 +35,7 @@ export declare function GridDataGet(props: GridLoadDataProps, template?: object,
|
|
|
35
35
|
* @param keepSource Keep source data
|
|
36
36
|
* @returns Json data
|
|
37
37
|
*/
|
|
38
|
-
export declare function GridDataGetData(data?: GridData, template?:
|
|
38
|
+
export declare function GridDataGetData<const T>(data?: GridData, template?: T, keepSource?: boolean): GridTemplateType<T>;
|
|
39
39
|
/**
|
|
40
40
|
* Grid Json data
|
|
41
41
|
*/
|
|
@@ -16,7 +16,7 @@ export const GridSizeGet = (size, input) => {
|
|
|
16
16
|
* @param keepSource Keep source data
|
|
17
17
|
* @returns Json data
|
|
18
18
|
*/
|
|
19
|
-
export function GridDataGet(props, template
|
|
19
|
+
export function GridDataGet(props, template, keepSource) {
|
|
20
20
|
// Destruct
|
|
21
21
|
const { data, ...rest } = props;
|
|
22
22
|
// DomUtils.dataAs(data, template);
|
|
@@ -29,7 +29,7 @@ export function GridDataGet(props, template = {}, keepSource = true) {
|
|
|
29
29
|
* @param keepSource Keep source data
|
|
30
30
|
* @returns Json data
|
|
31
31
|
*/
|
|
32
|
-
export function GridDataGetData(data, template
|
|
32
|
+
export function GridDataGetData(data, template, keepSource) {
|
|
33
33
|
// Clear form empty value
|
|
34
34
|
if (data instanceof FormData) {
|
|
35
35
|
DomUtils.clearFormData(data);
|
package/package.json
CHANGED
|
@@ -24,11 +24,11 @@ export type GridData = FormData | DataTypes.StringRecord;
|
|
|
24
24
|
/**
|
|
25
25
|
* Grid template type
|
|
26
26
|
*/
|
|
27
|
-
export type GridTemplateType<
|
|
28
|
-
[k in keyof
|
|
27
|
+
export type GridTemplateType<T> = DataTypes.BasicTemplateType<{
|
|
28
|
+
[k in keyof T]: T[k] extends "date"
|
|
29
29
|
? "date" | "string"
|
|
30
|
-
: k extends DataTypes.BasicNames
|
|
31
|
-
?
|
|
30
|
+
: T[k] extends DataTypes.BasicNames
|
|
31
|
+
? T[k]
|
|
32
32
|
: never;
|
|
33
33
|
}>;
|
|
34
34
|
|
|
@@ -39,16 +39,16 @@ export type GridTemplateType<o extends object> = DataTypes.BasicTemplateType<{
|
|
|
39
39
|
* @param keepSource Keep source data
|
|
40
40
|
* @returns Json data
|
|
41
41
|
*/
|
|
42
|
-
export function GridDataGet(
|
|
42
|
+
export function GridDataGet<const T>(
|
|
43
43
|
props: GridLoadDataProps,
|
|
44
|
-
template
|
|
45
|
-
keepSource
|
|
46
|
-
): GridJsonData & GridTemplateType<
|
|
44
|
+
template?: T,
|
|
45
|
+
keepSource?: boolean
|
|
46
|
+
): GridJsonData & GridTemplateType<T> {
|
|
47
47
|
// Destruct
|
|
48
48
|
const { data, ...rest } = props;
|
|
49
49
|
|
|
50
50
|
// DomUtils.dataAs(data, template);
|
|
51
|
-
return { ...GridDataGetData(data, template, keepSource), ...rest };
|
|
51
|
+
return { ...GridDataGetData<T>(data, template, keepSource), ...rest };
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -58,11 +58,11 @@ export function GridDataGet(
|
|
|
58
58
|
* @param keepSource Keep source data
|
|
59
59
|
* @returns Json data
|
|
60
60
|
*/
|
|
61
|
-
export function GridDataGetData(
|
|
61
|
+
export function GridDataGetData<const T>(
|
|
62
62
|
data?: GridData,
|
|
63
|
-
template
|
|
64
|
-
keepSource
|
|
65
|
-
): GridTemplateType<
|
|
63
|
+
template?: T,
|
|
64
|
+
keepSource?: boolean
|
|
65
|
+
): GridTemplateType<T> {
|
|
66
66
|
// Clear form empty value
|
|
67
67
|
if (data instanceof FormData) {
|
|
68
68
|
DomUtils.clearFormData(data);
|
|
@@ -70,12 +70,12 @@ export function GridDataGetData(
|
|
|
70
70
|
|
|
71
71
|
// Conditions
|
|
72
72
|
// Set keepSource to true to hold form data, even they are invisible from the conditions
|
|
73
|
-
const conditions
|
|
73
|
+
const conditions =
|
|
74
74
|
data == null
|
|
75
75
|
? {}
|
|
76
76
|
: DomUtils.dataAs(data, template as DataTypes.BasicTemplate, keepSource);
|
|
77
77
|
|
|
78
|
-
return conditions;
|
|
78
|
+
return conditions as any;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/**
|