Skip to content

Commit

Permalink
[IMPROVE] Rewrite Federation Dashboard (#17900)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored Jun 13, 2020
1 parent ed7eca5 commit ac987a1
Show file tree
Hide file tree
Showing 35 changed files with 384 additions and 380 deletions.
141 changes: 0 additions & 141 deletions app/federation/client/admin/dashboard.css

This file was deleted.

32 changes: 0 additions & 32 deletions app/federation/client/admin/dashboard.html

This file was deleted.

85 changes: 0 additions & 85 deletions app/federation/client/admin/dashboard.js

This file was deleted.

1 change: 0 additions & 1 deletion app/federation/client/index.js

This file was deleted.

23 changes: 23 additions & 0 deletions client/admin/federationDashboard/FederationDashboardPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Box } from '@rocket.chat/fuselage';
import React from 'react';

import Page from '../../components/basic/Page';
import { useTranslation } from '../../contexts/TranslationContext';
import OverviewSection from './OverviewSection';
import ServersSection from './ServersSection';

function FederationDashboardPage() {
const t = useTranslation();

return <Page>
<Page.Header title={t('Federation_Dashboard')} />
<Page.ScrollableContentWithShadow>
<Box margin='x24'>
<OverviewSection />
<ServersSection />
</Box>
</Page.ScrollableContentWithShadow>
</Page>;
}

export default FederationDashboardPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

import FederationDashboardPage from './FederationDashboardPage';

export default {
title: 'admin/federationDashboard/FederationDashboardPage',
component: FederationDashboardPage,
};

export const Default = () => <FederationDashboardPage />;
17 changes: 17 additions & 0 deletions client/admin/federationDashboard/FederationDashboardRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React, { FC } from 'react';

import { useRole } from '../../contexts/AuthorizationContext';
import NotAuthorizedPage from '../NotAuthorizedPage';
import FederationDashboardPage from './FederationDashboardPage';

const FederationDashboardRoute: FC<{}> = () => {
const authorized = useRole('admin');

if (!authorized) {
return <NotAuthorizedPage />;
}

return <FederationDashboardPage />;
};

export default FederationDashboardRoute;
40 changes: 40 additions & 0 deletions client/admin/federationDashboard/OverviewSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Box, Skeleton } from '@rocket.chat/fuselage';
import React from 'react';

import { useTranslation } from '../../contexts/TranslationContext';
import CounterSet from '../../components/data/CounterSet';
import { usePolledMethodData, AsyncState } from '../../contexts/ServerContext';

function OverviewSection() {
const t = useTranslation();
const [overviewData, overviewStatus] = usePolledMethodData('federation:getOverviewData', [], 10000);

const eventCount = (overviewStatus === AsyncState.LOADING && <Skeleton variant='text' />)
|| (overviewStatus === AsyncState.ERROR && <Box color='danger'>Error</Box>)
|| overviewData?.data[0]?.value;
const userCount = (overviewStatus === AsyncState.LOADING && <Skeleton variant='text' />)
|| (overviewStatus === AsyncState.ERROR && <Box color='danger'>Error</Box>)
|| overviewData?.data[1]?.value;
const serverCount = (overviewStatus === AsyncState.LOADING && <Skeleton variant='text' />)
|| (overviewStatus === AsyncState.ERROR && <Box color='danger'>Error</Box>)
|| overviewData?.data[2]?.value;

return <CounterSet
counters={[
{
count: eventCount,
description: t('Number_of_events'),
},
{
count: userCount,
description: t('Number_of_federated_users'),
},
{
count: serverCount,
description: t('Number_of_federated_servers'),
},
]}
/>;
}

export default OverviewSection;
10 changes: 10 additions & 0 deletions client/admin/federationDashboard/OverviewSection.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

import OverviewSection from './OverviewSection';

export default {
title: 'admin/federationDashboard/OverviewSection',
component: OverviewSection,
};

export const Default = () => <OverviewSection />;
26 changes: 26 additions & 0 deletions client/admin/federationDashboard/ServersSection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Box, Throbber } from '@rocket.chat/fuselage';
import React from 'react';

import { usePolledMethodData, AsyncState } from '../../contexts/ServerContext';

function ServersSection() {
const [serversData, serversStatus] = usePolledMethodData('federation:getServers', [], 10000);

if (serversStatus === AsyncState.LOADING) {
return <Throbber align='center' />;
}

if (serversData?.data?.length === 0) {
return null;
}

return <Box withRichContent>
<ul>
{serversData?.data?.map(({ domain }) => (
<li key={domain}>{domain}</li>
))}
</ul>
</Box>;
}

export default ServersSection;
Loading

0 comments on commit ac987a1

Please sign in to comment.