Skip to content

Commit

Permalink
Fix an issue where drag and drop object names is not working. #5761
Browse files Browse the repository at this point in the history
  • Loading branch information
adityatoshniwal committed Feb 6, 2023
1 parent c2acaa2 commit f3bb477
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion web/pgadmin/static/js/components/PgTree/FileTreeItem/index.tsx
Expand Up @@ -4,6 +4,7 @@ import { ClasslistComposite } from 'aspen-decorations'
import { Directory, FileEntry, IItemRendererProps, ItemType, PromptHandle, RenamePromptHandle, FileType, FileOrDir} from 'react-aspen'
import {IFileTreeXTriggerEvents, FileTreeXEvent } from '../types'
import _ from 'lodash'
import { Notificar } from 'notificar'

interface IItemRendererXProps {
/**
Expand All @@ -17,6 +18,7 @@ interface IItemRendererXProps {
decorations: ClasslistComposite
onClick: (ev: React.MouseEvent, item: FileEntry | Directory, type: ItemType) => void
onContextMenu: (ev: React.MouseEvent, item: FileEntry | Directory) => void
events: Notificar<FileTreeXEvent>
}

// DO NOT EXTEND FROM PureComponent!!! You might miss critical changes made deep within `item` prop
Expand Down Expand Up @@ -80,9 +82,10 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen
onContextMenu={this.handleContextMenu}
onClick={this.handleClick}
onDoubleClick={this.handleDoubleClick}
onDragStart={this.handleDragStartItem}
// required for rendering context menus when opened through context menu button on keyboard
ref={this.handleDivRef}
draggable={false}>
draggable={true}>

{!isNewPrompt && fileOrDir === 'directory' ?
<i className={cn('directory-toggle', isDirExpanded ? 'open' : '')} />
Expand Down Expand Up @@ -164,4 +167,14 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen
onDoubleClick(ev, item as FileEntry, itemType)
}
}

private handleDragStartItem = (e: React.DragEvent) => {
const { item, itemType, events } = this.props
if (itemType === ItemType.File || itemType === ItemType.Directory) {
const ref = FileTreeItem.itemIdToRefMap.get(item.id)
if (ref) {
events.dispatch(FileTreeXEvent.onTreeEvents, e, 'dragstart', item)
}
}
}
}

0 comments on commit f3bb477

Please sign in to comment.