Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Custom Text field value update
Tianzhou Chendbd6f2b6d2d1
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vueindex b3e15cd0ef..d37d72a3a7 100644--- a/frontend/src/views/TaskSidebar.vue+++ b/frontend/src/views/TaskSidebar.vue@@ -62,17 +62,82 @@<span v-if="field.required" class="text-red-600">*</span></h2><template v-if="field.type == 'String'">- <div class="lg:mt-3 w-3/4 lg:w-auto">+ <div+ class="lg:mt-3 w-3/4 lg:w-auto mt-1 flex"+ @focusin="state.activeCustomFieldIndex = index"+ @focusout="+ (e) => {+ // If we lose focus because of clicking the save/cancel button,+ // we should NOT reset the active index. Otherwise, the button+ // will be removed from the DOM before firing the click event.+ if (+ state.activeCustomFieldIndex == index &&+ e.relatedTarget !== customFieldSaveButton &&+ e.relatedTarget !== customFieldCancelButton+ ) {+ trySaveCustomTextField(index);+ }+ }+ "+ ><inputtype="text"- class="textfield w-full"+ autocomplete="off"+ class="z-10 flex-1 min-w-0 block w-full border border-r border-control-border focus:ring-control focus:border-control sm:text-sm"+ :class="+ state.activeCustomFieldIndex === index+ ? 'rounded-l-md'+ : 'rounded-md'+ "+ :ref="customFieldRefList[index]":name="field.id":value="fieldValue(field)":placeholder="field.placeholder"- @input="- $emit('update-custom-field', field, $event.target.value)- "/>+ <template v-if="state.activeCustomFieldIndex === index">+ <button+ tabindex="-1"+ class="z-0 -ml-px px-1 border border-control-border text-sm font-medium text-control-light bg-control-bg hover:bg-control-bg-hover focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"+ ref="customFieldSaveButton"+ @click="trySaveCustomTextField(index)"+ >+ <svg+ class="w-6 h-6 text-success"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M5 13l4 4L19 7"+ ></path>+ </svg>+ </button>+ <button+ tabindex="-1"+ class="z-0 -ml-px px-1 border border-control-border text-sm font-medium rounded-r-md text-control-light bg-control-bg hover:bg-control-bg-hover focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"+ ref="customFieldCancelButton"+ @click="state.activeCustomFieldIndex = -1"+ >+ <svg+ class="w-6 h-6 text-control"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M6 18L18 6M6 6l12 12"+ ></path>+ </svg>+ </button>+ </template></div></template><template v-else-if="field.type == 'Environment'">@@ -113,7 +178,16 @@</template><script lang="ts">-import { PropType, watchEffect, reactive } from "vue";+import {+ PropType,+ Ref,+ onMounted,+ onUnmounted,+ nextTick,+ reactive,+ ref,+ watchEffect,+} from "vue";import isEmpty from "lodash-es/isEmpty";import EnvironmentSelect from "../components/EnvironmentSelect.vue";import TaskStatusSelect from "../components/TaskStatusSelect.vue";@@ -123,6 +197,7 @@ import { activeStageIsRunning } from "../utils";interface LocalState {new: boolean;+ activeCustomFieldIndex: number;}export default {@@ -142,6 +217,39 @@ export default {setup(props, { emit }) {const state = reactive<LocalState>({new: isEmpty(props.task.id),+ activeCustomFieldIndex: -1,+ });++ const customFieldSaveButton = ref();+ const customFieldCancelButton = ref();+ const customFieldRefList: Ref<HTMLElement | undefined>[] = [];+ for (const _ of props.fieldList) {+ customFieldRefList.push(ref());+ }++ const keyboardHandler = (e: KeyboardEvent) => {+ if (state.activeCustomFieldIndex != -1) {+ if (e.code == "Escape") {+ const index = state.activeCustomFieldIndex;+ state.activeCustomFieldIndex = -1;+ nextTick(() =>+ (customFieldRefList[index].value as HTMLElement).blur()+ );+ } else if (e.code == "Enter") {+ nextTick(() =>+ (customFieldRefList[state.activeCustomFieldIndex]+ .value as HTMLElement).blur()+ );+ }+ }+ };++ onMounted(() => {+ document.addEventListener("keydown", keyboardHandler);+ });++ onUnmounted(() => {+ document.removeEventListener("keydown", keyboardHandler);});const refreshState = () => {@@ -154,9 +262,43 @@ export default {: props.task.attributes.payload[field.id];};+ const trySaveCustomTextField = (customFieldIndex: number) => {+ const field = props.fieldList[customFieldIndex];+ let value = "";+ if (field.type === "String") {+ value = (customFieldRefList[customFieldIndex].value as HTMLInputElement)+ .value;+ } else if (field.type === "Environment") {+ value = (customFieldRefList[customFieldIndex]+ .value as HTMLSelectElement).value;+ }++ if (field.required && isEmpty(value)) {+ // Refocus+ nextTick(() =>+ (customFieldRefList[customFieldIndex].value as HTMLElement).focus()+ );+ return;+ }++ if (value != fieldValue(field)) {+ emit("update-custom-field", field, value);+ }++ state.activeCustomFieldIndex = -1;+ };+watchEffect(refreshState);- return { state, activeStageIsRunning, fieldValue };+ return {+ state,+ customFieldSaveButton,+ customFieldCancelButton,+ customFieldRefList,+ activeStageIsRunning,+ fieldValue,+ trySaveCustomTextField,+ };},};</script>