You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by qi...@apache.org on 2024/12/09 03:14:10 UTC

(skywalking-banyandb) branch main updated: refactor: Add a common component to avoid hard code (#565)

This is an automated email from the ASF dual-hosted git repository.

qiuxiafan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


The following commit(s) were added to refs/heads/main by this push:
     new 3d44bf9e refactor: Add a common component to avoid hard code (#565)
3d44bf9e is described below

commit 3d44bf9ec38bbf07ef7b4091f4f596a706f4258f
Author: Fine0830 <fa...@gmail.com>
AuthorDate: Mon Dec 9 11:14:04 2024 +0800

    refactor: Add a common component to avoid hard code (#565)
---
 ui/src/components/Editor/index.vue                 | 22 +++-------
 ui/src/components/IndexRule/Editor.vue             | 17 ++------
 ui/src/components/IndexRule/index.vue              | 12 +-----
 ui/src/components/IndexRuleBinding/Editor.vue      | 24 +++--------
 ui/src/components/IndexRuleBinding/index.vue       | 12 +-----
 ui/src/components/Property/PropertyRead.vue        |  9 ++--
 ui/src/components/Property/PropertyValueReader.vue |  6 ---
 ui/src/components/Read/index.vue                   | 10 +----
 ui/src/components/TopNAggregation/Editor.vue       | 15 ++-----
 ui/src/components/TopNAggregation/index.vue        | 12 +-----
 ui/src/components/common/FormHeader.vue            | 50 ++++++++++++++++++++++
 11 files changed, 79 insertions(+), 110 deletions(-)

diff --git a/ui/src/components/Editor/index.vue b/ui/src/components/Editor/index.vue
index 133da5de..1005d051 100644
--- a/ui/src/components/Editor/index.vue
+++ b/ui/src/components/Editor/index.vue
@@ -25,7 +25,8 @@ import TagEditor from './tagEditor.vue'
 import FieldsEditor from './fieldsEditor.vue'
 import type { FormInstance } from 'element-plus'
 import { ElMessage } from 'element-plus'
-import { createResources, editResources, getStreamOrMeasureList, getStreamOrMeasure } from '@/api/index'
+import { createResources, editResources, getStreamOrMeasure } from '@/api/index'
+import FormHeader from '../common/FormHeader.vue'
 
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
 const $loadingClose = getCurrentInstance().appContext.config.globalProperties.$loadingClose
@@ -264,24 +265,13 @@ function initData() {
         <el-card shadow="always">
             <template #header>
                 <el-row>
-                    <el-col :span="12">
-                        <div class="flex align-item-center" style="height: 30px; width: 100%;">
-                            <div class="flex" style="height: 30px;">
-                                <span class="text-bold">Catalog: </span>
-                                <span style="margin-right: 20px;">{{ data.type }}</span>
-                                <span class="text-bold">Group: </span>
-                                <span style="margin-right: 20px;">{{ data.form.group }}</span>
-                                <span class="text-bold" v-if="data.form.name">Name:</span>
-                                <span style="margin-right: 20px;" v-if="data.form.name">{{ data.form.name }}</span>
-                                <span class="text-bold">Operation: </span>
-                                <span>{{ data.operator }}</span>
-                            </div>
-                        </div>
+                    <el-col :span="20">
+                        <FormHeader :fields="{...data, catalog: data.type}" />
                     </el-col>
-                    <el-col :span="12">
+                    <el-col :span="4">
                         <div class="flex align-item-center justify-end" style="height: 30px;">
                             <el-button size="small" type="primary" @click="submit(ruleFormRef)"
-                                color="#6E38F7">submit</el-button>
+                                color="#6E38F7">Submit</el-button>
                         </div>
                     </el-col>
                 </el-row>
diff --git a/ui/src/components/IndexRule/Editor.vue b/ui/src/components/IndexRule/Editor.vue
index 97078d63..c27aa892 100644
--- a/ui/src/components/IndexRule/Editor.vue
+++ b/ui/src/components/IndexRule/Editor.vue
@@ -24,6 +24,8 @@ import { useRoute, useRouter } from 'vue-router'
 import type { FormInstance } from 'element-plus'
 import { createSecondaryDataModel, getSecondaryDataModel, updateSecondaryDataModel } from '@/api/index'
 import { ElMessage } from 'element-plus'
+import FormHeader from '../common/FormHeader.vue'
+
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
 const $loadingClose = getCurrentInstance().appContext.config.globalProperties.$loadingClose
 const $bus = getCurrentInstance().appContext.config.globalProperties.mittBus
@@ -241,18 +243,7 @@ function initData() {
       <template #header>
         <el-row>
           <el-col :span="20">
-            <div class="flex align-item-center" style="height: 30px; width: 100%;">
-              <div class="flex" style="height: 30px;">
-                <span class="text-bold">Group: </span>
-                <span style="margin-right: 20px;">{{ data.group }}</span>
-                <span class="text-bold" v-if="data.operator == 'edit'">Name: </span>
-                <span style="margin-right: 20px;">{{ data.name }}</span>
-                <span class="text-bold">Type: </span>
-                <span style="margin-right: 20px;">{{ data.type }}</span>
-                <span class="text-bold">Operation: </span>
-                <span>{{ data.operator }}</span>
-              </div>
-            </div>
+            <FormHeader :fields="data" />
           </el-col>
           <el-col :span="4">
             <div class="flex align-item-center justify-end" style="height: 30px;">
@@ -291,6 +282,6 @@ function initData() {
 
 <style lang="scss" scoped>
 :deep(.el-card) {
-    margin: 15px;
+  margin: 15px;
 }
 </style>
\ No newline at end of file
diff --git a/ui/src/components/IndexRule/index.vue b/ui/src/components/IndexRule/index.vue
index b3d3e0cb..b663f2be 100644
--- a/ui/src/components/IndexRule/index.vue
+++ b/ui/src/components/IndexRule/index.vue
@@ -22,6 +22,7 @@ import { reactive } from 'vue';
 import { watch, getCurrentInstance } from '@vue/runtime-core'
 import { useRoute } from 'vue-router'
 import { getSecondaryDataModel } from '@/api/index'
+import FormHeader from '../common/FormHeader.vue'
 
 const { proxy } = getCurrentInstance()
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
@@ -73,16 +74,7 @@ function initData() {
   <div>
     <el-card>
       <template #header>
-        <div class="flex">
-          <span class="text-bold">Group: </span>
-          <span style="margin-right: 20px;">{{ data.group }}</span>
-          <span class="text-bold">Name: </span>
-          <span style="margin-right: 20px;">{{ data.name }}</span>
-          <span class="text-bold">Type: </span>
-          <span style="margin-right: 20px;">{{ data.type }}</span>
-          <span class="text-bold">Operation: </span>
-          <span>Read</span>
-        </div>
+        <FormHeader :fields="data" />
       </template>
       <el-form label-position="left" label-width="100px" :model="data.indexRule" style="width: 90%;">
         <el-form-item label="Analyzer">
diff --git a/ui/src/components/IndexRuleBinding/Editor.vue b/ui/src/components/IndexRuleBinding/Editor.vue
index 41b3875c..d7cd27ed 100644
--- a/ui/src/components/IndexRuleBinding/Editor.vue
+++ b/ui/src/components/IndexRuleBinding/Editor.vue
@@ -24,6 +24,8 @@ import { useRoute, useRouter } from 'vue-router'
 import type { FormInstance } from 'element-plus'
 import { createSecondaryDataModel, getSecondaryDataModel, updateSecondaryDataModel } from '@/api/index'
 import { ElMessage } from 'element-plus'
+import FormHeader from '../common/FormHeader.vue'
+
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
 const $loadingClose = getCurrentInstance().appContext.config.globalProperties.$loadingClose
 const $bus = getCurrentInstance().appContext.config.globalProperties.mittBus
@@ -52,7 +54,7 @@ const data = reactive({
   group: route.params.group,
   name: route.params.name,
   type: route.params.type,
-  operator: route.params.operator,
+  operator: route.params.operator || 'Read',
   schema: route.params.schema,
   form: {
     group: route.params.group,
@@ -211,22 +213,11 @@ function initData() {
       <template #header>
         <el-row>
           <el-col :span="20">
-            <div class="flex align-item-center header-content">
-              <div class="flex" style="height: 30px;">
-                <span class="text-bold">Group: </span>
-                <span class="item-value">{{ data.group }}</span>
-                <span class="text-bold" v-if="data.operator == 'edit'">Name: </span>
-                <span class="item-value">{{ data.name }}</span>
-                <span class="text-bold">Type: </span>
-                <span class="item-value">{{ data.type }}</span>
-                <span class="text-bold">Operation: </span>
-                <span class="item-value">{{ data.operator }}</span>
-              </div>
-            </div>
+            <FormHeader :fields="data" />
           </el-col>
           <el-col :span="4">
             <div class="flex align-item-center justify-end" style="height: 30px;">
-              <el-button type="primary" @click="submit(ruleFormRef)" color="#6E38F7">submit</el-button>
+              <el-button type="primary" @click="submit(ruleFormRef)" color="#6E38F7">Submit</el-button>
             </div>
           </el-col>
         </el-row>
@@ -265,9 +256,4 @@ function initData() {
   margin-right: 20px;
   margin-left: 5px;
 }
-.header-content {
-  height: 30px;
-  width: 100%;
-  line-height: 30px;
-}
 </style>
\ No newline at end of file
diff --git a/ui/src/components/IndexRuleBinding/index.vue b/ui/src/components/IndexRuleBinding/index.vue
index 8e5c745c..a7556b19 100644
--- a/ui/src/components/IndexRuleBinding/index.vue
+++ b/ui/src/components/IndexRuleBinding/index.vue
@@ -22,6 +22,7 @@ import { reactive } from 'vue';
 import { watch, getCurrentInstance } from '@vue/runtime-core'
 import { useRoute } from 'vue-router'
 import { getSecondaryDataModel } from '@/api/index'
+import FormHeader from '../common/FormHeader.vue'
 
 const { proxy } = getCurrentInstance()
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
@@ -73,16 +74,7 @@ function initData() {
   <div>
     <el-card>
       <template #header>
-        <div class="flex">
-          <span class="text-bold">Group: </span>
-          <span style="margin-right: 20px;">{{ data.group }}</span>
-          <span class="text-bold">Name: </span>
-          <span style="margin-right: 20px;">{{ data.name }}</span>
-          <span class="text-bold">Type: </span>
-          <span style="margin-right: 20px;">{{ data.type }}</span>
-          <span class="text-bold">Operation: </span>
-          <span>Read</span>
-        </div>
+        <FormHeader :fields="data" />
       </template>
       <el-form label-position="left" label-width="100px" :model="data.indexRuleBinding" style="width: 90%;">
         <el-form-item label="Begin At">
diff --git a/ui/src/components/Property/PropertyRead.vue b/ui/src/components/Property/PropertyRead.vue
index a7082a43..e37c114e 100644
--- a/ui/src/components/Property/PropertyRead.vue
+++ b/ui/src/components/Property/PropertyRead.vue
@@ -26,6 +26,7 @@ import { onMounted, reactive, ref } from 'vue';
 import { RefreshRight } from '@element-plus/icons-vue';
 import PropertyEditror from './PropertyEditror.vue';
 import PropertyValueReader from './PropertyValueReader.vue';
+import FormHeader from '../common/FormHeader.vue';
 
 const { proxy } = getCurrentInstance()
 // Loading
@@ -132,17 +133,13 @@ watch(() => route, () => {
 onMounted(() => {
     getProperty()
 })
+
 </script>
 <template>
     <div>
         <el-card shadow="always">
             <template #header>
-                <div class="flex">
-                    <span class="text-bold">Group: </span>
-                    <span style="margin-right: 20px;">{{ data.group }}</span>
-                    <span class="text-bold">Operation: </span>
-                    <span>Read</span>
-                </div>
+                <FormHeader :fields="data" />
             </template>
             <div class="button-group-operator">
                 <el-button size="small" type="primary" color="#6E38F7" @click="openAddProperty">Apply
diff --git a/ui/src/components/Property/PropertyValueReader.vue b/ui/src/components/Property/PropertyValueReader.vue
index 29457fed..133e72a2 100644
--- a/ui/src/components/Property/PropertyValueReader.vue
+++ b/ui/src/components/Property/PropertyValueReader.vue
@@ -18,13 +18,7 @@
 -->
 
 <script setup>
-import { applyProperty } from '@/api';
 import { reactive, ref } from 'vue';
-import { getCurrentInstance } from '@vue/runtime-core'
-import TagEditor from './TagEditor.vue';
-import { ElMessage } from 'element-plus';
-const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
-const $loadingClose = getCurrentInstance().appContext.config.globalProperties.$loadingClose
 const showDialog = ref(false)
 const title = ref('')
 const valueData = reactive({
diff --git a/ui/src/components/Read/index.vue b/ui/src/components/Read/index.vue
index 19614913..88ca6a56 100644
--- a/ui/src/components/Read/index.vue
+++ b/ui/src/components/Read/index.vue
@@ -27,6 +27,7 @@ import { jsonToYaml, yamlToJson } from '@/utils/yaml'
 import CodeMirror from '@/components/CodeMirror/index.vue'
 import { ElMessage } from 'element-plus'
 import { computed } from '@vue/runtime-core'
+import FormHeader from '../common/FormHeader.vue'
 
 const route = useRoute()
 
@@ -403,14 +404,7 @@ function changeFields() {
     <div>
         <el-card shadow="always">
             <template #header>
-                <div class="flex">
-                    <span class="text-bold">Group: </span>
-                    <span style="margin-right: 20px;">{{ data.group }}</span>
-                    <span class="text-bold">Name: </span>
-                    <span style="margin-right: 20px;">{{ data.name }}</span>
-                    <span class="text-bold">Operation: </span>
-                    <span>Read</span>
-                </div>
+                <FormHeader :fields="data" />
             </template>
             <el-row>
                 <el-col :span="16">
diff --git a/ui/src/components/TopNAggregation/Editor.vue b/ui/src/components/TopNAggregation/Editor.vue
index 0e59e7fc..5fe0dfc5 100644
--- a/ui/src/components/TopNAggregation/Editor.vue
+++ b/ui/src/components/TopNAggregation/Editor.vue
@@ -24,6 +24,8 @@ import { useRoute, useRouter } from 'vue-router'
 import type { FormInstance } from 'element-plus'
 import { createSecondaryDataModel, getSecondaryDataModel, updateSecondaryDataModel } from '@/api/index'
 import { ElMessage } from 'element-plus'
+import FormHeader from '../common/FormHeader.vue'
+
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
 const $loadingClose = getCurrentInstance().appContext.config.globalProperties.$loadingClose
 const $bus = getCurrentInstance().appContext.config.globalProperties.mittBus
@@ -269,18 +271,7 @@ function initData() {
       <template #header>
         <el-row>
           <el-col :span="12">
-            <div class="flex align-item-center" style="height: 30px; width: 100%;">
-              <div class="flex" style="height: 30px;">
-                <span class="text-bold">Group: </span>
-                <span style="margin-right: 20px;">{{ data.group }}</span>
-                <span class="text-bold" v-if="data.operator == 'edit'">Name: </span>
-                <span style="margin-right: 20px;">{{ data.name }}</span>
-                <span class="text-bold">Type: </span>
-                <span style="margin-right: 20px;">{{ data.type }}</span>
-                <span class="text-bold">Operation: </span>
-                <span>{{ data.operator }}</span>
-              </div>
-            </div>
+              <FormHeader :fields="data" />
           </el-col>
           <el-col :span="12">
             <div class="flex align-item-center justify-end" style="height: 30px;">
diff --git a/ui/src/components/TopNAggregation/index.vue b/ui/src/components/TopNAggregation/index.vue
index 8610f178..0853b762 100644
--- a/ui/src/components/TopNAggregation/index.vue
+++ b/ui/src/components/TopNAggregation/index.vue
@@ -22,6 +22,7 @@ import { reactive } from 'vue';
 import { watch, getCurrentInstance } from '@vue/runtime-core'
 import { useRoute } from 'vue-router'
 import { getSecondaryDataModel } from '@/api/index'
+import FormHeader from '../common/FormHeader.vue'
 
 const { proxy } = getCurrentInstance()
 const $loadingCreate = getCurrentInstance().appContext.config.globalProperties.$loadingCreate
@@ -75,16 +76,7 @@ function initData() {
   <div>
     <el-card>
       <template #header>
-        <div class="flex">
-          <span class="text-bold">Group: </span>
-          <span style="margin-right: 20px;">{{ data.group }}</span>
-          <span class="text-bold">Name: </span>
-          <span style="margin-right: 20px;">{{ data.name }}</span>
-          <span class="text-bold">Type: </span>
-          <span style="margin-right: 20px;">{{ data.type }}</span>
-          <span class="text-bold">Operation: </span>
-          <span>Read</span>
-        </div>
+        <FormHeader :fields="data" />
       </template>
       <el-form label-position="left" label-width="100px" :model="data.indexRule" style="width: 50%;">
         <el-form-item label="Measure Group">
diff --git a/ui/src/components/common/FormHeader.vue b/ui/src/components/common/FormHeader.vue
new file mode 100644
index 00000000..428d470c
--- /dev/null
+++ b/ui/src/components/common/FormHeader.vue
@@ -0,0 +1,50 @@
+<!-- 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. -->
+<script setup>
+defineProps({
+  fields: {
+    type: Object,
+    default: () => ({}),
+  },
+});
+</script>
+
+<template>
+  <div class="flex header-content">
+    <span class="text-bold">Group: </span>
+    <span class="item-value">{{ fields.group }}</span>
+    <span class="text-bold" v-show="fields.name">Name: </span>
+    <span class="item-value">{{ fields.name }}</span>
+    <span class="text-bold" v-show="fields.type">{{fields.catalog ? `Catalog:` : `Type:`}}</span>
+    <span class="item-value">{{ fields.type }}</span>
+    <span class="text-bold">Operation: </span>
+    <span class="item-value">{{ fields.operator == 'edit' ? fields.operator : `Read` }}</span>
+  </div>
+</template>
+
+<style lang="scss" scoped>
+:deep(.el-card) {
+  margin: 15px;
+}
+.item-value {
+  margin-right: 20px;
+  margin-left: 5px;
+}
+.header-content {
+  height: 30px;
+  width: 100%;
+  line-height: 30px;
+}
+</style>
\ No newline at end of file