-
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
frontend/src/component/admin/instance-admin/InstanceAdmin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import AdminMenu from '../menu/AdminMenu'; | ||
import { InstanceStats } from './InstanceStats/InstanceStats'; | ||
|
||
export const InstanceAdmin = () => { | ||
return ( | ||
<div> | ||
<AdminMenu /> | ||
<InstanceStats /> | ||
</div> | ||
); | ||
}; |
82 changes: 82 additions & 0 deletions
82
frontend/src/component/admin/instance-admin/InstanceStats/InstanceStats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Save } from '@mui/icons-material'; | ||
import { Button, IconButton, Link, Table, TableBody, TableCell, TableHead, TableRow } from '@mui/material'; | ||
import { Box } from '@mui/system'; | ||
import { VFC } from 'react'; | ||
import { useInstanceStats } from '../../../../hooks/api/getters/useInstanceStats/useInstanceStats'; | ||
import { formatApiPath } from '../../../../utils/formatPath'; | ||
import { PageContent } from '../../../common/PageContent/PageContent'; | ||
import { PageHeader } from '../../../common/PageHeader/PageHeader'; | ||
|
||
export const InstanceStats: VFC = () => { | ||
const { stats, loading } = useInstanceStats(); | ||
|
||
|
||
let versionTitle; | ||
let version; | ||
|
||
if(stats?.versionEnterprise) { | ||
versionTitle = 'Unleash Enterprise version'; | ||
version = stats.versionEnterprise; | ||
} else { | ||
versionTitle = 'Unleash OSS version'; | ||
version = stats?.versionOSS; | ||
} | ||
|
||
|
||
|
||
const rows = [ | ||
{title: 'Instance Id', value: stats?.instanceId}, | ||
{title: versionTitle, value: version}, | ||
{title: 'Users', value: stats?.users}, | ||
{title: 'Feature toggles', value: stats?.featureToggles}, | ||
{title: 'Projects', value: stats?.projects}, | ||
{title: 'Environments', value: stats?.environments}, | ||
{title: 'Roles', value: stats?.roles}, | ||
{title: 'Groups', value: stats?.groups}, | ||
{title: 'Context fields', value: stats?.contextFields}, | ||
{title: 'Strategies', value: stats?.strategies}, | ||
]; | ||
|
||
if(stats?.versionEnterprise) { | ||
rows.push( | ||
{title: 'SAML enabled', value: stats?.SAMLenabled ? 'Yes' : 'No'}, | ||
{title: 'OIDC enabled', value: stats?.OIDCenabled ? 'Yes' : 'No'}, | ||
); | ||
} | ||
|
||
return ( | ||
<PageContent header={<PageHeader title="Instance Statistics" />}> | ||
<Box sx={{ display: 'grid', gap: 4 }}> | ||
<Table aria-label="Instance statistics"> | ||
<TableHead> | ||
<TableRow> | ||
<TableCell>Item</TableCell> | ||
<TableCell align="right">Value</TableCell> | ||
</TableRow> | ||
</TableHead> | ||
<TableBody> | ||
{rows.map(row => ( | ||
<TableRow > | ||
<TableCell component="th" scope="row">{row.title}</TableCell> | ||
<TableCell align="right">{row.value}</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
<span style={{ textAlign: 'center' }}> | ||
<Button | ||
startIcon={<Save />} | ||
aria-label="Download instance statistics" | ||
color="primary" | ||
variant="contained" | ||
target="_blank" | ||
href={formatApiPath('/api/admin/instance-admin/statistics/csv')} | ||
> | ||
Download | ||
</Button> | ||
</span> | ||
</Box> | ||
|
||
</PageContent> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend/src/hooks/api/getters/useInstanceStats/useInstanceStats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import useSWR from 'swr'; | ||
import { useMemo } from 'react'; | ||
import { formatApiPath } from 'utils/formatPath'; | ||
import handleErrorResponses from '../httpErrorResponseHandler'; | ||
|
||
interface InstanceStats { | ||
instanceId: string; | ||
timestamp: Date; | ||
versionOSS: string; | ||
versionEnterprise?: string; | ||
users: number; | ||
featureToggles: number; | ||
projects: number; | ||
contextFields: number; | ||
roles: number; | ||
groups: number; | ||
environments: number; | ||
segments: number; | ||
strategies: number; | ||
SAMLenabled: boolean; | ||
OIDCenabled: boolean; | ||
} | ||
|
||
export interface IInstanceStatsResponse { | ||
stats?: InstanceStats; | ||
refetchGroup: () => void; | ||
loading: boolean; | ||
error?: Error; | ||
} | ||
|
||
export const mapGroupUsers = (users: any[]) => | ||
users.map(user => ({ | ||
...user.user, | ||
joinedAt: new Date(user.joinedAt), | ||
})); | ||
|
||
export const useInstanceStats = (): IInstanceStatsResponse => { | ||
const { data, error, mutate } = useSWR( | ||
formatApiPath(`api/admin/instance-admin/statistics`), | ||
fetcher | ||
); | ||
|
||
return useMemo( | ||
() => ({ | ||
stats: data, | ||
loading: !error && !data, | ||
refetchGroup: () => mutate(), | ||
error, | ||
}), | ||
[data, error, mutate] | ||
); | ||
}; | ||
|
||
const fetcher = (path: string) => { | ||
return fetch(path) | ||
.then(handleErrorResponses('Instance Stats')) | ||
.then(res => res.json()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters