@etsoo/react 1.4.4 → 1.4.8

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,5 +1,5 @@
1
- import { CoreApp, IAppSettings, ICoreApp, IUser, IUserData } from '@etsoo/appscript';
2
- import { NotificationRenderProps } from '@etsoo/notificationbase';
1
+ import { CoreApp, IActionResult, IAppSettings, ICoreApp, IUser, IUserData } from '@etsoo/appscript';
2
+ import { NotificationRenderProps, NotificationReturn } from '@etsoo/notificationbase';
3
3
  import { DataTypes } from '@etsoo/shared';
4
4
  import React from 'react';
5
5
  import { NotificationReactCallProps } from '../notifier/Notifier';
@@ -87,6 +87,12 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
87
87
  * @param name Application name
88
88
  */
89
89
  constructor(settings: S, name: string);
90
+ /**
91
+ * Override alert action result
92
+ * @param result Action result
93
+ * @param callback Callback
94
+ */
95
+ alertResult(result: IActionResult, callback?: NotificationReturn<void>): void;
90
96
  /**
91
97
  * Change culture
92
98
  * @param culture New culture definition
@@ -1,4 +1,4 @@
1
- import { CoreApp, createClient } from '@etsoo/appscript';
1
+ import { ActionResultError, CoreApp, createClient } from '@etsoo/appscript';
2
2
  import { WindowStorage } from '@etsoo/shared';
3
3
  import React from 'react';
4
4
  import { NotifierMU } from '../mu/NotifierMU';
@@ -83,6 +83,26 @@ export class ReactApp extends CoreApp {
83
83
  ReactApp._notifierProvider = NotifierMU.setup();
84
84
  return NotifierMU.instance;
85
85
  }
86
+ /**
87
+ * Override alert action result
88
+ * @param result Action result
89
+ * @param callback Callback
90
+ */
91
+ alertResult(result, callback) {
92
+ this.formatResult(result);
93
+ const message = ActionResultError.format(result);
94
+ if (message.endsWith(')')) {
95
+ const startPos = message.lastIndexOf('(');
96
+ if (startPos > 0) {
97
+ const main = message.substring(0, startPos).trim();
98
+ const tip = message.substring(startPos);
99
+ const titleNode = React.createElement(React.Fragment, null, main, React.createElement('div', { style: { fontSize: '9px' } }, tip));
100
+ this.notifier.alert(titleNode, callback);
101
+ return;
102
+ }
103
+ }
104
+ this.notifier.alert(message, callback);
105
+ }
86
106
  /**
87
107
  * Change culture
88
108
  * @param culture New culture definition
package/lib/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export * from './components/GridLoader';
14
14
  export * from './components/ListItemReact';
15
15
  export * from './components/ScrollerGrid';
16
16
  export * from './components/ScrollerList';
17
- export * from './mu/pages/AddPage';
18
17
  export * from './mu/pages/CommonPage';
19
18
  export * from './mu/pages/CommonPageProps';
20
19
  export * from './mu/pages/DataGridPage';
package/lib/index.js CHANGED
@@ -17,7 +17,6 @@ export * from './components/ListItemReact';
17
17
  export * from './components/ScrollerGrid';
18
18
  export * from './components/ScrollerList';
19
19
  // mu
20
- export * from './mu/pages/AddPage';
21
20
  export * from './mu/pages/CommonPage';
22
21
  export * from './mu/pages/CommonPageProps';
23
22
  export * from './mu/pages/DataGridPage';
@@ -3,8 +3,9 @@ import React from 'react';
3
3
  /**
4
4
  * Tooltip with click visibility props
5
5
  */
