Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transfer): [transfer] fix drag 2 item to right when set filterable=true #2492

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/renderless/src/transfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,20 @@ export const clearQuery = (refs: ITransferRenderlessParams['refs']) => (which: '

/** SortableJs 插件的回调逻辑, 添加,删除,更新事件后,触发本函数 */
export const logicFun =
({ props, emit, state }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ event, isAdd, pullMode }: { event: any; isAdd?: boolean; pullMode?: 'sort' }) => {
let currentValue = props.modelValue.slice()
let movedKeys = []

if (pullMode) {
currentValue.splice(event.newIndex, 0, currentValue.splice(event.oldIndex, 1)[0])
} else {
const rightPanel = vm.$refs.rightPanel
const leftPanel = vm.$refs.leftPanel

Comment on lines +228 to +230
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add null checks for panel refs.

The code assumes that panel refs will always be available. Add null checks to prevent runtime errors:

-      const rightPanel = vm.$refs.rightPanel
-      const leftPanel = vm.$refs.leftPanel
+      const rightPanel = vm.$refs.rightPanel
+      const leftPanel = vm.$refs.leftPanel
+      
+      if (!rightPanel?.state?.filteredData || !leftPanel?.state?.filteredData) {
+        console.warn('Transfer panel refs or filtered data not available')
+        return
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rightPanel = vm.$refs.rightPanel
const leftPanel = vm.$refs.leftPanel
const rightPanel = vm.$refs.rightPanel
const leftPanel = vm.$refs.leftPanel
if (!rightPanel?.state?.filteredData || !leftPanel?.state?.filteredData) {
console.warn('Transfer panel refs or filtered data not available')
return
}

const key = isAdd
? state.targetData[event.oldIndex][props.props.key]
: state.sourceData[event.oldIndex][props.props.key]
? rightPanel.state.filteredData[event.oldIndex][props.props.key]
: leftPanel.state.filteredData[event.oldIndex][props.props.key]
const index = isAdd ? state.rightChecked.indexOf(key) : state.leftChecked.indexOf(key)
const valueIndex = currentValue.indexOf(key)

Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/transfer/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const initState = ({ reactive, computed, api, props, h, slots }): ITransferState
export const renderless = (
props: ITransferProps,
{ computed, onMounted, reactive, h }: ISharedRenderlessParamHooks,
{ $prefix, emit, refs, parent, slots }: ITransferRenderlessParamUtils
{ $prefix, emit, refs, parent, slots, vm }: ITransferRenderlessParamUtils
) => {
const api = {} as ITransferApi
const Tree = $prefix + 'Tree'
Expand All @@ -80,7 +80,7 @@ export const renderless = (
addToRight: addToRight({ emit, refs, props, state, Tree }),
onTargetCheckedChange: onTargetCheckedChange({ emit, state }),
onSourceCheckedChange: onSourceCheckedChange({ emit, state }),
logicFun: logicFun({ props, emit, state }),
logicFun: logicFun({ props, emit, state, vm }),
getTargetData: getTargetData({ props, state, Tree, Table }),
sortableEvent: sortableEvent({ api, droppanel: DROPPANEL, props, queryDom: TRANSFERPANEL, refs })
})
Expand Down
Loading