@etsoo/materialui 1.0.66 → 1.0.68

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.
@@ -1,21 +1,11 @@
1
+ import { AuditLineDto } from '@etsoo/appscript';
1
2
  import { Theme } from '@mui/material';
2
3
  import React, { CSSProperties } from 'react';
3
4
  import { ListMoreDisplayProps } from './ListMoreDisplay';
4
- import { AuditLineUpdateData } from './ShowDataComparison';
5
- /**
6
- * Audit line data model
7
- */
8
- export interface AuditLine {
9
- id: number;
10
- creation: Date;
11
- user: string;
12
- action: string;
13
- changes?: AuditLineUpdateData;
14
- }
15
5
  /**
16
6
  * Audit display props
17
7
  */
18
- export interface AuditDisplayProps extends Omit<ListMoreDisplayProps<AuditLine>, 'children'> {
8
+ export interface AuditDisplayProps extends Omit<ListMoreDisplayProps<AuditLineDto>, 'children'> {
19
9
  /**
20
10
  * Get list item style callback
21
11
  */
@@ -23,7 +13,7 @@ export interface AuditDisplayProps extends Omit<ListMoreDisplayProps<AuditLine>,
23
13
  /**
24
14
  * Item/line renderer
25
15
  */
26
- itemRenderer?: (data: AuditLine, index: number) => React.ReactNode;
16
+ itemRenderer?: (data: AuditLineDto, index: number) => React.ReactNode;
27
17
  }
28
18
  /**
29
19
  * Audit display
@@ -32,7 +32,7 @@ export function AuditDisplay(props) {
32
32
  ? theme.palette.grey[100]
33
33
  : theme.palette.grey[50]
34
34
  }), itemRenderer = (data) => {
35
- const changes = data.changes;
35
+ const { newData, oldData, changes = { newData: newData !== null && newData !== void 0 ? newData : {}, oldData: oldData !== null && oldData !== void 0 ? oldData : {} } } = data;
36
36
  return (React.createElement(React.Fragment, null,
37
37
  changes != null && (React.createElement(Button, { variant: "outlined", size: "small", onClick: () => ShowDataComparison(changes, title), sx: {
38
38
  marginLeft: theme.spacing(1),
@@ -8,6 +8,7 @@ import React from 'react';
8
8
  * @returns Component
9
9
  */
10
10
  export function OptionGroup(props) {
11
+ var _a;
11
12
  // Destruct
12
13
  const { getOptionLabel, defaultValue, idField = 'id', label, labelField = 'label', multiple = false, mRef, name, onValueChange, options, readOnly, row, itemSize, helperText, variant, required, ...rest } = props;
13
14
  // Theme
@@ -23,11 +24,11 @@ export function OptionGroup(props) {
23
24
  // Checkbox values
24
25
  const [values, setValues] = React.useState([]);
25
26
  // Values
26
- const dv = defaultValue == null
27
+ const dv = React.useMemo(() => defaultValue == null
27
28
  ? []
28
29
  : Array.isArray(defaultValue)
29
30
  ? defaultValue
30
- : [defaultValue];
31
+ : [defaultValue], [defaultValue]);
31
32
  React.useEffect(() => {
32
33
  setValues(dv);
33
34
  }, [dv]);
@@ -83,7 +84,7 @@ export function OptionGroup(props) {
83
84
  return (React.createElement(FormControlLabel, { key: value, control: control, value: value, label: label }));
84
85
  });
85
86
  // Group
86
- const group = multiple ? (React.createElement(FormGroup, { row: row }, list)) : (React.createElement(RadioGroup, { row: row, name: name, value: values[0], onChange: (_event, value) => {
87
+ const group = multiple ? (React.createElement(FormGroup, { row: row }, list)) : (React.createElement(RadioGroup, { row: row, name: name, value: (_a = values[0]) !== null && _a !== void 0 ? _a : '', onChange: (_event, value) => {
87
88
  if (firstOptionValue == null)
88
89
  return;
89
90
  const typeValue = Utils.parseString(value, firstOptionValue);
@@ -1,20 +1,14 @@
1
+ import { AuditLineChangesDto } from '@etsoo/appscript';
1
2
  /**
2
- * Audit line update data model
3
- */
4
- export interface AuditLineUpdateData {
5
- oldData: Record<string, unknown>;
6
- newData: Record<string, unknown>;
7
- }
8
- /**
9
- * Check obj is instance of AuditLineUpdateData
3
+ * Check obj is instance of AuditLineChangesDto
10
4
  * @param obj Input
11
5
  * @returns Result
12
6
  */
13
- export declare function IsAuditLineUpdateData(obj: any): obj is AuditLineUpdateData;
7
+ export declare function IsAuditLineUpdateData(obj: any): obj is AuditLineChangesDto;
14
8
  /**
15
9
  * Show data comparison
16
10
  * @param data Data
17
11
  * @param modelTitle Model window title
18
12
  * @param getLabel Get label callback
19
13
  */
20
- export declare const ShowDataComparison: (data: AuditLineUpdateData, modelTitle?: string, getLabel?: ((field: string) => string) | undefined) => void;
14
+ export declare const ShowDataComparison: (data: AuditLineChangesDto, modelTitle?: string, getLabel?: ((field: string) => string) | undefined) => void;
@@ -4,7 +4,7 @@ import { Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material'
4
4
  import React from 'react';
5
5
  import { globalApp } from './app/ReactApp';
6
6
  /**
7
- * Check obj is instance of AuditLineUpdateData
7
+ * Check obj is instance of AuditLineChangesDto
8
8
  * @param obj Input
9
9
  * @returns Result
10
10
  */
@@ -44,10 +44,8 @@ export function TwoFieldInput(props) {
44
44
  return '';
45
45
  if (typeof v === 'number')
46
46
  return v;
47
- if (type === 'date')
48
- return DateUtils.formatForInput(v);
49
- if (type === 'datetime-local')
50
- return DateUtils.formatForInput(v, true);
47
+ if (type === 'date' || type === 'datetime-local')
48
+ return DateUtils.formatForInput(v, type);
51
49
  return v;
52
50
  };
53
51
  React.useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,10 +51,10 @@
51
51
  "@emotion/css": "^11.10.5",
52
52
  "@emotion/react": "^11.10.5",
53
53
  "@emotion/styled": "^11.10.5",
54
- "@etsoo/appscript": "^1.3.29",
54
+ "@etsoo/appscript": "^1.3.30",
55
55
  "@etsoo/notificationbase": "^1.1.14",
56
56
  "@etsoo/react": "^1.6.24",
57
- "@etsoo/shared": "^1.1.74",
57
+ "@etsoo/shared": "^1.1.75",
58
58
  "@mui/icons-material": "^5.10.9",
59
59
  "@mui/material": "^5.10.13",
60
60
  "@types/pica": "^9.0.1",
@@ -1,26 +1,16 @@
1
+ import { AuditLineDto } from '@etsoo/appscript';
1
2
  import { Utils } from '@etsoo/shared';
2
3
  import { Button, Divider, Theme, Typography, useTheme } from '@mui/material';
3
4
  import React, { CSSProperties } from 'react';
4
5
  import { globalApp } from './app/ReactApp';
5
6
  import { ListMoreDisplay, ListMoreDisplayProps } from './ListMoreDisplay';
6
- import { AuditLineUpdateData, ShowDataComparison } from './ShowDataComparison';
7
-
8
- /**
9
- * Audit line data model
10
- */
11
- export interface AuditLine {
12
- id: number;
13
- creation: Date;
14
- user: string;
15
- action: string;
16
- changes?: AuditLineUpdateData;
17
- }
7
+ import { ShowDataComparison } from './ShowDataComparison';
18
8
 
19
9
  /**
20
10
  * Audit display props
21
11
  */
22
12
  export interface AuditDisplayProps
23
- extends Omit<ListMoreDisplayProps<AuditLine>, 'children'> {
13
+ extends Omit<ListMoreDisplayProps<AuditLineDto>, 'children'> {
24
14
  /**
25
15
  * Get list item style callback
26
16
  */
@@ -29,7 +19,7 @@ export interface AuditDisplayProps
29
19
  /**
30
20
  * Item/line renderer
31
21
  */
32
- itemRenderer?: (data: AuditLine, index: number) => React.ReactNode;
22
+ itemRenderer?: (data: AuditLineDto, index: number) => React.ReactNode;
33
23
  }
34
24
 
35
25
  // Get label
@@ -65,7 +55,11 @@ export function AuditDisplay(props: AuditDisplayProps) {
65
55
  : theme.palette.grey[50]
66
56
  }),
67
57
  itemRenderer = (data) => {
68
- const changes = data.changes;
58
+ const {
59
+ newData,
60
+ oldData,
61
+ changes = { newData: newData ?? {}, oldData: oldData ?? {} }
62
+ } = data;
69
63
  return (
70
64
  <React.Fragment>
71
65
  {changes != null && (
@@ -103,7 +97,7 @@ export function AuditDisplay(props: AuditDisplayProps) {
103
97
 
104
98
  // Layout
105
99
  return (
106
- <ListMoreDisplay<AuditLine> headerTitle={headerTitle} {...rest}>
100
+ <ListMoreDisplay<AuditLineDto> headerTitle={headerTitle} {...rest}>
107
101
  {(data, index) => (
108
102
  <div key={data.id} style={getItemStyle(index, theme)}>
109
103
  {itemRenderer(data, index)}
@@ -157,12 +157,15 @@ export function OptionGroup<
157
157
  const [values, setValues] = React.useState<T[D][]>([]);
158
158
 
159
159
  // Values
160
- const dv =
161
- defaultValue == null
162
- ? []
163
- : Array.isArray(defaultValue)
164
- ? defaultValue
165
- : [defaultValue];
160
+ const dv = React.useMemo(
161
+ () =>
162
+ defaultValue == null
163
+ ? []
164
+ : Array.isArray(defaultValue)
165
+ ? defaultValue
166
+ : [defaultValue],
167
+ [defaultValue]
168
+ );
166
169
 
167
170
  React.useEffect(() => {
168
171
  setValues(dv);
@@ -261,7 +264,7 @@ export function OptionGroup<
261
264
  <RadioGroup
262
265
  row={row}
263
266
  name={name}
264
- value={values[0]}
267
+ value={values[0] ?? ''}
265
268
  onChange={(_event, value) => {
266
269
  if (firstOptionValue == null) return;
267
270
  const typeValue = Utils.parseString(value, firstOptionValue);
@@ -1,4 +1,4 @@
1
- import { IApp } from '@etsoo/appscript/lib/mjs/app/IApp';
1
+ import { AuditLineChangesDto, IApp } from '@etsoo/appscript';
2
2
  import { NotificationMessageType } from '@etsoo/notificationbase';
3
3
  import { Utils } from '@etsoo/shared';
4
4
  import {
@@ -12,19 +12,11 @@ import React from 'react';
12
12
  import { globalApp } from './app/ReactApp';
13
13
 
14
14
  /**
15
- * Audit line update data model
16
- */
17
- export interface AuditLineUpdateData {
18
- oldData: Record<string, unknown>;
19
- newData: Record<string, unknown>;
20
- }
21
-
22
- /**
23
- * Check obj is instance of AuditLineUpdateData
15
+ * Check obj is instance of AuditLineChangesDto
24
16
  * @param obj Input
25
17
  * @returns Result
26
18
  */
27
- export function IsAuditLineUpdateData(obj: any): obj is AuditLineUpdateData {
19
+ export function IsAuditLineUpdateData(obj: any): obj is AuditLineChangesDto {
28
20
  return (
29
21
  typeof obj === 'object' &&
30
22
  'oldData' in obj &&
@@ -48,7 +40,7 @@ const formatValue = (value: unknown, app: IApp) => {
48
40
  * @param getLabel Get label callback
49
41
  */
50
42
  export const ShowDataComparison = (
51
- data: AuditLineUpdateData,
43
+ data: AuditLineChangesDto,
52
44
  modelTitle?: string,
53
45
  getLabel?: (field: string) => string
54
46
  ) => {
@@ -83,8 +83,8 @@ export function TwoFieldInput(props: TwoFieldInputProps) {
83
83
  const formatValue = (v: ValueType, type?: string) => {
84
84
  if (v == null) return '';
85
85
  if (typeof v === 'number') return v;
86
- if (type === 'date') return DateUtils.formatForInput(v);
87
- if (type === 'datetime-local') return DateUtils.formatForInput(v, true);
86
+ if (type === 'date' || type === 'datetime-local')
87
+ return DateUtils.formatForInput(v, type);
88
88
  return v;
89
89
  };
90
90