6
- export interface TooltipClickProps extends Omit<TooltipProps, 'children' | 'open' | 'disableFocusListener' | 'disableHoverListener' | 'disableTouchListener'> {
6
+ export interface TooltipClickProps extends Omit<TooltipProps, 'children' | 'open' | 'disableFocusListener' | 'disableTouchListener'> {
7
7
  children: (openTooltip: (newTitle?: string) => void) => React.ReactElement<any, any>;
8
+ disableHoverListener?: boolean;
8
9
  }
9
10
  /**
10
11
  * Tooltip with click visibility
@@ -8,7 +8,7 @@ import React from 'react';
8
8
  export function TooltipClick(props) {
9
9
  // Destruct
10
10
  // leaveDelay set to 5 seconds to hide the tooltip automatically
11
- const { children, leaveDelay = 5000, onClose, title, ...rest } = props;
11
+ const { children, disableHoverListener = true, leaveDelay = 5000, onClose, title, ...rest } = props;
12
12
  // State
13
13
  const [localTitle, setTitle] = React.useState(title);
14
14
  const [open, setOpen] = React.useState(false);
@@ -42,5 +42,5 @@ export function TooltipClick(props) {
42
42
  setOpen(false);
43
43
  if (onClose)
44
44
  onClose(event);
45
- }, title: localTitle, open: open, disableFocusListener: true, disableHoverListener: true, disableTouchListener: true, ...rest }, children(openTooltip))));
45
+ }, title: localTitle, open: open, disableFocusListener: true, disableTouchListener: true, disableHoverListener: disableHoverListener, ...rest }, children(openTooltip))));
46
46
  }
@@ -1,15 +1,7 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import { RouteComponentProps } from '@reach/router';
3
1
  import { FormEventHandler } from 'react';
4
2
  import { CommonPageProps } from './CommonPageProps';
5
3
  /**
6
- * Edit page router props, include 'id' (/:id) query parameter
7
- */
8
- export declare type EditPageRouterProps<T extends DataTypes.IdType = number> = RouteComponentProps<{
9
- id: T;
10
- }>;
11
- /**
12
- * Edit page props
4
+ * Add / Edit page props
13
5
  */
14
6
  export interface EditPageProps extends Omit<CommonPageProps, 'onSubmit'> {
15
7
  /**
@@ -18,7 +10,7 @@ export interface EditPageProps extends Omit<CommonPageProps, 'onSubmit'> {
18
10
  onSubmit?: FormEventHandler<HTMLFormElement>;
19
11
  }
20
12
  /**
21
- * Edit page
13
+ * Add / Edit page
22
14
  * @param props Props
23
15
  */
24
16
  export declare function EditPage(props: EditPageProps): JSX.Element;
@@ -5,7 +5,7 @@ import { MUGlobal } from '../MUGlobal';
5
5
  import { CommonPage, CommonPageScrollContainer } from './CommonPage';
6
6
  import SaveIcon from '@mui/icons-material/Save';
7
7
  /**
8
- * Edit page
8
+ * Add / Edit page
9
9
  * @param props Props
10
10
  */
11
11
  export function EditPage(props) {
@@ -1,10 +1,27 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
2
  import { RouteComponentProps } from '@reach/router';
3
+ /**
4
+ * Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
5
+ */
6
+ export declare type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
7
+ /**
8
+ * Get edit page id
9
+ * @param props Route props
10
+ * @param type Target data type
11
+ * @returns Data
12
+ */
13
+ export declare function getEditPageId<T extends DataTypes.BasicNames>(props: EditPageRouterProps, type: T): DataTypes.BasicConditional<T> | undefined;
3
14
  /**
4
15
  * Id router props, include 'id' (/:id) query parameter
5
16
  */
6
- export declare type IdRouterProps<T extends DataTypes.IdType = number> = RouteComponentProps<{
7
- id: T;
17
+ export declare type IdRouterProps = RouteComponentProps<{
18
+ id: string;
19
+ }>;
20
+ /**
21
+ * Wildcard router props, (/*) query parameter
22
+ */
23
+ export declare type WildcardRouterProps = RouteComponentProps<{
24
+ '*': string;
8
25
  }>;
9
26
  /**
10
27
  * Id state router props, include 'id' in location.state
@@ -1 +1,14 @@
1
- export {};
1
+ import { DataTypes } from '@etsoo/shared';
2
+ /**
3
+ * Get edit page id
4
+ * @param props Route props
5
+ * @param type Target data type
6
+ * @returns Data
7
+ */
8
+ export function getEditPageId(props, type) {
9
+ var _a;
10
+ const id = (_a = props.id) !== null && _a !== void 0 ? _a : props['*'];
11
+ if (id == null || id === '')
12
+ return undefined;
13
+ return DataTypes.convertByType(id, type);
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.4",
3
+ "version": "1.4.8",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,11 +50,11 @@
50
50
  "@emotion/react": "^11.7.1",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.6.0",
53
- "@etsoo/appscript": "^1.2.15",
53
+ "@etsoo/appscript": "^1.2.18",
54
54
  "@etsoo/notificationbase": "^1.1.0",
55
- "@etsoo/shared": "^1.0.97",
55
+ "@etsoo/shared": "^1.1.0",
56
56
  "@mui/icons-material": "^5.2.5",
57
- "@mui/material": "^5.2.6",
57
+ "@mui/material": "^5.2.7",
58
58
  "@reach/router": "^1.3.4",
59
59
  "@types/pica": "^5.1.3",
60
60
  "@types/pulltorefreshjs": "^0.1.5",
@@ -83,11 +83,11 @@
83
83
  "@babel/runtime-corejs3": "^7.16.7",
84
84
  "@types/jest": "^27.4.0",
85
85
  "@types/react-test-renderer": "^17.0.1",
86
- "@typescript-eslint/eslint-plugin": "^5.8.1",
87
- "@typescript-eslint/parser": "^5.8.1",
88
- "eslint": "^8.5.0",
86
+ "@typescript-eslint/eslint-plugin": "^5.9.0",
87
+ "@typescript-eslint/parser": "^5.9.0",
88
+ "eslint": "^8.6.0",
89
89
  "eslint-config-airbnb-base": "^15.0.0",
90
- "eslint-plugin-import": "^2.25.3",
90
+ "eslint-plugin-import": "^2.25.4",
91
91
  "eslint-plugin-react": "^7.28.0",
92
92
  "jest": "^27.4.5",
93
93
  "react-test-renderer": "^17.0.2",
@@ -1,12 +1,17 @@
1
1
  import {
2
+ ActionResultError,
2
3
  CoreApp,
3
4
  createClient,
5
+ IActionResult,
4
6
  IAppSettings,
5
7
  ICoreApp,
6
8
  IUser,
7
9
  IUserData
8
10
  } from '@etsoo/appscript';
9
- import { NotificationRenderProps } from '@etsoo/notificationbase';
11
+ import {
12
+ NotificationRenderProps,
13
+ NotificationReturn
14
+ } from '@etsoo/notificationbase';
10
15
  import { DataTypes, WindowStorage } from '@etsoo/shared';
11
16
  import React from 'react';
12
17
  import { NotifierMU } from '../mu/NotifierMU';
@@ -197,6 +202,40 @@ export class ReactApp<
197
202
  globalApp = this;
198
203
  }
199
204
 
205
+ /**
206
+ * Override alert action result
207
+ * @param result Action result
208
+ * @param callback Callback
209
+ */
210
+ override alertResult(
211
+ result: IActionResult,
212
+ callback?: NotificationReturn<void>
213
+ ) {
214
+ this.formatResult(result);
215
+ const message = ActionResultError.format(result);
216
+ if (message.endsWith(')')) {
217
+ const startPos = message.lastIndexOf('(');
218
+ if (startPos > 0) {
219
+ const main = message.substring(0, startPos).trim();
220
+ const tip = message.substring(startPos);
221
+
222
+ const titleNode = React.createElement(
223
+ React.Fragment,
224
+ null,
225
+ main,
226
+ React.createElement(
227
+ 'div',
228
+ { style: { fontSize: '9px' } },
229
+ tip
230
+ )
231
+ );
232
+ this.notifier.alert(titleNode, callback);
233
+ return;
234
+ }
235
+ }
236
+ this.notifier.alert(message, callback);
237
+ }
238
+
200
239
  /**
201
240
  * Change culture
202
241
  * @param culture New culture definition
package/src/index.ts CHANGED
@@ -19,7 +19,6 @@ export * from './components/ScrollerGrid';
19
19
  export * from './components/ScrollerList';
20
20
 
21
21
  // mu
22
- export * from './mu/pages/AddPage';
23
22
  export * from './mu/pages/CommonPage';
24
23
  export * from './mu/pages/CommonPageProps';
25
24
  export * from './mu/pages/DataGridPage';
@@ -7,15 +7,13 @@ import React from 'react';
7
7
  export interface TooltipClickProps
8
8
  extends Omit<
9
9
  TooltipProps,
10
- | 'children'
11
- | 'open'
12
- | 'disableFocusListener'
13
- | 'disableHoverListener'
14
- | 'disableTouchListener'
10
+ 'children' | 'open' | 'disableFocusListener' | 'disableTouchListener'
15
11
  > {
16
12
  children: (
17
13
  openTooltip: (newTitle?: string) => void
18
14
  ) => React.ReactElement<any, any>;
15
+
16
+ disableHoverListener?: boolean;
19
17
  }
20
18
 
21
19
  /**
@@ -26,7 +24,14 @@ export interface TooltipClickProps
26
24
  export function TooltipClick(props: TooltipClickProps) {
27
25
  // Destruct
28
26
  // leaveDelay set to 5 seconds to hide the tooltip automatically
29
- const { children, leaveDelay = 5000, onClose, title, ...rest } = props;
27
+ const {
28
+ children,
29
+ disableHoverListener = true,
30
+ leaveDelay = 5000,
31
+ onClose,
32
+ title,
33
+ ...rest
34
+ } = props;
30
35
 
31
36
  // State
32
37
  const [localTitle, setTitle] = React.useState(title);
@@ -74,8 +79,8 @@ export function TooltipClick(props: TooltipClickProps) {
74
79
  title={localTitle}
75
80
  open={open}
76
81
  disableFocusListener
77
- disableHoverListener
78
82
  disableTouchListener
83
+ disableHoverListener={disableHoverListener}
79
84
  {...rest}
80
85
  >
81
86
  {children(openTooltip)}
@@ -1,6 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
2
1
  import { Button, Grid } from '@mui/material';
3
- import { RouteComponentProps } from '@reach/router';
4
2
  import React, { FormEventHandler } from 'react';
5
3
  import { Labels } from '../../app/Labels';
6
4
  import { MUGlobal } from '../MUGlobal';
@@ -9,13 +7,7 @@ import { CommonPageProps } from './CommonPageProps';
9
7
  import SaveIcon from '@mui/icons-material/Save';
10
8
 
11
9
  /**
12
- * Edit page router props, include 'id' (/:id) query parameter
13
- */
14
- export type EditPageRouterProps<T extends DataTypes.IdType = number> =
15
- RouteComponentProps<{ id: T }>;
16
-
17
- /**
18
- * Edit page props
10
+ * Add / Edit page props
19
11
  */
20
12
  export interface EditPageProps extends Omit<CommonPageProps, 'onSubmit'> {
21
13
  /**
@@ -25,7 +17,7 @@ export interface EditPageProps extends Omit<CommonPageProps, 'onSubmit'> {
25
17
  }
26
18
 
27
19
  /**
28
- * Edit page
20
+ * Add / Edit page
29
21
  * @param props Props
30
22
  */
31
23
  export function EditPage(props: EditPageProps) {
@@ -1,11 +1,36 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
2
  import { RouteComponentProps } from '@reach/router';
3
+ import { Props } from 'react-input-mask';
4
+
5
+ /**
6
+ * Add / Edit page router props, include 'id' (/:id) or none when adding query parameter
7
+ */
8
+ export type EditPageRouterProps = IdRouterProps & WildcardRouterProps;
9
+
10
+ /**
11
+ * Get edit page id
12
+ * @param props Route props
13
+ * @param type Target data type
14
+ * @returns Data
15
+ */
16
+ export function getEditPageId<T extends DataTypes.BasicNames>(
17
+ props: EditPageRouterProps,
18
+ type: T
19
+ ): DataTypes.BasicConditional<T> | undefined {
20
+ const id = props.id ?? props['*'];
21
+ if (id == null || id === '') return undefined;
22
+ return DataTypes.convertByType(id, type);
23
+ }
3
24
 
4
25
  /**
5
26
  * Id router props, include 'id' (/:id) query parameter
6
27
  */
7
- export type IdRouterProps<T extends DataTypes.IdType = number> =
8
- RouteComponentProps<{ id: T }>;
28
+ export type IdRouterProps = RouteComponentProps<{ id: string }>;
29
+
30
+ /**
31
+ * Wildcard router props, (/*) query parameter
32
+ */
33
+ export type WildcardRouterProps = RouteComponentProps<{ '*': string }>;
9
34
 
10
35
  /**
11
36
  * Id state router props, include 'id' in location.state
@@ -1,11 +0,0 @@
1
- import { CommonPageProps } from './CommonPageProps';
2
- /**
3
- * Add page props
4
- */
5
- export interface AddPageProps extends CommonPageProps {
6
- }
7
- /**
8
- * Add page
9
- * @param props Props
10
- */
11
- export declare function AddPage(props: AddPageProps): void;
@@ -1,5 +0,0 @@
1
- /**
2
- * Add page
3
- * @param props Props
4
- */
5
- export function AddPage(props) { }
@@ -1,12 +0,0 @@
1
- import { CommonPageProps } from './CommonPageProps';
2
-
3
- /**
4
- * Add page props
5
- */
6
- export interface AddPageProps extends CommonPageProps {}
7
-
8
- /**
9
- * Add page
10
- * @param props Props
11
- */
12
- export function AddPage(props: AddPageProps) {}