Skip to content

Commit 364fc12

Browse files
committed
refactor: Implement useTransition hook in the file tree to manage pending state with a loading indicator and reduce pagination page size.
1 parent 7baa6c8 commit 364fc12

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

analytics-gen-studio/src/components/events/FileTree.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useMemo, useCallback, memo, startTransition, useRef, useEffect } from 'react';
1+
import { useState, useMemo, useCallback, memo, useTransition, useRef, useEffect } from 'react';
22
import Box from '@mui/material/Box';
33
import List from '@mui/material/List';
44
import ListItemButton from '@mui/material/ListItemButton';
@@ -26,6 +26,7 @@ import SearchRounded from '@mui/icons-material/SearchRounded';
2626
import UnfoldMoreRounded from '@mui/icons-material/UnfoldMoreRounded';
2727
import UnfoldLessRounded from '@mui/icons-material/UnfoldLessRounded';
2828
import Tooltip from '@mui/material/Tooltip';
29+
import CircularProgress from '@mui/material/CircularProgress';
2930
import { alpha } from '@mui/material/styles';
3031
import { useStore } from '../../state/store.ts';
3132
import { DEFAULT_PARAM_TYPE } from '../../schemas/constants.ts';
@@ -184,6 +185,7 @@ export default function FileTree() {
184185
const [editValue, setEditValue] = useState('');
185186

186187
// Track expanded nodes — default ALL COLLAPSED for performance
188+
const [isPending, startTransition] = useTransition();
187189
const [expanded, setExpanded] = useState<Set<string>>(new Set());
188190
const [addFileOpen, setAddFileOpen] = useState(false);
189191
const [addDomainFor, setAddDomainFor] = useState<number | null>(null);
@@ -193,7 +195,7 @@ export default function FileTree() {
193195
const [addMenuAnchor, setAddMenuAnchor] = useState<HTMLElement | null>(null);
194196
const [confirmDelete, setConfirmDelete] = useState<{ title: string; message: string; action: () => void } | null>(null);
195197
// Pagination: track visible limit per parent key, default PAGE_SIZE
196-
const PAGE_SIZE = 20;
198+
const PAGE_SIZE = 10;
197199
const [visibleLimits, setVisibleLimits] = useState<Record<string, number>>({});
198200
const getLimit = (key: string) => visibleLimits[key] ?? PAGE_SIZE;
199201
const showMore = useCallback((key: string, total: number) => {
@@ -359,7 +361,18 @@ export default function FileTree() {
359361
</Box>
360362
)}
361363

362-
<List dense disablePadding sx={{ px: 0.5, pb: 1 }}>
364+
<Box sx={{ position: 'relative' }}>
365+
{isPending && (
366+
<Box sx={{
367+
position: 'absolute', inset: 0, zIndex: 2,
368+
display: 'flex', justifyContent: 'center', pt: 4,
369+
bgcolor: 'rgba(var(--mui-palette-background-paperChannel) / 0.6)',
370+
backdropFilter: 'blur(1px)',
371+
}}>
372+
<CircularProgress size={20} sx={{ color: '#DF4926' }} />
373+
</Box>
374+
)}
375+
<List dense disablePadding sx={{ px: 0.5, pb: 1, ...(isPending && { opacity: 0.4, pointerEvents: 'none' }) }}>
363376
{files.map((file, fi) => {
364377
if (!fileMatchesSearch(fi)) return null;
365378
const fk = `f${fi}`;
@@ -515,6 +528,7 @@ export default function FileTree() {
515528
);
516529
})}
517530
</List>
531+
</Box>
518532

519533
{q && files.length > 0 && files.every((_, fi) => !fileMatchesSearch(fi)) && (
520534
<Typography sx={{ px: 2, py: 3, textAlign: 'center', fontSize: '0.78rem', color: 'text.disabled' }}>

0 commit comments

Comments
 (0)