Skip to content

Commit c8a17e7

Browse files
Kinplemelonysfscream
authored andcommitted
fix(rule): support select placeholder when editing re pub payload
1 parent 0b1f4d1 commit c8a17e7

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

src/components/SelectAllowInput.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<!-- Only one can be selected -->
22
<template>
3-
<el-autocomplete v-model="inputValue" clearable :fetch-suggestions="querySearch" />
3+
<el-autocomplete
4+
v-model="inputValue"
5+
clearable
6+
:fetch-suggestions="querySearch"
7+
v-bind="$attrs"
8+
/>
49
</template>
510

611
<script setup lang="ts">
7-
import { isObject, isUndefined } from 'lodash'
12+
import { escapeRegExp, isObject, isUndefined } from 'lodash'
813
import { computed, defineEmits, defineProps, withDefaults } from 'vue'
914
1015
const props = withDefaults(
1116
defineProps<{
12-
modelValue: string
17+
modelValue?: string | boolean | number
1318
options: Array<Record<string, any>> | Array<string> | Array<number>
1419
valueKey?: string
1520
labelKey?: string
@@ -21,11 +26,11 @@ const props = withDefaults(
2126
},
2227
)
2328
const emit = defineEmits<{
24-
(e: 'update:modelValue', value: string): void
29+
(e: 'update:modelValue', value: string | number | boolean): void
2530
}>()
2631
2732
const inputValue = computed({
28-
get: () => props.modelValue,
33+
get: () => props.modelValue?.toString?.(),
2934
set: (val) => emit('update:modelValue', val),
3035
})
3136
@@ -45,6 +50,20 @@ const opts = computed(() => {
4550
})
4651
4752
const querySearch = (queryString: string, cb: (arg0: Array<Record<string, any>>) => void) => {
48-
cb(opts.value)
53+
if (!queryString) {
54+
cb(opts.value)
55+
} else {
56+
const filterReg = new RegExp(escapeRegExp(queryString), 'i')
57+
const ret = opts.value.reduce(
58+
(arr: Array<{ value: string }>, { value }: { value: string; item: string }) => {
59+
if (filterReg.test(value)) {
60+
arr.push({ value })
61+
}
62+
return arr
63+
},
64+
[] as Array<{ value: string }>,
65+
)
66+
cb(ret)
67+
}
4968
}
5069
</script>

src/hooks/Rule/bridge/useComponentsHandlers.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BridgeType } from '@/types/enum'
55
import { Properties, Property } from '@/types/schemaForm'
66
import { pick } from 'lodash'
77
import { useAvailableProviders } from '../useProvidersForMonaco'
8+
import useSQLAvailablePlaceholder from '../useSQLAvailablePlaceholder'
89

910
type Handler = ({ components, rules }: { components: Properties; rules: SchemaRules }) => {
1011
components: Properties
@@ -60,6 +61,7 @@ export default (
6061
prop.componentProps = Object.assign(prop.componentProps || {}, componentProps)
6162
}
6263

64+
const { availablePlaceholders } = useSQLAvailablePlaceholder()
6365
const { completionProvider } = useAvailableProviders()
6466

6567
const handleProp = (parm: Property) => {
@@ -111,12 +113,16 @@ export default (
111113
const { qos, retain, payload, topic } = components?.parameters?.properties || {}
112114
if (qos?.type === 'oneof') {
113115
qos.type = 'enum'
114-
qos.symbols = [...(getSymbolsFromOneOfArr(qos.oneOf) || []), '${qos}']
116+
qos.symbols = [
117+
...(getSymbolsFromOneOfArr(qos.oneOf) || []),
118+
'${qos}',
119+
...availablePlaceholders.value,
120+
]
115121
setComponentProps(qos, { filterable: true, allowCreate: true })
116122
}
117123
if (retain?.type === 'oneof') {
118124
retain.type = 'enum'
119-
retain.symbols = [true, false, '${flags.retain}']
125+
retain.symbols = [true, false, '${flags.retain}', ...availablePlaceholders.value]
120126
setComponentProps(retain, { filterable: true, allowCreate: true })
121127
}
122128
// for detect whether it is source or action

src/views/RuleEngine/components/RePubForm.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
json-without-validate
4545
:disabled="readonly"
4646
:id="createRandomString()"
47+
:completion-provider="completionProvider"
4748
/>
4849
</div>
4950
</CustomFormItem>
@@ -137,8 +138,9 @@ import { QoSOptions as defaultQoSOptions } from '@/common/constants'
137138
import { createRandomString } from '@/common/tools'
138139
import CustomFormItem from '@/components/CustomFormItem.vue'
139140
import FormItemLabel from '@/components/FormItemLabel.vue'
140-
import Monaco from '@/components/Monaco.vue'
141141
import SelectAllowInput from '@/components/SelectAllowInput.vue'
142+
import Monaco from '@/components/Monaco.vue'
143+
import { useAvailableProviders } from '@/hooks/Rule/useProvidersForMonaco'
142144
import useSQLAvailablePlaceholder from '@/hooks/Rule/useSQLAvailablePlaceholder'
143145
import useFormRules from '@/hooks/useFormRules'
144146
import useI18nTl from '@/hooks/useI18nTl'
@@ -188,6 +190,7 @@ const togglePubPropsEnabled = (val: string | number | boolean) => {
188190
}
189191
190192
const { availablePlaceholders } = useSQLAvailablePlaceholder()
193+
const { completionProvider } = useAvailableProviders()
191194
192195
const QoSOptions = [...defaultQoSOptions, '${qos}', ...availablePlaceholders.value]
193196

0 commit comments

Comments
 (0)