Skip to content

Commit cd12f51

Browse files
syntrydymoabu
andauthored
chore(admin-ui): changes required in Admin UI (#2522)
* chore(admin-ui): changes required in Admin UI #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 * chore(admin-ui): apply code review #2518 --------- Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
1 parent 1a8da14 commit cd12f51

File tree

22 files changed

+668
-437
lines changed

22 files changed

+668
-437
lines changed

admin-ui/app/routes/Dashboards/Chart/DashboardChart.tsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// @ts-nocheck
2-
import React from 'react'
1+
import React, { useMemo } from 'react'
32
import {
43
XAxis,
54
YAxis,
@@ -11,51 +10,53 @@ import {
1110
CartesianGrid,
1211
} from 'recharts'
1312
import './styles.css'
14-
import { useSelector } from 'react-redux'
1513
import TooltipDesign from './TooltipDesign'
1614
import moment from 'moment'
1715
import customColors from '@/customColors'
16+
import type { DashboardChartProps, MauStatEntry } from '../types'
1817

19-
const DashboardChart = () => {
20-
const statData = useSelector((state) => state.mauReducer.stat)
21-
const startMonth = useSelector((state) => state.mauReducer.startMonth)
22-
const endMonth = useSelector((state) => state.mauReducer.endMonth)
18+
const DashboardChart = ({ statData, startMonth, endMonth }: DashboardChartProps) => {
19+
const augmentedData = useMemo(() => {
20+
if (!statData) {
21+
return []
22+
}
23+
24+
const dateStart = moment(startMonth, 'YYYYMM')
25+
const dateEnd = moment(endMonth, 'YYYYMM')
26+
27+
if (dateStart.isAfter(dateEnd, 'month')) {
28+
return []
29+
}
2330

24-
function doDataAugmentation(stat) {
25-
if (startMonth && endMonth) {
26-
const dateStart = moment(startMonth, 'YYYYMM')
27-
const dateEnd = moment(endMonth, 'YYYYMM')
28-
const prepareStat = []
29-
while (dateEnd > dateStart || dateStart.format('M') === dateEnd.format('M')) {
30-
const available = stat.filter((obj) => {
31-
return obj.month == dateStart.format('YYYYMM')
31+
let current = dateStart.clone()
32+
const byMonth = new Map<number, MauStatEntry>()
33+
statData.forEach((entry) => byMonth.set(entry.month, entry))
34+
const prepareStat: MauStatEntry[] = []
35+
36+
while (current.isSameOrBefore(dateEnd, 'month')) {
37+
const monthNum = parseInt(current.format('YYYYMM'), 10)
38+
const available = byMonth.get(monthNum)
39+
40+
if (available) {
41+
prepareStat.push(available)
42+
} else {
43+
prepareStat.push({
44+
month: monthNum,
45+
mau: 0,
46+
client_credentials_access_token_count: 0,
47+
authz_code_access_token_count: 0,
48+
authz_code_idtoken_count: 0,
3249
})
33-
if (available.length) {
34-
prepareStat.push(available[0])
35-
} else {
36-
const newEntry = new Object()
37-
newEntry['month'] = dateStart.format('YYYYMM')
38-
newEntry['mau'] = 0
39-
newEntry['client_credentials_access_token_count'] = 0
40-
newEntry['authz_code_access_token_count'] = 0
41-
newEntry['authz_code_idtoken_count'] = 0
42-
prepareStat.push(newEntry)
43-
}
44-
dateStart.add(1, 'month')
4550
}
46-
return prepareStat
47-
} else {
48-
return stat
51+
current = current.clone().add(1, 'month')
4952
}
50-
}
53+
54+
return prepareStat
55+
}, [statData, startMonth, endMonth])
5156

5257
return (
5358
<ResponsiveContainer debounce={300} width="100%" height="100%">
54-
<BarChart
55-
data={doDataAugmentation(statData)}
56-
margin={{ top: 5, right: 30, bottom: 5 }}
57-
height={400}
58-
>
59+
<BarChart data={augmentedData} margin={{ top: 5, right: 30, bottom: 5 }} height={400}>
5960
<XAxis dataKey={'month'} />
6061
<YAxis />
6162
<CartesianGrid strokeDasharray="3 3" />

admin-ui/app/routes/Dashboards/Chart/TooltipDesign.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
// @ts-nocheck
21
import React from 'react'
32
import { useTranslation } from 'react-i18next'
3+
import type { TooltipDesignProps } from '../types'
44

5-
function TooltipDesign({ payload }) {
5+
function TooltipDesign({ payload = [] }: TooltipDesignProps) {
66
const { t } = useTranslation()
7-
const objValues = {
7+
const objValues: Record<string, string> = {
88
client_credentials_access_token_count: t('tooltips.client_credentials_access_token_count'),
99
authz_code_access_token_count: t('tooltips.authz_code_access_token_count'),
1010
authz_code_idtoken_count: t('tooltips.authz_code_idtoken_count'),
1111
}
12+
1213
return (
1314
<div className="bg-white thumbnail p-2">
14-
{payload.length &&
15+
{payload.length > 0 &&
1516
payload.map((item, key) => {
1617
return (
1718
<div key={key} style={{ fontSize: '12px' }}>

0 commit comments

Comments
 (0)