[bugfix]: actually implement size column

This commit is contained in:
Kendall Garner 2024-04-01 20:53:00 -07:00
parent 6bc778fa53
commit 2854a91700
No known key found for this signature in database
GPG key ID: 18D2767419676C87
16 changed files with 50 additions and 13 deletions

View file

@ -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,

View file

@ -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]}`;
};