@etsoo/react 1.4.63 → 1.4.64
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/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/mu/GridDataFormat.d.ts +10 -0
- package/lib/mu/GridDataFormat.js +43 -0
- package/lib/mu/pages/ViewPage.d.ts +10 -1
- package/lib/mu/pages/ViewPage.js +14 -6
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/mu/GridDataFormat.tsx +77 -0
- package/src/mu/pages/ViewPage.tsx +28 -3
package/lib/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export * from './mu/DraggablePaperComponent';
|
|
|
42
42
|
export * from './mu/EmailInput';
|
|
43
43
|
export * from './mu/FabBox';
|
|
44
44
|
export * from './mu/FlexBox';
|
|
45
|
+
export * from './mu/GridDataFormat';
|
|
45
46
|
export * from './mu/IconButtonLink';
|
|
46
47
|
export * from './mu/InputField';
|
|
47
48
|
export * from './mu/ItemList';
|
package/lib/index.js
CHANGED
|
@@ -45,6 +45,7 @@ export * from './mu/DraggablePaperComponent';
|
|
|
45
45
|
export * from './mu/EmailInput';
|
|
46
46
|
export * from './mu/FabBox';
|
|
47
47
|
export * from './mu/FlexBox';
|
|
48
|
+
export * from './mu/GridDataFormat';
|
|
48
49
|
export * from './mu/IconButtonLink';
|
|
49
50
|
export * from './mu/InputField';
|
|
50
51
|
export * from './mu/ItemList';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { GridColumnRenderProps, GridDataType } from '../components/GridColumn';
|
|
3
|
+
/**
|
|
4
|
+
* Grid data format
|
|
5
|
+
* @param data Input data
|
|
6
|
+
* @param type Data type
|
|
7
|
+
* @param renderProps Render props
|
|
8
|
+
* @returns Result
|
|
9
|
+
*/
|
|
10
|
+
export declare function GridDataFormat(data: unknown, type: GridDataType, renderProps?: GridColumnRenderProps): React.ReactNode;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DateUtils, NumberUtils } from '@etsoo/shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { DateText } from './texts/DateText';
|
|
4
|
+
import { GridDataType } from '../components/GridColumn';
|
|
5
|
+
/**
|
|
6
|
+
* Grid data format
|
|
7
|
+
* @param data Input data
|
|
8
|
+
* @param type Data type
|
|
9
|
+
* @param renderProps Render props
|
|
10
|
+
* @returns Result
|
|
11
|
+
*/
|
|
12
|
+
export function GridDataFormat(data, type, renderProps) {
|
|
13
|
+
// Null
|
|
14
|
+
if (data == null)
|
|
15
|
+
return undefined;
|
|
16
|
+
// For date time
|
|
17
|
+
// Conversion if necessary
|
|
18
|
+
if (type === GridDataType.Date || type === GridDataType.DateTime) {
|
|
19
|
+
const dateValue = data instanceof Date
|
|
20
|
+
? data
|
|
21
|
+
: typeof data === 'number' || typeof data === 'string'
|
|
22
|
+
? new Date(data)
|
|
23
|
+
: undefined;
|
|
24
|
+
if (dateValue == null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const option = type === GridDataType.DateTime ? 'ds' : 'd';
|
|
27
|
+
const nearDays = renderProps === null || renderProps === void 0 ? void 0 : renderProps.nearDays;
|
|
28
|
+
if (nearDays != null) {
|
|
29
|
+
return (React.createElement(DateText, { value: dateValue, locale: renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, timeZone: renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone, options: option, nearDays: nearDays }));
|
|
30
|
+
}
|
|
31
|
+
return DateUtils.format(dateValue, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, option, renderProps === null || renderProps === void 0 ? void 0 : renderProps.timeZone);
|
|
32
|
+
}
|
|
33
|
+
// For numbers
|
|
34
|
+
if (typeof data === 'number') {
|
|
35
|
+
if (type === GridDataType.Money || type === GridDataType.IntMoney)
|
|
36
|
+
return NumberUtils.formatMoney(data, renderProps === null || renderProps === void 0 ? void 0 : renderProps.currency, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, type === GridDataType.IntMoney, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
37
|
+
else
|
|
38
|
+
return NumberUtils.format(data, renderProps === null || renderProps === void 0 ? void 0 : renderProps.culture, renderProps === null || renderProps === void 0 ? void 0 : renderProps.numberFormatOptions);
|
|
39
|
+
}
|
|
40
|
+
if (typeof data === 'string')
|
|
41
|
+
return data;
|
|
42
|
+
return `${data}`;
|
|
43
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GridProps } from '@mui/material';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { GridColumnRenderProps, GridDataType } from '../../components/GridColumn';
|
|
3
4
|
import { CommonPageProps } from './CommonPageProps';
|
|
4
5
|
/**
|
|
5
6
|
* View page display field
|
|
@@ -9,6 +10,10 @@ export interface ViewPageField<T extends {}> extends GridProps {
|
|
|
9
10
|
* Data field
|
|
10
11
|
*/
|
|
11
12
|
data: keyof T | ((item: T) => React.ReactNode);
|
|
13
|
+
/**
|
|
14
|
+
* Data type
|
|
15
|
+
*/
|
|
16
|
+
dataType?: GridDataType;
|
|
12
17
|
/**
|
|
13
18
|
* Label field
|
|
14
19
|
*/
|
|
@@ -17,8 +22,12 @@ export interface ViewPageField<T extends {}> extends GridProps {
|
|
|
17
22
|
* Display as single row
|
|
18
23
|
*/
|
|
19
24
|
singleRow?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Render props
|
|
27
|
+
*/
|
|
28
|
+
renderProps?: GridColumnRenderProps;
|
|
20
29
|
}
|
|
21
|
-
declare type ViewPageFieldType<T> = (string & keyof T) | ViewPageField<T>;
|
|
30
|
+
declare type ViewPageFieldType<T> = (string & keyof T) | [string & keyof T, GridDataType, GridColumnRenderProps?] | ViewPageField<T>;
|
|
22
31
|
/**
|
|
23
32
|
* View page props
|
|
24
33
|
*/
|
package/lib/mu/pages/ViewPage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Grid, LinearProgress, Typography } from '@mui/material';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { globalApp } from '../../app/ReactApp';
|
|
4
|
+
import { GridDataFormat } from '../GridDataFormat';
|
|
4
5
|
import { MUGlobal } from '../MUGlobal';
|
|
5
6
|
import { CommonPage } from './CommonPage';
|
|
6
7
|
function formatItemData(fieldData) {
|
|
@@ -13,12 +14,17 @@ function formatItemData(fieldData) {
|
|
|
13
14
|
return `${fieldData}`;
|
|
14
15
|
}
|
|
15
16
|
function getItemField(field, data) {
|
|
16
|
-
var _a, _b;
|
|
17
|
+
var _a, _b, _c;
|
|
17
18
|
// Item data and label
|
|
18
19
|
let itemData, itemLabel, gridProps = {};
|
|
19
|
-
if (
|
|
20
|
+
if (Array.isArray(field)) {
|
|
21
|
+
const [fieldData, fieldType, renderProps] = field;
|
|
22
|
+
itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
|
|
23
|
+
itemLabel = (_a = globalApp.get(fieldData)) !== null && _a !== void 0 ? _a : fieldData;
|
|
24
|
+
}
|
|
25
|
+
else if (typeof field === 'object') {
|
|
20
26
|
// Destruct
|
|
21
|
-
const { data: fieldData, label: fieldLabel, singleRow = false, ...rest } = field;
|
|
27
|
+
const { data: fieldData, dataType, label: fieldLabel, renderProps, singleRow = false, ...rest } = field;
|
|
22
28
|
gridProps = {
|
|
23
29
|
...rest,
|
|
24
30
|
...(singleRow && { xs: 12, sm: 12, md: 12, lg: 12, xl: 12 })
|
|
@@ -26,17 +32,19 @@ function getItemField(field, data) {
|
|
|
26
32
|
// Field data
|
|
27
33
|
if (typeof fieldData === 'function')
|
|
28
34
|
itemData = fieldData(data);
|
|
29
|
-
else
|
|
35
|
+
else if (dataType == null)
|
|
30
36
|
itemData = formatItemData(data[fieldData]);
|
|
37
|
+
else
|
|
38
|
+
itemData = GridDataFormat(data[fieldData], dataType, renderProps);
|
|
31
39
|
// Field label
|
|
32
40
|
itemLabel =
|
|
33
41
|
typeof fieldLabel === 'function'
|
|
34
42
|
? fieldLabel()
|
|
35
|
-
: (
|
|
43
|
+
: (_b = globalApp.get(fieldLabel !== null && fieldLabel !== void 0 ? fieldLabel : (typeof fieldData === 'string' ? fieldData : 'noData'))) !== null && _b !== void 0 ? _b : fieldLabel;
|
|
36
44
|
}
|
|
37
45
|
else {
|
|
38
46
|
itemData = formatItemData(data[field]);
|
|
39
|
-
itemLabel = (
|
|
47
|
+
itemLabel = (_c = globalApp.get(field)) !== null && _c !== void 0 ? _c : field;
|
|
40
48
|
}
|
|
41
49
|
return [
|
|
42
50
|
itemData,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ export * from './mu/DraggablePaperComponent';
|
|
|
49
49
|
export * from './mu/EmailInput';
|
|
50
50
|
export * from './mu/FabBox';
|
|
51
51
|
export * from './mu/FlexBox';
|
|
52
|
+
export * from './mu/GridDataFormat';
|
|
52
53
|
export * from './mu/IconButtonLink';
|
|
53
54
|
export * from './mu/InputField';
|
|
54
55
|
export * from './mu/ItemList';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { DateUtils, NumberUtils } from '@etsoo/shared';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { DateText } from './texts/DateText';
|
|
4
|
+
import { GridColumnRenderProps, GridDataType } from '../components/GridColumn';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Grid data format
|
|
8
|
+
* @param data Input data
|
|
9
|
+
* @param type Data type
|
|
10
|
+
* @param renderProps Render props
|
|
11
|
+
* @returns Result
|
|
12
|
+
*/
|
|
13
|
+
export function GridDataFormat(
|
|
14
|
+
data: unknown,
|
|
15
|
+
type: GridDataType,
|
|
16
|
+
renderProps?: GridColumnRenderProps
|
|
17
|
+
): React.ReactNode {
|
|
18
|
+
// Null
|
|
19
|
+
if (data == null) return undefined;
|
|
20
|
+
|
|
21
|
+
// For date time
|
|
22
|
+
// Conversion if necessary
|
|
23
|
+
if (type === GridDataType.Date || type === GridDataType.DateTime) {
|
|
24
|
+
const dateValue =
|
|
25
|
+
data instanceof Date
|
|
26
|
+
? data
|
|
27
|
+
: typeof data === 'number' || typeof data === 'string'
|
|
28
|
+
? new Date(data)
|
|
29
|
+
: undefined;
|
|
30
|
+
|
|
31
|
+
if (dateValue == null) return undefined;
|
|
32
|
+
|
|
33
|
+
const option = type === GridDataType.DateTime ? 'ds' : 'd';
|
|
34
|
+
|
|
35
|
+
const nearDays = renderProps?.nearDays;
|
|
36
|
+
if (nearDays != null) {
|
|
37
|
+
return (
|
|
38
|
+
<DateText
|
|
39
|
+
value={dateValue}
|
|
40
|
+
locale={renderProps?.culture}
|
|
41
|
+
timeZone={renderProps?.timeZone}
|
|
42
|
+
options={option}
|
|
43
|
+
nearDays={nearDays}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return DateUtils.format(
|
|
49
|
+
dateValue,
|
|
50
|
+
renderProps?.culture,
|
|
51
|
+
option,
|
|
52
|
+
renderProps?.timeZone
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// For numbers
|
|
57
|
+
if (typeof data === 'number') {
|
|
58
|
+
if (type === GridDataType.Money || type === GridDataType.IntMoney)
|
|
59
|
+
return NumberUtils.formatMoney(
|
|
60
|
+
data,
|
|
61
|
+
renderProps?.currency,
|
|
62
|
+
renderProps?.culture,
|
|
63
|
+
type === GridDataType.IntMoney,
|
|
64
|
+
renderProps?.numberFormatOptions
|
|
65
|
+
);
|
|
66
|
+
else
|
|
67
|
+
return NumberUtils.format(
|
|
68
|
+
data,
|
|
69
|
+
renderProps?.culture,
|
|
70
|
+
renderProps?.numberFormatOptions
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof data === 'string') return data;
|
|
75
|
+
|
|
76
|
+
return `${data}`;
|
|
77
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Grid, GridProps, LinearProgress, Typography } from '@mui/material';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { globalApp } from '../../app/ReactApp';
|
|
4
|
+
import {
|
|
5
|
+
GridColumnRenderProps,
|
|
6
|
+
GridDataType
|
|
7
|
+
} from '../../components/GridColumn';
|
|
8
|
+
import { GridDataFormat } from '../GridDataFormat';
|
|
4
9
|
import { MUGlobal } from '../MUGlobal';
|
|
5
10
|
import { CommonPage } from './CommonPage';
|
|
6
11
|
import { CommonPageProps } from './CommonPageProps';
|
|
@@ -14,6 +19,11 @@ export interface ViewPageField<T extends {}> extends GridProps {
|
|
|
14
19
|
*/
|
|
15
20
|
data: keyof T | ((item: T) => React.ReactNode);
|
|
16
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Data type
|
|
24
|
+
*/
|
|
25
|
+
dataType?: GridDataType;
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* Label field
|
|
19
29
|
*/
|
|
@@ -23,9 +33,17 @@ export interface ViewPageField<T extends {}> extends GridProps {
|
|
|
23
33
|
* Display as single row
|
|
24
34
|
*/
|
|
25
35
|
singleRow?: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Render props
|
|
39
|
+
*/
|
|
40
|
+
renderProps?: GridColumnRenderProps;
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
type ViewPageFieldType<T> =
|
|
43
|
+
type ViewPageFieldType<T> =
|
|
44
|
+
| (string & keyof T)
|
|
45
|
+
| [string & keyof T, GridDataType, GridColumnRenderProps?]
|
|
46
|
+
| ViewPageField<T>;
|
|
29
47
|
|
|
30
48
|
/**
|
|
31
49
|
* View page props
|
|
@@ -63,11 +81,17 @@ function getItemField<T>(
|
|
|
63
81
|
itemLabel: React.ReactNode,
|
|
64
82
|
gridProps: GridProps = {};
|
|
65
83
|
|
|
66
|
-
if (
|
|
84
|
+
if (Array.isArray(field)) {
|
|
85
|
+
const [fieldData, fieldType, renderProps] = field;
|
|
86
|
+
itemData = GridDataFormat(data[fieldData], fieldType, renderProps);
|
|
87
|
+
itemLabel = globalApp.get<string>(fieldData) ?? fieldData;
|
|
88
|
+
} else if (typeof field === 'object') {
|
|
67
89
|
// Destruct
|
|
68
90
|
const {
|
|
69
91
|
data: fieldData,
|
|
92
|
+
dataType,
|
|
70
93
|
label: fieldLabel,
|
|
94
|
+
renderProps,
|
|
71
95
|
singleRow = false,
|
|
72
96
|
...rest
|
|
73
97
|
} = field;
|
|
@@ -79,7 +103,8 @@ function getItemField<T>(
|
|
|
79
103
|
|
|
80
104
|
// Field data
|
|
81
105
|
if (typeof fieldData === 'function') itemData = fieldData(data);
|
|
82
|
-
else itemData = formatItemData(data[fieldData]);
|
|
106
|
+
else if (dataType == null) itemData = formatItemData(data[fieldData]);
|
|
107
|
+
else itemData = GridDataFormat(data[fieldData], dataType, renderProps);
|
|
83
108
|
|
|
84
109
|
// Field label
|
|
85
110
|
itemLabel =
|