Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

UI change to allow editing statement field after issue creation

天舟d0a5a0a66910
diff --git a/frontend/src/components/IssueTaskStatementPanel.vue b/frontend/src/components/IssueTaskStatementPanel.vue
index 6efabf7057..177a06f7c8 100644
--- a/frontend/src/components/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/IssueTaskStatementPanel.vue
@@ -1,31 +1,101 @@
<template>
- <div class="flex items-center space-x-4">
- <div
- class="text-sm font-medium"
- :class="
- !rollback && isEmpty(state.editStatement)
- ? 'text-red-600'
- : 'text-control'
- "
- >
- {{ rollback ? "Rollback SQL" : "SQL" }}
- <span v-if="create && !rollback" class="text-red-600">*</span>
- <span v-if="!create && migrationType == 'BASELINE'" class="text-accent"
- >(This is a baseline migration and bytebase won't apply the SQL to the
- database, it will only record a baseline history)</span
+ <div class="flex justify-between">
+ <div class="flex space-x-4">
+ <div
+ class="text-sm font-medium"
+ :class="
+ !rollback && isEmpty(state.editStatement)
+ ? 'text-red-600'
+ : 'text-control'
+ "
+ >
+ {{ rollback ? "Rollback SQL" : "SQL" }}
+ <span v-if="create && !rollback" class="text-red-600">*</span>
+ <span v-if="!create && migrationType == 'BASELINE'" class="text-accent"
+ >(This is a baseline migration and bytebase won't apply the SQL to the
+ database, it will only record a baseline history)</span
+ >
+ </div>
+ <button
+ v-if="showApplyStatement"
+ :disabled="isEmpty(state.editStatement)"
+ type="button"
+ class="btn-small"
+ @click.prevent="
+ $emit('apply-statement-to-other-stages', state.editStatement)
+ "
>
+ Apply to other stages
+ </button>
+ </div>
+ <div v-if="!create" class="space-x-2">
+ <button
+ v-if="allowEdit && !state.editing"
+ type="button"
+ class="btn-icon"
+ @click.prevent="beginEdit"
+ >
+ <!-- Heroicon name: solid/pencil -->
+ <!-- Use h-5 to avoid flickering when show/hide icon -->
+ <svg
+ class="h-5 w-5"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
+ />
+ </svg>
+ </button>
+ <!-- mt-0.5 is to prevent jiggling betweening switching edit/none-edit -->
+ <button
+ v-if="state.editing"
+ type="button"
+ class="
+ mt-0.5
+ px-3
+ rounded-sm
+ text-control
+ hover:bg-control-bg-hover
+ disabled:bg-control-bg disabled:opacity-50 disabled:cursor-not-allowed
+ text-sm
+ leading-5
+ font-normal
+ focus:ring-control focus:outline-none
+ focus-visible:ring-2
+ focus:ring-offset-2
+ "
+ @click.prevent="cancelEdit"
+ >
+ Cancel
+ </button>
+ <button
+ v-if="state.editing"
+ type="button"
+ class="
+ mt-0.5
+ px-3
+ border border-control-border
+ rounded-sm
+ text-control
+ bg-control-bg
+ hover:bg-control-bg-hover
+ disabled:bg-control-bg disabled:opacity-50 disabled:cursor-not-allowed
+ text-sm
+ leading-5
+ font-normal
+ focus:ring-control focus:outline-none
+ focus-visible:ring-2
+ focus:ring-offset-2
+ "
+ :disabled="state.editStatement == statement"
+ @click.prevent="saveEdit"
+ >
+ Save
+ </button>
</div>
- <button
- v-if="showApplyStatement"
- :disabled="isEmpty(state.editStatement)"
- type="button"
- class="btn-small"
- @click.prevent="
- $emit('apply-statement-to-other-stages', state.editStatement)
- "
- >
- Apply to other stages
- </button>
</div>
<label class="sr-only">SQL statement</label>
<template v-if="state.editing">
@@ -86,7 +156,7 @@ import {
PropType,
} from "vue";
import { sizeToFit } from "../utils";
-import { MigrationType } from "../types";
+import { MigrationType, Task, TaskCreate } from "../types";
interface LocalState {
editing: boolean;
@@ -105,6 +175,10 @@ export default {
required: true,
type: Boolean,
},
+ allowEdit: {
+ required: true,
+ type: Boolean,
+ },
rollback: {
required: true,
type: Boolean,
@@ -164,9 +238,31 @@ export default {
}
);
+ const beginEdit = () => {
+ state.editStatement = props.statement;
+ state.editing = true;
+ nextTick(() => {
+ editStatementTextArea.value.focus();
+ });
+ };
+
+ const saveEdit = () => {
+ emit("update-statement", state.editStatement, () => {
+ state.editing = false;
+ });
+ };
+
+ const cancelEdit = () => {
+ state.editStatement = props.statement;
+ state.editing = false;
+ };
+
return {
editStatementTextArea,
state,
+ beginEdit,
+ saveEdit,
+ cancelEdit,
};
},
};
diff --git a/frontend/src/components/TaskCheckRunPanel.vue b/frontend/src/components/TaskCheckRunPanel.vue
index 2b520d9aab..33604546e3 100644
--- a/frontend/src/components/TaskCheckRunPanel.vue
+++ b/frontend/src/components/TaskCheckRunPanel.vue
@@ -10,7 +10,7 @@
:rowClickable="false"
>
<template v-slot:body="{ rowData: checkResult }">
- <BBTableCell :leftPadding="4" class="table-cell w-12">
+ <BBTableCell :leftPadding="4" class="table-cell w-4">
<div class="flex flex-row space-x-2">
<div
class="
@@ -71,9 +71,6 @@
<BBTableCell class="table-cell w-48">
{{ checkResult.content }}
</BBTableCell>
- <BBTableCell class="table-cell w-16">
- {{ humanizeTs(taskCheckRun.createdTs) }}
- </BBTableCell>
</template>
</BBTable>
</template>
@@ -93,9 +90,6 @@ const columnList: BBTableColumn[] = [
{
title: "Detail",
},
- {
- title: "Created",
- },
];
export default {
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index e724530860..a135151da8 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -13,6 +13,7 @@ import {
Task,
TaskCheckRun,
TaskId,
+ TaskPatch,
TaskRun,
TaskState,
TaskStatusPatch,
@@ -208,6 +209,35 @@ const actions = {
return task;
},
+ async patchTask(
+ { dispatch, rootGetters }: any,
+ {
+ issueId,
+ pipelineId,
+ taskId,
+ taskPatch,
+ }: {
+ issueId: IssueId;
+ pipelineId: PipelineId;
+ taskId: TaskId;
+ taskPatch: TaskPatch;
+ }
+ ) {
+ const data = (
+ await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}`, {
+ data: {
+ type: "taskPatch",
+ attributes: taskPatch,
+ },
+ })
+ ).data;
+ const task = convertPartial(data.data, data.included, rootGetters);
+
+ dispatch("issue/fetchIssueById", issueId, { root: true });
+
+ return task;
+ },
+
async runChecks(
{ dispatch, rootGetters }: any,
{
diff --git a/frontend/src/types/pipeline/task.ts b/frontend/src/types/pipeline/task.ts
index 24ebf23d11..7ef43e0af0 100644
--- a/frontend/src/types/pipeline/task.ts
+++ b/frontend/src/types/pipeline/task.ts
@@ -99,6 +99,10 @@ export type TaskCreate = {
migrationType?: MigrationType;
};
+export type TaskPatch = {
+ statement?: string;
+};
+
export type TaskStatusPatch = {
// Domain specific fields
status: TaskStatus;
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 73ddf23ca3..e9f00342ce 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -152,6 +152,7 @@
<IssueTaskStatementPanel
:statement="selectedStatement"
:create="state.create"
+ :allowEdit="true"
:rollback="false"
:migrationType="selectedMigrateType"
:showApplyStatement="showIssueTaskStatementApply"
@@ -168,6 +169,7 @@
<IssueTaskStatementPanel
:statement="statement(stage)"
:create="state.create"
+ :allowEdit="allowEditStatement"
:rollback="false"
:migrationType="selectedMigrateType"
:showApplyStatement="showIssueTaskStatementApply"
@@ -184,6 +186,7 @@
<IssueTaskStatementPanel
:statement="selectedRollbackStatement"
:create="state.create"
+ :allowEdit="false"
:rollback="true"
:migrationType="selectedMigrateType"
:showApplyStatement="showIssueTaskStatementApply"
@@ -202,6 +205,7 @@
<IssueTaskStatementPanel
:statement="rollbackStatement(stage)"
:create="state.create"
+ :allowEdit="false"
:rollback="true"
:migrationType="selectedMigrateType"
:showApplyStatement="showIssueTaskStatementApply"
@@ -297,6 +301,7 @@ import {
Project,
IssueId,
MigrationType,
+ TaskPatch,
} from "../types";
import {
defaulTemplate,
@@ -671,10 +676,22 @@ export default {
}
};
- // We only allow updating statement/rollbackStatement upon issue creation.
- const updateStatement = (newStatement: string) => {
- const stage = selectedStage.value as StageCreate;
- stage.taskList[0].statement = newStatement;
+ const updateStatement = (
+ newStatement: string,
+ postUpdated?: (updatedTask: Task) => void
+ ) => {
+ if (state.create) {
+ const stage = selectedStage.value as StageCreate;
+ stage.taskList[0].statement = newStatement;
+ } else {
+ patchTask(
+ (selectedTask.value as Task).id,
+ {
+ statement: newStatement,
+ },
+ postUpdated
+ );
+ }
};
const applyStatementToOtherStages = (newStatement: string) => {
@@ -856,6 +873,28 @@ export default {
});
};
+ const patchTask = (
+ taskId: TaskId,
+ taskPatch: TaskPatch,
+ postUpdated?: (updatedTask: Task) => void
+ ) => {
+ store
+ .dispatch("task/patchTask", {
+ issueId: (issue.value as Issue).id,
+ pipelineId: (issue.value as Issue).pipeline.id,
+ taskId,
+ taskPatch,
+ })
+ .then((updatedTask) => {
+ // task/patchTask already fetches the new issue, so we schedule
+ // the next poll in NORMAL_POLL_INTERVAL
+ pollIssue(NORMAL_POLL_INTERVAL);
+ if (postUpdated) {
+ postUpdated(updatedTask);
+ }
+ });
+ };
+
const currentPipelineType = computed((): PipelineType => {
return pipelineType(issue.value.pipeline);
});
@@ -1000,8 +1039,14 @@ export default {
);
});
- const allowEditSql = computed(() => {
- return state.create;
+ const allowEditStatement = computed(() => {
+ return (
+ state.create ||
+ ((issue.value as Issue).status == "OPEN" &&
+ (issue.value as Issue).creator.id == currentUser.value.id &&
+ // Only allow if it's UI workflow
+ (issue.value as Issue).project.workflowType == "UI")
+ );
});
// For now, we only support rollback for schema update issue when all below conditions met:
@@ -1126,7 +1171,7 @@ export default {
allowEditSidebar,
allowEditOutput,
allowEditNameAndDescription,
- allowEditSql,
+ allowEditStatement,
allowRollback,
showCancelBanner,
showSuccessBanner,