Skip to content

Commit 4f09454

Browse files
committed
Show grid loading before new row
1 parent 5cb7493 commit 4f09454

3 files changed

Lines changed: 6 additions & 27 deletions

File tree

src/components/database/components/grid/grid-row/__tests__/useRenderRows.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ function createWrapper() {
2323
}
2424

2525
describe('useRenderRows', () => {
26-
it('keeps the new-row control available while rows are loading', () => {
26+
it('renders the loading placeholder above the new-row control while rows are loading', () => {
2727
const { result } = renderHook(() => useRenderRows(undefined), {
2828
wrapper: createWrapper(),
2929
});
3030

3131
expect(result.current.rows.map((row) => row.type)).toEqual([
3232
RenderRowType.Header,
33-
RenderRowType.NewRow,
3433
RenderRowType.PlaceholderRow,
34+
RenderRowType.NewRow,
3535
]);
3636
});
3737

src/components/database/components/grid/grid-row/useRenderRows.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export function useRenderRows (rows?: Row[]) {
2323
{
2424
type: RenderRowType.Header,
2525
},
26-
!readOnly && {
27-
type: RenderRowType.NewRow,
28-
},
2926
{
3027
type: RenderRowType.PlaceholderRow,
3128
},
29+
!readOnly && {
30+
type: RenderRowType.NewRow,
31+
},
3232
].filter(Boolean) as RenderRow[];
3333

3434
// If rows are still loading, show placeholder rows

src/components/database/components/grid/grid-table/GridVirtualizer.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
22

3-
import { PADDING_END, useDatabaseContext, useDatabaseView } from '@/application/database-yjs';
4-
import { YjsDatabaseKey } from '@/application/types';
3+
import { PADDING_END, useDatabaseContext } from '@/application/database-yjs';
54
import LoadingDots from '@/components/_shared/LoadingDots';
65
import { GridDragContext } from '@/components/database/components/grid/drag-and-drop/GridDragContext';
76
import { RenderColumn } from '@/components/database/components/grid/grid-column/useRenderFields';
@@ -22,8 +21,6 @@ function GridVirtualizer({ columns }: { columns: RenderColumn[] }) {
2221
const { rows: data, resizeRows, onResizeRowEnd } = useGridContext();
2322
const { handleResizeStart, isResizing } = useColumnResize(columns);
2423
const { isDocumentBlock, paddingEnd } = useDatabaseContext();
25-
const view = useDatabaseView();
26-
const hasConditions = (view?.get(YjsDatabaseKey.sorts)?.length ?? 0) > 0 || (view?.get(YjsDatabaseKey.filters)?.length ?? 0) > 0;
2724

2825
const { parentRef, virtualizer, columnVirtualizer, scrollMarginTop, isReady } = useGridVirtualizer({
2926
data,
@@ -33,9 +30,6 @@ function GridVirtualizer({ columns }: { columns: RenderColumn[] }) {
3330
const rowItems = virtualizer.getVirtualItems();
3431
const columnItems = columnVirtualizer.getVirtualItems();
3532
const totalSize = columnVirtualizer.getTotalSize();
36-
const hasRegularRows = data.some((row) => row.type === RenderRowType.Row);
37-
const hasPlaceholderRow = data.some((row) => row.type === RenderRowType.PlaceholderRow);
38-
const showEmptyBodyLoading = hasConditions && !hasRegularRows && !hasPlaceholderRow;
3933

4034
const contextValue = useGridDnd(columns, virtualizer, columnVirtualizer);
4135
const bottomScrollbarRef = useRef<HTMLDivElement>(null);
@@ -234,21 +228,6 @@ function GridVirtualizer({ columns }: { columns: RenderColumn[] }) {
234228
</div>
235229
);
236230
})}
237-
{showEmptyBodyLoading && (
238-
<div
239-
className={'absolute flex min-h-[240px] items-center justify-center'}
240-
role={'status'}
241-
style={{
242-
top: 36,
243-
left: 0,
244-
paddingLeft: columnItems[0]?.start,
245-
paddingRight: isDocumentBlock ? 0 : PADDING_INLINE,
246-
width: totalSize - (paddingEnd ?? 0),
247-
}}
248-
>
249-
<LoadingDots className={'flex items-center justify-center opacity-80'} />
250-
</div>
251-
)}
252231
</div>
253232
{!isDocumentBlock && (
254233
<DatabaseStickyTopOverlay>

0 commit comments

Comments
 (0)