@j2inn/fin5-ui-utils 8.1.1-beta.5 → 8.1.1-beta.6
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/README.md +5 -5
- package/dist/fantomProps/createFin5Props/index.d.ts +12 -12
- package/dist/fantomProps/createFin5Props/index.js +146 -146
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -2
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.js +20 -20
- package/dist/fantomProps/fantomPropsToObject.d.ts +8 -8
- package/dist/fantomProps/fantomPropsToObject.js +183 -183
- package/dist/fantomProps/generateJsonFromFantomPropsFile.d.ts +4 -4
- package/dist/fantomProps/generateJsonFromFantomPropsFile.js +41 -41
- package/dist/fantomProps/localePropsToJson.d.ts +1 -1
- package/dist/fantomProps/localePropsToJson.js +50 -50
- package/dist/fantomProps/readFantomPropsFile.d.ts +5 -5
- package/dist/fantomProps/readFantomPropsFile.js +65 -65
- package/dist/fin5Top/fin5FileUpload.d.ts +24 -24
- package/dist/fin5Top/fin5FileUpload.js +51 -51
- package/dist/fin5Top/fin5Top.d.ts +165 -124
- package/dist/fin5Top/fin5Top.js +61 -53
- package/dist/fin5Top/fin5Top.js.map +1 -1
- package/dist/fin5Top/finEdge2Cloud.d.ts +6 -6
- package/dist/fin5Top/finEdge2Cloud.js +15 -15
- package/dist/fin5Top/getFin5BinUrl.d.ts +2 -2
- package/dist/fin5Top/getFin5BinUrl.js +9 -9
- package/dist/fin5Top/openFin5Alarm.d.ts +22 -22
- package/dist/fin5Top/openFin5Alarm.js +23 -23
- package/dist/fin5Top/openFin5Historian.d.ts +3 -3
- package/dist/fin5Top/openFin5Historian.js +19 -19
- package/dist/fin5Top/useFin5AppURLHashParameter.d.ts +18 -18
- package/dist/fin5Top/useFin5AppURLHashParameter.js +133 -133
- package/dist/index.d.ts +35 -35
- package/dist/index.js +69 -69
- package/dist/jobs/jobUtils.d.ts +14 -14
- package/dist/jobs/jobUtils.js +15 -15
- package/dist/react/app/Fin5AppContainer.d.ts +36 -36
- package/dist/react/app/Fin5AppContainer.js +145 -161
- package/dist/react/app/Fin5AppContainer.js.map +1 -1
- package/dist/react/app/Fin5AppRootStore.d.ts +40 -42
- package/dist/react/app/Fin5AppRootStore.js +90 -114
- package/dist/react/app/Fin5AppRootStore.js.map +1 -1
- package/dist/react/components/ErrorBoundary.d.ts +57 -57
- package/dist/react/components/ErrorBoundary.js +150 -150
- package/dist/react/components/ErrorDisplayer.d.ts +19 -19
- package/dist/react/components/ErrorDisplayer.js +36 -36
- package/dist/react/components/Loader.d.ts +9 -9
- package/dist/react/components/Loader.js +17 -17
- package/dist/react/components/LoadingSpinner.d.ts +2 -2
- package/dist/react/components/LoadingSpinner.js +27 -27
- package/dist/react/components/RecordImage.d.ts +20 -20
- package/dist/react/components/RecordImage.js +51 -51
- package/dist/react/components/charts/QRCode.d.ts +25 -25
- package/dist/react/components/charts/QRCode.js +82 -82
- package/dist/react/components/charts/line-bar/Chart.d.ts +166 -166
- package/dist/react/components/charts/line-bar/Chart.js +442 -442
- package/dist/react/components/charts/line-bar/HGridChart.d.ts +58 -58
- package/dist/react/components/charts/line-bar/HGridChart.js +285 -285
- package/dist/react/components/charts/pie/PieChart.d.ts +94 -94
- package/dist/react/components/charts/pie/PieChart.js +204 -204
- package/dist/react/components/charts/pie/SimplePieChart.d.ts +21 -21
- package/dist/react/components/charts/pie/SimplePieChart.js +55 -55
- package/dist/react/components/graphics/GraphicViewer.d.ts +10 -10
- package/dist/react/components/graphics/GraphicViewer.js +29 -29
- package/dist/react/components/graphics/GraphicsTabViewer.d.ts +17 -17
- package/dist/react/components/graphics/GraphicsTabViewer.js +90 -90
- package/dist/react/components/makeCustomElement.d.ts +16 -16
- package/dist/react/components/makeCustomElement.js +150 -150
- package/dist/react/components/navigation/BasicLayout.d.ts +41 -41
- package/dist/react/components/navigation/BasicLayout.js +155 -155
- package/dist/react/components/navigation/HeaderSiderLayout.d.ts +13 -13
- package/dist/react/components/navigation/HeaderSiderLayout.js +110 -110
- package/dist/react/components/navigation/MenuPage.d.ts +37 -37
- package/dist/react/components/navigation/MenuPage.js +36 -36
- package/dist/react/components/navigation/MenuTrigger.d.ts +9 -9
- package/dist/react/components/navigation/MenuTrigger.js +33 -33
- package/dist/react/components/navigation/ReactRouterHeaderSiderLayout.d.ts +11 -11
- package/dist/react/components/navigation/ReactRouterHeaderSiderLayout.js +25 -25
- package/dist/react/components/navigation/ReactRouterLayout.d.ts +46 -46
- package/dist/react/components/navigation/ReactRouterLayout.js +132 -132
- package/dist/react/components/navigation/customRouting/Router.d.ts +12 -12
- package/dist/react/components/navigation/customRouting/Router.js +45 -45
- package/dist/react/components/navigation/customRouting/RouterLayout.d.ts +11 -11
- package/dist/react/components/navigation/customRouting/RouterLayout.js +61 -61
- package/dist/react/components/resolvable/configurationForm/ConfigurationForm.d.ts +27 -27
- package/dist/react/components/resolvable/configurationForm/ConfigurationForm.js +95 -95
- package/dist/react/components/resolvable/configurationForm/ConfigurationFormEntry.d.ts +16 -16
- package/dist/react/components/resolvable/configurationForm/ConfigurationFormEntry.js +88 -88
- package/dist/react/components/resolvable/configurationForm/getSectionDefault.d.ts +16 -16
- package/dist/react/components/resolvable/configurationForm/getSectionDefault.js +99 -99
- package/dist/react/hooks/useFin5BinUrl.d.ts +6 -6
- package/dist/react/hooks/useFin5BinUrl.js +15 -15
- package/dist/react/hooks/useFin5ColorScheme.d.ts +2 -2
- package/dist/react/hooks/useFin5ColorScheme.js +56 -56
- package/dist/react/hooks/useScreenSize.d.ts +7 -7
- package/dist/react/hooks/useScreenSize.js +31 -31
- package/dist_es/fantomProps/createFin5Props/index.d.ts +12 -12
- package/dist_es/fantomProps/createFin5Props/index.js +140 -140
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -2
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.js +15 -15
- package/dist_es/fantomProps/fantomPropsToObject.d.ts +8 -8
- package/dist_es/fantomProps/fantomPropsToObject.js +178 -178
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.d.ts +4 -4
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.js +12 -12
- package/dist_es/fantomProps/localePropsToJson.d.ts +1 -1
- package/dist_es/fantomProps/localePropsToJson.js +21 -21
- package/dist_es/fantomProps/readFantomPropsFile.d.ts +5 -5
- package/dist_es/fantomProps/readFantomPropsFile.js +39 -39
- package/dist_es/fin5Top/fin5FileUpload.d.ts +24 -24
- package/dist_es/fin5Top/fin5FileUpload.js +47 -47
- package/dist_es/fin5Top/fin5Top.d.ts +165 -124
- package/dist_es/fin5Top/fin5Top.js +57 -49
- package/dist_es/fin5Top/fin5Top.js.map +1 -1
- package/dist_es/fin5Top/finEdge2Cloud.d.ts +6 -6
- package/dist_es/fin5Top/finEdge2Cloud.js +11 -11
- package/dist_es/fin5Top/getFin5BinUrl.d.ts +2 -2
- package/dist_es/fin5Top/getFin5BinUrl.js +5 -5
- package/dist_es/fin5Top/openFin5Alarm.d.ts +22 -22
- package/dist_es/fin5Top/openFin5Alarm.js +19 -19
- package/dist_es/fin5Top/openFin5Historian.d.ts +3 -3
- package/dist_es/fin5Top/openFin5Historian.js +15 -15
- package/dist_es/fin5Top/useFin5AppURLHashParameter.d.ts +18 -18
- package/dist_es/fin5Top/useFin5AppURLHashParameter.js +124 -124
- package/dist_es/index.d.ts +35 -35
- package/dist_es/index.js +53 -53
- package/dist_es/jobs/jobUtils.d.ts +14 -14
- package/dist_es/jobs/jobUtils.js +9 -9
- package/dist_es/react/app/Fin5AppContainer.d.ts +36 -36
- package/dist_es/react/app/Fin5AppContainer.js +116 -132
- package/dist_es/react/app/Fin5AppContainer.js.map +1 -1
- package/dist_es/react/app/Fin5AppContainer.jsx +82 -0
- package/dist_es/react/app/Fin5AppContainer.jsx.map +1 -0
- package/dist_es/react/app/Fin5AppRootStore.d.ts +40 -42
- package/dist_es/react/app/Fin5AppRootStore.js +86 -110
- package/dist_es/react/app/Fin5AppRootStore.js.map +1 -1
- package/dist_es/react/components/ErrorBoundary.d.ts +57 -57
- package/dist_es/react/components/ErrorBoundary.js +123 -123
- 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 -19
- package/dist_es/react/components/ErrorDisplayer.js +28 -28
- 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 -9
- package/dist_es/react/components/Loader.js +12 -12
- 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 +2 -2
- package/dist_es/react/components/LoadingSpinner.js +20 -20
- package/dist_es/react/components/LoadingSpinner.jsx +22 -0
- package/dist_es/react/components/LoadingSpinner.jsx.map +1 -0
- package/dist_es/react/components/RecordImage.d.ts +20 -20
- package/dist_es/react/components/RecordImage.js +24 -24
- package/dist_es/react/components/charts/QRCode.d.ts +25 -25
- package/dist_es/react/components/charts/QRCode.js +52 -52
- package/dist_es/react/components/charts/line-bar/Chart.d.ts +166 -166
- package/dist_es/react/components/charts/line-bar/Chart.js +415 -415
- package/dist_es/react/components/charts/line-bar/HGridChart.d.ts +58 -58
- package/dist_es/react/components/charts/line-bar/HGridChart.js +250 -250
- package/dist_es/react/components/charts/line-bar/ZincGridChart.d.ts +12 -0
- package/dist_es/react/components/charts/line-bar/ZincGridChart.js +17 -0
- package/dist_es/react/components/charts/line-bar/ZincGridChart.js.map +1 -0
- package/dist_es/react/components/charts/pie/PieChart.d.ts +94 -94
- package/dist_es/react/components/charts/pie/PieChart.js +177 -177
- package/dist_es/react/components/charts/pie/SimplePieChart.d.ts +21 -21
- package/dist_es/react/components/charts/pie/SimplePieChart.js +25 -25
- package/dist_es/react/components/graphics/GraphicViewer.d.ts +10 -10
- package/dist_es/react/components/graphics/GraphicViewer.js +22 -22
- package/dist_es/react/components/graphics/GraphicViewer.jsx +23 -0
- package/dist_es/react/components/graphics/GraphicViewer.jsx.map +1 -0
- package/dist_es/react/components/graphics/GraphicsTabViewer.d.ts +17 -17
- package/dist_es/react/components/graphics/GraphicsTabViewer.js +60 -60
- package/dist_es/react/components/graphics/GraphicsTabViewer.jsx +63 -0
- package/dist_es/react/components/graphics/GraphicsTabViewer.jsx.map +1 -0
- package/dist_es/react/components/makeCustomElement.d.ts +16 -16
- package/dist_es/react/components/makeCustomElement.js +142 -142
- package/dist_es/react/components/navigation/BasicLayout.d.ts +41 -41
- package/dist_es/react/components/navigation/BasicLayout.js +124 -124
- package/dist_es/react/components/navigation/BasicLayout.jsx +133 -0
- package/dist_es/react/components/navigation/BasicLayout.jsx.map +1 -0
- package/dist_es/react/components/navigation/HeaderSiderLayout.d.ts +13 -13
- package/dist_es/react/components/navigation/HeaderSiderLayout.js +80 -80
- package/dist_es/react/components/navigation/MenuPage.d.ts +37 -37
- package/dist_es/react/components/navigation/MenuPage.js +30 -30
- 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/MenuTrigger.d.ts +9 -9
- package/dist_es/react/components/navigation/MenuTrigger.js +28 -28
- package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.d.ts +11 -11
- package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.js +18 -18
- package/dist_es/react/components/navigation/ReactRouterLayout.d.ts +46 -46
- package/dist_es/react/components/navigation/ReactRouterLayout.js +99 -99
- package/dist_es/react/components/navigation/Router.d.ts +12 -0
- package/dist_es/react/components/navigation/Router.js +19 -0
- package/dist_es/react/components/navigation/Router.js.map +1 -0
- package/dist_es/react/components/navigation/Router.jsx +19 -0
- package/dist_es/react/components/navigation/Router.jsx.map +1 -0
- package/dist_es/react/components/navigation/customRouting/Router.d.ts +12 -12
- package/dist_es/react/components/navigation/customRouting/Router.js +18 -18
- package/dist_es/react/components/navigation/customRouting/RouterLayout.d.ts +11 -11
- package/dist_es/react/components/navigation/customRouting/RouterLayout.js +34 -34
- package/dist_es/react/components/navigation/react-router/BasicLayout.d.ts +23 -0
- package/dist_es/react/components/navigation/react-router/BasicLayout.js +82 -0
- package/dist_es/react/components/navigation/react-router/BasicLayout.js.map +1 -0
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.d.ts +24 -0
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.js +82 -0
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.js.map +1 -0
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationForm.d.ts +27 -27
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationForm.js +64 -64
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationFormEntry.d.ts +16 -16
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationFormEntry.js +58 -58
- package/dist_es/react/components/resolvable/configurationForm/getSectionDefault.d.ts +16 -16
- package/dist_es/react/components/resolvable/configurationForm/getSectionDefault.js +94 -94
- package/dist_es/react/hooks/useFin5BinUrl.d.ts +6 -6
- package/dist_es/react/hooks/useFin5BinUrl.js +11 -11
- package/dist_es/react/hooks/useFin5ColorScheme.d.ts +2 -2
- package/dist_es/react/hooks/useFin5ColorScheme.js +52 -52
- package/dist_es/react/hooks/useScreenSize.d.ts +7 -7
- package/dist_es/react/hooks/useScreenSize.js +27 -27
- package/package.json +1 -1
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
5
|
-
import { Outlet, useLocation, useNavigate, } from 'react-router';
|
|
6
|
-
import { IN_IFRAME, fin5SkipHashUpdate, getFin5HashFrameParameters, getTopLocation, } from '../../../fin5Top/useFin5AppURLHashParameter';
|
|
7
|
-
import { BasicLayout } from './BasicLayout';
|
|
8
|
-
import { pageTreeToPageList } from './MenuPage';
|
|
9
|
-
/**
|
|
10
|
-
* This hook can be used with react-router/BasicLayout,
|
|
11
|
-
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
12
|
-
* This does not skip the hash update and should be used only with
|
|
13
|
-
* FIN >= 5.1.7.92, otherwise FIN will reload the entire page.
|
|
14
|
-
*/
|
|
15
|
-
export const useLocationUpdate = () => {
|
|
16
|
-
const location = useLocation();
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
if (IN_IFRAME) {
|
|
19
|
-
setHash(location);
|
|
20
|
-
}
|
|
21
|
-
}, [location]);
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* This hook can be used with react-router/BasicLayout,
|
|
25
|
-
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
26
|
-
* This skips the hash update and should be used only with
|
|
27
|
-
* FIN < 5.1.7.92.
|
|
28
|
-
* @deprecated use only with FIN < 5.1.7.92
|
|
29
|
-
* @see {@link useLocationUpdate} for FIN >= 5.1.7.92
|
|
30
|
-
*/
|
|
31
|
-
export const useLocationUpdateSkippingHash = () => {
|
|
32
|
-
const location = useLocation();
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (IN_IFRAME) {
|
|
35
|
-
fin5SkipHashUpdate()?.then(() => {
|
|
36
|
-
setHash(location);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}, [location]);
|
|
40
|
-
};
|
|
41
|
-
const setHash = (location) => {
|
|
42
|
-
const hash = location.pathname;
|
|
43
|
-
const queryParams = location.search;
|
|
44
|
-
const frameParameters = getFin5HashFrameParameters();
|
|
45
|
-
frameParameters.set('url', frameParameters.get('url')?.split('#')[0] + '#' + hash + queryParams);
|
|
46
|
-
getTopLocation().hash = `#${getTopLocation().hash.slice(1).split('?')[0]}?${frameParameters.toString()}`;
|
|
47
|
-
};
|
|
48
|
-
export const useSelectedRoutes = (pages, isSelectedRoute = (page, location) => location.pathname.includes(page.route)) => {
|
|
49
|
-
const location = useLocation();
|
|
50
|
-
const flatPages = useMemo(() => pageTreeToPageList(pages), [pages]);
|
|
51
|
-
return useMemo(() => {
|
|
52
|
-
return flatPages
|
|
53
|
-
.filter((page) => isSelectedRoute(page, location))
|
|
54
|
-
.map((page) => page.key);
|
|
55
|
-
}, [location, flatPages, isSelectedRoute]);
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* If we are inside a frame (FIN5), the route is left as is.
|
|
59
|
-
* If we are outside FIN5 frame, the route needs to be prefixed with a segment containing the project name.
|
|
60
|
-
* @param route
|
|
61
|
-
* @returns the correct route for the environment
|
|
62
|
-
*/
|
|
63
|
-
export const getRoute = (route) => {
|
|
64
|
-
const prefixedRoute = route.startsWith('/') ? route : `/${route}`;
|
|
65
|
-
return !IN_IFRAME ? `/proj/:projectName${prefixedRoute}` : prefixedRoute;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Create a map that holds the page key and its related route.
|
|
69
|
-
* @param pages
|
|
70
|
-
* @returns the map page key - route
|
|
71
|
-
*/
|
|
72
|
-
export const useGetPageKeyRouteMap = (pages) => useMemo(() => {
|
|
73
|
-
const flatPages = pageTreeToPageList(pages);
|
|
74
|
-
const result = new Map();
|
|
75
|
-
flatPages.forEach((page) => {
|
|
76
|
-
result.set(page.key, page.route);
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
79
|
-
}, [pages]);
|
|
80
|
-
export const useDefaultOnSelect = (navigate, pageKeyRouteMap, pages) => useCallback((key) => {
|
|
81
|
-
const route = pageKeyRouteMap.get(key);
|
|
82
|
-
if (route) {
|
|
83
|
-
navigate(route);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
console.warn('Could not find route for page key', key, 'pages', pages);
|
|
87
|
-
}
|
|
88
|
-
}, [navigate, pageKeyRouteMap]);
|
|
89
|
-
/**
|
|
90
|
-
* Basic layout that uses React Router.
|
|
91
|
-
*/
|
|
92
|
-
export const ReactRouterLayout = ({ isSelectedRoute, pages = [], onSelect, ...otherProps }) => {
|
|
93
|
-
const navigate = useNavigate();
|
|
94
|
-
const selectedRoutes = useSelectedRoutes(pages, isSelectedRoute);
|
|
95
|
-
const pageKeyRouteMap = useGetPageKeyRouteMap(pages);
|
|
96
|
-
const defaultOnSelect = useDefaultOnSelect(navigate, pageKeyRouteMap, pages);
|
|
97
|
-
return (React.createElement(BasicLayout, { ...otherProps, pages: pages, onSelect: onSelect ?? defaultOnSelect, selectedPages: selectedRoutes },
|
|
98
|
-
React.createElement(Outlet, null)));
|
|
99
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
5
|
+
import { Outlet, useLocation, useNavigate, } from 'react-router';
|
|
6
|
+
import { IN_IFRAME, fin5SkipHashUpdate, getFin5HashFrameParameters, getTopLocation, } from '../../../fin5Top/useFin5AppURLHashParameter';
|
|
7
|
+
import { BasicLayout } from './BasicLayout';
|
|
8
|
+
import { pageTreeToPageList } from './MenuPage';
|
|
9
|
+
/**
|
|
10
|
+
* This hook can be used with react-router/BasicLayout,
|
|
11
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
12
|
+
* This does not skip the hash update and should be used only with
|
|
13
|
+
* FIN >= 5.1.7.92, otherwise FIN will reload the entire page.
|
|
14
|
+
*/
|
|
15
|
+
export const useLocationUpdate = () => {
|
|
16
|
+
const location = useLocation();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (IN_IFRAME) {
|
|
19
|
+
setHash(location);
|
|
20
|
+
}
|
|
21
|
+
}, [location]);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* This hook can be used with react-router/BasicLayout,
|
|
25
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
26
|
+
* This skips the hash update and should be used only with
|
|
27
|
+
* FIN < 5.1.7.92.
|
|
28
|
+
* @deprecated use only with FIN < 5.1.7.92
|
|
29
|
+
* @see {@link useLocationUpdate} for FIN >= 5.1.7.92
|
|
30
|
+
*/
|
|
31
|
+
export const useLocationUpdateSkippingHash = () => {
|
|
32
|
+
const location = useLocation();
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (IN_IFRAME) {
|
|
35
|
+
fin5SkipHashUpdate()?.then(() => {
|
|
36
|
+
setHash(location);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}, [location]);
|
|
40
|
+
};
|
|
41
|
+
const setHash = (location) => {
|
|
42
|
+
const hash = location.pathname;
|
|
43
|
+
const queryParams = location.search;
|
|
44
|
+
const frameParameters = getFin5HashFrameParameters();
|
|
45
|
+
frameParameters.set('url', frameParameters.get('url')?.split('#')[0] + '#' + hash + queryParams);
|
|
46
|
+
getTopLocation().hash = `#${getTopLocation().hash.slice(1).split('?')[0]}?${frameParameters.toString()}`;
|
|
47
|
+
};
|
|
48
|
+
export const useSelectedRoutes = (pages, isSelectedRoute = (page, location) => location.pathname.includes(page.route)) => {
|
|
49
|
+
const location = useLocation();
|
|
50
|
+
const flatPages = useMemo(() => pageTreeToPageList(pages), [pages]);
|
|
51
|
+
return useMemo(() => {
|
|
52
|
+
return flatPages
|
|
53
|
+
.filter((page) => isSelectedRoute(page, location))
|
|
54
|
+
.map((page) => page.key);
|
|
55
|
+
}, [location, flatPages, isSelectedRoute]);
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* If we are inside a frame (FIN5), the route is left as is.
|
|
59
|
+
* If we are outside FIN5 frame, the route needs to be prefixed with a segment containing the project name.
|
|
60
|
+
* @param route
|
|
61
|
+
* @returns the correct route for the environment
|
|
62
|
+
*/
|
|
63
|
+
export const getRoute = (route) => {
|
|
64
|
+
const prefixedRoute = route.startsWith('/') ? route : `/${route}`;
|
|
65
|
+
return !IN_IFRAME ? `/proj/:projectName${prefixedRoute}` : prefixedRoute;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Create a map that holds the page key and its related route.
|
|
69
|
+
* @param pages
|
|
70
|
+
* @returns the map page key - route
|
|
71
|
+
*/
|
|
72
|
+
export const useGetPageKeyRouteMap = (pages) => useMemo(() => {
|
|
73
|
+
const flatPages = pageTreeToPageList(pages);
|
|
74
|
+
const result = new Map();
|
|
75
|
+
flatPages.forEach((page) => {
|
|
76
|
+
result.set(page.key, page.route);
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
}, [pages]);
|
|
80
|
+
export const useDefaultOnSelect = (navigate, pageKeyRouteMap, pages) => useCallback((key) => {
|
|
81
|
+
const route = pageKeyRouteMap.get(key);
|
|
82
|
+
if (route) {
|
|
83
|
+
navigate(route);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.warn('Could not find route for page key', key, 'pages', pages);
|
|
87
|
+
}
|
|
88
|
+
}, [navigate, pageKeyRouteMap]);
|
|
89
|
+
/**
|
|
90
|
+
* Basic layout that uses React Router.
|
|
91
|
+
*/
|
|
92
|
+
export const ReactRouterLayout = ({ isSelectedRoute, pages = [], onSelect, ...otherProps }) => {
|
|
93
|
+
const navigate = useNavigate();
|
|
94
|
+
const selectedRoutes = useSelectedRoutes(pages, isSelectedRoute);
|
|
95
|
+
const pageKeyRouteMap = useGetPageKeyRouteMap(pages);
|
|
96
|
+
const defaultOnSelect = useDefaultOnSelect(navigate, pageKeyRouteMap, pages);
|
|
97
|
+
return (React.createElement(BasicLayout, { ...otherProps, pages: pages, onSelect: onSelect ?? defaultOnSelect, selectedPages: selectedRoutes },
|
|
98
|
+
React.createElement(Outlet, null)));
|
|
99
|
+
};
|
|
100
100
|
//# sourceMappingURL=ReactRouterLayout.js.map
|
|
@@ -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 ? (React.createElement(Suspense, { fallback: React.createElement(LoadingSpinner, null) }, React.createElement(page.component, page?.props))) : (fallbackComponent ?? React.createElement("div", null,
|
|
16
|
+
currentPage,
|
|
17
|
+
" page not found"));
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.js","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,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,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,oBAAC,QAAQ,IAAC,QAAQ,EAAE,oBAAC,cAAc,OAAG,IACpC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CACvC,CACX,CAAC,CAAC,CAAC,CACH,iBAAiB,IAAI;QAAM,WAAW;0BAAsB,CAC5D,CAAA;AACF,CAAC"}
|
|
@@ -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,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,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"}
|
|
@@ -1,12 +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;
|
|
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;
|
|
@@ -1,19 +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 ? (React.createElement(Suspense, { fallback: React.createElement(LoadingSpinner, null) }, React.createElement(page.component, page?.props))) : (fallbackComponent ?? React.createElement("div", null,
|
|
16
|
-
currentPage,
|
|
17
|
-
" page not found"));
|
|
18
|
-
}
|
|
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 ? (React.createElement(Suspense, { fallback: React.createElement(LoadingSpinner, null) }, React.createElement(page.component, page?.props))) : (fallbackComponent ?? React.createElement("div", null,
|
|
16
|
+
currentPage,
|
|
17
|
+
" page not found"));
|
|
18
|
+
}
|
|
19
19
|
//# sourceMappingURL=Router.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { BasicLayoutProps } from '../BasicLayout';
|
|
3
|
-
import { MenuPage } from '../MenuPage';
|
|
4
|
-
export interface RouterLayoutProps extends BasicLayoutProps<MenuPage> {
|
|
5
|
-
page?: string;
|
|
6
|
-
onPageChange?: (page: string) => void;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Basic layout that uses a custom router.
|
|
10
|
-
*/
|
|
11
|
-
export declare const RouterLayout: React.FC<RouterLayoutProps>;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BasicLayoutProps } from '../BasicLayout';
|
|
3
|
+
import { MenuPage } from '../MenuPage';
|
|
4
|
+
export interface RouterLayoutProps extends BasicLayoutProps<MenuPage> {
|
|
5
|
+
page?: string;
|
|
6
|
+
onPageChange?: (page: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Basic layout that uses a custom router.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RouterLayout: React.FC<RouterLayoutProps>;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import { Button } from '@j2inn/ui';
|
|
5
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
|
-
import { ErrorDisplayer } from '../../ErrorDisplayer';
|
|
7
|
-
import { BasicLayout } from '../BasicLayout';
|
|
8
|
-
import { findPageByName } from '../MenuPage';
|
|
9
|
-
import { Router } from './Router';
|
|
10
|
-
/**
|
|
11
|
-
* Basic layout that uses a custom router.
|
|
12
|
-
*/
|
|
13
|
-
export const RouterLayout = ({ pages = [], defaultPage = pages?.[0].key ?? '', onPageChange, page, ...otherProps }) => {
|
|
14
|
-
const [currentPage, setCurrentPage] = useState(page ?? defaultPage);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (page) {
|
|
17
|
-
setCurrentPage(page);
|
|
18
|
-
}
|
|
19
|
-
}, [page]);
|
|
20
|
-
// Fire onChange
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
onPageChange?.(currentPage);
|
|
23
|
-
}, [currentPage]);
|
|
24
|
-
const onSelect = useCallback((key) => {
|
|
25
|
-
const page = findPageByName(pages, key);
|
|
26
|
-
if (page?.component) {
|
|
27
|
-
setCurrentPage(key);
|
|
28
|
-
}
|
|
29
|
-
}, [pages]);
|
|
30
|
-
return (React.createElement(BasicLayout, { ...otherProps, pages: pages, defaultPage: defaultPage, onSelect: onSelect, selectedPages: [currentPage] },
|
|
31
|
-
React.createElement(Router, { pages: pages, currentPage: currentPage, fallbackComponent: React.createElement(ErrorDisplayer, { error: new Error('Page Not Found'), extra: [
|
|
32
|
-
React.createElement(Button, { type: 'primary', key: 'refresh', onClick: () => setCurrentPage(defaultPage) }, "Go Home"),
|
|
33
|
-
] }) })));
|
|
34
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { Button } from '@j2inn/ui';
|
|
5
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import { ErrorDisplayer } from '../../ErrorDisplayer';
|
|
7
|
+
import { BasicLayout } from '../BasicLayout';
|
|
8
|
+
import { findPageByName } from '../MenuPage';
|
|
9
|
+
import { Router } from './Router';
|
|
10
|
+
/**
|
|
11
|
+
* Basic layout that uses a custom router.
|
|
12
|
+
*/
|
|
13
|
+
export const RouterLayout = ({ pages = [], defaultPage = pages?.[0].key ?? '', onPageChange, page, ...otherProps }) => {
|
|
14
|
+
const [currentPage, setCurrentPage] = useState(page ?? defaultPage);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (page) {
|
|
17
|
+
setCurrentPage(page);
|
|
18
|
+
}
|
|
19
|
+
}, [page]);
|
|
20
|
+
// Fire onChange
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
onPageChange?.(currentPage);
|
|
23
|
+
}, [currentPage]);
|
|
24
|
+
const onSelect = useCallback((key) => {
|
|
25
|
+
const page = findPageByName(pages, key);
|
|
26
|
+
if (page?.component) {
|
|
27
|
+
setCurrentPage(key);
|
|
28
|
+
}
|
|
29
|
+
}, [pages]);
|
|
30
|
+
return (React.createElement(BasicLayout, { ...otherProps, pages: pages, defaultPage: defaultPage, onSelect: onSelect, selectedPages: [currentPage] },
|
|
31
|
+
React.createElement(Router, { pages: pages, currentPage: currentPage, fallbackComponent: React.createElement(ErrorDisplayer, { error: new Error('Page Not Found'), extra: [
|
|
32
|
+
React.createElement(Button, { type: 'primary', key: 'refresh', onClick: () => setCurrentPage(defaultPage) }, "Go Home"),
|
|
33
|
+
] }) })));
|
|
34
|
+
};
|
|
35
35
|
//# sourceMappingURL=RouterLayout.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Location } from '@remix-run/router';
|
|
2
|
+
import { LayoutProps, MenuProps, SiderProps } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { MenuPage } from '../MenuPage';
|
|
5
|
+
export interface BasicLayoutProps {
|
|
6
|
+
pages?: MenuPage[];
|
|
7
|
+
compactSider?: boolean;
|
|
8
|
+
layoutProps?: LayoutProps;
|
|
9
|
+
mobileHeaderProps?: LayoutProps;
|
|
10
|
+
siderProps?: SiderProps;
|
|
11
|
+
contentProps?: LayoutProps;
|
|
12
|
+
menuProps?: Omit<MenuProps, 'items' | 'selectedKeys' | 'onSelect'>;
|
|
13
|
+
isSelectedRoute?: (page: MenuPage, location: Location) => boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This hook can be used with react-router/BasicLayout,
|
|
17
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
18
|
+
*/
|
|
19
|
+
export declare const useLocationUpdate: () => void;
|
|
20
|
+
/**
|
|
21
|
+
* Basic layout that uses React Router.
|
|
22
|
+
*/
|
|
23
|
+
export declare const BasicLayout: React.FC<BasicLayoutProps>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
|
|
5
|
+
import { Layout, Menu } from '@j2inn/ui';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { IN_IFRAME, fin5SkipHashUpdate, getFin5HashFrameParameters, getTopLocation, } from 'fin5Top/useFin5AppURLHashParameter';
|
|
8
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
|
+
import { Outlet, useLocation, useNavigate } from 'react-router';
|
|
10
|
+
import { HEADER_HEIGHT, getMenuPages, useStyles } from '../BasicLayout';
|
|
11
|
+
import { pageTreeToPageList } from '../MenuPage';
|
|
12
|
+
// Workaround j2inn/ui exporting problem
|
|
13
|
+
const Header = Layout.Header;
|
|
14
|
+
const Sider = Layout.Sider;
|
|
15
|
+
const Content = Layout.Content;
|
|
16
|
+
/**
|
|
17
|
+
* This hook can be used with react-router/BasicLayout,
|
|
18
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
19
|
+
*/
|
|
20
|
+
export const useLocationUpdate = () => {
|
|
21
|
+
const location = useLocation();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
console.debug('Location changed', location);
|
|
24
|
+
const hash = location.pathname;
|
|
25
|
+
const queryParams = location.search;
|
|
26
|
+
if (IN_IFRAME) {
|
|
27
|
+
fin5SkipHashUpdate()?.then(() => {
|
|
28
|
+
const frameParameters = getFin5HashFrameParameters();
|
|
29
|
+
frameParameters.set('url', frameParameters.get('url')?.split('#')[0] +
|
|
30
|
+
'#' +
|
|
31
|
+
hash +
|
|
32
|
+
queryParams);
|
|
33
|
+
getTopLocation().hash = `#${getTopLocation().hash.slice(1).split('?')[0]}?${frameParameters.toString()}`;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [location]);
|
|
37
|
+
};
|
|
38
|
+
const useSelectedRoutes = (pages, isSelectedRoute = (page, location) => location.pathname.includes(`/${page.key}`)) => {
|
|
39
|
+
const location = useLocation();
|
|
40
|
+
return useMemo(() => {
|
|
41
|
+
const flatPages = pageTreeToPageList(pages);
|
|
42
|
+
return flatPages
|
|
43
|
+
.filter((page) => isSelectedRoute(page, location))
|
|
44
|
+
.map((page) => page.key);
|
|
45
|
+
}, [location, pages]);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Basic layout that uses React Router.
|
|
49
|
+
*/
|
|
50
|
+
export const BasicLayout = ({ pages = [], compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, isSelectedRoute, }) => {
|
|
51
|
+
const navigate = useNavigate();
|
|
52
|
+
const selectedRoutes = useSelectedRoutes(pages, isSelectedRoute);
|
|
53
|
+
// manage mobile navigation
|
|
54
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
55
|
+
const [hiddenSider, setHiddenSider] = useState(false);
|
|
56
|
+
const siderWidth = siderProps?.width;
|
|
57
|
+
const classes = useStyles({ isMobile, compactSider, siderWidth });
|
|
58
|
+
const menuPages = useMemo(() => getMenuPages(pages), [pages]);
|
|
59
|
+
return (React.createElement(Layout, { hasSider: true, ...layoutProps },
|
|
60
|
+
isMobile && (React.createElement(Header, { ...mobileHeaderProps, className: classNames(classes.header, mobileHeaderProps?.className) }, hiddenSider ? (React.createElement(MenuUnfoldOutlined, { className: classes.menuTrigger, onClick: () => {
|
|
61
|
+
setHiddenSider(!hiddenSider);
|
|
62
|
+
} })) : (React.createElement(MenuFoldOutlined, { className: classes.menuTrigger, onClick: () => {
|
|
63
|
+
setHiddenSider(!hiddenSider);
|
|
64
|
+
} })))),
|
|
65
|
+
React.createElement(Sider, { ...siderProps, className: classNames(classes.sider, siderProps?.className), breakpoint: 'md', onBreakpoint: (broken) => {
|
|
66
|
+
setIsMobile(broken);
|
|
67
|
+
setHiddenSider(true);
|
|
68
|
+
}, collapsed: (isMobile && hiddenSider) || compactSider, collapsedWidth: isMobile && hiddenSider
|
|
69
|
+
? 0
|
|
70
|
+
: compactSider
|
|
71
|
+
? HEADER_HEIGHT
|
|
72
|
+
: 0, trigger: null },
|
|
73
|
+
React.createElement(Menu, { ...menuProps, items: menuPages, selectedKeys: selectedRoutes, onSelect: ({ key }) => {
|
|
74
|
+
if (!hiddenSider) {
|
|
75
|
+
setHiddenSider(true);
|
|
76
|
+
}
|
|
77
|
+
navigate(key);
|
|
78
|
+
} })),
|
|
79
|
+
React.createElement(Content, { ...contentProps, className: classNames(classes.content, contentProps?.className) },
|
|
80
|
+
React.createElement(Outlet, null))));
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=BasicLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BasicLayout.js","sourceRoot":"","sources":["../../../../../src/react/components/nav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AAM,CAAC,CAAA;gBACnB,cAAc,CAAC,IAAI,CAAC,CAAA;YACrB,CAAC,EACD,SAAS,EAAE,CAAC,QAAQ,IAAI,WAAW,CAAC,IAAI,YAAY,EACpD,cAAc,EACb,QAAQ,IAAI,WAAW;gBACtB,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,aAAa;oBACf,CAAC,CAAC,CAAC,EAEL,OAAO,EAAE,IAAI;YACb,oBAAC,IAAI,OACA,SAAS,EACb,KAAK,EAAE,SAAS,EAChB,YAAY,EAAE,cAAc,EAC5B,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE;oBACrB,IAAI,CAAC,WAAW,EAAE;wBACjB,cAAc,CAAC,IAAI,CAAC,CAAA;qBACpB;oBACD,QAAQ,CAAC,GAAG,CAAC,CAAA;gBACd,CAAC,GACA,CACK;QACR,oBAAC,OAAO,OACH,YAAY,EAChB,SAAS,EAAE,UAAU,CACpB,OAAO,CAAC,OAAO,EACf,YAAY,EAAE,SAAS,CACvB;YACD,oBAAC,MAAM,OAAG,CACD,CACF,CACT,CAAA;AACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Location } from '@remix-run/router';
|
|
2
|
+
import { LayoutProps, MenuProps, SiderProps } from 'antd';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { MenuPage } from '../MenuPage';
|
|
5
|
+
export interface ReactRouterBasicLayoutProps {
|
|
6
|
+
pages?: MenuPage[];
|
|
7
|
+
defaultPage?: string;
|
|
8
|
+
compactSider?: boolean;
|
|
9
|
+
layoutProps?: LayoutProps;
|
|
10
|
+
mobileHeaderProps?: LayoutProps;
|
|
11
|
+
siderProps?: SiderProps;
|
|
12
|
+
contentProps?: LayoutProps;
|
|
13
|
+
menuProps?: Omit<MenuProps, 'items' | 'selectedKeys' | 'onSelect'>;
|
|
14
|
+
isSelectedRoute?: (page: MenuPage, location: Location) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This hook can be used with react-router/BasicLayout,
|
|
18
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
19
|
+
*/
|
|
20
|
+
export declare const useLocationUpdate: () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Basic layout that uses React Router.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ReactRouterBasicLayout: React.FC<ReactRouterBasicLayoutProps>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons';
|
|
5
|
+
import { Layout, Menu } from '@j2inn/ui';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { Outlet, useLocation, useNavigate } from 'react-router';
|
|
9
|
+
import { IN_IFRAME, fin5SkipHashUpdate, getFin5HashFrameParameters, getTopLocation, } from '../../../../fin5Top/useFin5AppURLHashParameter';
|
|
10
|
+
import { HEADER_HEIGHT, getMenuPages, useStyles } from '../BasicLayout';
|
|
11
|
+
import { pageTreeToPageList } from '../MenuPage';
|
|
12
|
+
// Workaround j2inn/ui exporting problem
|
|
13
|
+
const Header = Layout.Header;
|
|
14
|
+
const Sider = Layout.Sider;
|
|
15
|
+
const Content = Layout.Content;
|
|
16
|
+
/**
|
|
17
|
+
* This hook can be used with react-router/BasicLayout,
|
|
18
|
+
* to ensure FIN5 URL is aligned with the internal frame URL.
|
|
19
|
+
*/
|
|
20
|
+
export const useLocationUpdate = () => {
|
|
21
|
+
const location = useLocation();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
console.debug('Location changed', location);
|
|
24
|
+
const hash = location.pathname;
|
|
25
|
+
const queryParams = location.search;
|
|
26
|
+
if (IN_IFRAME) {
|
|
27
|
+
fin5SkipHashUpdate()?.then(() => {
|
|
28
|
+
const frameParameters = getFin5HashFrameParameters();
|
|
29
|
+
frameParameters.set('url', frameParameters.get('url')?.split('#')[0] +
|
|
30
|
+
'#' +
|
|
31
|
+
hash +
|
|
32
|
+
queryParams);
|
|
33
|
+
getTopLocation().hash = `#${getTopLocation().hash.slice(1).split('?')[0]}?${frameParameters.toString()}`;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [location]);
|
|
37
|
+
};
|
|
38
|
+
const useSelectedRoutes = (pages, isSelectedRoute = (page, location) => location.pathname.includes(`/${page.key}`)) => {
|
|
39
|
+
const location = useLocation();
|
|
40
|
+
return useMemo(() => {
|
|
41
|
+
const flatPages = pageTreeToPageList(pages);
|
|
42
|
+
return flatPages
|
|
43
|
+
.filter((page) => isSelectedRoute(page, location))
|
|
44
|
+
.map((page) => page.key);
|
|
45
|
+
}, [location, pages]);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Basic layout that uses React Router.
|
|
49
|
+
*/
|
|
50
|
+
export const ReactRouterBasicLayout = ({ pages = [], defaultPage, compactSider, layoutProps, mobileHeaderProps, siderProps, contentProps, menuProps, isSelectedRoute, }) => {
|
|
51
|
+
const navigate = useNavigate();
|
|
52
|
+
const selectedRoutes = useSelectedRoutes(pages, isSelectedRoute);
|
|
53
|
+
// manage mobile navigation
|
|
54
|
+
const [isMobile, setIsMobile] = useState(false);
|
|
55
|
+
const [hiddenSider, setHiddenSider] = useState(false);
|
|
56
|
+
const siderWidth = siderProps?.width;
|
|
57
|
+
const classes = useStyles({ isMobile, compactSider, siderWidth });
|
|
58
|
+
const menuPages = useMemo(() => getMenuPages(pages), [pages]);
|
|
59
|
+
return (React.createElement(Layout, { hasSider: true, ...layoutProps },
|
|
60
|
+
isMobile && (React.createElement(Header, { ...mobileHeaderProps, className: classNames(classes.header, mobileHeaderProps?.className) }, hiddenSider ? (React.createElement(MenuUnfoldOutlined, { className: classes.menuTrigger, onClick: () => {
|
|
61
|
+
setHiddenSider(!hiddenSider);
|
|
62
|
+
} })) : (React.createElement(MenuFoldOutlined, { className: classes.menuTrigger, onClick: () => {
|
|
63
|
+
setHiddenSider(!hiddenSider);
|
|
64
|
+
} })))),
|
|
65
|
+
React.createElement(Sider, { ...siderProps, className: classNames(classes.sider, siderProps?.className), breakpoint: 'md', onBreakpoint: (broken) => {
|
|
66
|
+
setIsMobile(broken);
|
|
67
|
+
setHiddenSider(true);
|
|
68
|
+
}, collapsed: (isMobile && hiddenSider) || compactSider, collapsedWidth: isMobile && hiddenSider
|
|
69
|
+
? 0
|
|
70
|
+
: compactSider
|
|
71
|
+
? HEADER_HEIGHT
|
|
72
|
+
: 0, trigger: null },
|
|
73
|
+
React.createElement(Menu, { ...menuProps, defaultSelectedKeys: defaultPage ? [defaultPage] : undefined, items: menuPages, selectedKeys: selectedRoutes, onSelect: ({ key }) => {
|
|
74
|
+
if (!hiddenSider) {
|
|
75
|
+
setHiddenSider(true);
|
|
76
|
+
}
|
|
77
|
+
navigate(key);
|
|
78
|
+
} })),
|
|
79
|
+
React.createElement(Content, { ...contentProps, className: classNames(classes.content, contentProps?.className) },
|
|
80
|
+
React.createElement(Outlet, null))));
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=ReactRouterBasicLayout.js.map
|