@j2inn/fin5-ui-utils 0.0.2 → 0.0.5-beta.1
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/dist/fantomProps/createFin5Props/index.d.ts +12 -0
- package/dist/fantomProps/createFin5Props/index.js +147 -0
- package/dist/fantomProps/createFin5Props/index.js.map +1 -0
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -0
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.js +17 -0
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.js.map +1 -0
- package/dist/fantomProps/fantomPropsToObject.js +3 -0
- package/dist/fantomProps/fantomPropsToObject.js.map +1 -1
- package/dist/fantomProps/generateJsonFromFantomPropsFile.js +3 -0
- package/dist/fantomProps/generateJsonFromFantomPropsFile.js.map +1 -1
- package/dist/fantomProps/localePropsToJson.js +3 -0
- package/dist/fantomProps/localePropsToJson.js.map +1 -1
- package/dist/fantomProps/readFantomPropsFile.js +3 -0
- package/dist/fantomProps/readFantomPropsFile.js.map +1 -1
- package/dist/fin5Top/fin5Top.js +3 -0
- package/dist/fin5Top/fin5Top.js.map +1 -1
- package/dist/fin5Top/getFin5BinUrl.js +3 -0
- package/dist/fin5Top/getFin5BinUrl.js.map +1 -1
- package/dist/fin5Top/openFin5Alarm.js +5 -2
- package/dist/fin5Top/openFin5Alarm.js.map +1 -1
- package/dist/fin5Top/openFin5Historian.js +5 -2
- package/dist/fin5Top/openFin5Historian.js.map +1 -1
- package/dist/fin5Top/useFin5AppURLHashParameter.d.ts +7 -0
- package/dist/fin5Top/useFin5AppURLHashParameter.js +72 -0
- package/dist/fin5Top/useFin5AppURLHashParameter.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/react/app/Fin5AppContainer.d.ts +36 -0
- package/dist/react/app/Fin5AppContainer.jsx +102 -0
- package/dist/react/app/Fin5AppContainer.jsx.map +1 -0
- package/dist/react/app/Fin5AppRootStore.d.ts +38 -0
- package/dist/react/app/Fin5AppRootStore.js +66 -0
- package/dist/react/app/Fin5AppRootStore.js.map +1 -0
- package/dist/react/components/ErrorBoundary.d.ts +57 -0
- package/dist/react/components/ErrorBoundary.jsx +177 -0
- package/dist/react/components/ErrorBoundary.jsx.map +1 -0
- package/dist/react/components/Loader.d.ts +9 -0
- package/dist/react/components/Loader.jsx +18 -0
- package/dist/react/components/Loader.jsx.map +1 -0
- package/dist/react/components/LoadingSpinner.jsx +19 -3
- package/dist/react/components/LoadingSpinner.jsx.map +1 -1
- package/dist/react/components/navigation/BasicLayout.d.ts +2 -1
- package/dist/react/components/navigation/BasicLayout.jsx +10 -3
- package/dist/react/components/navigation/BasicLayout.jsx.map +1 -1
- package/dist/react/components/navigation/MenuPage.jsx +3 -0
- package/dist/react/components/navigation/MenuPage.jsx.map +1 -1
- package/dist/react/components/navigation/Router.jsx +3 -0
- package/dist/react/components/navigation/Router.jsx.map +1 -1
- package/dist_es/fantomProps/createFin5Props/index.d.ts +12 -0
- package/dist_es/fantomProps/createFin5Props/index.js +141 -0
- package/dist_es/fantomProps/createFin5Props/index.js.map +1 -0
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -0
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.js +12 -0
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.js.map +1 -0
- package/dist_es/fantomProps/fantomPropsToObject.d.ts +8 -0
- package/dist_es/fantomProps/fantomPropsToObject.js +179 -0
- package/dist_es/fantomProps/fantomPropsToObject.js.map +1 -0
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.d.ts +4 -0
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.js +13 -0
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.js.map +1 -0
- package/dist_es/fantomProps/localePropsToJson.d.ts +1 -0
- package/dist_es/fantomProps/localePropsToJson.js +22 -0
- package/dist_es/fantomProps/localePropsToJson.js.map +1 -0
- package/dist_es/fantomProps/readFantomPropsFile.d.ts +5 -0
- package/dist_es/fantomProps/readFantomPropsFile.js +36 -0
- package/dist_es/fantomProps/readFantomPropsFile.js.map +1 -0
- package/dist_es/fin5Top/fin5Top.d.ts +111 -0
- package/dist_es/fin5Top/fin5Top.js +55 -0
- package/dist_es/fin5Top/fin5Top.js.map +1 -0
- package/dist_es/fin5Top/getFin5BinUrl.d.ts +2 -0
- package/dist_es/fin5Top/getFin5BinUrl.js +6 -0
- package/dist_es/fin5Top/getFin5BinUrl.js.map +1 -0
- package/dist_es/fin5Top/openFin5Alarm.d.ts +22 -0
- package/dist_es/fin5Top/openFin5Alarm.js +20 -0
- package/dist_es/fin5Top/openFin5Alarm.js.map +1 -0
- package/dist_es/fin5Top/openFin5Historian.d.ts +3 -0
- package/dist_es/fin5Top/openFin5Historian.js +16 -0
- package/dist_es/fin5Top/openFin5Historian.js.map +1 -0
- package/dist_es/fin5Top/useFin5AppURLHashParameter.d.ts +7 -0
- package/dist_es/fin5Top/useFin5AppURLHashParameter.js +68 -0
- package/dist_es/fin5Top/useFin5AppURLHashParameter.js.map +1 -0
- package/dist_es/index.d.ts +18 -0
- package/dist_es/index.js +34 -0
- package/dist_es/index.js.map +1 -0
- package/dist_es/react/app/Fin5AppContainer.d.ts +36 -0
- package/dist_es/react/app/Fin5AppContainer.jsx +73 -0
- package/dist_es/react/app/Fin5AppContainer.jsx.map +1 -0
- package/dist_es/react/app/Fin5AppRootStore.d.ts +38 -0
- package/dist_es/react/app/Fin5AppRootStore.js +62 -0
- package/dist_es/react/app/Fin5AppRootStore.js.map +1 -0
- package/dist_es/react/components/ErrorBoundary.d.ts +57 -0
- package/dist_es/react/components/ErrorBoundary.jsx +150 -0
- package/dist_es/react/components/ErrorBoundary.jsx.map +1 -0
- package/dist_es/react/components/ErrorDisplayer.d.ts +19 -0
- package/dist_es/react/components/ErrorDisplayer.jsx +36 -0
- package/dist_es/react/components/ErrorDisplayer.jsx.map +1 -0
- package/dist_es/react/components/Loader.d.ts +9 -0
- package/dist_es/react/components/Loader.jsx +13 -0
- package/dist_es/react/components/Loader.jsx.map +1 -0
- package/dist_es/react/components/LoadingSpinner.d.ts +3 -0
- package/dist_es/react/components/LoadingSpinner.jsx +23 -0
- package/dist_es/react/components/LoadingSpinner.jsx.map +1 -0
- package/dist_es/react/components/navigation/BasicLayout.d.ts +21 -0
- package/dist_es/react/components/navigation/BasicLayout.jsx +104 -0
- package/dist_es/react/components/navigation/BasicLayout.jsx.map +1 -0
- package/dist_es/react/components/navigation/MenuPage.d.ts +33 -0
- package/dist_es/react/components/navigation/MenuPage.jsx +31 -0
- package/dist_es/react/components/navigation/MenuPage.jsx.map +1 -0
- package/dist_es/react/components/navigation/Router.d.ts +12 -0
- package/dist_es/react/components/navigation/Router.jsx +19 -0
- package/dist_es/react/components/navigation/Router.jsx.map +1 -0
- package/package.json +22 -11
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import React, { useState } from 'react';
|
|
5
|
+
import { Button, Checkbox, Divider, Message, Container, ColorVals, } from '@j2inn/ui';
|
|
6
|
+
import { usei18n } from '@j2inn/utils';
|
|
7
|
+
import { createUseStyles, useTheme } from 'react-jss';
|
|
8
|
+
const boundryStyles = createUseStyles((theme) => ({
|
|
9
|
+
errorBoundry: {
|
|
10
|
+
backgroundColor: theme.bodyBg,
|
|
11
|
+
flex: `1 1 auto`,
|
|
12
|
+
},
|
|
13
|
+
boundryContainer: {
|
|
14
|
+
margin: '0 auto',
|
|
15
|
+
flex: `1 1 auto`,
|
|
16
|
+
padding: `2rem`,
|
|
17
|
+
maxWidth: 1024,
|
|
18
|
+
backgroundColor: theme.bgColor,
|
|
19
|
+
[`& h1, & h3`]: {
|
|
20
|
+
paddingBottom: `1rem`,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
errorDetails: {
|
|
24
|
+
[`& pre`]: {
|
|
25
|
+
overflow: 'auto',
|
|
26
|
+
marginTop: '1rem',
|
|
27
|
+
backgroundColor: ColorVals.Black,
|
|
28
|
+
color: ColorVals.White,
|
|
29
|
+
padding: '0.3rem',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
function get(i18n, key, fallback) {
|
|
34
|
+
return i18n.has(key) ? i18n.get(key) : fallback;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Format an error message into something more useful for the clipboard.
|
|
38
|
+
*/
|
|
39
|
+
function formatErrorMessage(error, appId) {
|
|
40
|
+
return JSON.stringify({
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
appId: appId ?? '',
|
|
43
|
+
location: location.href,
|
|
44
|
+
navigator: {
|
|
45
|
+
cookieEnabled: navigator.cookieEnabled,
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
deviceMemory: navigator.deviceMemory,
|
|
48
|
+
language: navigator.language,
|
|
49
|
+
languages: navigator.languages,
|
|
50
|
+
onLine: navigator.onLine,
|
|
51
|
+
userAgent: navigator.userAgent,
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
userAgentData: navigator.userAgentData,
|
|
54
|
+
vendor: navigator.vendor,
|
|
55
|
+
},
|
|
56
|
+
error: String(error.stack),
|
|
57
|
+
}, null, 2);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Shows the internal error details to a user.
|
|
61
|
+
*/
|
|
62
|
+
const ErrorDetails = ({ showDetails, setShowDetails, error, appId, }) => {
|
|
63
|
+
const i18n = usei18n();
|
|
64
|
+
const classes = boundryStyles();
|
|
65
|
+
const theme = useTheme();
|
|
66
|
+
const copyToClipboard = () => {
|
|
67
|
+
navigator.clipboard.writeText(formatErrorMessage(error, appId));
|
|
68
|
+
Message.success(theme, get(i18n, 'finUi.errorBoundary.copiedErrorToClipboard', 'Copied error to clipboard'));
|
|
69
|
+
};
|
|
70
|
+
return (<div className={classes.errorDetails}>
|
|
71
|
+
<Checkbox onChange={(e) => {
|
|
72
|
+
setShowDetails(e.target.checked);
|
|
73
|
+
}} defaultChecked={showDetails} value={showDetails}>
|
|
74
|
+
{get(i18n, 'finUi.errorBoundary.showDetails', 'Show details')}
|
|
75
|
+
</Checkbox>
|
|
76
|
+
{showDetails && (<>
|
|
77
|
+
<pre>{error.stack}</pre>
|
|
78
|
+
<Container horizontal middle right>
|
|
79
|
+
<Button onClick={copyToClipboard}>
|
|
80
|
+
{get(i18n, 'finUi.errorBoundary.copyToClipboard', 'Copy to clipboard')}
|
|
81
|
+
</Button>
|
|
82
|
+
</Container>
|
|
83
|
+
</>)}
|
|
84
|
+
</div>);
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The inner error boundary component. This is required so
|
|
88
|
+
* we can use hooks that can't be used in a normal class component.
|
|
89
|
+
*/
|
|
90
|
+
const ErrorBoundaryInner = ({ error, mode, appId, showReportDialog, }) => {
|
|
91
|
+
const i18n = usei18n();
|
|
92
|
+
const [showDetails, setShowDetails] = useState(true);
|
|
93
|
+
const classes = boundryStyles();
|
|
94
|
+
const title = `finUi.errorBoundary.${mode}.title`;
|
|
95
|
+
const appName = `${appId}.name`;
|
|
96
|
+
const header = get(i18n, title, mode === 'global' ? 'Error' : 'Application error') +
|
|
97
|
+
(appId ? `: ${get(i18n, appName, appName)}` : '');
|
|
98
|
+
const continueMsg = get(i18n, `finUi.errorBoundary.${mode}.continue`, mode === 'global'
|
|
99
|
+
? 'To continue, please reload or navigate to the home page.'
|
|
100
|
+
: 'To continue, please reload, navigate to the home page or another application.');
|
|
101
|
+
return (<Container vertical top center className={classes.errorBoundry}>
|
|
102
|
+
<div className={classes.boundryContainer} style={{ gap: `1rem` }}>
|
|
103
|
+
<h1>{header}</h1>
|
|
104
|
+
|
|
105
|
+
<h3>
|
|
106
|
+
{get(i18n, 'finUi.errorBoundary.description', 'The application has encountered an error when trying to display some content.')}
|
|
107
|
+
</h3>
|
|
108
|
+
|
|
109
|
+
<p>{continueMsg}</p>
|
|
110
|
+
|
|
111
|
+
<div>
|
|
112
|
+
<ErrorDetails showDetails={showDetails} setShowDetails={setShowDetails} error={error} appId={appId}/>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<Divider />
|
|
116
|
+
|
|
117
|
+
<Container horizontal middle left style={{ gap: `1rem` }}>
|
|
118
|
+
<Button onClick={() => window.location.reload()} type='primary'>
|
|
119
|
+
{get(i18n, 'finUi.common.reload', 'Reload')}
|
|
120
|
+
</Button>
|
|
121
|
+
<Button onClick={() => window.location.assign('/')}>
|
|
122
|
+
{get(i18n, 'finUi.common.home', 'Home')}
|
|
123
|
+
</Button>
|
|
124
|
+
</Container>
|
|
125
|
+
|
|
126
|
+
{showReportDialog && (<div style={{ marginTop: `0.5rem` }}>
|
|
127
|
+
<small onClick={showReportDialog}>
|
|
128
|
+
{get(i18n, 'finUi.errorBoundary.additionalDetails', 'If you’d like, click here to include an additional error report to our team. Any details you provide will be helpful.')}
|
|
129
|
+
</small>
|
|
130
|
+
</div>)}
|
|
131
|
+
</div>
|
|
132
|
+
</Container>);
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* A common error boundary used to capture errors.
|
|
136
|
+
*/
|
|
137
|
+
export class ErrorBoundary extends React.Component {
|
|
138
|
+
state = {};
|
|
139
|
+
componentDidCatch(error, info) {
|
|
140
|
+
this.props.onError?.(error);
|
|
141
|
+
console.error(error, info);
|
|
142
|
+
}
|
|
143
|
+
static getDerivedStateFromError(error) {
|
|
144
|
+
return { error };
|
|
145
|
+
}
|
|
146
|
+
render() {
|
|
147
|
+
return this.state.error ? (<ErrorBoundaryInner error={this.state.error} mode={this.props.mode} appId={this.props.appId} showReportDialog={this.props.showReportDialog}/>) : (this.props.children);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=ErrorBoundary.jsx.map
|
|
@@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KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CACxB,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CACtB,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CACxB,gBAAgB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAC7C,CACF,CAAC,CAAC,CAAC,CACH,IAAI,CAAC,KAAK,CAAC,QAAQ,CACnB,CAAA;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ErrorInfo, ReactNode } from 'react';
|
|
2
|
+
interface ErrorBoundaryState {
|
|
3
|
+
error?: Error;
|
|
4
|
+
}
|
|
5
|
+
interface ErrorBoundaryProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export declare class DefaultErrorBoundary extends React.Component<ErrorBoundaryProps> {
|
|
9
|
+
state: ErrorBoundaryState;
|
|
10
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
11
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
12
|
+
render(): ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export interface ErrorDisplayerProps {
|
|
15
|
+
error: Error;
|
|
16
|
+
extra: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export declare const ErrorDisplayer: React.FC<ErrorDisplayerProps>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Button, Collapse, Container, Result, Typography } from '@j2inn/ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export class DefaultErrorBoundary extends React.Component {
|
|
4
|
+
state = {};
|
|
5
|
+
static getDerivedStateFromError(error) {
|
|
6
|
+
// Update state so the next render will show the fallback UI.
|
|
7
|
+
return { error: error };
|
|
8
|
+
}
|
|
9
|
+
componentDidCatch(error, errorInfo) {
|
|
10
|
+
// You can also log the error to an error reporting service
|
|
11
|
+
console.error(error, errorInfo);
|
|
12
|
+
}
|
|
13
|
+
render() {
|
|
14
|
+
if (this.state.error) {
|
|
15
|
+
// You can render any custom fallback UI
|
|
16
|
+
return (<ErrorDisplayer error={this.state.error} extra={[
|
|
17
|
+
<Button type='primary' key='refresh' onClick={() => window.location.reload()}>
|
|
18
|
+
Refresh The Page
|
|
19
|
+
</Button>,
|
|
20
|
+
]}/>);
|
|
21
|
+
}
|
|
22
|
+
return this.props.children;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export const ErrorDisplayer = ({ error, extra, }) => {
|
|
26
|
+
return (<Result status='error' title='Ouch... Something Went Wrong' subTitle={<Container center>
|
|
27
|
+
<Collapse style={{ width: 600, textAlign: 'left' }}>
|
|
28
|
+
<Collapse.Panel header={`${error.toString()}`} key='1'>
|
|
29
|
+
<Typography.Text style={{ width: 400 }}>
|
|
30
|
+
{error.stack}
|
|
31
|
+
</Typography.Text>
|
|
32
|
+
</Collapse.Panel>
|
|
33
|
+
</Collapse>
|
|
34
|
+
</Container>} extra={extra}/>);
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=ErrorDisplayer.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorDisplayer.jsx","sourceRoot":"","sources":["../../../src/react/components/ErrorDisplayer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3E,OAAO,KAA+B,MAAM,OAAO,CAAA;AAUnD,MAAM,OAAO,oBAAqB,SAAQ,KAAK,CAAC,SAA6B;IACnE,KAAK,GAAuB,EAAE,CAAA;IAEvC,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC3C,6DAA6D;QAC7D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACxB,CAAC;IAEQ,iBAAiB,CAAC,KAAY,EAAE,SAAoB;QAC5D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A,EAAE,SAAS,CAAC,CACZ,CACD,KAAK,CAAC,CAAC,KAAK,CAAC,EACZ,CACF,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import LoadingSpinner from './LoadingSpinner';
|
|
6
|
+
/**
|
|
7
|
+
* A simple UI loader.
|
|
8
|
+
*/
|
|
9
|
+
const Loader = ({ loading, children, }) => {
|
|
10
|
+
return loading ? <LoadingSpinner /> : <>{children}</>;
|
|
11
|
+
};
|
|
12
|
+
export default Loader;
|
|
13
|
+
//# sourceMappingURL=Loader.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Loader.jsx","sourceRoot":"","sources":["../../../src/react/components/Loader.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,GAAG,CAAC,EACf,OAAO,EACP,QAAQ,GAIR,EAAe,EAAE;IACjB,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,AAAD,EAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAA;AACtD,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { Spin } from '@j2inn/ui';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { createUseStyles } from 'react-jss';
|
|
7
|
+
const useStyles = createUseStyles(() => ({
|
|
8
|
+
container: {
|
|
9
|
+
display: 'flex',
|
|
10
|
+
alignItems: 'center',
|
|
11
|
+
justifyContent: 'center',
|
|
12
|
+
height: '100%',
|
|
13
|
+
width: '100%',
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
const LoadingSpinner = () => {
|
|
17
|
+
const classes = useStyles();
|
|
18
|
+
return (<div className={classes.container}>
|
|
19
|
+
<Spin size='large'></Spin>
|
|
20
|
+
</div>);
|
|
21
|
+
};
|
|
22
|
+
export default LoadingSpinner;
|
|
23
|
+
//# sourceMappingURL=LoadingSpinner.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LoadingSpinner.jsx","sourceRoot":"","sources":["../../../src/react/components/LoadingSpinner.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;IACxC,SAAS,EAAE;QACV,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;QACxB,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,MAAM;KACb;CACD,CAAC,CAAC,CAAA;AAEH,MAAM,cAAc,GAAa,GAAG,EAAE;IACrC,MAAM,OAAO,GAAG,SAAS,EAAE,CAAA;IAC3B,OAAO,CACN,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACjC;GAAA,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAC1B;EAAA,EAAE,GAAG,CAAC,CACN,CAAA;AACF,CAAC,CAAA;AAED,eAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LayoutProps, MenuProps, SiderProps } from 'antd';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { MenuPage } from './MenuPage';
|
|
4
|
+
export interface BasicLayoutProps {
|
|
5
|
+
/**
|
|
6
|
+
* List of pages for the menu and the routing
|
|
7
|
+
*/
|
|
8
|
+
pages?: MenuPage[];
|
|
9
|
+
defaultPage?: string;
|
|
10
|
+
onPageChange?: (page: string) => void;
|
|
11
|
+
compactSider?: boolean;
|
|
12
|
+
layoutProps?: LayoutProps;
|
|
13
|
+
mobileHeaderProps?: LayoutProps;
|
|
14
|
+
siderProps?: SiderProps;
|
|
15
|
+
contentProps?: LayoutProps;
|
|
16
|
+
menuProps?: Omit<MenuProps, 'items' | 'selectedKeys' | 'onSelect'>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Basic layout that combines menu and routing into one.
|
|
20
|
+
*/
|
|
21
|
+
export declare const BasicLayout: React.FC<BasicLayoutProps>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
|
|
5
|
+
import { Button, Layout, Menu } from '@j2inn/ui';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import React, { useEffect, useState } from 'react';
|
|
8
|
+
import { createUseStyles } from 'react-jss';
|
|
9
|
+
import { ErrorDisplayer } from '../ErrorDisplayer';
|
|
10
|
+
import { findPageByName } from './MenuPage';
|
|
11
|
+
import { Router } from './Router';
|
|
12
|
+
const HEADER_HEIGHT = 45;
|
|
13
|
+
const useStyles = createUseStyles((theme) => {
|
|
14
|
+
return {
|
|
15
|
+
header: {
|
|
16
|
+
position: 'fixed',
|
|
17
|
+
width: '100%',
|
|
18
|
+
zIndex: 1000,
|
|
19
|
+
padding: 0,
|
|
20
|
+
height: HEADER_HEIGHT,
|
|
21
|
+
lineHeight: '45px',
|
|
22
|
+
},
|
|
23
|
+
sider: {
|
|
24
|
+
overflow: 'auto',
|
|
25
|
+
height: '100vh',
|
|
26
|
+
position: 'fixed',
|
|
27
|
+
left: 0,
|
|
28
|
+
top: 0,
|
|
29
|
+
bottom: 0,
|
|
30
|
+
zIndex: 999,
|
|
31
|
+
paddingTop: ({ isMobile }) => isMobile ? HEADER_HEIGHT : 0,
|
|
32
|
+
},
|
|
33
|
+
menuTrigger: {
|
|
34
|
+
width: 45,
|
|
35
|
+
height: '100%',
|
|
36
|
+
textAlign: 'center',
|
|
37
|
+
fontSize: 18,
|
|
38
|
+
cursor: 'pointer',
|
|
39
|
+
transition: 'color 0.3s ease-in-out',
|
|
40
|
+
backgroundColor: 'transparent',
|
|
41
|
+
color: 'white',
|
|
42
|
+
'&:hover': {
|
|
43
|
+
color: theme.linkActiveColor,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
content: ({ isMobile, compactSider }) => ({
|
|
47
|
+
paddingLeft: isMobile ? 0 : compactSider ? 45 : 200,
|
|
48
|
+
paddingTop: isMobile ? HEADER_HEIGHT : 0,
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
// Workaround j2inn/ui exporting problem
|
|
53
|
+
const Header = Layout.Header;
|
|
54
|
+
const Sider = Layout.Sider;
|
|
55
|
+
const Content = Layout.Content;
|
|
56
|
+
/**
|
|
57
|
+
* Basic layout that combines menu and routing into one.
|
|
58
|
+
*/
|
|
59
|
+
export const BasicLayout = ({ pages = [], defaultPage = pages?.[0].key ?? '', onPageChange, compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, }) => {
|
|
60
|
+
const [currentPage, setCurrentPage] = useState(defaultPage);
|
|
61
|
+
// Fire onChange
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
onPageChange?.(currentPage);
|
|
64
|
+
}, [currentPage]);
|
|
65
|
+
// manage mobile navigation
|
|
66
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
67
|
+
const [hiddenSider, setHiddenSider] = useState(false);
|
|
68
|
+
const classes = useStyles({ isMobile, compactSider });
|
|
69
|
+
return (<Layout hasSider {...layoutProps}>
|
|
70
|
+
{isMobile && (<Header className={classes.header} {...mobileHeaderProps}>
|
|
71
|
+
{hiddenSider ? (<MenuUnfoldOutlined className={classes.menuTrigger} onClick={() => {
|
|
72
|
+
setHiddenSider(!hiddenSider);
|
|
73
|
+
}}/>) : (<MenuFoldOutlined className={classes.menuTrigger} onClick={() => {
|
|
74
|
+
setHiddenSider(!hiddenSider);
|
|
75
|
+
}}/>)}
|
|
76
|
+
</Header>)}
|
|
77
|
+
<Sider {...siderProps} className={classNames(classes.sider, siderProps?.className)} breakpoint='md' onBreakpoint={(broken) => {
|
|
78
|
+
setIsMobile(broken);
|
|
79
|
+
setHiddenSider(true);
|
|
80
|
+
}} collapsed={(isMobile && hiddenSider) || compactSider} collapsedWidth={isMobile && hiddenSider
|
|
81
|
+
? 0
|
|
82
|
+
: compactSider
|
|
83
|
+
? HEADER_HEIGHT
|
|
84
|
+
: 0} trigger={null}>
|
|
85
|
+
<Menu {...menuProps} items={pages} selectedKeys={[currentPage]} onSelect={({ key }) => {
|
|
86
|
+
if (!hiddenSider) {
|
|
87
|
+
setHiddenSider(true);
|
|
88
|
+
}
|
|
89
|
+
const page = findPageByName(pages, key);
|
|
90
|
+
if (page?.component) {
|
|
91
|
+
setCurrentPage(key);
|
|
92
|
+
}
|
|
93
|
+
}}/>
|
|
94
|
+
</Sider>
|
|
95
|
+
<Content className={classes.content} {...contentProps}>
|
|
96
|
+
<Router pages={pages} currentPage={currentPage ?? defaultPage} fallbackComponent={<ErrorDisplayer error={new Error('Page Not Found')} extra={[
|
|
97
|
+
<Button type='primary' key='refresh' onClick={() => setCurrentPage(defaultPage)}>
|
|
98
|
+
Go Home
|
|
99
|
+
</Button>,
|
|
100
|
+
]}/>}/>
|
|
101
|
+
</Content>
|
|
102
|
+
</Layout>);
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=BasicLayout.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasicLayout.jsx","sourceRoot":"","sources":["../../../../src/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
+
* Menu page has both the data required by the menu and the data required to actually render the page.
|
|
5
|
+
*/
|
|
6
|
+
export declare type MenuPage<T = Record<string, unknown>> = ItemType & Page<T>;
|
|
7
|
+
/**
|
|
8
|
+
* Menu Item that represents an application page
|
|
9
|
+
*/
|
|
10
|
+
interface Page<T = Record<string, unknown>> {
|
|
11
|
+
key: string;
|
|
12
|
+
component?: React.LazyExoticComponent<React.FC<T>>;
|
|
13
|
+
props?: PropsWithChildren<T>;
|
|
14
|
+
children?: Page<T>[];
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve a specific page or subPage from a root page list
|
|
19
|
+
* @param name the name of the searched page
|
|
20
|
+
* @param pages the list of root pages
|
|
21
|
+
*/
|
|
22
|
+
export declare function findPageByName<T extends MenuPage>(pages: T[], name?: string): T | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Expands the list of pages to include all the subpages
|
|
25
|
+
*/
|
|
26
|
+
export declare function pageTreeToPageList<T extends MenuPage>(pages: T[]): T[];
|
|
27
|
+
/**
|
|
28
|
+
* Recursively get all the subPages of a root page
|
|
29
|
+
* @param page root page
|
|
30
|
+
* @returns the whole tree of subPages as a list
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAllSubPages<T extends MenuPage>(page: T): T[];
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Retrieve a specific page or subPage from a root page list
|
|
6
|
+
* @param name the name of the searched page
|
|
7
|
+
* @param pages the list of root pages
|
|
8
|
+
*/
|
|
9
|
+
export function findPageByName(pages, name) {
|
|
10
|
+
return pageTreeToPageList(pages).find((page) => page.key === name && !page.disabled);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Expands the list of pages to include all the subpages
|
|
14
|
+
*/
|
|
15
|
+
export function pageTreeToPageList(pages) {
|
|
16
|
+
return pages.flatMap((page) => getAllSubPages(page));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Recursively get all the subPages of a root page
|
|
20
|
+
* @param page root page
|
|
21
|
+
* @returns the whole tree of subPages as a list
|
|
22
|
+
*/
|
|
23
|
+
export function getAllSubPages(page) {
|
|
24
|
+
if (page.children) {
|
|
25
|
+
return [page].concat(...page.children.map((subPage) => getAllSubPages(subPage)));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return [page];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=MenuPage.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuPage.jsx","sourceRoot":"","sources":["../../../../src/react/components/navigation/MenuPage.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAqBH;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAU,EACV,IAAa;IAEb,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC,IAAI,CACpC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAC7C,CAAA;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAqB,KAAU;IAChE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAS,CAAC,CAAC,CAAA;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAqB,IAAO;IACzD,IAAI,IAAI,CAAC,QAAQ,EAAE;QAClB,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CACnB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,OAAY,CAAC,CAAC,CAC/D,CAAA;KACD;SAAM;QACN,OAAO,CAAC,IAAI,CAAC,CAAA;KACb;AACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactElement } from 'react';
|
|
2
|
+
import { MenuPage } from './MenuPage';
|
|
3
|
+
export interface RouterProps<T extends MenuPage> {
|
|
4
|
+
pages?: T[];
|
|
5
|
+
currentPage: string;
|
|
6
|
+
onPageChange?: (selectedPage?: T) => void;
|
|
7
|
+
fallbackComponent?: ReactElement;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Renders the currently selected page from a tree of pages
|
|
11
|
+
*/
|
|
12
|
+
export declare function Router<T extends MenuPage>({ pages, currentPage, onPageChange, fallbackComponent, }: PropsWithChildren<RouterProps<T>>): JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import React, { Suspense, useEffect, useMemo, } from 'react';
|
|
5
|
+
import LoadingSpinner from '../LoadingSpinner';
|
|
6
|
+
import { findPageByName } from './MenuPage';
|
|
7
|
+
/**
|
|
8
|
+
* Renders the currently selected page from a tree of pages
|
|
9
|
+
*/
|
|
10
|
+
export function Router({ pages = [], currentPage, onPageChange, fallbackComponent, }) {
|
|
11
|
+
const page = useMemo(() => findPageByName(pages, currentPage), [pages, currentPage]);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
onPageChange?.(page);
|
|
14
|
+
}, [page]);
|
|
15
|
+
return page?.component ? (<Suspense fallback={<LoadingSpinner />}>
|
|
16
|
+
{React.createElement(page.component, page?.props)}
|
|
17
|
+
</Suspense>) : (fallbackComponent ?? <div>{currentPage} page not found</div>);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Router.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.jsx","sourceRoot":"","sources":["../../../../src/react/components/navigation/Router.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,EAGb,QAAQ,EACR,SAAS,EACT,OAAO,GACP,MAAM,OAAO,CAAA;AACd,OAAO,cAAc,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAY,MAAM,YAAY,CAAA;AASrD;;GAEG;AACH,MAAM,UAAU,MAAM,CAAqB,EAC1C,KAAK,GAAG,EAAE,EACV,WAAW,EACX,YAAY,EACZ,iBAAiB,GACkB;IACnC,MAAM,IAAI,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,EACxC,CAAC,KAAK,EAAE,WAAW,CAAC,CACpB,CAAA;IAED,SAAS,CAAC,GAAG,EAAE;QACd,YAAY,EAAE,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;IAEV,OAAO,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CACxB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,AAAD,EAAG,CAAC,CACtC;GAAA,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAClD;EAAA,EAAE,QAAQ,CAAC,CACX,CAAC,CAAC,CAAC,CACH,iBAAiB,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,CAAE,eAAc,EAAE,GAAG,CAAC,CAC5D,CAAA;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j2inn/fin5-ui-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-beta.1",
|
|
4
4
|
"description": "A set of useful client-side utilities useful for creating UI applications on top of FIN 5",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,26 +16,29 @@
|
|
|
16
16
|
"lint": "eslint --fix --ext ts,tsx,js,jsx src/",
|
|
17
17
|
"lint-staged": "lint-staged",
|
|
18
18
|
"test": "cross-env NODE_ENV=test && npm run test:jest",
|
|
19
|
-
"test:jest": "jest
|
|
19
|
+
"test:jest": "jest",
|
|
20
20
|
"prepack": "npm run lint && npm run test && npm run build"
|
|
21
21
|
},
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"files": [
|
|
25
25
|
"dist/**/*",
|
|
26
|
-
"
|
|
26
|
+
"dist_es/**/*"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@hot-loader/react-dom": "^17.0.2",
|
|
30
|
-
"@j2inn/react-config": "^4.0.
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"haystack-core": "^2.0.29",
|
|
34
|
-
"haystack-nclient": "^3.0.12",
|
|
35
|
-
"haystack-react": "^3.0.3",
|
|
36
|
-
"haystack-units": "^1.0.12"
|
|
30
|
+
"@j2inn/react-config": "^4.0.16",
|
|
31
|
+
"classnames": "^2.3.1",
|
|
32
|
+
"js-yaml": "^4.1.0"
|
|
37
33
|
},
|
|
38
34
|
"peerDependencies": {
|
|
35
|
+
"@j2inn/app": "^1.0.17",
|
|
36
|
+
"@j2inn/ui": "^5.0.0-beta.17",
|
|
37
|
+
"@j2inn/utils": "^5.0.8",
|
|
38
|
+
"haystack-core": "^2.0.35",
|
|
39
|
+
"haystack-nclient": "^3.0.24",
|
|
40
|
+
"haystack-react": "^3.0.8",
|
|
41
|
+
"haystack-units": "^1.0.18",
|
|
39
42
|
"react": "^17.0.2",
|
|
40
43
|
"react-dom": "^17.0.2",
|
|
41
44
|
"react-jss": "^10.9.0"
|
|
@@ -57,7 +60,11 @@
|
|
|
57
60
|
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
58
61
|
"@babel/preset-typescript": "^7.16.7",
|
|
59
62
|
"@babel/runtime": "^7.17.8",
|
|
63
|
+
"@j2inn/app": "^1.0.17",
|
|
64
|
+
"@j2inn/ui": "^5.0.0-beta.17",
|
|
65
|
+
"@j2inn/utils": "^5.0.8",
|
|
60
66
|
"@types/jest": "^27.4.0",
|
|
67
|
+
"@types/js-yaml": "^4.0.5",
|
|
61
68
|
"@types/node": "^15.0.2",
|
|
62
69
|
"@types/react": "^17.0.8",
|
|
63
70
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
@@ -79,6 +86,10 @@
|
|
|
79
86
|
"eslint-plugin-prettier": "^4.0.0",
|
|
80
87
|
"eslint-plugin-react": "^7.29.4",
|
|
81
88
|
"extract-css-chunks-webpack-plugin": "^4.9.0",
|
|
89
|
+
"haystack-core": "^2.0.35",
|
|
90
|
+
"haystack-nclient": "^3.0.24",
|
|
91
|
+
"haystack-react": "^3.0.8",
|
|
92
|
+
"haystack-units": "^1.0.18",
|
|
82
93
|
"husky": "^7.0.4",
|
|
83
94
|
"jest": "^27.0.3",
|
|
84
95
|
"jest-chain": "^1.1.5",
|
|
@@ -109,4 +120,4 @@
|
|
|
109
120
|
"eslint --fix"
|
|
110
121
|
]
|
|
111
122
|
}
|
|
112
|
-
}
|
|
123
|
+
}
|