@etsoo/react 1.5.1 → 1.5.5

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,6 +1,7 @@
1
1
  import { CoreApp, IActionResult, IAppSettings, ICoreApp, IUser, IUserData } from '@etsoo/appscript';
2
2
  import { NotificationRenderProps, NotificationReturn } from '@etsoo/notificationbase';
3
3
  import { DataTypes } from '@etsoo/shared';
4
+ import { History } from '@reach/router';
4
5
  import React from 'react';
5
6
  import { NotificationReactCallProps } from '../notifier/Notifier';
6
7
  import { CultureAction, CultureState } from '../states/CultureState';
@@ -30,6 +31,10 @@ export interface IReactApp<S extends IAppSettings, D extends IUser, P extends IP
30
31
  * User state
31
32
  */
32
33
  readonly userState: UserState<D>;
34
+ /**
35
+ * Router history
36
+ */
37
+ readonly history?: History;
33
38
  /**
34
39
  * Is screen size down 'sm'
35
40
  */
@@ -69,6 +74,10 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
69
74
  * Culture state
70
75
  */
71
76
  readonly cultureState: CultureState;
77
+ /**
78
+ * Router history
79
+ */
80
+ readonly history?: History;
72
81
  /**
73
82
  * Page state
74
83
  */
@@ -8,6 +8,7 @@ import { CultureState } from '../states/CultureState';
8
8
  import { PageActionType, PageState } from '../states/PageState';
9
9
  import { UserActionType, UserState } from '../states/UserState';
10
10
  import { Labels } from './Labels';
11
+ import { Utils } from './Utils';
11
12
  /**
12
13
  * Global application
13
14
  */
