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
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import { CheckBox, Table, Tag, Pagination, TableHead, TableRow, TableCell, TableBody } from '@rocket.chat/fuselage';
|
|
import type { Dispatch, SetStateAction, ChangeEvent } from 'react';
|
|
import { useState, useCallback } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import type { ChannelDescriptor } from './ChannelDescriptor';
|
|
|
|
export type PrepareChannelsProps = {
|
|
channelsCount: number;
|
|
channels: ChannelDescriptor[];
|
|
setChannels: Dispatch<SetStateAction<ChannelDescriptor[]>>;
|
|
};
|
|
|
|
// TODO: review inner logic
|
|
const PrepareChannels = ({ channels, channelsCount, setChannels }: PrepareChannelsProps) => {
|
|
const { t } = useTranslation();
|
|
const [current, setCurrent] = useState(0);
|
|
const [itemsPerPage, setItemsPerPage] = useState<25 | 50 | 100>(25);
|
|
const showingResultsLabel = useCallback(
|
|
({ count, current, itemsPerPage }: { count: number; current: number; itemsPerPage: 25 | 50 | 100 }) =>
|
|
t('Showing_results_of', { from: current + 1, to: Math.min(current + itemsPerPage, count), total: count }),
|
|
[t],
|
|
);
|
|
const itemsPerPageLabel = useCallback(() => t('Items_per_page:'), [t]);
|
|
|
|
if (!channels.length) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Table>
|
|
<TableHead>
|
|
<TableRow>
|
|
<TableCell width='x36'>
|
|
<CheckBox
|
|
checked={channelsCount > 0}
|
|
indeterminate={channelsCount > 0 && channelsCount !== channels.length}
|
|
onChange={(): void => {
|
|
setChannels((channels) => {
|
|
const hasCheckedArchivedChannels = channels.some(({ is_archived, do_import }) => is_archived && do_import);
|
|
const isChecking = channelsCount === 0;
|
|
|
|
if (isChecking) {
|
|
return channels.map((channel) => ({ ...channel, do_import: true }));
|
|
}
|
|
|
|
if (hasCheckedArchivedChannels) {
|
|
return channels.map((channel) => (channel.is_archived ? { ...channel, do_import: false } : channel));
|
|
}
|
|
|
|
return channels.map((channel) => ({ ...channel, do_import: false }));
|
|
});
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
<TableCell is='th'>{t('Name')}</TableCell>
|
|
<TableCell is='th' align='end'></TableCell>
|
|
</TableRow>
|
|
</TableHead>
|
|
<TableBody>
|
|
{channels.slice(current, current + itemsPerPage).map((channel) => (
|
|
<TableRow key={channel.channel_id}>
|
|
<TableCell width='x36'>
|
|
<CheckBox
|
|
checked={channel.do_import}
|
|
onChange={(event: ChangeEvent<HTMLInputElement>): void => {
|
|
const { checked } = event.currentTarget;
|
|
setChannels((channels) =>
|
|
channels.map((_channel) => (_channel === channel ? { ..._channel, do_import: checked } : _channel)),
|
|
);
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
<TableCell>{channel.name}</TableCell>
|
|
<TableCell align='end'>{channel.is_archived && <Tag variant='danger'>{t('Importer_Archived')}</Tag>}</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
</Table>
|
|
<Pagination
|
|
current={current}
|
|
itemsPerPage={itemsPerPage}
|
|
itemsPerPageLabel={itemsPerPageLabel}
|
|
showingResultsLabel={showingResultsLabel}
|
|
count={channels.length || 0}
|
|
onSetItemsPerPage={setItemsPerPage}
|
|
onSetCurrent={setCurrent}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default PrepareChannels;
|