Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
135 lines
4.3 KiB
TypeScript
135 lines
4.3 KiB
TypeScript
import { Icon, Margins, Pagination, Skeleton, Table, TableBody, TableCell, TableHead, TableRow, Tile } from '@rocket.chat/fuselage';
|
||
import { format } from 'date-fns';
|
||
import { useMemo, useState } from 'react';
|
||
import { useTranslation } from 'react-i18next';
|
||
|
||
import { useChannelsList } from './useChannelsList';
|
||
import DownloadDataButton from '../../../../components/dashboards/DownloadDataButton';
|
||
import PeriodSelector from '../../../../components/dashboards/PeriodSelector';
|
||
import { usePeriodSelectorState } from '../../../../components/dashboards/usePeriodSelectorState';
|
||
import Growth from '../../../../components/dataView/Growth';
|
||
import EngagementDashboardCardFilter from '../EngagementDashboardCardFilter';
|
||
|
||
const ChannelsOverview = () => {
|
||
const [period, periodSelectorProps] = usePeriodSelectorState('last 7 days', 'last 30 days', 'last 90 days');
|
||
|
||
const { t } = useTranslation();
|
||
|
||
const [current, setCurrent] = useState(0);
|
||
const [itemsPerPage, setItemsPerPage] = useState<25 | 50 | 100>(25);
|
||
|
||
const { data } = useChannelsList({
|
||
period,
|
||
offset: current,
|
||
count: itemsPerPage,
|
||
});
|
||
|
||
const channels = useMemo(() => {
|
||
if (!data) {
|
||
return;
|
||
}
|
||
|
||
return data?.channels?.map(({ room: { t, name, usernames, ts, _updatedAt }, messages, diffFromLastWeek }) => ({
|
||
t,
|
||
name: name || usernames?.join(' × '),
|
||
createdAt: ts,
|
||
updatedAt: _updatedAt,
|
||
messagesCount: messages,
|
||
messagesVariation: diffFromLastWeek,
|
||
}));
|
||
}, [data]);
|
||
|
||
return (
|
||
<>
|
||
<EngagementDashboardCardFilter>
|
||
<PeriodSelector {...periodSelectorProps} />
|
||
<DownloadDataButton
|
||
attachmentName={`Channels_start_${data?.start}_end_${data?.end}`}
|
||
headers={['Room type', 'Name', 'Messages', 'Last Update Date', 'Creation Date']}
|
||
dataAvailable={!!data}
|
||
dataExtractor={(): unknown[][] | undefined =>
|
||
data?.channels?.map(({ room: { t, name, usernames, ts, _updatedAt }, messages }) => [
|
||
t,
|
||
name || usernames?.join(' × '),
|
||
messages,
|
||
_updatedAt,
|
||
ts,
|
||
])
|
||
}
|
||
/>
|
||
</EngagementDashboardCardFilter>
|
||
<div>
|
||
{channels && !channels.length && (
|
||
<Tile fontScale='p1' color='hint' style={{ textAlign: 'center' }}>
|
||
{t('No_data_found')}
|
||
</Tile>
|
||
)}
|
||
{(!channels || channels.length) && (
|
||
<Table>
|
||
<TableHead>
|
||
<TableRow>
|
||
<TableCell>#</TableCell>
|
||
<TableCell>{t('Channel')}</TableCell>
|
||
<TableCell>{t('Created')}</TableCell>
|
||
<TableCell>{t('Last_active')}</TableCell>
|
||
<TableCell>{t('Messages_sent')}</TableCell>
|
||
</TableRow>
|
||
</TableHead>
|
||
<TableBody>
|
||
{channels?.map(({ t, name, createdAt, updatedAt, messagesCount, messagesVariation }, i) => (
|
||
<TableRow key={i}>
|
||
<TableCell>{i + 1}.</TableCell>
|
||
<TableCell>
|
||
<Margins inlineEnd={4}>
|
||
{(t === 'd' && <Icon name='at' />) || (t === 'p' && <Icon name='lock' />) || (t === 'c' && <Icon name='hashtag' />)}
|
||
</Margins>
|
||
{name}
|
||
</TableCell>
|
||
<TableCell>{format(new Date(createdAt ?? new Date()), 'P')}</TableCell>
|
||
<TableCell>{format(new Date(updatedAt ?? new Date()), 'P')}</TableCell>
|
||
<TableCell>
|
||
{messagesCount} <Growth>{messagesVariation}</Growth>
|
||
</TableCell>
|
||
</TableRow>
|
||
))}
|
||
{!channels &&
|
||
Array.from({ length: 5 }, (_, i) => (
|
||
<TableRow key={i}>
|
||
<TableCell>
|
||
<Skeleton width='100%' />
|
||
</TableCell>
|
||
<TableCell>
|
||
<Skeleton width='100%' />
|
||
</TableCell>
|
||
<TableCell>
|
||
<Skeleton width='100%' />
|
||
</TableCell>
|
||
<TableCell>
|
||
<Skeleton width='100%' />
|
||
</TableCell>
|
||
<TableCell>
|
||
<Skeleton width='100%' />
|
||
</TableCell>
|
||
</TableRow>
|
||
))}
|
||
</TableBody>
|
||
</Table>
|
||
)}
|
||
<Pagination
|
||
current={current}
|
||
itemsPerPage={itemsPerPage}
|
||
itemsPerPageLabel={(): string => t('Items_per_page:')}
|
||
showingResultsLabel={({ count, current, itemsPerPage }): string =>
|
||
t('Showing_results_of', { from: current + 1, to: Math.min(current + itemsPerPage, count), total: count })
|
||
}
|
||
count={data?.total || 0}
|
||
onSetItemsPerPage={setItemsPerPage}
|
||
onSetCurrent={setCurrent}
|
||
/>
|
||
</div>
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default ChannelsOverview;
|