From bf098cdc54cdf9195561e405a660e4f27cec7a91 Mon Sep 17 00:00:00 2001 From: Sergei Garin Date: Fri, 1 Nov 2024 14:14:35 +0300 Subject: [PATCH] Virtualization draft --- .../AriaComponents/Dialog/DialogTrigger.tsx | 17 ++++- .../components/dashboard/AssetRow.tsx | 20 +++--- .../dashboard/DirectoryNameColumn.tsx | 50 ++++++++------- .../components/dashboard/ProjectIcon.tsx | 13 ++-- .../dashboard/column/LabelsColumn.tsx | 11 +++- app/gui/src/dashboard/layouts/AssetsTable.tsx | 62 +++++++++++-------- 6 files changed, 102 insertions(+), 71 deletions(-) diff --git a/app/gui/src/dashboard/components/AriaComponents/Dialog/DialogTrigger.tsx b/app/gui/src/dashboard/components/AriaComponents/Dialog/DialogTrigger.tsx index 7c855b0fc4..6f7feb24ce 100644 --- a/app/gui/src/dashboard/components/AriaComponents/Dialog/DialogTrigger.tsx +++ b/app/gui/src/dashboard/components/AriaComponents/Dialog/DialogTrigger.tsx @@ -67,10 +67,21 @@ export function DialogTrigger(props: DialogTriggerProps) { } satisfies DialogTriggerRenderProps return ( - + {trigger} - {typeof dialog === 'function' ? dialog(renderProps) : dialog} - + {state.isOpen ? + typeof dialog === 'function' ? + dialog(renderProps) + : dialog + : null} + ) } + +/** + * A DialogTriggerInner is a DialogTrigger that has a stable reference. + */ +function DialogTriggerInner(props: aria.DialogTriggerProps) { + return +} diff --git a/app/gui/src/dashboard/components/dashboard/AssetRow.tsx b/app/gui/src/dashboard/components/dashboard/AssetRow.tsx index 20b2ef11c7..acf474964e 100644 --- a/app/gui/src/dashboard/components/dashboard/AssetRow.tsx +++ b/app/gui/src/dashboard/components/dashboard/AssetRow.tsx @@ -113,15 +113,12 @@ export interface AssetRowProps { event: React.DragEvent, item: backendModule.AnyAsset, ) => void - readonly rowHeight: number - readonly rowOffset: number } /** A row containing an {@link backendModule.AnyAsset}. */ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) { const { id, parentId, isKeyboardSelected, isOpened, select, state, columns, onClick } = props const { path, hidden: hiddenRaw, grabKeyboardFocus, visibility: visibilityRaw, depth } = props - const { rowHeight, rowOffset } = props const { initialAssetEvents } = props const { nodeMap, doCopy, doCut, doPaste, doDelete: doDeleteRaw } = state const { doRestore, doMove, category, scrollContainerRef, rootDirectoryId, backend } = state @@ -509,10 +506,9 @@ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) { <> {!hidden && ( - { rootRef.current = element @@ -699,7 +695,7 @@ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) { ) })} - + )} {selected && allowContextMenu && !hidden && ( @@ -724,7 +720,7 @@ export const AssetRow = React.memo(function AssetRow(props: AssetRowProps) { } case backendModule.AssetType.specialLoading: { return hidden ? null : ( - +
- +
) } case backendModule.AssetType.specialEmpty: { return hidden ? null : ( - +
- +
) } case backendModule.AssetType.specialError: { return hidden ? null : ( - +
- +
) } } diff --git a/app/gui/src/dashboard/components/dashboard/DirectoryNameColumn.tsx b/app/gui/src/dashboard/components/dashboard/DirectoryNameColumn.tsx index 6de65c08a5..d1fae3a131 100644 --- a/app/gui/src/dashboard/components/dashboard/DirectoryNameColumn.tsx +++ b/app/gui/src/dashboard/components/dashboard/DirectoryNameColumn.tsx @@ -16,6 +16,7 @@ import SvgMask from '#/components/SvgMask' import * as backendModule from '#/services/Backend' +import { useEventCallback } from '#/hooks/eventCallbackHooks' import * as eventModule from '#/utilities/event' import * as indent from '#/utilities/indent' import * as object from '#/utilities/object' @@ -46,7 +47,7 @@ export default function DirectoryNameColumn(props: DirectoryNameColumnProps) { const updateDirectoryMutation = useMutation(backendMutationOptions(backend, 'updateDirectory')) - const setIsEditing = (isEditingName: boolean) => { + const setIsEditing = useEventCallback((isEditingName: boolean) => { if (isEditable) { setRowState(object.merger({ isEditingName })) } @@ -54,20 +55,38 @@ export default function DirectoryNameColumn(props: DirectoryNameColumnProps) { if (!isEditingName) { driveStore.setState({ newestFolderId: null }) } - } + }) - const doRename = async (newTitle: string) => { + const doRename = useEventCallback(async (newTitle: string) => { if (isEditable) { setIsEditing(false) if (!string.isWhitespaceOnly(newTitle) && newTitle !== item.title) { await updateDirectoryMutation.mutateAsync([item.id, { title: newTitle }, item.title]) } } - } + }) + + const toggleExpanded = useEventCallback(() => { + doToggleDirectoryExpansion(item.id, item.id) + }) + + const checkSubmittable = useEventCallback( + (newTitle: string) => + validation.DIRECTORY_NAME_REGEX.test(newTitle) && + backendModule.isNewTitleValid( + item, + newTitle, + nodeMap.current.get(item.parentId)?.children?.map((child) => child.item), + ), + ) + + const onCancel = useEventCallback(() => { + setIsEditing(false) + }) return (