Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Introduce TaskFieldReferenceProvider
天舟d2eca31658de
diff --git a/frontend/src/components/TaskStatusTransitionForm.vue b/frontend/src/components/TaskStatusTransitionForm.vueindex 978a932c11..b558714ed9 100644--- a/frontend/src/components/TaskStatusTransitionForm.vue+++ b/frontend/src/components/TaskStatusTransitionForm.vue@@ -3,11 +3,21 @@<div class="mt-2 grid grid-cols-1 gap-x-4 sm:grid-cols-4"><template v-if="transition.type == 'RESOLVE'"><template v-for="(field, index) in outputFieldList" :key="index">- <div class="sm:col-span-1">- <label class="textlabel">- {{ field.name- }}<span v-if="field.required" class="text-red-600">*</span>- </label>+ <div class="flex flex-row items-center text-sm">+ <div class="sm:col-span-1">+ <label class="textlabel">+ {{ field.name+ }}<span v-if="field.required" class="text-red-600">*</span>+ </label>+ </div>+ <template v-if="fieldProvider(field)">+ <router-link+ :to="fieldProvider(field).link"+ class="ml-2 normal-link"+ >+ {{ fieldProvider(field).title }}+ </router-link>+ </template></div><div class="sm:col-span-4 sm:col-start-1"><div class="mt-1 flex rounded-md shadow-sm">@@ -75,7 +85,11 @@import { computed, onMounted, reactive, ref, PropType } from "vue";import cloneDeep from "lodash-es/cloneDeep";import { Task, TaskStatusTransition } from "../types";-import { TaskField } from "../plugins";+import {+ TaskField,+ TaskFieldReferenceProvider,+ TaskFieldReferenceProviderContext,+} from "../plugins";interface LocalState {comment: string;@@ -141,11 +155,24 @@ export default {return true;});+ const fieldProvider = (+ field: TaskField+ ): TaskFieldReferenceProvider | undefined => {+ if (field.provider) {+ return field.provider({+ task: props.task,+ field,+ });+ }+ return undefined;+ };+return {state,commentTextArea,submitButtonStyle,allowSubmit,+ fieldProvider,};},};diff --git a/frontend/src/plugins/task/DatabaseRequestTemplate.ts b/frontend/src/plugins/task/DatabaseRequestTemplate.tsindex be185f886e..7693f11db0 100644--- a/frontend/src/plugins/task/DatabaseRequestTemplate.ts+++ b/frontend/src/plugins/task/DatabaseRequestTemplate.ts@@ -1,12 +1,14 @@import isEmpty from "lodash-es/isEmpty";import {+ TaskField,TaskTemplate,TemplateContext,TaskBuiltinFieldId,+ TaskFieldReferenceProviderContext,DatabaseFieldPayload,} from "../types";--import { TaskNew, EnvironmentId } from "../../types";+import { linkfy, validLink } from "../../utils";+import { Task, TaskNew, EnvironmentId } from "../../types";const template: TaskTemplate = {type: "bytebase.database.request",@@ -72,12 +74,56 @@ const template: TaskTemplate = {category: "OUTPUT",id: "99",slug: "datasource",- name: "Data Source URL",+ name: "Data source",type: "String",required: true,isEmpty: (value: string): boolean => {return isEmpty(value?.trim());},+ provider: ({ task, field }: { task: Task; field: TaskField }) => {+ const currentValue = task.payload[field.id];+ if (validLink(currentValue)) {+ return {+ title: "view data source",+ link: linkfy(currentValue),+ };+ }++ let title = "create data source";+ let link = "/db/new";+ const databasePayload: DatabaseFieldPayload =+ task.payload[TaskBuiltinFieldId.DATABASE];+ if (!databasePayload.isNew) {+ title = "assign data source";+ }++ const queryParamList: string[] = [];++ const environmentId = task.payload[TaskBuiltinFieldId.ENVIRONMENT];+ if (environmentId) {+ queryParamList.push(`env=${environmentId}`);+ }++ if (databasePayload.name) {+ queryParamList.push(`name=${databasePayload.name}`);+ }++ // If we are creating a new database, we always assign RW to the owner.+ if (!databasePayload.isNew && databasePayload.readOnly) {+ queryParamList.push(`readonly=true`);+ }++ queryParamList.push(`owner=${task.creator.id}`);++ queryParamList.push(`task=${task.id}`);++ link += "?" + queryParamList.join("&");++ return {+ title,+ link,+ };+ },},],};diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.tsindex 5f27303b85..3c3b0e00cc 100644--- a/frontend/src/plugins/types.ts+++ b/frontend/src/plugins/types.ts@@ -1,4 +1,4 @@-import { Environment, Principal, TaskNew, DatabaseId } from "../types";+import { Environment, Principal, TaskNew, Task, DatabaseId } from "../types";// Taskexport type TaskFieldId = string;@@ -23,6 +23,16 @@ export type TaskFieldType =| "NewDatabase"| "Switch";+export type TaskFieldReferenceProvider = {+ title: string;+ link: string;+};++export type TaskFieldReferenceProviderContext = {+ task: Task;+ field: TaskField;+};+export type TaskField = {category: "INPUT" | "OUTPUT";// Used as the key to store the data. This must NOT be changed after@@ -47,6 +57,13 @@ export type TaskField = {isEmpty: (value: any) => boolean;// Placeholder displayed on UI.placeholder?: string;+ // Provides the reference to the place where the field originates. e.g. the request database+ // task requires to fill the data source field when resolving the task, while the data source value+ // can be found in the data source / database page. This provider can return the relevant link to+ // be displayed on the UI, which helps user navigate to the place to acquire the required info.+ provider?: (+ ctx: TaskFieldReferenceProviderContext+ ) => TaskFieldReferenceProvider;};// Field payload for "Database" and "NewDatabase" fielddiff --git a/frontend/src/views/TaskOutputPanel.vue b/frontend/src/views/TaskOutputPanel.vueindex e128e77531..aa454bb3aa 100644--- a/frontend/src/views/TaskOutputPanel.vue+++ b/frontend/src/views/TaskOutputPanel.vue@@ -2,71 +2,79 @@<h2 class="px-4 text-lg font-medium">Result<span class="text-base font-normal text-control-light">- (assignee should fill the required field(s) before resolving the task)+ (these fields will be filled by the assignee before resolving the task)</span></h2><div class="my-2 mx-4 space-y-2"><template v-for="(field, index) in fieldList" :key="index">- <div class="flex">- <span- class="whitespace-nowrap inline-flex items-center px-3 rounded-l-md border border-l border-r-0 border-control-border bg-gray-50 text-control-light sm:text-sm"- >+ <div class="flex flex-col">+ <div class="textlabel">{{ field.name }}<span v-if="field.required" class="text-red-600">*</span>- </span>- <input- type="text"- class="flex-1 min-w-0 block w-full px-3 py-2 border border-r border-control-border focus:mr-0.5 focus:ring-control focus:border-control sm:text-sm disabled:bg-gray-50"- :disabled="!allowEdit"- :name="field.id"- :value="task.payload[field.id]"- autocomplete="off"- @blur="$emit('update-custom-field', field, $event.target.value)"- />- <!-- Disallow tabbing since the focus ring is partially covered by the text field due to overlaying -->- <button- tabindex="-1"- :disabled="!task.payload[field.id]"- class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1 disabled:cursor-not-allowed"- @click.prevent="copyText(field)"- >- <svg- class="w-6 h-6"- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- xmlns="http://www.w3.org/2000/svg"+ <template v-if="fieldProvider(field)">+ <router-link+ :to="fieldProvider(field).link"+ class="ml-2 normal-link"+ >+ {{ fieldProvider(field).title }}+ </router-link>+ </template>+ </div>+ <div class="mt-1 flex flex-row">+ <input+ type="text"+ class="flex-1 min-w-0 block w-full px-3 py-2 rounded-l-md border border-r border-control-border focus:mr-0.5 focus:ring-control focus:border-control sm:text-sm disabled:bg-gray-50"+ :disabled="!allowEdit"+ :name="field.id"+ :value="task.payload[field.id]"+ autocomplete="off"+ @blur="$emit('update-custom-field', field, $event.target.value)"+ />+ <!-- Disallow tabbing since the focus ring is partially covered by the text field due to overlaying -->+ <button+ tabindex="-1"+ :disabled="!task.payload[field.id]"+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1 disabled:cursor-not-allowed"+ @click.prevent="copyText(field)">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"- ></path>- </svg>- </button>- <button- tabindex="-1"- :disabled="!isValidLink(task.payload[field.id])"- class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium rounded-r-md text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"- @click.prevent="goToLink(task.payload[field.id])"- >- <svg- class="w-6 h-6"- fill="none"- stroke="currentColor"- viewBox="0 0 24 24"- xmlns="http://www.w3.org/2000/svg"+ <svg+ class="w-6 h-6"+ 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="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"+ ></path>+ </svg>+ </button>+ <button+ tabindex="-1"+ :disabled="!isValidLink(task.payload[field.id])"+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium rounded-r-md text-control-light disabled:text-gray-300 bg-gray-50 hover:bg-gray-100 disabled:bg-gray-50 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"+ @click.prevent="goToLink(task.payload[field.id])">- <path- stroke-linecap="round"- stroke-linejoin="round"- stroke-width="2"- d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"- ></path>- </svg>- </button>+ <svg+ class="w-6 h-6"+ 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="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"+ ></path>+ </svg>+ </button>+ </div></div></template></div>@@ -77,7 +85,7 @@ import { PropType, computed, reactive } from "vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import { toClipboard } from "@soerenmartius/vue3-clipboard";-import { TaskField } from "../plugins";+import { TaskField, TaskFieldReferenceProvider } from "../plugins";import { Task } from "../types";interface LocalState {}@@ -119,6 +127,18 @@ export default {return link?.trim().length > 0;};+ const fieldProvider = (+ field: TaskField+ ): TaskFieldReferenceProvider | undefined => {+ if (field.provider) {+ return field.provider({+ task: props.task,+ field,+ });+ }+ return undefined;+ };+const copyText = (field: TaskField) => {toClipboard(props.task.payload[field.id]).then(() => {store.dispatch("notification/pushNotification", {@@ -143,7 +163,7 @@ export default {}};- return { state, allowEdit, isValidLink, copyText, goToLink };+ return { state, allowEdit, isValidLink, fieldProvider, copyText, goToLink };},};</script>