|
1 | | -import type { Feed } from "@fnndsc/chrisapi"; |
| 1 | +import type { Feed, FileBrowserFolder } from "@fnndsc/chrisapi"; |
2 | 2 | import { ChartDonutUtilization } from "@patternfly/react-charts"; |
3 | 3 | import { |
4 | 4 | Button, |
@@ -384,17 +384,27 @@ const TableRow: React.FC<TableRowProps> = ({ |
384 | 384 | const navigate = useNavigate(); |
385 | 385 | const { isDarkTheme } = useContext(ThemeContext); |
386 | 386 |
|
| 387 | + // Add a cache for folder data with proper typing |
| 388 | + const folderCache = useRef<FileBrowserFolder | null>(null); |
| 389 | + |
387 | 390 | /** |
388 | 391 | * Track row progress state for background color |
389 | 392 | */ |
390 | 393 | const [rowProgress, setRowProgress] = useState<number | null>(null); |
391 | 394 | const [rowError, setRowError] = useState<boolean>(false); |
392 | 395 |
|
393 | 396 | /** |
394 | | - * Get folder for this feed |
| 397 | + * Get folder for this feed - with caching |
395 | 398 | */ |
396 | 399 | const getFolderForThisFeed = async () => { |
| 400 | + // Return cached data if available |
| 401 | + if (folderCache.current) { |
| 402 | + return folderCache.current; |
| 403 | + } |
| 404 | + |
| 405 | + // Otherwise fetch and cache |
397 | 406 | const payload = await feed.getFolder(); |
| 407 | + folderCache.current = payload; |
398 | 408 | return payload; |
399 | 409 | }; |
400 | 410 |
|
@@ -455,7 +465,22 @@ const TableRow: React.FC<TableRowProps> = ({ |
455 | 465 | onSelect: async (event) => { |
456 | 466 | event.stopPropagation(); |
457 | 467 | const isChecked = event.currentTarget.checked; |
458 | | - const payload = await getFolderForThisFeed(); |
| 468 | + |
| 469 | + // Only fetch folder data if the checkbox is being checked |
| 470 | + // This prevents the delay when simply rendering checkboxes |
| 471 | + let payload: FileBrowserFolder | null = null; |
| 472 | + if (isChecked) { |
| 473 | + payload = await getFolderForThisFeed(); |
| 474 | + } else if (isSelected) { |
| 475 | + // If unchecking, we don't need to fetch again, just use the path |
| 476 | + handlers.handleCheckboxChange( |
| 477 | + event, |
| 478 | + feed.data.folder_path, |
| 479 | + null, |
| 480 | + "folder", |
| 481 | + ); |
| 482 | + return; |
| 483 | + } |
459 | 484 |
|
460 | 485 | /** |
461 | 486 | * Create a new event object with the captured value |
|
0 commit comments