betodealmeida commented on code in PR #36239: URL: https://github.com/apache/superset/pull/36239#discussion_r2582740665
########## superset-frontend/src/components/Datasource/FoldersEditor/constants.ts: ########## @@ -0,0 +1,58 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + DatasourceFolder, + DatasourceFolderItem, +} from 'src/explore/components/DatasourcePanel/types'; +import { FoldersEditorItemType } from '../types'; + +// Default folder UUIDs +export const DEFAULT_METRICS_FOLDER_UUID = 'default-metric-folder-uuid'; +export const DEFAULT_COLUMNS_FOLDER_UUID = 'default-column-folder-uuid'; Review Comment: These should be actual UUIDs, no? ########## superset-frontend/src/components/Datasource/FoldersEditor/hooks/useDragHandlers.ts: ########## @@ -0,0 +1,561 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { useCallback, useMemo, useRef, useState } from 'react'; +import { t } from '@superset-ui/core'; +import { + UniqueIdentifier, + DragStartEvent, + DragMoveEvent, + DragEndEvent, + DragOverEvent, +} from '@dnd-kit/core'; +import { FoldersEditorItemType } from '../../types'; +import { + isDefaultFolder, + DEFAULT_COLUMNS_FOLDER_UUID, + DEFAULT_METRICS_FOLDER_UUID, + TreeItem as TreeItemType, + FlattenedTreeItem, + DRAG_INDENTATION_WIDTH, +} from '../constants'; +import { buildTree, getProjection, serializeForAPI } from '../treeUtils'; + +interface UseDragHandlersProps { + items: TreeItemType[]; + setItems: React.Dispatch<React.SetStateAction<TreeItemType[]>>; + computeFlattenedItems: ( + activeId: UniqueIdentifier | null, + ) => FlattenedTreeItem[]; + fullFlattenedItems: FlattenedTreeItem[]; + selectedItemIds: Set<string>; + onChange: (folders: ReturnType<typeof serializeForAPI>) => void; + addWarningToast: (message: string) => void; +} + +export function useDragHandlers({ + items, + setItems, + computeFlattenedItems, + fullFlattenedItems, + selectedItemIds, + onChange, + addWarningToast, +}: UseDragHandlersProps) { + const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null); + const [overId, setOverId] = useState<UniqueIdentifier | null>(null); + const [dragOverlayWidth, setDragOverlayWidth] = useState<number | null>(null); + const offsetLeftRef = useRef(0); + const [projectedParentId, setProjectedParentId] = useState<string | null>( + null, + ); + const [draggedItemIds, setDraggedItemIds] = useState<Set<string>>(new Set()); + + const pendingParentIdRef = useRef<string | null>(null); + const rafIdRef = useRef<number | null>(null); + + const scheduleProjectedParentUpdate = useCallback( + (newParentId: string | null) => { + pendingParentIdRef.current = newParentId; + + // Only schedule if not already scheduled + if (rafIdRef.current === null) { + rafIdRef.current = requestAnimationFrame(() => { + rafIdRef.current = null; + setProjectedParentId(prev => + prev === pendingParentIdRef.current + ? prev + : pendingParentIdRef.current, + ); Review Comment: Isn't this the same as: ```suggestion setProjectedParentId(pendingParentIdRef.current); ``` ########## superset/commands/dataset/update.py: ########## @@ -212,27 +212,38 @@ def _validate_semantics(self, exceptions: list[ValidationError]) -> None: valid_uuids: set[UUID] = set() if metrics: valid_uuids.update( - UUID(metric["uuid"]) for metric in metrics if "uuid" in metric + ( + metric["uuid"] + if isinstance(metric["uuid"], UUID) + else UUID(metric["uuid"]) Review Comment: It would be better if `metric["uuid"]` was consistently always a UUID... can we have the client always send a valid UUID so we don't need this check and we have more consistent types? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
