Skip to content

Commit

Permalink
feat: put MAU under admin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed Mar 3, 2022
1 parent 6aa59af commit bed0fa5
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 64 deletions.
3 changes: 2 additions & 1 deletion admin-ui/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"scripts": "Scripts",
"services": "Services",
"settings": "Settings",
"signout": "Sign out"
"signout": "Sign out",
"maugraph": "MAU"
},
"messages": {
"action_commit_question": "Audit log: Want to apply changes made on this page?",
Expand Down
3 changes: 2 additions & 1 deletion admin-ui/app/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"scripts": "Scénarios",
"services": "Prestations de service",
"settings": "Paramètres",
"signout": "Déconnexion"
"signout": "Déconnexion",
"maugraph": "MAU"
},
"actions": {
"accept": "J'accepte",
Expand Down
3 changes: 2 additions & 1 deletion admin-ui/app/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"scripts": "Scripts",
"services": "Serviços",
"settings": "Configurações",
"signout": "Sair"
"signout": "Sair",
"maugraph": "MAU"
},
"actions": {
"accept": "Aceitar",
Expand Down
2 changes: 1 addition & 1 deletion admin-ui/app/redux/reducers/MauReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GET_MAU, GET_MAU_RESPONSE } from '../actions/types'
import reducerRegistry from './ReducerRegistry'
const INIT_STATE = {
stat: [],
loading: true,
loading: false,
}

