nicoespeon / abracadabra

Automated refactorings for VS Code (JS & TS) ✨ It's magic ✨
https://marketplace.visualstudio.com/items?itemName=nicoespeon.abracadabra
MIT License
809 stars 48 forks source link

I didn't find a valid if statement to convert from current selection #1072

Closed yinluobing closed 3 weeks ago

yinluobing commented 1 month ago

Describe the bug

I didn't find a valid if statement to convert from current selection I didn't find a valid...

Screenshots

vue3 typescript setup

<script lang="ts" setup>
import { bdApi } from '@/api/bd'
import { formatDate, getFutureDate } from '@/utils/date'
import { useDictData, useDictOptions } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/usePaging'
import Popup from '@/components/popup/index.vue'
import FileItem from '@/components/material/file.vue'
import preview from '@/components/material/preview.vue'
import { number } from 'echarts';
import type { PropType } from 'vue'
const props = defineProps({
    userId: {
        // 弹窗标题
        type: [Number, String] as PropType<number | string>,
        required: true
    },
    pageNo: {
        // 页面
        type: [Number] as PropType<number>,
        default: 1
    },
})
const emit = defineEmits(['success', 'close'])
// const formRef = shallowRef<FormInstance>()
const imageList = shallowRef<InstanceType<typeof Popup>>()
const selectedImags = ref<any[]>([[], [], []])
const imageSize = ref('1140*640');
const filters = ref<any[]>([{ 'field': 'width', 'op': 'eq', 'values': '1140' }, { 'field': 'height', 'op': 'eq', 'values': '640' }])
const queryParams = reactive({
    api: "ImageManageService",
    fun: "getImageList",
    userId: props.userId,
    filters: filters,
})

watch(queryParams, (newQueryParams, oldQueryParams) => { getLists(); }, { deep: true })

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: bdApi,
    params: queryParams,
    size: 6,
    page: props.pageNo
})
// one all three
const mode = ref('all')
const popupTitle = computed(() => {
    return mode.value = '图片列表'
})

const showPreview = ref(false)
const previewUrl = ref('')
const handlePreview = (row: any, index = -1) => {
    if (index == -1) {
        previewUrl.value = row.url
    } else {
        previewUrl.value = selectedImags.value[index].map((v: any) => v.url).join()
    }
    showPreview.value = true

}

const handleSubmit = async () => {
    imageList.value?.close();
    emit('success', pager.lists);
};

const handleDelete = async (row: any) => {

}

const handleSelectImageSize = async (v: any) => {
    if (v == '0') { queryParams.filters = [] } else {
        const imageSizeArr = imageSize.value.split('*')
        queryParams.filters = [{ 'field': 'width', 'op': 'eq', 'values': [imageSizeArr[0]] }, { 'field': 'height', 'op': 'eq', 'values': [imageSizeArr[1]] }]
    }
}

const handleSelectTables = async (v: any) => {
    if (imageSize.value == '1140*640') {
        if (mode.value == 'all') {
            selectedImags.value[0] = 1
        } else {
            selectedImags.value[0] = 2
        }
        // [...new Set([...v])]
    }
    if (imageSize.value == '640*1140') { selectedImags.value[1] = [...new Set([...v])] }
    if (imageSize.value == '750*1000') { selectedImags.value[2] = [...new Set([...v])] }
}

const handleAdd = async (row: any) => {
    emit('success', [row])
    imageList.value?.close()
}

const open = (type = 'all', filters = [{ 'field': 'width', 'op': 'eq', 'values': ['1140'] }, { 'field': 'height', 'op': 'eq', 'values': ['640'] }]) => {
    queryParams.filters = filters
    imageList.value?.open()
}

const handleClose = () => {
    emit('close')
    imageList.value?.close()
}
defineExpose({
    open,
})
getLists()
</script>
nicoespeon commented 1 month ago

Hi there @yinluobing and thanks for reporting!

I'm trying to repro but it's working for me, so I will need some more details to understand what is going wrong:

https://github.com/user-attachments/assets/6582f2ad-9d09-49bd-8cbf-6b630eef2079

  1. What version of Abracadabra do you have?
  2. What is the file extension? Is it a regular .svelte file?
  3. Which refactoring are you trying to execute? On which part of the code?

Just in case, try to update your VS Code and Abracadabra extension just to be sure you are on the latest versions.

Thanks 😉

yinluobing commented 1 month ago

邮件已收到,回头给你回复!   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

nicoespeon commented 1 month ago

Closing this issue because I can't repro it. Feel free to re-open one if you figure out more details to repro. See my suggestions in my previous comment 😉

acabreragnz commented 1 month ago

@nicoespeon First of all, thank you for this amazing extension.

It is straightforward to replicate this bug in vue (vue 3 in my case) with the options API.

a02be688-8405-4539-a9fa-227d0ff0d414.webm

image

nicoespeon commented 1 month ago

Thanks for the recording @acabreragnz, that's gonna be quite helpful for me. I'll have another look at that and see why it doesn't work in this case 😃

nicoespeon commented 3 weeks ago

Great news: I figured out what happened!

We were miscalculating the position of the cursor when executing the refactoring since the changes I made in 9.2.1 to preserve the position with an action provider: https://github.com/nicoespeon/abracadabra/commit/dc175c49a93f5e3311061de05190df1bdaa798ec

That was an easy fix. And I failed to repro because my repro didn't involve content above the <script> tag 😓

Shipping a new release with that. Abracadabra should become usable on Vue files again now.

nicoespeon commented 3 weeks ago

@allcontributors please add yinluobing and acabreragnz for bug

Thank you guys for the report 😉

allcontributors[bot] commented 3 weeks ago

@nicoespeon

I've put up a pull request to add @yinluobing! :tada:

nicoespeon commented 3 weeks ago

@allcontributors please add acabreragnz for bug

allcontributors[bot] commented 3 weeks ago

@nicoespeon

I've put up a pull request to add @acabreragnz! :tada:

acabreragnz commented 3 weeks ago

@nicoespeon you are amazing, and now I understand why abracadabra is so cool.

Thank you very much!