@campxdev/shared 1.11.39 → 1.11.41
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campxdev/shared",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.41",
|
|
4
4
|
"main": "./exports.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "react-scripts start",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"react-table": "^7.8.0",
|
|
57
57
|
"react-toastify": "^9.0.1",
|
|
58
58
|
"styled-components": "^5.3.5",
|
|
59
|
+
"@mongodb-js/charts-embed-dom": "3.2.1",
|
|
59
60
|
"swiper": "^8.1.5",
|
|
60
61
|
"typescript": "^5.2.2",
|
|
61
62
|
"use-immer": "^0.8.1",
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import ChartsEmbedSDK from '@mongodb-js/charts-embed-dom'
|
|
2
|
+
import { useEffect, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
interface DashboardProps {
|
|
5
|
+
token: any
|
|
6
|
+
dashboardId: string
|
|
7
|
+
charts: any
|
|
8
|
+
chartFilters: any
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const MongoDashboard: React.FC<DashboardProps> = ({
|
|
12
|
+
token,
|
|
13
|
+
dashboardId,
|
|
14
|
+
charts,
|
|
15
|
+
chartFilters,
|
|
16
|
+
}) => {
|
|
17
|
+
const [rendered, setRendered] = useState<Boolean>(false)
|
|
18
|
+
const [dashboard, setDashboard] = useState<any>(null)
|
|
19
|
+
const chartDiv = useRef(null)
|
|
20
|
+
|
|
21
|
+
const sdk = new ChartsEmbedSDK({
|
|
22
|
+
baseUrl: 'https://charts.mongodb.com/charts-project-0-cnovv',
|
|
23
|
+
getUserToken: () => token,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const initDashboard = async () => {
|
|
28
|
+
const dashboard = sdk.createDashboard({
|
|
29
|
+
dashboardId: dashboardId,
|
|
30
|
+
showAttribution: false,
|
|
31
|
+
background: 'transparent',
|
|
32
|
+
widthMode: 'scale',
|
|
33
|
+
heightMode: 'scale',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
setDashboard(dashboard)
|
|
37
|
+
try {
|
|
38
|
+
await dashboard.render(chartDiv.current)
|
|
39
|
+
|
|
40
|
+
setRendered(true)
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log('Error during Charts rendering:', err)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
initDashboard()
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (dashboard && rendered) {
|
|
51
|
+
const applyFiltersToChart = async () => {
|
|
52
|
+
charts.map((chartGroup, index) => {
|
|
53
|
+
chartGroup.map(async (chartId) => {
|
|
54
|
+
const chart = await dashboard.getChart(chartId)
|
|
55
|
+
console.log(chartFilters[index], chart)
|
|
56
|
+
try {
|
|
57
|
+
await chart.setFilter(chartFilters[index])
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.log(
|
|
60
|
+
'Error while applying filters to specific chart.',
|
|
61
|
+
err,
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// charts.default.map(async (chartId) => {
|
|
68
|
+
// const chart = await dashboard.getChart(chartId)
|
|
69
|
+
|
|
70
|
+
// try {
|
|
71
|
+
// await chart.setFilter(filters)
|
|
72
|
+
// } catch (err) {
|
|
73
|
+
// console.log('Error while applying filters to specific chart.', err)
|
|
74
|
+
// }
|
|
75
|
+
// })
|
|
76
|
+
|
|
77
|
+
// charts.lessThanAcademicYear.map(async (chartId) => {
|
|
78
|
+
// const chart = await dashboard.getChart(chartId)
|
|
79
|
+
|
|
80
|
+
// try {
|
|
81
|
+
// await chart.setFilter({
|
|
82
|
+
// ...filters,
|
|
83
|
+
// academicYear: { $lt: filters.academicYear },
|
|
84
|
+
// })
|
|
85
|
+
// } catch (err) {
|
|
86
|
+
// console.log('Error while applying filters to specific chart.', err)
|
|
87
|
+
// }
|
|
88
|
+
// })
|
|
89
|
+
|
|
90
|
+
// charts.lessThanOrEqualAcademicYear.map(async (chartId) => {
|
|
91
|
+
// const chart = await dashboard.getChart(chartId)
|
|
92
|
+
|
|
93
|
+
// try {
|
|
94
|
+
// await chart.setFilter({
|
|
95
|
+
// ...filters,
|
|
96
|
+
// academicYear: { $lte: filters.academicYear },
|
|
97
|
+
// })
|
|
98
|
+
// } catch (err) {
|
|
99
|
+
// console.log('Error while applying filters to specific chart.', err)
|
|
100
|
+
// }
|
|
101
|
+
// })
|
|
102
|
+
|
|
103
|
+
// charts.dateRangeByAcademicYear.map(async (chartId) => {
|
|
104
|
+
// const chart = await dashboard.getChart(chartId)
|
|
105
|
+
|
|
106
|
+
// try {
|
|
107
|
+
// await chart.setFilter({
|
|
108
|
+
// 'admissionSubValue.tenantId':
|
|
109
|
+
// filters['admissionSubValue.tenantId'],
|
|
110
|
+
// 'admissionSubValue.institutionId':
|
|
111
|
+
// filters['admissionSubValue.institutionId'],
|
|
112
|
+
// 'feeTypeObject.feeType': filters['feeTypeObject.feeType'],
|
|
113
|
+
// createdAt: {
|
|
114
|
+
// $gte: startDate,
|
|
115
|
+
// $lte: endDate,
|
|
116
|
+
// },
|
|
117
|
+
// })
|
|
118
|
+
// } catch (err) {
|
|
119
|
+
// console.log('Error while applying filters to specific chart.', err)
|
|
120
|
+
// }
|
|
121
|
+
// })
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
applyFiltersToChart()
|
|
125
|
+
}
|
|
126
|
+
}, [dashboard, chartFilters, rendered])
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div
|
|
130
|
+
className="chart"
|
|
131
|
+
ref={chartDiv}
|
|
132
|
+
style={{
|
|
133
|
+
height: '200vh',
|
|
134
|
+
margin: '25px 10px',
|
|
135
|
+
backgroundColor: '#EEEE',
|
|
136
|
+
padding: '15px 0px',
|
|
137
|
+
borderRadius: '10px',
|
|
138
|
+
}}
|
|
139
|
+
/>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default MongoDashboard
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './MongoDashboard'
|
|
@@ -27,14 +27,14 @@ export default function TabsContainer({
|
|
|
27
27
|
tabMobileUnderlineColor,
|
|
28
28
|
currentTabIndex = 0,
|
|
29
29
|
}: TabsContainerProps) {
|
|
30
|
-
const [currentTab, setCurrentTab] = useState(tabs[currentTabIndex]
|
|
30
|
+
const [currentTab, setCurrentTab] = useState(tabs[currentTabIndex]?.key)
|
|
31
31
|
|
|
32
32
|
const handleTabsChange = (_event: ChangeEvent<{}>, value: string): void => {
|
|
33
33
|
setCurrentTab(value)
|
|
34
34
|
onTabChange && onTabChange(value)
|
|
35
35
|
}
|
|
36
36
|
useEffect(() => {
|
|
37
|
-
setCurrentTab(tabs[currentTabIndex]
|
|
37
|
+
setCurrentTab(tabs[currentTabIndex]?.key)
|
|
38
38
|
}, [])
|
|
39
39
|
|
|
40
40
|
return (
|
|
@@ -53,9 +53,9 @@ export default function TabsContainer({
|
|
|
53
53
|
>
|
|
54
54
|
{tabs.map((tab) => (
|
|
55
55
|
<Tab
|
|
56
|
-
key={tab
|
|
56
|
+
key={tab?.key}
|
|
57
57
|
label={tab.label}
|
|
58
|
-
value={tab
|
|
58
|
+
value={tab?.key}
|
|
59
59
|
icon={tab.highlight ? <span>{'.'}</span> : null}
|
|
60
60
|
iconPosition="end"
|
|
61
61
|
/>
|
|
@@ -63,7 +63,7 @@ export default function TabsContainer({
|
|
|
63
63
|
</StyledTabs>
|
|
64
64
|
<StyledComponentWrapper containerVariant={containerVariant}>
|
|
65
65
|
<ErrorBoundary>
|
|
66
|
-
{tabs.find((tab) => tab
|
|
66
|
+
{tabs.find((tab) => tab?.key === currentTab)?.component}
|
|
67
67
|
</ErrorBoundary>
|
|
68
68
|
</StyledComponentWrapper>
|
|
69
69
|
</StyledContainer>
|
package/src/components/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { DialogButton, DrawerButton } from './ModalButtons'
|
|
|
27
27
|
import { CustomDialog } from './ModalButtons/DialogButton'
|
|
28
28
|
import { CustomDrawer } from './ModalButtons/DrawerButton'
|
|
29
29
|
import PopoverButton from './ModalButtons/PopoverButton'
|
|
30
|
+
import MongoDashboard from './MongoCharts'
|
|
30
31
|
import PageNotFound from './PageNotFound'
|
|
31
32
|
import ReactJoyRide from './ReactJoyRide'
|
|
32
33
|
import ResetPassword from './ResetPassword'
|
|
@@ -95,6 +96,7 @@ export {
|
|
|
95
96
|
LayoutWrapper,
|
|
96
97
|
ListItemButton,
|
|
97
98
|
LoginForm,
|
|
99
|
+
MongoDashboard,
|
|
98
100
|
NavigationTabs,
|
|
99
101
|
PageNotFound,
|
|
100
102
|
PopoverButton,
|