@@ -64,6 +65,10 @@ export class ReactApp extends CoreApp {
64
65
  * User state
65
66
  */
66
67
  this.userState = new UserState();
68
+ this.history =
69
+ window.location.hostname === ''
70
+ ? Utils.getMemoryHistory()
71
+ : undefined;
67
72
  this.cultureState = new CultureState(settings.currentCulture);
68
73
  this.pageState = new PageState();
69
74
  globalApp = this;
@@ -194,7 +199,7 @@ export class ReactApp extends CoreApp {
194
199
  * @param url Url
195
200
  */
196
201
  redirectTo(url) {
197
- navigate(url);
202
+ (this.history == null ? navigate : this.history.navigate)(url);
198
203
  }
199
204
  /**
200
205
  * Set page data
@@ -1,4 +1,4 @@
1
- import { createClient } from '@etsoo/appscript';
1
+ import { BridgeUtils, createClient } from '@etsoo/appscript';
2
2
  import { DomUtils } from '@etsoo/shared';
3
3
  import { CoreConstants } from './CoreConstants';
4
4
  import { ReactApp } from './ReactApp';
@@ -44,16 +44,14 @@ export class ServiceApp extends ReactApp {
44
44
  * @param tryLogin Try to login again
45
45
  */
46
46
  toLoginPage(tryLogin) {
47
- const coreUrl = this.settings.webUrl;
48
- window.location.href =
49
- coreUrl +
50
- '?serviceId=' +
51
- this.settings.serviceId +
52
- '&' +
53
- DomUtils.CultureField +
54
- '=' +
55
- this.culture +
56
- (tryLogin ? '' : '&tryLogin=false');
47
+ const parameters = `?serviceId=${this.settings.serviceId}&${DomUtils.CultureField}=${this.culture}${tryLogin ? '' : '&tryLogin=false'}`;
48
+ if (BridgeUtils.host == null) {
49
+ const coreUrl = this.settings.webUrl;
50
+ window.location.href = coreUrl + parameters;
51
+ }
52
+ else {
53
+ BridgeUtils.host.loadApp('core', parameters);
54
+ }
57
55
  }
58
56
  /**
59
57
  * Refresh token
@@ -1,3 +1,4 @@
1
+ import { History } from '@reach/router';
1
2
  import React from 'react';
2
3
  /**
3
4
  * React utils
@@ -9,6 +10,11 @@ export declare namespace Utils {
9
10
  * @returns Formatted value
10
11
  */
11
12
  function formatInputValue(value: unknown): string | number | any[] | undefined;
13
+ /**
14
+ * Get memory history
15
+ * @returns History
16
+ */
17
+ function getMemoryHistory(): History;
12
18
  /**
13
19
  * Is safe click
14
20
  * @param event Mouse event
package/lib/app/Utils.js CHANGED
@@ -1,8 +1,12 @@
1
+ import { createHistory, createMemorySource } from '@reach/router';
1
2
  /**
2
3
  * React utils
3
4
  */
4
5
  export var Utils;
5
6
  (function (Utils) {
7
+ // Memory history
8
+ // https://github.com/reach/router/issues/225
9
+ let memoryHistory;
6
10
  /**
7
11
  * Format input value
8
12
  * @param value Input value
@@ -20,6 +24,17 @@ export var Utils;
20
24
  return String(value);
21
25
  }
22
26
  Utils.formatInputValue = formatInputValue;
27
+ /**
28
+ * Get memory history
29
+ * @returns History
30
+ */
31
+ function getMemoryHistory() {
32
+ if (memoryHistory == null) {
33
+ memoryHistory = createHistory(createMemorySource('/'));
34
+ }
35
+ return memoryHistory;
36
+ }
37
+ Utils.getMemoryHistory = getMemoryHistory;
23
38
  /**
24
39
  * Is safe click
25
40
  * @param event Mouse event
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.1",
3
+ "version": "1.5.5",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
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.43",
53
+ "@etsoo/appscript": "^1.2.44",
54
54
  "@etsoo/notificationbase": "^1.1.1",
55
55
  "@etsoo/shared": "^1.1.11",
56
56
  "@mui/icons-material": "^5.4.1",
@@ -14,7 +14,7 @@ import {
14
14
  NotificationReturn
15
15
  } from '@etsoo/notificationbase';
16
16
  import { DataTypes, WindowStorage } from '@etsoo/shared';
17
- import { navigate } from '@reach/router';
17
+ import { History, navigate } from '@reach/router';
18
18
  import React from 'react';
19
19
  import { NotifierMU } from '../mu/NotifierMU';
20
20
  import { ProgressCount } from '../mu/ProgressCount';
@@ -35,6 +35,7 @@ import {
35
35
  } from '../states/UserState';
36
36
  import { InputDialogProps } from './InputDialogProps';
37
37
  import { Labels } from './Labels';
38
+ import { Utils } from './Utils';
38
39
 
39
40
  /**
40
41
  * Global application
@@ -98,6 +99,11 @@ export interface IReactApp<
98
99
  */
99
100
  readonly userState: UserState<D>;
100
101
 
102
+ /**
103
+ * Router history
104
+ */
105
+ readonly history?: History;
106
+
101
107
  /**
102
108
  * Is screen size down 'sm'
103
109
  */
@@ -167,6 +173,11 @@ export class ReactApp<
167
173
  */
168
174
  readonly cultureState: CultureState;
169
175
 
176
+ /**
177
+ * Router history
178
+ */
179
+ readonly history?: History;
180
+
170
181
  /**
171
182
  * Page state
172
183
  */
@@ -210,6 +221,10 @@ export class ReactApp<
210
221
  new WindowStorage(),
211
222
  name
212
223
  );
224
+ this.history =
225
+ window.location.hostname === ''
226
+ ? Utils.getMemoryHistory()
227
+ : undefined;
213
228
  this.cultureState = new CultureState(settings.currentCulture);
214
229
  this.pageState = new PageState<P>();
215
230
 
@@ -355,7 +370,7 @@ export class ReactApp<
355
370
  * @param url Url
356
371
  */
357
372
  override redirectTo(url: string) {
358
- navigate(url);
373
+ (this.history == null ? navigate : this.history.navigate)(url);
359
374
  }
360
375
 
361
376
  /**
@@ -1,4 +1,5 @@
1
1
  import {
2
+ BridgeUtils,
2
3
  createClient,
3
4
  IApi,
4
5
  IApiPayload,
@@ -72,16 +73,16 @@ export class ServiceApp<
72
73
  * @param tryLogin Try to login again
73
74
  */
74
75
  override toLoginPage(tryLogin?: boolean) {
75
- const coreUrl = this.settings.webUrl;
76
- window.location.href =
77
- coreUrl +
78
- '?serviceId=' +
79
- this.settings.serviceId +
80
- '&' +
81
- DomUtils.CultureField +
82
- '=' +
83
- this.culture +
84
- (tryLogin ? '' : '&tryLogin=false');
76
+ const parameters = `?serviceId=${this.settings.serviceId}&${
77
+ DomUtils.CultureField
78
+ }=${this.culture}${tryLogin ? '' : '&tryLogin=false'}`;
79
+
80
+ if (BridgeUtils.host == null) {
81
+ const coreUrl = this.settings.webUrl;
82
+ window.location.href = coreUrl + parameters;
83
+ } else {
84
+ BridgeUtils.host.loadApp('core', parameters);
85
+ }
85
86
  }
86
87
 
87
88
  /**
package/src/app/Utils.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import { createHistory, createMemorySource, History } from '@reach/router';
1
2
  import React from 'react';
2
3
 
3
4
  /**
4
5
  * React utils
5
6
  */
6
7
  export namespace Utils {
8
+ // Memory history
9
+ // https://github.com/reach/router/issues/225
10
+ let memoryHistory: History | null;
11
+
7
12
  /**
8
13
  * Format input value
9
14
  * @param value Input value
@@ -21,6 +26,17 @@ export namespace Utils {
21
26
  return String(value);
22
27
  }
23
28
 
29
+ /**
30
+ * Get memory history
31
+ * @returns History
32
+ */
33
+ export function getMemoryHistory() {
34
+ if (memoryHistory == null) {
35
+ memoryHistory = createHistory(createMemorySource('/'));
36
+ }
37
+ return memoryHistory;
38
+ }
39
+
24
40
  /**
25
41
  * Is safe click
26
42
  * @param event Mouse event