@equinor/fusion-react-errorboundary 0.1.0-beta.0
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/ErrorMessage.d.ts +5 -0
- package/dist/ErrorMessage.d.ts.map +1 -0
- package/dist/ErrorMessage.js +56 -0
- package/dist/ErrorMessage.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +15 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/useErrorStyles.d.ts +3 -0
- package/dist/useErrorStyles.d.ts.map +1 -0
- package/dist/useErrorStyles.js +36 -0
- package/dist/useErrorStyles.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ErrorMessageProps } from './types';
|
|
3
|
+
export declare const ErrorMessage: ({ hasError, errorType, message, resourceName, title, children, icon, action, onTakeAction, }: React.PropsWithChildren<ErrorMessageProps>) => JSX.Element;
|
|
4
|
+
export default ErrorMessage;
|
|
5
|
+
//# sourceMappingURL=ErrorMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorMessage.d.ts","sourceRoot":"","sources":["../src/ErrorMessage.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,eAAO,MAAM,YAAY,iGAUtB,MAAM,iBAAiB,CAAC,iBAAiB,CAAC,KAAG,WAgE/C,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { Button } from '@equinor/fusion-react-button';
|
|
4
|
+
import { clsx } from '@equinor/fusion-react-styles';
|
|
5
|
+
import { Icon } from '@equinor/fusion-react-icon';
|
|
6
|
+
import useErrorStyles from './useErrorStyles';
|
|
7
|
+
export const ErrorMessage = ({ hasError, errorType = 'error', message, resourceName, title, children, icon, action, onTakeAction, }) => {
|
|
8
|
+
const styles = useErrorStyles();
|
|
9
|
+
const getErrorMessageForType = (errorType) => {
|
|
10
|
+
const iconProps = {
|
|
11
|
+
width: 80,
|
|
12
|
+
height: 80,
|
|
13
|
+
cursor: 'default',
|
|
14
|
+
color: '#666666',
|
|
15
|
+
};
|
|
16
|
+
switch (errorType) {
|
|
17
|
+
case 'accessDenied':
|
|
18
|
+
return {
|
|
19
|
+
title: "It seems like you don't have access to this content",
|
|
20
|
+
icon: _jsx(Icon, { icon: "block", ...iconProps }),
|
|
21
|
+
};
|
|
22
|
+
case 'notFound':
|
|
23
|
+
return {
|
|
24
|
+
title: `The ${resourceName} could not be found`,
|
|
25
|
+
icon: _jsx(Icon, { icon: "warning_outlined", ...iconProps }),
|
|
26
|
+
};
|
|
27
|
+
case 'noData':
|
|
28
|
+
return {
|
|
29
|
+
title: `Unfortunately, we could not find any data for this component`,
|
|
30
|
+
icon: _jsx(Icon, { icon: "sync_off", ...iconProps }),
|
|
31
|
+
};
|
|
32
|
+
case 'failedDependency': // 424
|
|
33
|
+
return {
|
|
34
|
+
title: `Unfortunately, we had problem with communicate with dependent system, ${resourceName}`,
|
|
35
|
+
icon: _jsx(Icon, { icon: "sync_off", ...iconProps }),
|
|
36
|
+
};
|
|
37
|
+
case 'throttle': // 429
|
|
38
|
+
return {
|
|
39
|
+
title: `Unfortunately, we experience too many request for resource ${resourceName}`,
|
|
40
|
+
icon: _jsx(Icon, { icon: "sync_off", ...iconProps }),
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
return {
|
|
44
|
+
title: 'Oops! Something went wrong!',
|
|
45
|
+
icon: _jsx(Icon, { icon: "warning_outlined", ...iconProps }),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const error = useMemo(() => getErrorMessageForType(errorType), [errorType]);
|
|
50
|
+
if (!hasError) {
|
|
51
|
+
return _jsx(_Fragment, { children: children });
|
|
52
|
+
}
|
|
53
|
+
return (_jsx("div", { className: styles.container, children: _jsxs("div", { className: clsx(styles.messageContainer, 'comfortable'), children: [icon || error.icon, _jsx("div", { className: "title", children: title || error.title }), _jsx("div", { className: "message", children: message }), action ? (_jsx(Button, { variant: "outlined", onClick: onTakeAction, children: action })) : null] }) }));
|
|
54
|
+
};
|
|
55
|
+
export default ErrorMessage;
|
|
56
|
+
//# sourceMappingURL=ErrorMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorMessage.js","sourceRoot":"","sources":["../src/ErrorMessage.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAElD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAK9C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,QAAQ,EACR,SAAS,GAAG,OAAO,EACnB,OAAO,EACP,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,YAAY,GAC+B,EAAe,EAAE;IAC5D,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,EAAE;QACnD,MAAM,SAAS,GAAG;YAChB,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,SAAS;SACjB,CAAC;QAEF,QAAQ,SAAS,EA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AC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,aACzD,IAAI,IAAI,KAAK,CAAC,IAAI,EACnB,cAAK,SAAS,EAAC,OAAO,YAAE,KAAK,IAAI,KAAK,CAAC,KAAK,GAAO,EACnD,cAAK,SAAS,EAAC,SAAS,YAAE,OAAO,GAAO,EACvC,MAAM,CAAC,CAAC,CAAC,CACR,KAAC,MAAM,IAAC,OAAO,EAAC,UAAU,EAAC,OAAO,EAAE,YAAY,YAC7C,MAAM,GACA,CACV,CAAC,CAAC,CAAC,IAAI,IACJ,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import type { ErrorMessageProps } from './types';
|
|
3
|
+
export declare class ErrorBoundary extends Component<ErrorMessageProps> {
|
|
4
|
+
state: {
|
|
5
|
+
didCatch: boolean;
|
|
6
|
+
};
|
|
7
|
+
render(): JSX.Element;
|
|
8
|
+
componentDidCatch(): void;
|
|
9
|
+
}
|
|
10
|
+
export default ErrorBoundary;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIlC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIjD,qBAAa,aAAc,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IAC7D,KAAK;;MAAuB;IAC5B,MAAM;IAeN,iBAAiB;CAGlB;AAED,eAAe,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
import ErrorMessage from './ErrorMessage';
|
|
4
|
+
import useErrorStyles from './useErrorStyles';
|
|
5
|
+
const styles = useErrorStyles();
|
|
6
|
+
export class ErrorBoundary extends Component {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.state = { didCatch: false };
|
|
10
|
+
}
|
|
11
|
+
render() {
|
|
12
|
+
if (this.state.didCatch) {
|
|
13
|
+
return (_jsx("div", { className: styles.container, children: _jsxs("div", { className: styles.messageContainer, children: [_jsx("div", { className: styles.title, children: "Something went wrong" }), _jsx("div", { className: styles.message, children: "Please try refresh browser, if problem persists, please contact support through service now" })] }) }));
|
|
14
|
+
}
|
|
15
|
+
return _jsx(ErrorMessage, { ...this.props, children: this.props.children });
|
|
16
|
+
}
|
|
17
|
+
componentDidCatch() {
|
|
18
|
+
this.setState({ didCatch: true });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default ErrorBoundary;
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAG9C,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;AAEhC,MAAM,OAAO,aAAc,SAAQ,SAA4B;IAA/D;;QACE,UAAK,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAmB9B,CAAC;IAlBC,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,OAAO,CACL,cAAK,SAAS,EAAE,MAAM,CAAC,SAAS,YAC9B,eAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,aACrC,cAAK,SAAS,EAAE,MAAM,CAAC,KAAK,qCAA4B,EACxD,cAAK,SAAS,EAAE,MAAM,CAAC,OAAO,4GAExB,IACF,GACF,CACP,CAAC;SACH;QACD,OAAO,KAAC,YAAY,OAAK,IAAI,CAAC,KAAK,YAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAgB,CAAC;IAC5E,CAAC;IACD,iBAAiB;QACf,IAAI,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;AAED,eAAe,aAAa,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
type ErrorTypes = 'error' | 'accessDenied' | 'notFound' | 'noData' | 'failedDependency' | 'throttle';
|
|
3
|
+
export type ErrorMessageProps = {
|
|
4
|
+
hasError?: boolean;
|
|
5
|
+
errorType?: ErrorTypes;
|
|
6
|
+
message?: string;
|
|
7
|
+
resourceName?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
children?: React.ReactChildren;
|
|
10
|
+
icon?: string;
|
|
11
|
+
action?: string;
|
|
12
|
+
onTakeAction?: (event?: React.SyntheticEvent<Element, Event>) => void;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AACA,KAAK,UAAU,GAAG,OAAO,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,kBAAkB,GAAG,UAAU,CAAC;AAErG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC;CACvE,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useErrorStyles.d.ts","sourceRoot":"","sources":["../src/useErrorStyles.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,cAAc,gIAkCnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createStyles, makeStyles } from '@equinor/fusion-react-styles';
|
|
2
|
+
const useErrorStyles = makeStyles(() => createStyles({
|
|
3
|
+
container: {
|
|
4
|
+
position: 'relative',
|
|
5
|
+
width: '100%',
|
|
6
|
+
height: '100%',
|
|
7
|
+
},
|
|
8
|
+
messageContainer: {
|
|
9
|
+
position: 'relative',
|
|
10
|
+
left: '0',
|
|
11
|
+
bottom: '0',
|
|
12
|
+
right: '0',
|
|
13
|
+
display: 'flex',
|
|
14
|
+
alignContent: 'center',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
flexDirection: 'column',
|
|
18
|
+
marginTop: 'calc(var(--grid-unit) * 15px)',
|
|
19
|
+
zIndex: '999',
|
|
20
|
+
},
|
|
21
|
+
title: {
|
|
22
|
+
paddingTop: 'calc(var(--grid-unit) * 6px)',
|
|
23
|
+
fontSize: '28px',
|
|
24
|
+
height: 'calc(var(--grid-unit) * 4px)',
|
|
25
|
+
overflow: 'hidden',
|
|
26
|
+
},
|
|
27
|
+
message: {
|
|
28
|
+
fontSize: '20px',
|
|
29
|
+
paddingBottom: 'calc(var(--grid-unit) * 5px)',
|
|
30
|
+
paddingTop: 'calc(var(--grid-unit) * 3px)',
|
|
31
|
+
height: 'auto',
|
|
32
|
+
textAlign: 'center',
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
export default useErrorStyles;
|
|
36
|
+
//# sourceMappingURL=useErrorStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useErrorStyles.js","sourceRoot":"","sources":["../src/useErrorStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AACxE,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE,CACrC,YAAY,CAAC;IACX,SAAS,EAAE;QACT,QAAQ,EAAE,UAAU;QACpB,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;KACf;IACD,gBAAgB,EAAE;QAChB,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,GAAG;QACT,MAAM,EAAE,GAAG;QACX,KAAK,EAAE,GAAG;QACV,OAAO,EAAE,MAAM;QACf,YAAY,EAAE,QAAQ;QACtB,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;QACxB,aAAa,EAAE,QAAQ;QACvB,SAAS,EAAE,+BAA+B;QAC1C,MAAM,EAAE,KAAK;KACd;IACD,KAAK,EAAE;QACL,UAAU,EAAE,8BAA8B;QAC1C,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,8BAA8B;QACtC,QAAQ,EAAE,QAAQ;KACnB;IACD,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM;QAChB,aAAa,EAAE,8BAA8B;QAC7C,UAAU,EAAE,8BAA8B;QAC1C,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,QAAQ;KACpB;CACF,CAAC,CACH,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-react-errorboundary",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "React component for errorboundary",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"errorboundary",
|
|
7
|
+
"react",
|
|
8
|
+
"fusion",
|
|
9
|
+
"equinor"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/equinor/fusion-react-components/tree/master/packages/errorboundary#readme",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"directories": {
|
|
15
|
+
"dist": "dist"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/equinor/fusion-react-components.git"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -b",
|
|
29
|
+
"lint": "eslint --ext .ts,.tsx,.js src/",
|
|
30
|
+
"lint:fix": "eslint --ext .ts,.tsx,.js src/ --fix",
|
|
31
|
+
"prepack": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/equinor/fusion-react-components/issues"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@equinor/fusion-react-button": "^0.8.1",
|
|
38
|
+
"@equinor/fusion-react-icon": "^0.2.15",
|
|
39
|
+
"@equinor/fusion-react-styles": "^0.5.5",
|
|
40
|
+
"@equinor/fusion-react-utils": "^2.0.4"
|
|
41
|
+
},
|
|
42
|
+
"gitHead": "ef5fa4173a1235ea9ed8ecdcc82b30e4ab6222f7"
|
|
43
|
+
}
|