Skip to content

Commit

Permalink
feat: licensed users chart
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Nov 25, 2024
1 parent b4bf68a commit 12a47b0
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import type { FC } from 'react';
import 'chartjs-adapter-date-fns';
import type { LicensedUsersSchema } from 'openapi';
import { LineChart } from 'component/insights/components/LineChart/LineChart';
import { useTheme } from '@mui/material';

interface ILicensedUsersChartProps {
licensedUsers: LicensedUsersSchema['licensedUsers']['history'];
}

export const LicensedUsersChart: FC<ILicensedUsersChartProps> = ({
licensedUsers,
}) => {
const theme = useTheme();

const data = {
datasets: [
{
label: 'Licensed users',
data: licensedUsers,
borderColor: theme.palette.primary.main,
backgroundColor: theme.palette.primary.main,
fill: false,
},
],
};
return (
<LineChart
data={data}
overrideOptions={{
parsing: {
yAxisKey: 'count',
xAxisKey: 'date',
},
scales: {
y: {
beginAtZero: true,
type: 'linear',
grid: {
color: theme.palette.divider,
borderColor: theme.palette.divider,
},
ticks: {
color: theme.palette.text.secondary,
display: true,
precision: 0,
},
},
x: {
type: 'time',
time: {
unit: 'month',
tooltipFormat: 'MMM yyyy',
displayFormats: {
month: 'MMM',
},
},
grid: {
color: 'transparent',
borderColor: 'transparent',
},
ticks: {
color: theme.palette.text.secondary,
display: true,
source: 'data',
maxRotation: 90,
minRotation: 23.5,
},
},
},
}}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Alert, Button, styled, Typography } from '@mui/material';
import { DynamicSidebarModal } from 'component/common/SidebarModal/SidebarModal';
import type React from 'react';
import { LicensedUsersChart } from './LicensedUsersChart';
import { useLicensedUsers } from '../../../../hooks/useLicensedUsers';
const ModalContentContainer = styled('section')(({ theme }) => ({
minHeight: '100vh',
maxWidth: 700,
Expand Down Expand Up @@ -74,6 +76,7 @@ export const LicensedUsersSidebar = ({
open,
close,
}: LicensedUsersSidebarProps) => {
const { data } = useLicensedUsers();
return (
<DynamicSidebarModal
open={open}
Expand All @@ -94,7 +97,10 @@ export const LicensedUsersSidebar = ({
<RowHeader>Last 30 days</RowHeader>
<InfoRow>
<LicenceBox>
<Typography fontWeight='bold'>11/25</Typography>
<Typography fontWeight='bold'>
{data.licensedUsers.current}/
{data.seatCount}
</Typography>
<Typography variant='body2'>
Used seats last 30 days
</Typography>
Expand All @@ -108,7 +114,9 @@ export const LicensedUsersSidebar = ({
</Row>
<Row>
<RowHeader>Last year</RowHeader>
<div>this will be great grid</div>
<LicensedUsersChart
licensedUsers={data.licensedUsers.history}
/>
</Row>
</WidgetContainer>
<CloseRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const StyledElement = styled(Box)(({ theme }) => ({
export const UsersHeader = () => {
const licensedUsers = useUiFlag('licensedUsers');
const { isOss } = useUiConfig();
const licensedUsersEnabled = licensedUsers && !isOss();
const licensedUsersEnabled = true;

return (
<StyledContainer licensedUsersEnabled={licensedUsersEnabled}>
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/hooks/useLicensedUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { LicensedUsersSchema } from '../openapi';
import { useApiGetter, fetcher } from './api/getters/useApiGetter/useApiGetter';
import { formatApiPath } from '../utils/formatPath';

const path = `api/admin/licensed-users`;

const placeholderData: LicensedUsersSchema = {
seatCount: 0,
licensedUsers: {
current: 0,
history: [],
},
};

export const useLicensedUsers = () => {
const { data, refetch, loading, error } = useApiGetter<LicensedUsersSchema>(
formatApiPath(path),
() => fetcher(formatApiPath(path), 'Licensed users'),
);

return { data: data || placeholderData, refetch, loading, error };
};

0 comments on commit 12a47b0

Please sign in to comment.