mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
handle table row index values on paginated lists
This commit is contained in:
@@ -37,11 +37,16 @@ const DefaultRowIndexColumn = (props: ItemTableListInnerColumn) => {
|
|||||||
internalState,
|
internalState,
|
||||||
itemType,
|
itemType,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
|
startRowIndex,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const adjustedRowIndex =
|
let adjustedRowIndex =
|
||||||
adjustedRowIndexMap?.get(rowIndex) ?? (enableHeader ? rowIndex : rowIndex + 1);
|
adjustedRowIndexMap?.get(rowIndex) ?? (enableHeader ? rowIndex : rowIndex + 1);
|
||||||
|
|
||||||
|
if (startRowIndex !== undefined && adjustedRowIndex > 0) {
|
||||||
|
adjustedRowIndex = startRowIndex + adjustedRowIndex;
|
||||||
|
}
|
||||||
|
|
||||||
if (enableExpansion) {
|
if (enableExpansion) {
|
||||||
return (
|
return (
|
||||||
<TableColumnContainer {...props}>
|
<TableColumnContainer {...props}>
|
||||||
@@ -75,10 +80,14 @@ const QueueSongRowIndexColumn = (props: ItemTableListInnerColumn) => {
|
|||||||
const song = props.data[props.rowIndex] as QueueSong;
|
const song = props.data[props.rowIndex] as QueueSong;
|
||||||
const isActive = props.activeRowId === song?._uniqueId;
|
const isActive = props.activeRowId === song?._uniqueId;
|
||||||
|
|
||||||
const adjustedRowIndex =
|
let adjustedRowIndex =
|
||||||
props.adjustedRowIndexMap?.get(props.rowIndex) ??
|
props.adjustedRowIndexMap?.get(props.rowIndex) ??
|
||||||
(props.enableHeader ? props.rowIndex : props.rowIndex + 1);
|
(props.enableHeader ? props.rowIndex : props.rowIndex + 1);
|
||||||
|
|
||||||
|
if (props.startRowIndex !== undefined && adjustedRowIndex > 0) {
|
||||||
|
adjustedRowIndex = props.startRowIndex + adjustedRowIndex;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableColumnTextContainer {...props}>
|
<TableColumnTextContainer {...props}>
|
||||||
{isActive ? (
|
{isActive ? (
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ interface VirtualizedTableGridProps {
|
|||||||
showRightShadow: boolean;
|
showRightShadow: boolean;
|
||||||
showTopShadow: boolean;
|
showTopShadow: boolean;
|
||||||
size: 'compact' | 'default' | 'large';
|
size: 'compact' | 'default' | 'large';
|
||||||
|
startRowIndex?: number;
|
||||||
tableId: string;
|
tableId: string;
|
||||||
totalColumnCount: number;
|
totalColumnCount: number;
|
||||||
totalRowCount: number;
|
totalRowCount: number;
|
||||||
@@ -161,6 +162,7 @@ const VirtualizedTableGrid = React.memo(
|
|||||||
showRightShadow,
|
showRightShadow,
|
||||||
showTopShadow,
|
showTopShadow,
|
||||||
size,
|
size,
|
||||||
|
startRowIndex,
|
||||||
tableId,
|
tableId,
|
||||||
totalColumnCount,
|
totalColumnCount,
|
||||||
totalRowCount,
|
totalRowCount,
|
||||||
@@ -300,6 +302,7 @@ const VirtualizedTableGrid = React.memo(
|
|||||||
pinnedRightColumnWidths,
|
pinnedRightColumnWidths,
|
||||||
playerContext,
|
playerContext,
|
||||||
size,
|
size,
|
||||||
|
startRowIndex,
|
||||||
tableId,
|
tableId,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
@@ -330,6 +333,7 @@ const VirtualizedTableGrid = React.memo(
|
|||||||
pinnedRightColumnWidths,
|
pinnedRightColumnWidths,
|
||||||
playerContext,
|
playerContext,
|
||||||
size,
|
size,
|
||||||
|
startRowIndex,
|
||||||
tableId,
|
tableId,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -654,6 +658,7 @@ export interface TableItemProps {
|
|||||||
pinnedRightColumnWidths?: number[];
|
pinnedRightColumnWidths?: number[];
|
||||||
playerContext: PlayerContext;
|
playerContext: PlayerContext;
|
||||||
size?: ItemTableListProps['size'];
|
size?: ItemTableListProps['size'];
|
||||||
|
startRowIndex?: number;
|
||||||
tableId: string;
|
tableId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,7 +668,6 @@ interface ItemTableListProps {
|
|||||||
CellComponent: JSXElementConstructor<CellComponentProps<TableItemProps>>;
|
CellComponent: JSXElementConstructor<CellComponentProps<TableItemProps>>;
|
||||||
cellPadding?: 'lg' | 'md' | 'sm' | 'xl' | 'xs';
|
cellPadding?: 'lg' | 'md' | 'sm' | 'xl' | 'xs';
|
||||||
columns: ItemTableListColumnConfig[];
|
columns: ItemTableListColumnConfig[];
|
||||||
currentPage?: number;
|
|
||||||
data: unknown[];
|
data: unknown[];
|
||||||
enableAlternateRowColors?: boolean;
|
enableAlternateRowColors?: boolean;
|
||||||
enableDrag?: boolean;
|
enableDrag?: boolean;
|
||||||
@@ -684,6 +688,7 @@ interface ItemTableListProps {
|
|||||||
type: 'index' | 'offset';
|
type: 'index' | 'offset';
|
||||||
};
|
};
|
||||||
itemType: LibraryItem;
|
itemType: LibraryItem;
|
||||||
|
startRowIndex?: number;
|
||||||
onColumnReordered?: (
|
onColumnReordered?: (
|
||||||
columnIdFrom: TableColumn,
|
columnIdFrom: TableColumn,
|
||||||
columnIdTo: TableColumn,
|
columnIdTo: TableColumn,
|
||||||
@@ -703,7 +708,6 @@ export const ItemTableList = ({
|
|||||||
CellComponent,
|
CellComponent,
|
||||||
cellPadding = 'sm',
|
cellPadding = 'sm',
|
||||||
columns,
|
columns,
|
||||||
currentPage,
|
|
||||||
data,
|
data,
|
||||||
enableAlternateRowColors = false,
|
enableAlternateRowColors = false,
|
||||||
enableDrag = true,
|
enableDrag = true,
|
||||||
@@ -727,6 +731,7 @@ export const ItemTableList = ({
|
|||||||
ref,
|
ref,
|
||||||
rowHeight,
|
rowHeight,
|
||||||
size = 'default',
|
size = 'default',
|
||||||
|
startRowIndex,
|
||||||
}: ItemTableListProps) => {
|
}: ItemTableListProps) => {
|
||||||
const tableId = useId();
|
const tableId = useId();
|
||||||
const totalItemCount = enableHeader ? data.length + 1 : data.length;
|
const totalItemCount = enableHeader ? data.length + 1 : data.length;
|
||||||
@@ -1682,12 +1687,12 @@ export const ItemTableList = ({
|
|||||||
}
|
}
|
||||||
}, [initialTop, scrollToTableIndex, scrollToTableOffset]);
|
}, [initialTop, scrollToTableIndex, scrollToTableOffset]);
|
||||||
|
|
||||||
// Scroll to top when currentPage changes
|
// Scroll to top when startRowIndex changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentPage !== undefined) {
|
if (startRowIndex !== undefined) {
|
||||||
scrollToTableOffset(0);
|
scrollToTableOffset(0);
|
||||||
}
|
}
|
||||||
}, [currentPage, scrollToTableOffset]);
|
}, [startRowIndex, scrollToTableOffset]);
|
||||||
|
|
||||||
const imperativeHandle: ItemListHandle = useMemo(() => {
|
const imperativeHandle: ItemListHandle = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
@@ -2068,6 +2073,7 @@ export const ItemTableList = ({
|
|||||||
showRightShadow={showRightShadow}
|
showRightShadow={showRightShadow}
|
||||||
showTopShadow={showTopShadow}
|
showTopShadow={showTopShadow}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
tableId={tableId}
|
tableId={tableId}
|
||||||
totalColumnCount={totalColumnCount}
|
totalColumnCount={totalColumnCount}
|
||||||
totalRowCount={totalRowCount}
|
totalRowCount={totalRowCount}
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ export const AlbumListPaginatedTable = forwardRef<any, AlbumListPaginatedTablePr
|
|||||||
itemListKey: ItemListKey.ALBUM,
|
itemListKey: ItemListKey.ALBUM,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -86,7 +88,6 @@ export const AlbumListPaginatedTable = forwardRef<any, AlbumListPaginatedTablePr
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableHorizontalBorders={enableHorizontalBorders}
|
enableHorizontalBorders={enableHorizontalBorders}
|
||||||
@@ -103,6 +104,7 @@ export const AlbumListPaginatedTable = forwardRef<any, AlbumListPaginatedTablePr
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ export const AlbumArtistListPaginatedTable = forwardRef<any, AlbumArtistListPagi
|
|||||||
itemListKey: ItemListKey.ALBUM_ARTIST,
|
itemListKey: ItemListKey.ALBUM_ARTIST,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -87,7 +89,6 @@ export const AlbumArtistListPaginatedTable = forwardRef<any, AlbumArtistListPagi
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableExpansion={false}
|
enableExpansion={false}
|
||||||
@@ -105,6 +106,7 @@ export const AlbumArtistListPaginatedTable = forwardRef<any, AlbumArtistListPagi
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ import { useItemListPaginatedLoader } from '/@/renderer/components/item-list/hel
|
|||||||
import { useItemListColumnReorder } from '/@/renderer/components/item-list/helpers/use-item-list-column-reorder';
|
import { useItemListColumnReorder } from '/@/renderer/components/item-list/helpers/use-item-list-column-reorder';
|
||||||
import { useItemListColumnResize } from '/@/renderer/components/item-list/helpers/use-item-list-column-resize';
|
import { useItemListColumnResize } from '/@/renderer/components/item-list/helpers/use-item-list-column-resize';
|
||||||
import { useItemListScrollPersist } from '/@/renderer/components/item-list/helpers/use-item-list-scroll-persist';
|
import { useItemListScrollPersist } from '/@/renderer/components/item-list/helpers/use-item-list-scroll-persist';
|
||||||
import { ItemTableList } from '/@/renderer/components/item-list/item-table-list/item-table-list';
|
|
||||||
import { ItemTableListColumn } from '/@/renderer/components/item-list/item-table-list/item-table-list-column';
|
|
||||||
import { ItemListWithPagination } from '/@/renderer/components/item-list/item-list-pagination/item-list-pagination';
|
import { ItemListWithPagination } from '/@/renderer/components/item-list/item-list-pagination/item-list-pagination';
|
||||||
import { useItemListPagination } from '/@/renderer/components/item-list/item-list-pagination/use-item-list-pagination';
|
import { useItemListPagination } from '/@/renderer/components/item-list/item-list-pagination/use-item-list-pagination';
|
||||||
|
import { ItemTableList } from '/@/renderer/components/item-list/item-table-list/item-table-list';
|
||||||
|
import { ItemTableListColumn } from '/@/renderer/components/item-list/item-table-list/item-table-list-column';
|
||||||
import { ItemListTableComponentProps } from '/@/renderer/components/item-list/types';
|
import { ItemListTableComponentProps } from '/@/renderer/components/item-list/types';
|
||||||
import { artistsQueries } from '/@/renderer/features/artists/api/artists-api';
|
import { artistsQueries } from '/@/renderer/features/artists/api/artists-api';
|
||||||
import {
|
import {
|
||||||
@@ -74,6 +74,8 @@ export const ArtistListPaginatedTable = forwardRef<any, ArtistListPaginatedTable
|
|||||||
itemListKey: ItemListKey.ARTIST,
|
itemListKey: ItemListKey.ARTIST,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -86,7 +88,6 @@ export const ArtistListPaginatedTable = forwardRef<any, ArtistListPaginatedTable
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableExpansion={false}
|
enableExpansion={false}
|
||||||
@@ -104,6 +105,7 @@ export const ArtistListPaginatedTable = forwardRef<any, ArtistListPaginatedTable
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ export const GenreListPaginatedTable = forwardRef<any, GenreListPaginatedTablePr
|
|||||||
itemListKey: ItemListKey.GENRE,
|
itemListKey: ItemListKey.GENRE,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -86,7 +88,6 @@ export const GenreListPaginatedTable = forwardRef<any, GenreListPaginatedTablePr
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableExpansion={false}
|
enableExpansion={false}
|
||||||
@@ -104,6 +105,7 @@ export const GenreListPaginatedTable = forwardRef<any, GenreListPaginatedTablePr
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ export const PlaylistListPaginatedTable = forwardRef<any, PlaylistListPaginatedT
|
|||||||
itemListKey: ItemListKey.PLAYLIST,
|
itemListKey: ItemListKey.PLAYLIST,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -86,7 +88,6 @@ export const PlaylistListPaginatedTable = forwardRef<any, PlaylistListPaginatedT
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableHorizontalBorders={enableHorizontalBorders}
|
enableHorizontalBorders={enableHorizontalBorders}
|
||||||
@@ -103,6 +104,7 @@ export const PlaylistListPaginatedTable = forwardRef<any, PlaylistListPaginatedT
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ export const SongListPaginatedTable = forwardRef<any, SongListPaginatedTableProp
|
|||||||
itemListKey: ItemListKey.SONG,
|
itemListKey: ItemListKey.SONG,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const startRowIndex = currentPage * itemsPerPage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ItemListWithPagination
|
<ItemListWithPagination
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -81,7 +83,6 @@ export const SongListPaginatedTable = forwardRef<any, SongListPaginatedTableProp
|
|||||||
autoFitColumns={autoFitColumns}
|
autoFitColumns={autoFitColumns}
|
||||||
CellComponent={ItemTableListColumn}
|
CellComponent={ItemTableListColumn}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
currentPage={currentPage}
|
|
||||||
data={data || []}
|
data={data || []}
|
||||||
enableAlternateRowColors={enableAlternateRowColors}
|
enableAlternateRowColors={enableAlternateRowColors}
|
||||||
enableExpansion={false}
|
enableExpansion={false}
|
||||||
@@ -99,6 +100,7 @@ export const SongListPaginatedTable = forwardRef<any, SongListPaginatedTableProp
|
|||||||
onScrollEnd={handleOnScrollEnd}
|
onScrollEnd={handleOnScrollEnd}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
size={size}
|
size={size}
|
||||||
|
startRowIndex={startRowIndex}
|
||||||
/>
|
/>
|
||||||
</ItemListWithPagination>
|
</ItemListWithPagination>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user