From a74aa5412cb6bc22a858574e45a77e4cbbb9a4c1 Mon Sep 17 00:00:00 2001 From: Yossi Hillali Date: Sat, 23 Mar 2024 18:26:59 +0200 Subject: [PATCH] Columns customize (#1975) * Columns customization Related issue: #1471 Related issue: #1832 Related issue: #1354 Related issue: #1929 --- .../locales/en/modules/torrents-status.json | 16 +++++-- src/widgets/torrent/TorrentTile.spec.ts | 14 ++++++ src/widgets/torrent/TorrentTile.tsx | 44 +++++++++---------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/public/locales/en/modules/torrents-status.json b/public/locales/en/modules/torrents-status.json index 594b34e00a0..ffb8df33130 100644 --- a/public/locales/en/modules/torrents-status.json +++ b/public/locales/en/modules/torrents-status.json @@ -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" } } }, @@ -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": { diff --git a/src/widgets/torrent/TorrentTile.spec.ts b/src/widgets/torrent/TorrentTile.spec.ts index 9854c45af0d..a5633496216 100644 --- a/src/widgets/torrent/TorrentTile.spec.ts +++ b/src/widgets/torrent/TorrentTile.spec.ts @@ -24,6 +24,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: false, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -62,6 +64,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -100,6 +104,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -138,6 +144,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -192,6 +200,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -230,6 +240,8 @@ describe('TorrentTile', () => { speedLimitOfActiveTorrents: 10, displayStaleTorrents: true, displayRatioWithFilter: false, + columns: [], + nameColumnSize: 0, }, }; const torrents: NormalizedTorrent[] = [ @@ -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)]; diff --git a/src/widgets/torrent/TorrentTile.tsx b/src/widgets/torrent/TorrentTile.tsx index 19921f6cee8..6971787e10c 100644 --- a/src/widgets/torrent/TorrentTile.tsx +++ b/src/widgets/torrent/TorrentTile.tsx @@ -3,7 +3,6 @@ import { Center, Flex, Group, - Loader, Popover, Progress, Stack, @@ -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'; @@ -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'; @@ -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, @@ -146,8 +158,7 @@ function TorrentTile({ widget }: TorrentTileProps) { ), - maxSize: 1, - size: 1, + maxSize: widget.properties.nameColumnSize, }, { accessorKey: 'totalSelected', @@ -184,7 +195,7 @@ function TorrentTile({ widget }: TorrentTileProps) { Cell: ({ cell, row }) => ( - {(Number(cell.getValue()) * 100).toFixed(1)}% + {(Number(cell.getValue()) * 100).toPrecision(3)}% 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'), }, }, }); @@ -259,21 +271,7 @@ function TorrentTile({ widget }: TorrentTileProps) { } if (isInitialLoading || !data) { - return ( - - - - {t('card.loading.title')} - {t('card.loading.description')} - - - ); + return ; } if (data.apps.length === 0) {