Skip to content

Commit a986bb6

Browse files
committed
refactor: replace VirtuosoMasonry with VirtuosoGrid in DnD grid component and update item rendering logic; adjust lineClamp to 1 in various card components
1 parent 3682dba commit a986bb6

File tree

7 files changed

+55
-23
lines changed

7 files changed

+55
-23
lines changed

src/shared/ui/virtualized-dnd-grid/virtualized-dnd-grid.shared.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import {
1313
} from '@dnd-kit/core'
1414
import { arrayMove, rectSortingStrategy, SortableContext } from '@dnd-kit/sortable'
1515
import { restrictToWindowEdges } from '@dnd-kit/modifiers'
16-
import { VirtuosoMasonry } from '@virtuoso.dev/masonry'
1716
import { ReactNode, useEffect, useState } from 'react'
17+
import { VirtuosoGrid } from 'react-virtuoso'
1818
import { Box } from '@mantine/core'
1919

20+
import { VirtualizedGridComponents } from './virtualized-grid-components'
2021
import classes from './virtualized-dnd-grid.module.css'
2122

2223
interface VirtualizedDndGridProps<T extends { uuid: string }> {
@@ -33,7 +34,6 @@ interface VirtualizedDndGridProps<T extends { uuid: string }> {
3334
export function VirtualizedDndGrid<T extends { uuid: string }>(props: VirtualizedDndGridProps<T>) {
3435
const {
3536
items: initialItems,
36-
columnCount,
3737
renderItem,
3838
renderDragOverlay,
3939
onReorder,
@@ -91,27 +91,24 @@ export function VirtualizedDndGrid<T extends { uuid: string }>(props: Virtualize
9191

9292
const draggedItem = activeId ? items.find((item) => item.uuid === activeId) : null
9393

94-
const ItemWrapper: React.FC<{
95-
context?: unknown
96-
data: T
97-
index: number
98-
}> = ({ data, index }) => {
99-
if (!data) return null
94+
const itemContent = (index: number) => {
95+
const item = items[index]
96+
if (!item) return null
10097

10198
return (
102-
<div className={classes.itemWrapper} style={{ padding: '5px', width: '100%' }}>
103-
{renderItem(data, index)}
99+
<div className={classes.itemWrapper} style={{ width: '100%' }}>
100+
{renderItem(item, index)}
104101
</div>
105102
)
106103
}
107104

108105
if (!enableDnd) {
109106
return (
110107
<Box style={style}>
111-
<VirtuosoMasonry
112-
columnCount={columnCount}
113-
data={items}
114-
ItemContent={ItemWrapper}
108+
<VirtuosoGrid
109+
components={VirtualizedGridComponents}
110+
itemContent={itemContent}
111+
totalCount={items.length}
115112
useWindowScroll={useWindowScroll}
116113
/>
117114
</Box>
@@ -129,10 +126,14 @@ export function VirtualizedDndGrid<T extends { uuid: string }>(props: Virtualize
129126
>
130127
<SortableContext items={items.map((item) => item.uuid)} strategy={rectSortingStrategy}>
131128
<Box style={style}>
132-
<VirtuosoMasonry
133-
columnCount={columnCount}
134-
data={items}
135-
ItemContent={ItemWrapper}
129+
<VirtuosoGrid
130+
components={VirtualizedGridComponents}
131+
itemContent={itemContent}
132+
overscan={{
133+
main: 4,
134+
reverse: 4
135+
}}
136+
totalCount={items.length}
136137
useWindowScroll={useWindowScroll}
137138
/>
138139
</Box>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { SimpleGrid } from '@mantine/core'
2+
import { forwardRef } from 'react'
3+
4+
export const VirtualizedGridComponents = {
5+
List: forwardRef<HTMLDivElement, React.HTMLProps<HTMLDivElement>>(
6+
({ style, children, ...props }, ref) => (
7+
<SimpleGrid
8+
{...props}
9+
cols={{
10+
base: 1,
11+
'800px': 2,
12+
'1000px': 3,
13+
'1200px': 4,
14+
'1800px': 5,
15+
'2400px': 6,
16+
'3000px': 7
17+
}}
18+
ref={ref}
19+
style={{
20+
...style
21+
}}
22+
type="container"
23+
>
24+
{children}
25+
</SimpleGrid>
26+
)
27+
),
28+
Item: ({ children, ...props }: React.HTMLProps<HTMLDivElement>) => (
29+
<div {...props}>{children}</div>
30+
)
31+
}

src/widgets/dashboard/config-profiles/config-profile-card/config-profile-card.widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export function ConfigProfileCardWidget(props: IProps) {
182182
className={classes.title}
183183
ff="monospace"
184184
fw={700}
185-
lineClamp={2}
185+
lineClamp={1}
186186
size="lg"
187187
title={configProfile.name}
188188
>

src/widgets/dashboard/external-squads/external-squad-card/external-squad-card.widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function ExternalSquadCardWidget(props: IProps) {
104104
className={classes.title}
105105
ff="monospace"
106106
fw={700}
107-
lineClamp={2}
107+
lineClamp={1}
108108
size="lg"
109109
title={externalSquad.name}
110110
>

src/widgets/dashboard/external-squads/external-squads-drawer/external-squads.drawer.widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const ExternalSquadsDrawer = memo(() => {
100100
className={classes.title}
101101
ff="monospace"
102102
fw={700}
103-
lineClamp={2}
103+
lineClamp={1}
104104
size="lg"
105105
title={externalSquad.name}
106106
>

src/widgets/dashboard/internal-squads/internal-squad-card/internal-squad-card.widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function InternalSquadCardWidget(props: IProps) {
9898
className={classes.title}
9999
ff="monospace"
100100
fw={700}
101-
lineClamp={2}
101+
lineClamp={1}
102102
size="lg"
103103
title={internalSquad.name}
104104
>

src/widgets/dashboard/templates/template-card/templates-card.widget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function TemplatesCardWidget(props: IProps) {
8181
className={classes.title}
8282
ff="monospace"
8383
fw={700}
84-
lineClamp={2}
84+
lineClamp={1}
8585
size="lg"
8686
title={template.name}
8787
>

0 commit comments

Comments
 (0)