Browse Source

fix(nc-gui): channel multi select logic

pull/5349/head
Wing-Kam Wong 2 years ago
parent
commit
d50c24b871
  1. 49
      packages/nc-gui/components/webhook/ChannelMultiSelect.vue

49
packages/nc-gui/components/webhook/ChannelMultiSelect.vue

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, useVModel, watch } from '#imports' import { onBeforeMount, useVModel, watch } from '#imports'
interface Props { interface Props {
modelValue: Record<string, any>[] modelValue: Record<string, any>[]
@ -17,24 +17,9 @@ const vModel = useVModel(rest, 'modelValue', emit)
const localChannelValues = $ref<number[]>([]) const localChannelValues = $ref<number[]>([])
// availableChannelList with idx enriched // availableChannelList with idx enriched
let availableChannelWithIdxList = $ref<Record<string, any>[]>() let availableChannelWithIdxList = $ref<Record<string, any>[]>([])
watch( function setAvailableChannelWithIdxList(availableChannelList: Record<string, any>[]) {
() => localChannelValues,
(v) => {
const res = []
for (const channelIdx of v) {
const target = availableChannelWithIdxList.find((availableChannel) => availableChannel.idx === channelIdx)
if (target) {
// push without target.idx
res.push({ webhook_url: target.webhook_url, channel: target.channel })
}
}
vModel.value = res
},
)
onMounted(() => {
if (availableChannelList.length) { if (availableChannelList.length) {
// enrich idx // enrich idx
let idx = 0 let idx = 0
@ -54,7 +39,33 @@ onMounted(() => {
} }
} }
} }
}) }
watch(
() => availableChannelList,
(n, o) => {
if (n !== o) {
setAvailableChannelWithIdxList(n)
}
},
)
watch(
() => localChannelValues,
(v) => {
const res = []
for (const channelIdx of v) {
const target = availableChannelWithIdxList.find((availableChannel) => availableChannel.idx === channelIdx)
if (target) {
// push without target.idx
res.push({ webhook_url: target.webhook_url, channel: target.channel })
}
}
vModel.value = res
},
)
onBeforeMount(() => setAvailableChannelWithIdxList(availableChannelList))
</script> </script>
<template> <template>

Loading…
Cancel
Save