Skip to content

Commit a74aa54

Browse files
authored
Columns customize (#1975)
* Columns customization Related issue: #1471 Related issue: #1832 Related issue: #1354 Related issue: #1929
1 parent 0677271 commit a74aa54

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

public/locales/en/modules/torrents-status.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929
"displayRatioWithFilter": {
3030
"label": "Display filtered torrents list ratio",
3131
"info": "If disabled, only the global ratio will be display. The global ratio will still use the labels if set"
32+
},
33+
"columns": {
34+
"label": "Select columns to display",
35+
"data": {
36+
"down": "Down",
37+
"up": "Up",
38+
"eta": "ETA",
39+
"progress": "Progress"
40+
}
41+
},
42+
"nameColumnSize": {
43+
"label": "Change the name column size"
3244
}
3345
}
3446
},
@@ -84,10 +96,6 @@
8496
"text": "Unable to communicate with your Torrent clients. Please check your configuration"
8597
}
8698
},
87-
"loading": {
88-
"title": "Loading",
89-
"description": "Establishing a connection"
90-
},
9199
"popover": {
92100
"introductionPrefix": "Managed by",
93101
"metrics": {

src/widgets/torrent/TorrentTile.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ describe('TorrentTile', () => {
2424
speedLimitOfActiveTorrents: 10,
2525
displayStaleTorrents: false,
2626
displayRatioWithFilter: false,
27+
columns: [],
28+
nameColumnSize: 0,
2729
},
2830
};
2931
const torrents: NormalizedTorrent[] = [
@@ -62,6 +64,8 @@ describe('TorrentTile', () => {
6264
speedLimitOfActiveTorrents: 10,
6365
displayStaleTorrents: true,
6466
displayRatioWithFilter: false,
67+
columns: [],
68+
nameColumnSize: 0,
6569
},
6670
};
6771
const torrents: NormalizedTorrent[] = [
@@ -100,6 +104,8 @@ describe('TorrentTile', () => {
100104
speedLimitOfActiveTorrents: 10,
101105
displayStaleTorrents: true,
102106
displayRatioWithFilter: false,
107+
columns: [],
108+
nameColumnSize: 0,
103109
},
104110
};
105111
const torrents: NormalizedTorrent[] = [
@@ -138,6 +144,8 @@ describe('TorrentTile', () => {
138144
speedLimitOfActiveTorrents: 10,
139145
displayStaleTorrents: true,
140146
displayRatioWithFilter: false,
147+
columns: [],
148+
nameColumnSize: 0,
141149
},
142150
};
143151
const torrents: NormalizedTorrent[] = [
@@ -192,6 +200,8 @@ describe('TorrentTile', () => {
192200
speedLimitOfActiveTorrents: 10,
193201
displayStaleTorrents: true,
194202
displayRatioWithFilter: false,
203+
columns: [],
204+
nameColumnSize: 0,
195205
},
196206
};
197207
const torrents: NormalizedTorrent[] = [
@@ -230,6 +240,8 @@ describe('TorrentTile', () => {
230240
speedLimitOfActiveTorrents: 10,
231241
displayStaleTorrents: true,
232242
displayRatioWithFilter: false,
243+
columns: [],
244+
nameColumnSize: 0,
233245
},
234246
};
235247
const torrents: NormalizedTorrent[] = [
@@ -268,6 +280,8 @@ describe('TorrentTile', () => {
268280
speedLimitOfActiveTorrents: 10,
269281
displayStaleTorrents: true,
270282
displayRatioWithFilter: false,
283+
columns: [],
284+
nameColumnSize: 0,
271285
},
272286
};
273287
const torrents: NormalizedTorrent[] = [constructTorrent('HH', 'I am completed', true, 0, 0)];

src/widgets/torrent/TorrentTile.tsx

+21-23
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Center,
44
Flex,
55
Group,
6-
Loader,
76
Popover,
87
Progress,
98
Stack,
@@ -16,7 +15,7 @@ import { IconFileDownload } from '@tabler/icons-react';
1615
import dayjs from 'dayjs';
1716
import duration from 'dayjs/plugin/duration';
1817
import relativeTime from 'dayjs/plugin/relativeTime';
19-
import { MRT_TableContainer, useMantineReactTable, type MRT_ColumnDef } from 'mantine-react-table';
18+
import { type MRT_ColumnDef, MRT_TableContainer, useMantineReactTable } from 'mantine-react-table';
2019
import { useTranslation } from 'next-i18next';
2120
import { useMemo } from 'react';
2221
import { MIN_WIDTH_MOBILE } from '~/constants/constants';
@@ -29,6 +28,7 @@ import {
2928

3029
import { useGetDownloadClientsQueue } from '../download-speed/useGetNetworkSpeed';
3130
import { defineWidget } from '../helper';
31+
import { WidgetLoading } from '../loading';
3232
import { IWidget } from '../widgets';
3333
import { TorrentQueuePopover } from './TorrentQueueItem';
3434

@@ -69,6 +69,18 @@ const definition = defineWidget({
6969
defaultValue: true,
7070
info: true,
7171
},
72+
columns: {
73+
type: 'multi-select',
74+
defaultValue: ['up', 'down', 'eta', 'progress'],
75+
data: [{ value: 'up' }, { value: 'down' }, { value: 'eta' }, { value: 'progress' }],
76+
},
77+
nameColumnSize: {
78+
type: 'slider',
79+
defaultValue: 2,
80+
min: 1,
81+
max: 4,
82+
step: 1,
83+
},
7284
},
7385
gridstack: {
7486
minWidth: 2,
@@ -146,8 +158,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
146158
</Popover.Dropdown>
147159
</Popover>
148160
),
149-
maxSize: 1,
150-
size: 1,
161+
maxSize: widget.properties.nameColumnSize,
151162
},
152163
{
153164
accessorKey: 'totalSelected',
@@ -184,7 +195,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
184195
Cell: ({ cell, row }) => (
185196
<Flex>
186197
<Text className={useStyles().classes.noTextBreak}>
187-
{(Number(cell.getValue()) * 100).toFixed(1)}%
198+
{(Number(cell.getValue()) * 100).toPrecision(3)}%
188199
</Text>
189200
<Progress
190201
radius="lg"
@@ -240,9 +251,10 @@ function TorrentTile({ widget }: TorrentTileProps) {
240251
columnVisibility: {
241252
isCompleted: false,
242253
dateAdded: false,
243-
uploadSpeed: width > MIN_WIDTH_MOBILE,
244-
downloadSpeed: width > MIN_WIDTH_MOBILE,
245-
eta: width > MIN_WIDTH_MOBILE,
254+
uploadSpeed: widget.properties.columns.includes('up') && width > MIN_WIDTH_MOBILE,
255+
downloadSpeed: widget.properties.columns.includes('down') && width > MIN_WIDTH_MOBILE,
256+
eta: widget.properties.columns.includes('eta') && width > MIN_WIDTH_MOBILE,
257+
progress: widget.properties.columns.includes('progress'),
246258
},
247259
},
248260
});
@@ -259,21 +271,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
259271
}
260272

261273
if (isInitialLoading || !data) {
262-
return (
263-
<Stack
264-
align="center"
265-
justify="center"
266-
style={{
267-
height: '100%',
268-
}}
269-
>
270-
<Loader />
271-
<Stack align="center" spacing={0}>
272-
<Text>{t('card.loading.title')}</Text>
273-
<Text color="dimmed">{t('card.loading.description')}</Text>
274-
</Stack>
275-
</Stack>
276-
);
274+
return <WidgetLoading />;
277275
}
278276

279277
if (data.apps.length === 0) {

0 commit comments

Comments
 (0)