From 2854a917003b5010768d3c8eafbe0258a5b86f6c Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:53:00 -0700 Subject: [PATCH] [bugfix]: actually implement size column --- src/i18n/locales/cs.json | 3 ++- src/i18n/locales/de.json | 3 ++- src/i18n/locales/en.json | 1 + src/i18n/locales/es.json | 3 ++- src/i18n/locales/fr.json | 3 ++- src/i18n/locales/it.json | 3 ++- src/i18n/locales/ja.json | 3 ++- src/i18n/locales/nl.json | 3 ++- src/i18n/locales/pl.json | 3 ++- src/i18n/locales/pt-BR.json | 3 ++- src/i18n/locales/ru.json | 3 ++- src/i18n/locales/sr.json | 3 ++- src/i18n/locales/zh-Hans.json | 3 ++- src/i18n/locales/zh-Hant.json | 3 ++- src/renderer/components/virtual-table/index.tsx | 11 +++++++++++ src/renderer/utils/format-size-string.ts | 12 ++++++++++++ 16 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 src/renderer/utils/format-size-string.ts diff --git a/src/i18n/locales/cs.json b/src/i18n/locales/cs.json index 826bc696..0afd5ae5 100644 --- a/src/i18n/locales/cs.json +++ b/src/i18n/locales/cs.json @@ -365,7 +365,8 @@ "albumArtist": "umělec alba", "path": "cesta", "discNumber": "disk", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } }, "error": { diff --git a/src/i18n/locales/de.json b/src/i18n/locales/de.json index 8b1309db..618a4f60 100644 --- a/src/i18n/locales/de.json +++ b/src/i18n/locales/de.json @@ -310,7 +310,8 @@ "discNumber": "Disk", "genre": "$t(entity.genre_one)", "songCount": "$t(entity.track_other)", - "trackNumber": "Nr." + "trackNumber": "Nr.", + "size": "$t(common.size)" } }, "page": { diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index b7965f77..a1e0ab5c 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -610,6 +610,7 @@ "rating": "rating", "releaseDate": "release date", "releaseYear": "year", + "size": "$t(common.size)", "songCount": "$t(entity.track_other)", "title": "title", "trackNumber": "track" diff --git a/src/i18n/locales/es.json b/src/i18n/locales/es.json index d463414b..62e92ac1 100644 --- a/src/i18n/locales/es.json +++ b/src/i18n/locales/es.json @@ -541,7 +541,8 @@ "albumArtist": "artista de álbum", "path": "ruta", "discNumber": "disco", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" }, "config": { "label": { diff --git a/src/i18n/locales/fr.json b/src/i18n/locales/fr.json index 25cfdc68..0d126815 100644 --- a/src/i18n/locales/fr.json +++ b/src/i18n/locales/fr.json @@ -625,7 +625,8 @@ "artist": "$t(entity.artist_one)", "genre": "$t(entity.genre_one)", "songCount": "$t(entity.track_other)", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } } } diff --git a/src/i18n/locales/it.json b/src/i18n/locales/it.json index 87b1fec6..a6cf75ea 100644 --- a/src/i18n/locales/it.json +++ b/src/i18n/locales/it.json @@ -572,7 +572,8 @@ "albumArtist": "artista album", "path": "percorso", "discNumber": "disco", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } }, "entity": { diff --git a/src/i18n/locales/ja.json b/src/i18n/locales/ja.json index 4a84464e..de959b08 100644 --- a/src/i18n/locales/ja.json +++ b/src/i18n/locales/ja.json @@ -353,7 +353,8 @@ "albumArtist": "アルバムアーティスト", "path": "パス", "discNumber": "ディスク", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } }, "error": { diff --git a/src/i18n/locales/nl.json b/src/i18n/locales/nl.json index f23e8bda..2198c04e 100644 --- a/src/i18n/locales/nl.json +++ b/src/i18n/locales/nl.json @@ -249,7 +249,8 @@ }, "table": { "column": { - "rating": "rating" + "rating": "rating", + "size": "$t(common.size)" }, "config": { "label": { diff --git a/src/i18n/locales/pl.json b/src/i18n/locales/pl.json index 22793599..e2c64b28 100644 --- a/src/i18n/locales/pl.json +++ b/src/i18n/locales/pl.json @@ -625,7 +625,8 @@ "albumArtist": "artysta albumu", "path": "ścieżka", "discNumber": "płyta", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } } } diff --git a/src/i18n/locales/pt-BR.json b/src/i18n/locales/pt-BR.json index 56446a48..78c84ee6 100644 --- a/src/i18n/locales/pt-BR.json +++ b/src/i18n/locales/pt-BR.json @@ -139,7 +139,8 @@ }, "column": { "title": "titulo", - "discNumber": "disco" + "discNumber": "disco", + "size": "$t(common.size)" } }, "page": { diff --git a/src/i18n/locales/ru.json b/src/i18n/locales/ru.json index 5c008ee7..892bdcf6 100644 --- a/src/i18n/locales/ru.json +++ b/src/i18n/locales/ru.json @@ -204,7 +204,8 @@ "trackNumber": "трек", "genre": "$t(entity.genre_one)", "path": "путь", - "discNumber": "диск" + "discNumber": "диск", + "size": "$t(common.size)" } }, "error": { diff --git a/src/i18n/locales/sr.json b/src/i18n/locales/sr.json index 7a146fea..b038516d 100644 --- a/src/i18n/locales/sr.json +++ b/src/i18n/locales/sr.json @@ -359,7 +359,8 @@ "albumArtist": "album artist", "path": "putanja", "discNumber": "disk", - "channels": "$t(common.channel_other)" + "channels": "$t(common.channel_other)", + "size": "$t(common.size)" } }, "error": { diff --git a/src/i18n/locales/zh-Hans.json b/src/i18n/locales/zh-Hans.json index f8d9e2c2..452f0a86 100644 --- a/src/i18n/locales/zh-Hans.json +++ b/src/i18n/locales/zh-Hans.json @@ -595,7 +595,8 @@ "albumArtist": "专辑艺术家", "path": "路径", "channels": "$t(common.channel_other)", - "discNumber": "盘" + "discNumber": "盘", + "size": "$t(common.size)" } } } diff --git a/src/i18n/locales/zh-Hant.json b/src/i18n/locales/zh-Hant.json index 2ac9c349..6d35dee5 100644 --- a/src/i18n/locales/zh-Hant.json +++ b/src/i18n/locales/zh-Hant.json @@ -463,7 +463,8 @@ "bpm": "bpm", "songCount": "$t(entity.track_other)", "title": "標題", - "trackNumber": "音軌編號" + "trackNumber": "音軌編號", + "size": "$t(common.size)" } }, "action": { diff --git a/src/renderer/components/virtual-table/index.tsx b/src/renderer/components/virtual-table/index.tsx index 42dc722a..889667eb 100644 --- a/src/renderer/components/virtual-table/index.tsx +++ b/src/renderer/components/virtual-table/index.tsx @@ -43,6 +43,7 @@ import { useFixedTableHeader } from '/@/renderer/components/virtual-table/hooks/ import { NoteCell } from '/@/renderer/components/virtual-table/cells/note-cell'; import { RowIndexCell } from '/@/renderer/components/virtual-table/cells/row-index-cell'; import i18n from '/@/i18n/i18n'; +import { formatSizeString } from '/@/renderer/utils/format-size-string'; export * from './table-config-dropdown'; export * from './table-pagination'; @@ -320,6 +321,16 @@ const tableColumns: { [key: string]: ColDef } = { }, width: 65, }, + size: { + cellRenderer: (params: ICellRendererParams) => GenericCell(params, { position: 'center' }), + colId: TableColumn.SIZE, + headerComponent: (params: IHeaderParams) => + GenericTableHeader(params, { position: 'center' }), + headerName: i18n.t('table.column.size'), + valueGetter: (params: ValueGetterParams) => + params.data ? formatSizeString(params.data.size) : undefined, + width: 60, + }, songCount: { cellRenderer: (params: ICellRendererParams) => GenericCell(params, { position: 'center' }), colId: TableColumn.SONG_COUNT, diff --git a/src/renderer/utils/format-size-string.ts b/src/renderer/utils/format-size-string.ts new file mode 100644 index 00000000..00bb7f5e --- /dev/null +++ b/src/renderer/utils/format-size-string.ts @@ -0,0 +1,12 @@ +const SIZES = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; + +export const formatSizeString = (size: number): string => { + let count = 0; + let finalSize = size; + while (finalSize > 1024) { + finalSize /= 1024; + count += 1; + } + + return `${finalSize.toFixed(2)} ${SIZES[count]}`; +};