const reducerName = 'mauReducer'
Expand Down
59 changes: 0 additions & 59 deletions admin-ui/app/routes/Dashboards/DashboardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import moment from 'moment'
import CustomBarGraph from './Grapths/CustomBarGraph'
import CustomLineChart from './Grapths/CustomLineChart'
import CustomBadgeRow from './Grapths/CustomBadgeRow'
import CustomPieGraph from './Grapths/CustomPieGraph'
import ActiveUsersGraph from './Grapths/ActiveUsersGraph'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
import GluuLoader from '../Apps/Gluu/GluuLoader'
import GluuViewWrapper from '../Apps/Gluu/GluuViewWrapper'
import { getMau } from '../../redux/actions/MauActions'
import { getClients } from '../../redux/actions/InitActions'
import applicationstyle from '../Apps/Gluu/styles/applicationstyle'
import GluuLabel from '../Apps/Gluu/GluuLabel'
import GluuRibbon from '../Apps/Gluu/GluuRibbon'
import {
Button,
Expand All @@ -22,7 +18,6 @@ import {
CardBody,
FormGroup,
Col,
Row,
} from '../../../app/components'
import {
hasBoth,
Expand Down Expand Up @@ -152,60 +147,6 @@ function DashboardPage({ statData, permissions, clients, loading, dispatch }) {
<FormGroup row />
<FormGroup row />
<CardBody>
<Row>
<Col sm={2}></Col>
<Col sm={10}>
<GluuLabel label="Select a date range" size="4" />
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
selectsStart
isClearable
startDate={startDate}
dateFormat="MM/yyyy"
showMonthYearPicker
endDate={endDate}
customInput={<CustomButton />}
/>
&nbsp;&nbsp;
<DatePicker
selected={endDate}
onChange={(date) => setEndDate(date)}
selectsEnd
isClearable
startDate={startDate}
endDate={endDate}
dateFormat="MM/yyyy"
showMonthYearPicker
minDate={startDate}
maxDate={new Date()}
customInput={<CustomButton />}
/>
&nbsp;&nbsp;
<Button
style={applicationstyle.customButtonStyle}
color="primary"
onClick={search}
>
<i className="fa fa-search mr-2"></i>
{t('actions.view')}
</Button>
</Col>
</Row>
<FormGroup row />
<FormGroup row />
<FormGroup row>
<Col sm={6}>
<ActiveUsersGraph data={doDataAugmentation(statData)} />
</Col>
<Col sm={6}>
<CustomPieGraph
data={statData.filter((entry) => entry.mau !== 0)}
dataKey="mau"
nameKey="month"
/>
</Col>
</FormGroup>
<FormGroup row>
<Col sm={6}>
<CustomBarGraph data={statData} />
Expand Down
206 changes: 206 additions & 0 deletions admin-ui/plugins/admin/components/MAU/MauGraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import React, { useState, useEffect } from 'react'
import { subMonths } from 'date-fns'
import moment from 'moment'
import CustomPieGraph from '../../../../app/routes/Dashboards/Grapths/CustomPieGraph'
import ActiveUsersGraph from '../../../../app/routes/Dashboards/Grapths/ActiveUsersGraph'
import DatePicker from 'react-datepicker'
import 'react-datepicker/dist/react-datepicker.css'
import GluuLoader from '../../../../app/routes/Apps/Gluu/GluuLoader'
import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
import { getMau } from '../../../../app/redux/actions/MauActions'
import { getClients } from '../../../../app/redux/actions/InitActions'
import applicationstyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle'
import GluuLabel from '../../../../app/routes/Apps/Gluu/GluuLabel'
import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon'
import {
Button,
Card,
CardFooter,
CardBody,
FormGroup,
Col,
Row,
} from '../../../../app/components'
import {
hasBoth,
buildPayload,
STAT_READ,
STAT_JANS_READ,
} from '../../../../app/utils/PermChecker'
import { useTranslation } from 'react-i18next'
import { connect } from 'react-redux'

function MauGraph({ statData, permissions, clients, loading, dispatch }) {
const { t } = useTranslation()
const [startDate, setStartDate] = useState(subMonths(new Date(), 3))
const [endDate, setEndDate] = useState(new Date())
const userAction = {}
const options = {}
useEffect(() => {
let count = 0
const interval = setInterval(() => {
if (statData.length === 0 && count < 2) {
search()
}
if (clients.length === 0 && count < 2) {
buildPayload(userAction, 'Fetch openid connect clients', {})
dispatch(getClients(userAction))
}
count++
}, 1000)
return () => clearInterval(interval)
}, [1000])

function search() {
options['month'] = getFormattedMonth()
buildPayload(userAction, 'GET MAU', options)
dispatch(getMau(userAction))
}

function doDataAugmentation(input) {
let stat = input
if (stat && stat.length >= 1) {
let flattendStat = stat.map((entry) => entry['month'])
let aRange = generateDateRange(moment(startDate), moment(endDate))
for (const ele of aRange) {
const currentMonth = getYearMonth(new Date(ele))
if (flattendStat.indexOf(parseInt(currentMonth, 10)) === -1) {
let newEntry = new Object()
newEntry['month'] = parseInt(getYearMonth(new Date(ele)), 10)
newEntry['mau'] = 0
newEntry['client_credentials_access_token_count'] = 0
newEntry['authz_code_access_token_count'] = 0
newEntry['authz_code_idtoken_count'] = 0
stat.push(newEntry)
}
}
return Array.from(new Set(stat)).sort(
(a, b) => parseInt(a.month, 10) - parseInt(b.month, 10),
)
}
return stat
}
function getYearMonth(date) {
return date.getFullYear() + getMonth(date)
}
function getFormattedMonth() {
return getYearMonth(startDate) + '%' + getYearMonth(endDate)
}
function getMonth(aDate) {
let value = String(aDate.getMonth() + 1)
if (value.length > 1) {
return value
} else {
return '0' + value
}
}

function generateDateRange(start, end) {
var result = []
while (start.isBefore(end)) {
result.push(start.format('YYYY-MM-01'))
start.add(1, 'month')
}
return result
}

const CustomButton = React.forwardRef(({ value, onClick }, ref) => (
<Button
color="primary"
outline
style={applicationstyle.customButtonStyle}
className="example-custom-input"
onClick={onClick}
ref={ref}
>
{value}
</Button>
))

return (
<GluuLoader blocking={loading}>
<GluuViewWrapper
canShow={hasBoth(permissions, STAT_READ, STAT_JANS_READ)}
>
<Card>
<GluuRibbon title={t('fields.monthly_active_users')} fromLeft />
<FormGroup row />
<FormGroup row />
<FormGroup row />
<FormGroup row />
<FormGroup row />
<FormGroup row />

<CardBody>
<Row>
<Col sm={2}></Col>
<Col sm={10}>
<GluuLabel label="Select a date range" size="4" />
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
selectsStart
isClearable
startDate={startDate}
dateFormat="MM/yyyy"
showMonthYearPicker
endDate={endDate}
customInput={<CustomButton />}
/>
&nbsp;&nbsp;
<DatePicker
selected={endDate}
onChange={(date) => setEndDate(date)}
selectsEnd
isClearable
startDate={startDate}
endDate={endDate}
dateFormat="MM/yyyy"
showMonthYearPicker
minDate={startDate}
maxDate={new Date()}
customInput={<CustomButton />}
/>
&nbsp;&nbsp;
<Button
style={applicationstyle.customButtonStyle}
color="primary"
onClick={search}
>
<i className="fa fa-search mr-2"></i>
{t('actions.view')}
</Button>
</Col>
</Row>
<FormGroup row />
<FormGroup row />
<FormGroup row>
<Col sm={6}>
<ActiveUsersGraph data={doDataAugmentation(statData)} />
</Col>
<Col sm={6}>
<CustomPieGraph
data={statData.filter((entry) => entry.mau !== 0)}
dataKey="mau"
nameKey="month"
/>
</Col>
</FormGroup>
</CardBody>
<CardFooter className="p-4 bt-0"></CardFooter>
</Card>
</GluuViewWrapper>
</GluuLoader>
)
}

const mapStateToProps = (state) => {
return {
statData: state.mauReducer.stat,
loading: state.mauReducer.loading,
clients: state.initReducer.clients,
permissions: state.authReducer.permissions,
}
}

export default connect(mapStateToProps)(MauGraph)
12 changes: 11 additions & 1 deletion admin-ui/plugins/admin/plugin-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ScriptListPage from './components/CustomScripts/ScriptListPage'
import CustomScriptAddPage from './components/CustomScripts/CustomScriptAddPage'
import CustomScriptEditPage from './components/CustomScripts/CustomScriptEditPage'
import SettingsPage from './components/Settings/SettingsPage'

import MauGraph from './components/MAU/MauGraph'
import scriptSaga from './redux/sagas/CustomScriptSaga'
import licenseDetailsSaga from './redux/sagas/LicenseDetailsSaga'
import apiRoleSaga from './redux/sagas/ApiRoleSaga'
Expand Down Expand Up @@ -67,6 +67,11 @@ const pluginMetadata = {
path: PLUGIN_BASE_APTH + '/scripts',
permission: SCRIPT_READ,
},
{
title: 'menus.maugraph',
path: PLUGIN_BASE_APTH + '/maugraph',
permission: ACR_READ,
},
{
title: 'menus.settings',
path: PLUGIN_BASE_APTH + '/settings',
Expand All @@ -76,6 +81,11 @@ const pluginMetadata = {
},
],
routes: [
{
component: MauGraph,
path: PLUGIN_BASE_APTH + '/maugraph',
permission: ACR_READ,
},
{
component: HealthPage,
path: PLUGIN_BASE_APTH + '/health',
Expand Down

0 comments on commit bed0fa5

Please sign in to comment.