diff --git a/databox/client/src/components/AssetList/Layouts/Grid/GridPage.tsx b/databox/client/src/components/AssetList/Layouts/Grid/GridPage.tsx index 07d0434a2..2a2b932d7 100644 --- a/databox/client/src/components/AssetList/Layouts/Grid/GridPage.tsx +++ b/databox/client/src/components/AssetList/Layouts/Grid/GridPage.tsx @@ -28,7 +28,7 @@ function GridPage({ {page > 1 && ( ({ + textSx={() => ({ fontWeight: 700, fontSize: 15, })} diff --git a/databox/client/src/components/AssetList/Layouts/GroupDivider.tsx b/databox/client/src/components/AssetList/Layouts/GroupDivider.tsx index 0fe05b649..4ab512039 100644 --- a/databox/client/src/components/AssetList/Layouts/GroupDivider.tsx +++ b/databox/client/src/components/AssetList/Layouts/GroupDivider.tsx @@ -13,9 +13,14 @@ import {getAttributeType} from '../../Media/Asset/Attribute/types'; type Props = PropsWithChildren<{ groupValue: GroupValue; top?: number | undefined; + page?: number | undefined; }>; -export default function GroupDivider({groupValue, top}: Props) { +export default function GroupDivider({ + groupValue, + top, + page, +}: Props) { const formatContext = React.useContext(AttributeFormatContext); const {values, type, name} = groupValue; @@ -23,6 +28,7 @@ export default function GroupDivider({groupValue, top}: Props) { return ( + {page ? <> + # {page}{' - '} + : ''} {formatContext.hasFormats(type) && ( ({ toolbarHeight, @@ -142,6 +142,14 @@ export default function ListLayout({ // @ts-expect-error Element | undefined ref={registerChild} > + {page > 0 && pageIndex === 0 ? ( + + ) : ( + '' + )}
({ : undefined } > - {page > 0 && pageIndex === 0 ? ( - ({ - fontWeight: 700, - fontSize: 15, - })} - > - # {page + 1} - - ) : ( - '' - )} ({ onScroll={onScroll} /> - {hasGroups ? ( + {pages.length > 1 || hasGroups ? ( ({ {page > 1 && ( ({ + textSx={() => ({ fontWeight: 700, fontSize: 15, })} diff --git a/databox/client/src/components/AssetList/Layouts/VirtualizedGroups.tsx b/databox/client/src/components/AssetList/Layouts/VirtualizedGroups.tsx index c469d6257..14581206d 100644 --- a/databox/client/src/components/AssetList/Layouts/VirtualizedGroups.tsx +++ b/databox/client/src/components/AssetList/Layouts/VirtualizedGroups.tsx @@ -1,8 +1,9 @@ -import React, {ForwardedRef, ReactNode, RefObject} from 'react'; +import React, {ForwardedRef, RefObject} from 'react'; import {Asset, AssetOrAssetContainer, GroupValue} from '../../../types'; import {ItemToAssetFunc} from '../types.ts'; import GroupDivider from './GroupDivider.tsx'; import {CellMeasurerCache} from 'react-virtualized'; +import PageDivider from "../PageDivider.tsx"; type GroupSet = { index: number; @@ -10,41 +11,51 @@ type GroupSet = { key: string | null; }; +type Position = { + page?: number; + group?: GroupValue; + height?: number; +} + type Props = { pages: Item[][]; itemToAsset: ItemToAssetFunc | undefined; cellMeasurer: CellMeasurerCache; height: number; + hasGroups: boolean; }; export default React.forwardRef>( function VirtualizedGroups( - {pages, height, itemToAsset, cellMeasurer}: Props, + {pages, height, itemToAsset, cellMeasurer, hasGroups}: Props, ref: ForwardedRef ) { const [_inc, setInc] = React.useState(0); - const {groups, rowCount} = React.useMemo(() => { + const {groups, rowCount, perPage} = React.useMemo(() => { const groups: GroupSet[] = []; - + const perPage = pages[0]?.length ?? 0; const all = pages.flat(); const rowCount = all.length; - all.map((item, index) => { - const asset: Asset = itemToAsset - ? itemToAsset(item) - : (item as unknown as Asset); - - const {groupValue} = asset; - - if (groupValue) { - groups.push({ - value: groupValue, - key: groupValue.key, - index, - }); - } - }); - return {groups, rowCount}; + if (hasGroups) { + all.map((item, index) => { + const asset: Asset = itemToAsset + ? itemToAsset(item) + : (item as unknown as Asset); + + const {groupValue} = asset; + + if (groupValue) { + groups.push({ + value: groupValue, + key: groupValue.key, + index, + }); + } + }); + } + + return {groups, rowCount, perPage}; }, [pages, cellMeasurer]); React.useEffect(() => { @@ -65,35 +76,40 @@ export default React.forwardRef>( }; }, [ref]); - const divs: ReactNode[] = []; - let groupIndex = 0; - let i = 0; - while (groups[groupIndex] && i < rowCount) { - let nextHeight: number | undefined = undefined; - - const g = groups[groupIndex]; - const nextGroup = groups[groupIndex + 1]; - if (nextGroup) { - while (i < nextGroup.index) { - nextHeight = - (nextHeight ?? 0) + cellMeasurer.rowHeight({index: i}); - i++; + const positions: Position[] = [{}]; + let groupCursor = 0; + let currentGroup: GroupSet | undefined = groups[groupCursor]; + let currPos: Position = positions[0]; + + const flush = () => { + currPos.height ??= 0; + positions.push({...currPos}); + currPos = {}; + } + + let currentPage : number | undefined; + for (let i = 0; i < rowCount; i++) { + const isNewGroup = currentGroup && i === currentGroup.index; + if (isNewGroup) { + flush(); + currPos.group = currentGroup.value; + if (currentPage) { + currPos.page = currentPage; } + ++groupCursor; + currentGroup = groups[groupCursor]; } - divs.push( -
- -
- ); + if (i > 0 && (i % perPage) === 0) { + if (!isNewGroup) { + flush(); + } - if (groupIndex === groups.length - 1) { - break; + currentPage = Math.floor(i / perPage) + 1; + currPos.page = currentPage; } - groupIndex++; + + currPos.height = (currPos.height ?? 0) + cellMeasurer.rowHeight({index: i}); } return ( @@ -102,7 +118,7 @@ export default React.forwardRef>( position: 'absolute', top: 0, left: 0, - right: 0, + right: 10, pointerEvents: 'none', }} > @@ -114,7 +130,22 @@ export default React.forwardRef>( }} ref={ref} > - {divs} + {positions.map((p, index) =>
+ {p.page && !p.group ? : ''} + {p.group ? : ''} +
)}
); diff --git a/databox/client/src/components/AssetList/PageDivider.tsx b/databox/client/src/components/AssetList/PageDivider.tsx new file mode 100644 index 000000000..3d19c52d1 --- /dev/null +++ b/databox/client/src/components/AssetList/PageDivider.tsx @@ -0,0 +1,22 @@ +import SectionDivider from "./SectionDivider.tsx"; + +type Props = { + page: number; + top?: number; +}; + +export default function PageDivider({ + page, + top, +}: Props) { + + return ({ + fontWeight: 700, + fontSize: 15, + })} + > + # {page} + +} diff --git a/databox/client/src/components/AssetList/SectionDivider.tsx b/databox/client/src/components/AssetList/SectionDivider.tsx index cf811d6fd..70a64abf4 100644 --- a/databox/client/src/components/AssetList/SectionDivider.tsx +++ b/databox/client/src/components/AssetList/SectionDivider.tsx @@ -20,8 +20,8 @@ function applyStyle( export const sectionDividerClassname = 'section-divider'; type Props = PropsWithChildren<{ - textStyle?: (theme: Theme) => CSSProperties; - rootStyle?: (theme: Theme) => CSSProperties; + textSx?: (theme: Theme) => CSSProperties; + rootSx?: (theme: Theme) => CSSProperties; dividerSx?: SxProps; top: number | undefined; }>; @@ -29,8 +29,8 @@ type Props = PropsWithChildren<{ export default function SectionDivider({ top, children, - rootStyle, - textStyle, + rootSx, + textSx, dividerSx, }: Props) { const theme = useTheme(); @@ -45,11 +45,14 @@ export default function SectionDivider({ top, backgroundColor: theme.palette.common.white, }, - rootStyle + rootSx )} className={sectionDividerClassname} > - +
{children} diff --git a/databox/client/src/components/Basket/BasketMenuItem.tsx b/databox/client/src/components/Basket/BasketMenuItem.tsx index d3ddd9674..ad1cbc892 100644 --- a/databox/client/src/components/Basket/BasketMenuItem.tsx +++ b/databox/client/src/components/Basket/BasketMenuItem.tsx @@ -79,8 +79,8 @@ export default function BasketMenuItem({ primary={ data.titleHighlight ? replaceHighlight(data.titleHighlight) - : data.title || - t('basket.default.title', 'My Basket') + : (data.title || + t('basket.default.title', 'My Basket')) } secondary={ data.descriptionHighlight diff --git a/databox/client/src/components/Basket/BasketsPanel.tsx b/databox/client/src/components/Basket/BasketsPanel.tsx index 9d0e69b44..c0fb023f6 100644 --- a/databox/client/src/components/Basket/BasketsPanel.tsx +++ b/databox/client/src/components/Basket/BasketsPanel.tsx @@ -106,9 +106,7 @@ function BasketsPanel({selected}: Props) { const hasLOadMore = loadedSearchQuery ? !!searchResult.next : hasMore(); const results = loadedSearchQuery - ? searchResult?.pages.flat().map(b => { - return baskets.find(_b => _b.id === b.id) || b; - }) + ? searchResult?.pages.flat() : baskets; return ( diff --git a/databox/client/src/components/Form/BasketForm.tsx b/databox/client/src/components/Form/BasketForm.tsx index 36724e6c9..ec1bbecb4 100644 --- a/databox/client/src/components/Form/BasketForm.tsx +++ b/databox/client/src/components/Form/BasketForm.tsx @@ -33,6 +33,7 @@ export const BasketForm: FC> = function ({