songjianet commented on code in PR #14833: URL: https://github.com/apache/dolphinscheduler/pull/14833#discussion_r1311115183
########## dolphinscheduler-ui/src/views/security/listener-instance-manage/use-form.ts: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { reactive, ref, Ref } from 'vue' +import { useI18n } from 'vue-i18n' +import { + queryUiPluginsByType, + queryUiPluginDetailById +} from '@/service/modules/ui-plugins' +import type { + IPluginId, + IPlugin, + IFormRules, + IMeta, + IJsonItem, + IRecord +} from './types' +export function useForm() { + const { t } = useI18n() + + const eventTypes = { + SERVER_DOWN: { + value: "SERVER_DOWN", Review Comment: Please use single quotes. ########## dolphinscheduler-ui/src/views/security/listener-instance-manage/detail.tsx: ########## @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + defineComponent, + toRefs, + watch, + onMounted, + ref, + getCurrentInstance +} from 'vue' +import { NSelect, NInput, NCheckboxGroup, NSpace, NCheckbox } from 'naive-ui' +import { isFunction } from 'lodash' +import { useI18n } from 'vue-i18n' +import { useForm } from './use-form' +import { useDetail } from './use-detail' +import Modal from '@/components/modal' +import Form from '@/components/form' +import getElementByJson from '@/components/form/get-elements-by-json' +import type { IRecord, IFormRules, IFormItem } from './types' +import type { PropType, Ref } from 'vue' +import { stateType } from '@/common/common' + +interface IElements extends Omit<Ref, 'value'> { + value: IFormItem[] +} + +const props = { + show: { + type: Boolean as PropType<boolean>, + default: false + }, + currentRecord: { + type: Object as PropType<IRecord>, + default: {} + } +} +const DetailModal = defineComponent({ + name: 'DetailModal', + props, + emits: ['cancel', 'update'], + setup(props, ctx) { + const { t } = useI18n() + + const rules = ref<IFormRules>({}) + const elements = ref<IFormItem[]>([]) as IElements + const { + meta, + state, + eventTypes, + setDetail, + initForm, + resetForm, + getFormValues, + changePlugin + } = useForm() + + const { status, createOrUpdate } = useDetail(getFormValues) + + const onCancel = () => { + resetForm() + rules.value = {} + elements.value = [] + ctx.emit('cancel') + } + + const onSubmit = async () => { + await state.detailFormRef.validate() + const res = await createOrUpdate(props.currentRecord, state.json) + if (res) { + onCancel() + ctx.emit('update') + } + } + const onChangePlugin = changePlugin + + const trim = getCurrentInstance()?.appContext.config.globalProperties.trim + + watch( + () => props.show, + async () => { + props.show && props.currentRecord && setDetail(props.currentRecord) + } + ) + watch( + () => state.json, + () => { + if (!state.json?.length) return + state.json.forEach((item) => { + const mergedItem = isFunction(item) ? item() : item + mergedItem.name = mergedItem.title + }) + const { rules: fieldsRules, elements: fieldsElements } = + getElementByJson(state.json, state.detailForm) + rules.value = fieldsRules + elements.value = fieldsElements + } + ) + + onMounted(() => { + initForm() + }) + + return { + t, + ...toRefs(state), + ...toRefs(status), + meta, + rules, + elements, + eventTypes, + onChangePlugin, + onSubmit, + onCancel, + trim + } + }, + render(props: { currentRecord: IRecord }) { + const { + show, + t, + meta, + rules, + elements, + detailForm, + uiPlugins, + eventTypes, + pluginsLoading, + loading, + saving, + onChangePlugin, + onCancel, + onSubmit + } = this + const { currentRecord } = props + return ( + <Modal + show={show} + title={t( + currentRecord?.id + ? 'security.listener_instance.edit_listener_instance' + : 'security.listener_instance.create_listener_instance' + )} + onConfirm={onSubmit} + confirmLoading={saving || loading} + onCancel={onCancel} + > + {{ + default: () => ( + <Form + ref='detailFormRef' + loading={loading || pluginsLoading} + meta={{ + ...meta, + rules: { + ...meta.rules, + ...rules + }, + elements: [ + { + path: 'instanceName', + label: t('security.listener_instance.instance_name'), + widget: ( + <NInput + allowInput={this.trim} + v-model={[detailForm.instanceName, 'value']} + placeholder={t( + 'security.listener_instance.instance_name_tips' + )} + /> + ) + }, + { + path: 'listenerEventTypes', + label: t('security.listener_instance.listener_event_types'), + widget: ( + <NCheckboxGroup + disabled={!this.trim} + v-model={[detailForm.listenerEventTypes, 'value']}> + <NSpace style="display: flex;"> + { + Object.values( + eventTypes + ).map((item)=>{ + return <NCheckbox value={item.value} label={item.label} defaultChecked={true}/> + }) Review Comment: `map((item) => <NCheckbox value={item.value} label={item.label} defaultChecked={true} />)` ########## dolphinscheduler-ui/src/views/security/listener-plugin-manage/components/listener-plugin-modal.tsx: ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + defineComponent, + getCurrentInstance, + PropType, Review Comment: type PropType ########## dolphinscheduler-ui/src/views/security/listener-plugin-manage/components/use-modalData.ts: ########## @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { reactive, ref, SetupContext } from 'vue' Review Comment: type SetupContext ########## dolphinscheduler-ui/src/views/security/listener-plugin-manage/components/listener-plugin-modal.tsx: ########## @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + defineComponent, + getCurrentInstance, + PropType, + toRefs, + watch +} from 'vue' +import Modal from '@/components/modal' +import { NButton, NForm, NFormItem, NInput, NSelect, NUpload } from 'naive-ui' +import { useModalData } from './use-modalData' +import { useI18n } from 'vue-i18n' + +const ListenerPluginModal = defineComponent({ + name: 'tenant-modal', + props: { + showModalRef: { + type: Boolean as PropType<boolean>, + default: false + }, + statusRef: { + type: Number as PropType<number>, + default: 0 + }, + row: { + type: Object as PropType<any>, + default: {} + } + }, + emits: ['cancelModal', 'confirmModal'], + setup(props, ctx) { + const { variables, handleValidate } = useModalData(props, ctx) + const { t } = useI18n() + + const cancelModal = () => { + if (props.statusRef === 0) { + variables.model.classPath = '' + variables.model.pluginJar = '' + } + ctx.emit('cancelModal', props.showModalRef) + } + + const confirmModal = () => { + handleValidate(props.statusRef) + } + + const trim = getCurrentInstance()?.appContext.config.globalProperties.trim + + const customRequest = ({ file }: any) => { + variables.model.pluginJar = file.file + variables.listenerPluginFormRef.validate() + } + + // watch( + // () => props.showModalRef, + // () => { + // props.showModalRef && getListData(props.statusRef) + // } + // ) Review Comment: Delete this. ########## dolphinscheduler-ui/src/views/security/listener-instance-manage/detail.tsx: ########## @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + defineComponent, + toRefs, + watch, + onMounted, + ref, + getCurrentInstance +} from 'vue' +import { NSelect, NInput, NCheckboxGroup, NSpace, NCheckbox } from 'naive-ui' +import { isFunction } from 'lodash' +import { useI18n } from 'vue-i18n' +import { useForm } from './use-form' +import { useDetail } from './use-detail' +import Modal from '@/components/modal' +import Form from '@/components/form' +import getElementByJson from '@/components/form/get-elements-by-json' +import type { IRecord, IFormRules, IFormItem } from './types' +import type { PropType, Ref } from 'vue' +import { stateType } from '@/common/common' + +interface IElements extends Omit<Ref, 'value'> { + value: IFormItem[] +} + +const props = { + show: { + type: Boolean as PropType<boolean>, + default: false + }, + currentRecord: { + type: Object as PropType<IRecord>, + default: {} + } +} +const DetailModal = defineComponent({ + name: 'DetailModal', + props, + emits: ['cancel', 'update'], + setup(props, ctx) { + const { t } = useI18n() + + const rules = ref<IFormRules>({}) + const elements = ref<IFormItem[]>([]) as IElements + const { + meta, + state, + eventTypes, + setDetail, + initForm, + resetForm, + getFormValues, + changePlugin + } = useForm() + + const { status, createOrUpdate } = useDetail(getFormValues) + + const onCancel = () => { + resetForm() + rules.value = {} + elements.value = [] + ctx.emit('cancel') + } + + const onSubmit = async () => { + await state.detailFormRef.validate() + const res = await createOrUpdate(props.currentRecord, state.json) + if (res) { + onCancel() + ctx.emit('update') + } Review Comment: if (!res) return false onCancel() ctx.emit('update') ########## dolphinscheduler-ui/src/views/security/listener-instance-manage/use-table.ts: ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { reactive } from 'vue' +import { + queryListenerInstanceListPaging, + deleteListenerInstanceById +} from '@/service/modules/listener-instance' +import { format } from 'date-fns' +import { parseTime } from '@/common/common' +import type { IRecord } from './types' + +export function useTable() { + const data = reactive({ + page: 1, + pageSize: 10, + itemCount: 0, + searchVal: '', + list: [], + loading: false + }) + + const getList = async () => { + if (data.loading) return + data.loading = true + + const { totalList, total } = await queryListenerInstanceListPaging({ + pageNo: data.page, + pageSize: data.pageSize, + searchVal: data.searchVal + }) + data.loading = false + if (!totalList) throw Error() + data.list = totalList.map((record: IRecord) => { + record.createTime = record.createTime + ? format(parseTime(record.createTime), 'yyyy-MM-dd HH:mm:ss') + : '' Review Comment: `record.createTime && record.createTime = format(parseTime(record.createTime), 'yyyy-MM-dd HH:mm:ss')` ########## dolphinscheduler-ui/src/views/security/listener-instance-manage/use-table.ts: ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { reactive } from 'vue' +import { + queryListenerInstanceListPaging, + deleteListenerInstanceById +} from '@/service/modules/listener-instance' +import { format } from 'date-fns' +import { parseTime } from '@/common/common' +import type { IRecord } from './types' + +export function useTable() { + const data = reactive({ + page: 1, + pageSize: 10, + itemCount: 0, + searchVal: '', + list: [], + loading: false + }) + + const getList = async () => { + if (data.loading) return + data.loading = true + + const { totalList, total } = await queryListenerInstanceListPaging({ + pageNo: data.page, + pageSize: data.pageSize, + searchVal: data.searchVal + }) + data.loading = false + if (!totalList) throw Error() + data.list = totalList.map((record: IRecord) => { + record.createTime = record.createTime + ? format(parseTime(record.createTime), 'yyyy-MM-dd HH:mm:ss') + : '' + record.updateTime = record.updateTime + ? format(parseTime(record.updateTime), 'yyyy-MM-dd HH:mm:ss') + : '' Review Comment: Ditto -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
