Skip to content

Commit

Permalink
Columns customize (#1975)
Browse files Browse the repository at this point in the history
* Columns customization

Related issue: #1471
Related issue: #1832
Related issue: #1354
Related issue: #1929
  • Loading branch information
hillaliy authored Mar 23, 2024
1 parent 0677271 commit a74aa54
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
16 changes: 12 additions & 4 deletions public/locales/en/modules/torrents-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
"displayRatioWithFilter": {
"label": "Display filtered torrents list ratio",
"info": "If disabled, only the global ratio will be display. The global ratio will still use the labels if set"
},
"columns": {
"label": "Select columns to display",
"data": {
"down": "Down",
"up": "Up",
"eta": "ETA",
"progress": "Progress"
}
},
"nameColumnSize": {
"label": "Change the name column size"
}
}
},
Expand Down Expand Up @@ -84,10 +96,6 @@
"text": "Unable to communicate with your Torrent clients. Please check your configuration"
}
},
"loading": {
"title": "Loading",
"description": "Establishing a connection"
},
"popover": {
"introductionPrefix": "Managed by",
"metrics": {
Expand Down
14 changes: 14 additions & 0 deletions src/widgets/torrent/TorrentTile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: false,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -62,6 +64,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -100,6 +104,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -138,6 +144,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -192,6 +200,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -230,6 +240,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [
Expand Down Expand Up @@ -268,6 +280,8 @@ describe('TorrentTile', () => {
speedLimitOfActiveTorrents: 10,
displayStaleTorrents: true,
displayRatioWithFilter: false,
columns: [],
nameColumnSize: 0,
},
};
const torrents: NormalizedTorrent[] = [constructTorrent('HH', 'I am completed', true, 0, 0)];
Expand Down
44 changes: 21 additions & 23 deletions src/widgets/torrent/TorrentTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Center,
Flex,
Group,
Loader,
Popover,
Progress,
Stack,
Expand All @@ -16,7 +15,7 @@ import { IconFileDownload } from '@tabler/icons-react';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
import { MRT_TableContainer, useMantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
import { type MRT_ColumnDef, MRT_TableContainer, useMantineReactTable } from 'mantine-react-table';
import { useTranslation } from 'next-i18next';
import { useMemo } from 'react';
import { MIN_WIDTH_MOBILE } from '~/constants/constants';
Expand All @@ -29,6 +28,7 @@ import {

import { useGetDownloadClientsQueue } from '../download-speed/useGetNetworkSpeed';
import { defineWidget } from '../helper';
import { WidgetLoading } from '../loading';
import { IWidget } from '../widgets';
import { TorrentQueuePopover } from './TorrentQueueItem';

Expand Down Expand Up @@ -69,6 +69,18 @@ const definition = defineWidget({
defaultValue: true,
info: true,
},
columns: {
type: 'multi-select',
defaultValue: ['up', 'down', 'eta', 'progress'],
data: [{ value: 'up' }, { value: 'down' }, { value: 'eta' }, { value: 'progress' }],
},
nameColumnSize: {
type: 'slider',
defaultValue: 2,
min: 1,
max: 4,
step: 1,
},
},
gridstack: {
minWidth: 2,
Expand Down Expand Up @@ -146,8 +158,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
</Popover.Dropdown>
</Popover>
),
maxSize: 1,
size: 1,
maxSize: widget.properties.nameColumnSize,
},
{
accessorKey: 'totalSelected',
Expand Down Expand Up @@ -184,7 +195,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
Cell: ({ cell, row }) => (
<Flex>
<Text className={useStyles().classes.noTextBreak}>
{(Number(cell.getValue()) * 100).toFixed(1)}%
{(Number(cell.getValue()) * 100).toPrecision(3)}%
</Text>
<Progress
radius="lg"
Expand Down Expand Up @@ -240,9 +251,10 @@ function TorrentTile({ widget }: TorrentTileProps) {
columnVisibility: {
isCompleted: false,
dateAdded: false,
uploadSpeed: width > MIN_WIDTH_MOBILE,
downloadSpeed: width > MIN_WIDTH_MOBILE,
eta: width > MIN_WIDTH_MOBILE,
uploadSpeed: widget.properties.columns.includes('up') && width > MIN_WIDTH_MOBILE,
downloadSpeed: widget.properties.columns.includes('down') && width > MIN_WIDTH_MOBILE,
eta: widget.properties.columns.includes('eta') && width > MIN_WIDTH_MOBILE,
progress: widget.properties.columns.includes('progress'),
},
},
});
Expand All @@ -259,21 +271,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
}

if (isInitialLoading || !data) {
return (
<Stack
align="center"
justify="center"
style={{
height: '100%',
}}
>
<Loader />
<Stack align="center" spacing={0}>
<Text>{t('card.loading.title')}</Text>
<Text color="dimmed">{t('card.loading.description')}</Text>
</Stack>
</Stack>
);
return <WidgetLoading />;
}

if (data.apps.length === 0) {
Expand Down

0 comments on commit a74aa54

Please sign in to comment.