Skip to content

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

refactor(frontend): IssueDetail part.3 (#1273)

Liu Ji7ca5eeda6136
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index c3d2580143..4709b2567d 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -4,211 +4,161 @@
class="flex-1 overflow-auto focus:outline-none"
tabindex="0"
>
- <IssueBanner v-if="!create" :issue="(issue as Issue)" />
+ <component :is="logicProviderType" ref="issueLogic">
+ <IssueBanner v-if="!create" :issue="(issue as Issue)" />
- <!-- Highlight Panel -->
- <div class="bg-white px-4 pb-4">
- <IssueHighlightPanel
- :issue="(issue as Issue)"
- :create="create"
- :allow-edit="allowEditNameAndDescription"
- @update-name="updateName"
- >
- <IssueStatusTransitionButtonGroup
+ <!-- Highlight Panel -->
+ <div class="bg-white px-4 pb-4">
+ <IssueHighlightPanel
+ :issue="(issue as Issue)"
:create="create"
- :issue="issue"
- :issue-template="issueTemplate"
- @create="doCreate"
- @change-issue-status="changeIssueStatus"
- @change-task-status="changeTaskStatus"
- />
- </IssueHighlightPanel>
- </div>
+ :allow-edit="allowEditNameAndDescription"
+ @update-name="updateName"
+ >
+ <IssueStatusTransitionButtonGroup
+ @change-issue-status="changeIssueStatus"
+ @change-task-status="changeTaskStatus"
+ />
+ </IssueHighlightPanel>
+ </div>
- <!-- Remind banner for bb.feature.backward-compatibility -->
- <FeatureAttention
- v-if="
- !hasBackwardCompatibilityFeature && supportBackwardCompatibilityFeature
- "
- custom-class="m-5 mt-0"
- feature="bb.feature.backward-compatibility"
- :description="
- $t('subscription.features.bb-feature-backward-compatibility.desc')
- "
- />
+ <!-- Remind banner for bb.feature.backward-compatibility -->
+ <FeatureAttention
+ v-if="
+ !hasBackwardCompatibilityFeature &&
+ supportBackwardCompatibilityFeature
+ "
+ custom-class="m-5 mt-0"
+ feature="bb.feature.backward-compatibility"
+ :description="
+ $t('subscription.features.bb-feature-backward-compatibility.desc')
+ "
+ />
- <!-- Stage Flow Bar -->
- <template v-if="showPipelineFlowBar">
- <template v-if="isTenantDeployMode">
- <PipelineTenantFlow v-if="project" class="border-t border-b" />
- </template>
- <template v-else-if="isGhostMode">
- <PipelineGhostFlow v-if="project" class="border-t border-b" />
- </template>
- <template v-else>
- <PipelineSimpleFlow class="border-t border-b" />
+ <!-- Stage Flow Bar -->
+ <template v-if="showPipelineFlowBar">
+ <template v-if="isTenantMode">
+ <PipelineTenantFlow v-if="project" class="border-t border-b" />
+ </template>
+ <template v-else-if="isGhostMode">
+ <PipelineGhostFlow v-if="project" class="border-t border-b" />
+ </template>
+ <template v-else>
+ <PipelineSimpleFlow class="border-t border-b" />
+ </template>
+
+ <div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b">
+ <IssueStagePanel
+ :stage="(selectedStage as Stage)"
+ :selected-task="(selectedTask as Task)"
+ :is-tenant-mode="isTenantMode"
+ :is-ghost-mode="isGhostMode"
+ />
+ </div>
</template>
- <div v-if="!create" class="px-4 py-4 md:flex md:flex-col border-b">
- <IssueStagePanel
- :stage="(selectedStage as Stage)"
- :selected-task="(selectedTask as Task)"
- :is-tenant-mode="isTenantDeployMode"
- :is-ghost-mode="isGhostMode"
+ <!-- Output Panel -->
+ <!-- Only render the top border if PipelineFlowBar is not displayed, otherwise it would overlap with the bottom border of that -->
+ <div
+ v-if="showIssueOutputPanel"
+ class="px-2 py-4 md:flex md:flex-col"
+ :class="showPipelineFlowBar ? '' : 'lg:border-t'"
+ >
+ <IssueOutputPanel
+ :issue="(issue as Issue)"
+ :output-field-list="issueTemplate.outputFieldList"
+ :allow-edit="allowEditOutput"
+ @update-custom-field="updateCustomField"
/>
</div>
- </template>
-
- <!-- Output Panel -->
- <!-- Only render the top border if PipelineFlowBar is not displayed, otherwise it would overlap with the bottom border of that -->
- <div
- v-if="showIssueOutputPanel"
- class="px-2 py-4 md:flex md:flex-col"
- :class="showPipelineFlowBar ? '' : 'lg:border-t'"
- >
- <IssueOutputPanel
- :issue="(issue as Issue)"
- :output-field-list="issueTemplate.outputFieldList"
- :allow-edit="allowEditOutput"
- @update-custom-field="updateCustomField"
- />
- </div>
-
- <!-- Main Content -->
- <main
- class="flex-1 relative overflow-y-auto focus:outline-none"
- :class="
- showPipelineFlowBar && !showIssueOutputPanel
- ? ''
- : 'lg:border-t lg:border-block-border'
- "
- tabindex="-1"
- >
- <div class="flex max-w-3xl mx-auto px-6 lg:max-w-full">
- <div class="flex flex-col flex-1 lg:flex-row-reverse lg:col-span-2">
- <div
- class="py-6 lg:pl-4 lg:w-96 xl:w-112 lg:border-l lg:border-block-border overflow-hidden"
- >
- <IssueSidebar
- :issue="issue"
- :database="database"
- :instance="instance"
- :create="create"
- :selected-stage="selectedStage"
- :task="selectedTask"
- :input-field-list="issueTemplate.inputFieldList"
- :allow-edit="allowEditSidebar"
- :is-tenant-deploy-mode="isTenantDeployMode"
- @update-assignee-id="updateAssigneeId"
- @update-earliest-allowed-time="updateEarliestAllowedTime"
- @add-subscriber-id="addSubscriberId"
- @remove-subscriber-id="removeSubscriberId"
- @update-custom-field="updateCustomField"
- @select-stage-id="selectStageOrTask"
- @select-task-id="selectTaskId"
- />
- </div>
- <div class="lg:hidden border-t border-block-border" />
- <div class="w-full py-4 pr-4">
- <section v-if="showIssueTaskStatementPanel" class="border-b mb-4">
- <div v-if="!create" class="mb-4">
- <TaskCheckBar
- :task="(selectedTask as Task)"
- @run-checks="runTaskChecks"
- />
- </div>
- <template v-if="isTenantDeployMode">
- <!--
- For tenant deploy mode, we provide only one statement panel.
- It's editable only when creating an issue.
- It is not allowed to "Apply to other stages".
- -->
- <IssueTaskStatementPanel
- :sql-hint="sqlHint()"
- :statement="selectedStatement"
- :create="create"
- :allow-edit="create"
- :show-apply-statement="false"
- @update-statement="updateStatement"
- />
- </template>
- <template v-else-if="isGhostMode">
- <!--
- For gh-ost mode, only the first task (bb.task.database.schema.update.ghost.sync)
- has a SQL statement.
- TODO(jim): When the other two tasks are selected we should show the SQL which will be internally
- executed (change table name and drop table).
- -->
- <template v-if="isGhostSyncTaskSelected">
- <IssueTaskStatementPanel
- :sql-hint="sqlHint()"
- :statement="selectedStatement"
- :create="create"
- :allow-edit="allowEditStatement"
- :show-apply-statement="showIssueTaskStatementApply"
- @update-statement="updateStatement"
- @apply-statement-to-other-stages="
- applyStatementToOtherStages
- "
- />
- </template>
- </template>
- <template v-else>
- <IssueTaskStatementPanel
- v-if="create"
- :sql-hint="sqlHint()"
- :statement="selectedStatement"
- :create="create"
- :allow-edit="true"
- :show-apply-statement="showIssueTaskStatementApply"
- @update-statement="updateStatement"
- @apply-statement-to-other-stages="applyStatementToOtherStages"
- />
- <IssueTaskStatementPanel
- v-else
- :sql-hint="sqlHint()"
- :statement="statement(selectedStage as Stage)"
- :create="create"
- :allow-edit="allowEditStatement"
- :show-apply-statement="showIssueTaskStatementApply"
- @update-statement="updateStatement"
- />
- </template>
- </section>
- <IssueDescriptionPanel
- :issue="issue"
- :create="create"
- :allow-edit="allowEditNameAndDescription"
- @update-description="updateDescription"
- />
- <section
- v-if="!create"
- aria-labelledby="activity-title"
- class="mt-4"
+ <!-- Main Content -->
+ <main
+ class="flex-1 relative overflow-y-auto focus:outline-none"
+ :class="
+ showPipelineFlowBar && !showIssueOutputPanel
+ ? ''
+ : 'lg:border-t lg:border-block-border'
+ "
+ tabindex="-1"
+ >
+ <div class="flex max-w-3xl mx-auto px-6 lg:max-w-full">
+ <div class="flex flex-col flex-1 lg:flex-row-reverse lg:col-span-2">
+ <div
+ class="py-6 lg:pl-4 lg:w-96 xl:w-112 lg:border-l lg:border-block-border overflow-hidden"
>
- <IssueActivityPanel
- :issue="(issue as Issue)"
- :issue-template="issueTemplate"
+ <IssueSidebar
+ :issue="issue"
+ :database="database"
+ :instance="instance"
+ :create="create"
+ :selected-stage="selectedStage"
+ :task="selectedTask"
+ :input-field-list="issueTemplate.inputFieldList"
+ :allow-edit="allowEditSidebar"
+ :is-tenant-deploy-mode="isTenantMode"
+ @update-assignee-id="updateAssigneeId"
+ @update-earliest-allowed-time="updateEarliestAllowedTime"
@add-subscriber-id="addSubscriberId"
+ @remove-subscriber-id="removeSubscriberId"
+ @update-custom-field="updateCustomField"
+ @select-stage-id="selectStageOrTask"
+ @select-task-id="selectTaskId"
+ />
+ </div>
+ <div class="lg:hidden border-t border-block-border" />
+ <div class="w-full py-4 pr-4">
+ <section v-if="showIssueTaskStatementPanel" class="border-b mb-4">
+ <div v-if="!create" class="mb-4">
+ <TaskCheckBar
+ :task="(selectedTask as Task)"
+ @run-checks="runTaskChecks"
+ />
+ </div>
+ <IssueTaskStatementPanel :sql-hint="sqlHint()" />
+ </section>
+
+ <IssueDescriptionPanel
+ :issue="issue"
+ :create="create"
+ :allow-edit="allowEditNameAndDescription"
+ @update-description="updateDescription"
/>
- </section>
+ <section
+ v-if="!create"
+ aria-labelledby="activity-title"
+ class="mt-4"
+ >
+ <IssueActivityPanel
+ :issue="(issue as Issue)"
+ :issue-template="issueTemplate"
+ @add-subscriber-id="addSubscriberId"
+ />
+ </section>
+ </div>
</div>
</div>
- </div>
- </main>
+ </main>
+ </component>
</div>
</template>
<script lang="ts" setup>
/* eslint-disable vue/no-mutating-props */
-import { computed, nextTick, onMounted, PropType, watchEffect } from "vue";
+import {
+ computed,
+ nextTick,
+ onMounted,
+ PropType,
+ ref,
+ watch,
+ watchEffect,
+} from "vue";
import { useRoute, useRouter } from "vue-router";
import { cloneDeep, isEmpty, isEqual } from "lodash-es";
import {
idFromSlug,
- issueSlug,
pipelineType,
PipelineType,
indexFromSlug,
@@ -218,6 +168,7 @@ import {
isDev,
activeTaskInStage,
activeTask,
+ issueSlug,
} from "@/utils";
import IssueBanner from "./IssueBanner.vue";
import IssueHighlightPanel from "./IssueHighlightPanel.vue";
@@ -248,19 +199,11 @@ import type {
IssueStatusPatch,
Task,
TaskDatabaseSchemaUpdatePayload,
- TaskDatabaseDataUpdatePayload,
StageCreate,
TaskCreate,
- TaskDatabaseCreatePayload,
- TaskGeneralPayload,
Project,
MigrationType,
TaskPatch,
- UpdateSchemaContext,
- UpdateSchemaDetail,
- TaskDatabaseSchemaUpdateGhostSyncPayload,
- UpdateSchemaGhostContext,
- SQLDialect,
} from "@/types";
import {
defaultTemplate,
@@ -277,10 +220,15 @@ import {
useIssueSubscriberStore,
useProjectStore,
useTaskStore,
- useUIStateStore,
} from "@/store";
-import formatSQL from "../MonacoEditor/sqlFormatter";
-import { provideIssueContext } from "./context";
+import {
+ provideIssueLogic,
+ TenantModeProvider,
+ GhostModeProvider,
+ StandardModeProvider,
+ TaskTypeWithStatement,
+ IssueLogic,
+} from "./logic";
const props = defineProps({
create: {
@@ -307,6 +255,11 @@ const taskStore = useTaskStore();
const projectStore = useProjectStore();
const databaseStore = useDatabaseStore();
+const create = computed(() => props.create);
+const issue = computed(() => props.issue);
+
+const issueLogic = ref<IssueLogic>();
+
watchEffect(function prepare() {
if (props.create) {
projectStore.fetchProjectById((props.issue as IssueCreate).projectId);
@@ -324,31 +277,6 @@ const project = computed((): Project => {
return (props.issue as Issue).project;
});
-const formatStatementIfNeeded = (
- statement: string,
- database?: Database
-): string => {
- const uiStateStore = useUIStateStore();
- if (!uiStateStore.issueFormatStatementOnSave) {
- // Don't format if user closed this feature
- return statement;
- }
-
- // Default to use mysql dialect but use postgresql dialect if needed
- let dialect: SQLDialect = "mysql";
- if (database && database.instance.engine === "POSTGRES") {
- dialect = "postgresql";
- }
-
- const result = formatSQL(statement, dialect);
- if (!result.error) {
- return result.data;
- }
-
- // Fallback to the input statement if error occurs while formatting
- return statement;
-};
-
const updateName = (
newName: string,
postUpdated: (updatedIssue: Issue) => void
@@ -365,64 +293,6 @@ const updateName = (
}
};
-const updateStatement = (
- newStatement: string,
- postUpdated?: (updatedTask: Task) => void
-) => {
- if (props.create) {
- if (isTenantDeployMode.value) {
- // For tenant deploy mode, we apply the statement to all stages and all tasks
- const issueCreate = props.issue as IssueCreate;
- const context = issueCreate.createContext as UpdateSchemaContext;
- issueCreate.pipeline?.stageList.forEach((stage: StageCreate) => {
- stage.taskList.forEach((task) => {
- task.statement = newStatement;
- });
- });
- // We also apply it to the CreateContext
- context.updateSchemaDetailList.forEach(
- (detail) => (detail.statement = newStatement)
- );
- } else {
- // otherwise apply it to the only one task in stage
- // i.e. selectedStage.taskList[0]
- const stage = selectedStage.value as StageCreate;
- stage.taskList[0].statement = newStatement;
- }
- } else {
- if (isTenantDeployMode.value) {
- // <del>For tenant deploy mode, we patch the issue's create context</del>
- // nope, we are not allowed to update statement in tenant deploy mode anyway
- } else {
- // otherwise, patch the task
- const task = selectedTask.value as Task;
- patchTask(
- task.id,
- {
- statement: formatStatementIfNeeded(newStatement, task.database),
- },
- postUpdated
- );
- }
- }
-};
-
-const applyStatementToOtherStages = (newStatement: string) => {
- for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {
- for (const task of stage.taskList) {
- if (
- task.type == "bb.task.general" ||
- task.type == "bb.task.database.create" ||
- task.type == "bb.task.database.schema.update" ||
- task.type == "bb.task.database.schema.update.ghost.sync" ||
- task.type == "bb.task.database.data.update"
- ) {
- task.statement = newStatement;
- }
- }
- }
-};
-
const updateDescription = (
newDescription: string,
postUpdated: (updatedIssue: Issue) => void
@@ -499,66 +369,6 @@ const updateCustomField = (field: InputField | OutputField, value: any) => {
}
};
-const doCreate = () => {
- const issue = cloneDeep(props.issue) as IssueCreate;
- if (!isTenantDeployMode.value) {
- // for standard issue pipeline (1 * 1 or M * 1)
- // copy user edited tasks back to issue.createContext
- const taskList = issue.pipeline!.stageList.map(
- (stage) => stage.taskList[0]
- );
- const detailList: UpdateSchemaDetail[] = taskList.map((task) => {
- const db = databaseStore.getDatabaseById(task.databaseId!);
- return {
- databaseId: task.databaseId!,
- databaseName: task.databaseName!,
- statement: formatStatementIfNeeded(task.statement, db),
- earliestAllowedTs: task.earliestAllowedTs,
- };
- });
- issue.createContext = {
- migrationType: taskList[0].migrationType!,
- updateSchemaDetailList: detailList,
- };
- } else if (isGhostMode.value) {
- // for gh-ost mode, copy user edited tasks back to issue.createContext
- // only the first subtask (bb.task.database.schema.update.ghost.sync) has statement
- const stageList = issue.pipeline!.stageList;
- const createContext = issue.createContext as UpdateSchemaGhostContext;
- const detailList = createContext.updateSchemaDetailList;
- stageList.forEach((stage, i) => {
- const detail = detailList[i];
- const syncTask = stage.taskList[0];
- const db = databaseStore.getDatabaseById(syncTask.databaseId!);
-
- detail.databaseId = syncTask.databaseId!;
- detail.databaseName = syncTask.databaseName!;
- detail.statement = formatStatementIfNeeded(syncTask.statement, db);
- detail.earliestAllowedTs = syncTask.earliestAllowedTs;
- });
- } else {
- // for multi-tenancy issue pipeline (M * N)
- // createContext is up-to-date already
- // so we just format the statement if needed
- const context = issue.createContext as UpdateSchemaContext;
- context.updateSchemaDetailList.forEach((detail) => {
- const db = databaseStore.getDatabaseById(detail.databaseId!);
- detail.statement = formatStatementIfNeeded(detail.statement, db);
- });
- }
-
- // then empty issue.pipeline and issue.payload
- // because we are no longer passing parameters via issue.pipeline
- // we are using issue.createContext instead
- delete issue.pipeline;
- issue.payload = {};
-
- issueStore.createIssue(issue).then((createdIssue) => {
- // Use replace to omit the new issue url in the navigation history.
- router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);
- });
-};
-
const changeIssueStatus = (newStatus: IssueStatus, comment: string) => {
const issueStatusPatch: IssueStatusPatch = {
status: newStatus,
@@ -650,7 +460,6 @@ const patchTask = (
.then((updatedTask) => {
// For now, the only task/patchTask is to change statement, which will trigger async task check.
// Thus we use the short poll interval
- // pollIssue(POST_CHANGE_POLL_INTERVAL);
emit("status-changed", true);
if (postUpdated) {
postUpdated(updatedTask);
@@ -658,6 +467,19 @@ const patchTask = (
});
};
+const createIssue = (issue: IssueCreate) => {
+ // Set issue.pipeline and issue.payload to empty
+ // because we are no longer passing parameters via issue.pipeline
+ // we are using issue.createContext instead
+ delete issue.pipeline;
+ issue.payload = {};
+
+ issueStore.createIssue(issue).then((createdIssue) => {
+ // Use replace to omit the new issue url in the navigation history.
+ router.replace(`/issue/${issueSlug(createdIssue.name, createdIssue.id)}`);
+ });
+};
+
const currentPipelineType = computed((): PipelineType => {
return pipelineType(props.issue.pipeline!);
});
@@ -746,35 +568,7 @@ const selectedTask = computed((): Task | TaskCreate => {
return taskList[0];
});
-const statement = (stage: Stage): string => {
- const task = stage.taskList[0];
- switch (task.type) {
- case "bb.task.general":
- return ((task as Task).payload as TaskGeneralPayload).statement || "";
- case "bb.task.database.create":
- return (
- ((task as Task).payload as TaskDatabaseCreatePayload).statement || ""
- );
- case "bb.task.database.schema.update":
- return (
- ((task as Task).payload as TaskDatabaseSchemaUpdatePayload).statement ||
- ""
- );
- case "bb.task.database.data.update":
- return (
- ((task as Task).payload as TaskDatabaseDataUpdatePayload).statement ||
- ""
- );
- case "bb.task.database.restore":
- return "";
- case "bb.task.database.schema.update.ghost.sync":
- case "bb.task.database.schema.update.ghost.cutover":
- case "bb.task.database.schema.update.ghost.drop-original-table":
- return ""; // should never reach here
- }
-};
-
-const isTenantDeployMode = computed((): boolean => {
+const isTenantMode = computed((): boolean => {
if (project.value.tenantMode !== "TENANT") return false;
return (
props.issue.type === "bb.issue.database.schema.update" ||
@@ -788,51 +582,6 @@ const isGhostMode = computed((): boolean => {
return props.issue.type === "bb.issue.database.schema.update.ghost";
});
-const isGhostSyncTaskSelected = computed((): boolean => {
- return (
- selectedTask.value.type === "bb.task.database.schema.update.ghost.sync"
- );
-});
-
-const selectedStatement = computed((): string => {
- if (isTenantDeployMode.value) {
- // In tenant mode, the entire issue shares only one SQL statement
- if (props.create) {
- const issueCreate = props.issue as IssueCreate;
- const context = issueCreate.createContext as UpdateSchemaContext;
- return context.updateSchemaDetailList[0].statement;
- } else {
- const issue = props.issue as Issue;
- const task = issue.pipeline.stageList[0].taskList[0];
- const payload = task.payload as TaskDatabaseSchemaUpdatePayload;
- return payload.statement;
- }
- } else if (isGhostMode.value) {
- // In gh-ost mode, each stage can own its SQL statement
- // But only for task.type === "bb.task.database.schema.update.ghost.sync"
- const task = selectedTask.value;
- if (task.type === "bb.task.database.schema.update.ghost.sync") {
- if (props.create) {
- return (task as TaskCreate).statement;
- } else {
- const payload = (task as Task)
- .payload as TaskDatabaseSchemaUpdateGhostSyncPayload;
- return payload.statement;
- }
- } else {
- return "";
- }
- } else {
- if (router.currentRoute.value.query.sql) {
- const sql = router.currentRoute.value.query.sql as string;
- updateStatement(sql);
- }
-
- const task = (selectedStage.value as StageCreate).taskList[0];
- return task.statement;
- }
-});
-
const selectedMigrateType = computed((): MigrationType => {
if (
!props.create &&
@@ -876,42 +625,6 @@ const allowEditNameAndDescription = computed(() => {
);
});
-const allowEditStatement = computed(() => {
- // if creating an issue, it's editable
- if (props.create) {
- return true;
- }
- const checkTask = (task: Task) => {
- return (
- task.status == "PENDING" ||
- task.status == "PENDING_APPROVAL" ||
- task.status == "FAILED"
- );
- };
-
- const issue = props.issue as Issue;
- // if not creating, we are allowed to edit sql statement only when:
- // 1. issue.status is OPEN
- // 2. AND currentUser is the creator
- // 3. AND workflowType is UI
- if (issue.status !== "OPEN") return false;
- if (issue.creator.id !== currentUser.value.id) return false;
- if (issue.project.workflowType !== "UI") return false;
-
- if (isTenantDeployMode.value) {
- // <del>then if in tenant deploy mode, EVERY task must be PENDING or PENDING_APPROVAL or FAILED</del>
- // nope, we are not allowed to update statement in tenant deploy mode anyway
- // const allTasks = issue.pipeline.stageList.flatMap(
- // (stage) => stage.taskList
- // );
- // return allTasks.every((task) => checkTask(task));
- return false;
- } else {
- // otherwise, check `selectedTask`, expected to be PENDING or PENDING_APPROVAL or FAILED
- return checkTask(selectedTask.value as Task);
- }
-});
-
const showPipelineFlowBar = computed(() => {
return currentPipelineType.value != "NO_PIPELINE";
});
@@ -922,37 +635,7 @@ const showIssueOutputPanel = computed(() => {
const showIssueTaskStatementPanel = computed(() => {
const task = selectedTask.value;
- return (
- task.type == "bb.task.general" ||
- task.type == "bb.task.database.create" ||
- task.type == "bb.task.database.schema.update" ||
- task.type == "bb.task.database.schema.update.ghost.sync" ||
- task.type == "bb.task.database.data.update"
- );
-});
-
-const showIssueTaskStatementApply = computed(() => {
- if (!props.create) {
- return false;
- }
- if (isTenantDeployMode.value) {
- return false;
- }
- let count = 0;
- for (const stage of (props.issue as IssueCreate).pipeline!.stageList) {
- for (const task of stage.taskList) {
- if (
- task.type == "bb.task.general" ||
- task.type == "bb.task.database.create" ||
- task.type == "bb.task.database.schema.update" ||
- task.type == "bb.task.database.schema.update.ghost.sync" ||
- task.type == "bb.task.database.data.update"
- ) {
- count++;
- }
- }
- }
- return count > 1;
+ return TaskTypeWithStatement.includes(task.type);
});
const database = computed((): Database | undefined => {
@@ -1020,12 +703,7 @@ const isValidStage = (stage: Stage | StageCreate) => {
}
for (const task of stage.taskList) {
- if (
- task.type === "bb.task.database.create" ||
- task.type === "bb.task.database.schema.update" ||
- task.type === "bb.task.database.data.update" ||
- task.type === "bb.task.database.schema.update.ghost.sync"
- ) {
+ if (TaskTypeWithStatement.includes(task.type)) {
if (isEmpty((task as TaskCreate).statement)) {
return false;
}
@@ -1034,20 +712,46 @@ const isValidStage = (stage: Stage | StageCreate) => {
return true;
};
-provideIssueContext(
+// Determine which type of IssueLogicProvider should be used
+const logicProviderType = computed(() => {
+ if (isTenantMode.value) return TenantModeProvider;
+ if (isGhostMode.value) return GhostModeProvider;
+ return StandardModeProvider;
+});
+
+watch(
+ [create, issue, () => route.query.sql as string, issueLogic],
+ ([create, issue, sql, provider]) => {
+ // If 'sql' in URL query, update the issueCreate's statement
+ // Only works for the first time.
+ // E.g. redirected from SQL editor when user wants to execute DML.
+ if (create && issue && sql && provider) {
+ provider.updateStatement(sql);
+ }
+ }
+);
+
+provideIssueLogic(
{
- create: computed(() => props.create),
- issue: computed(() => props.issue),
+ create,
+ issue,
project: project,
+ template: issueTemplate,
selectedStage,
selectedTask,
+ isTenantMode,
+ isGhostMode,
isValidStage,
taskStatusOfStage,
activeStageOfPipeline: activeStage,
activeTaskOfPipeline: activeTask,
activeTaskOfStage: activeTaskInStage,
selectStageOrTask: selectStageOrTask,
+ patchTask,
+ patchIssue,
+ createIssue,
},
- true // root context
+ true
+ // This is the root logic, could be overwritten by other (standard, gh-ost, tenant...) logic providers.
);
</script>
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index 5f7272cdf8..49bbcb5b9f 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -83,19 +83,19 @@
<StatusTransitionForm
:mode="updateStatusModalState.mode"
:ok-text="updateStatusModalState.okText"
- :issue="issue"
+ :issue="(issue as Issue)"
:task="currentTask"
- :transition="updateStatusModalState.transition"
+ :transition="updateStatusModalState.transition!"
:output-field-list="issueTemplate.outputFieldList"
@submit="
(comment) => {
updateStatusModalState.show = false;
if (updateStatusModalState.mode == 'ISSUE') {
- doIssueStatusTransition(updateStatusModalState.transition, comment);
+ doIssueStatusTransition(updateStatusModalState.transition as IssueStatusTransition, comment);
} else if (updateStatusModalState.mode == 'TASK') {
doTaskStatusTransition(
- updateStatusModalState.transition,
- updateStatusModalState.payload,
+ updateStatusModalState.transition as TaskStatusTransition,
+ updateStatusModalState.payload!,
comment
);
}
@@ -110,35 +110,44 @@
</BBModal>
</template>
-<script lang="ts">
-import { PropType, computed, reactive, defineComponent, ref } from "vue";
-import StatusTransitionForm from "./StatusTransitionForm.vue";
-import {
- activeTask,
- allTaskList,
- applicableTaskTransition,
- isDBAOrOwner,
- TaskStatusTransition,
-} from "../../utils";
-import {
- ASSIGNEE_APPLICABLE_ACTION_LIST,
- CREATOR_APPLICABLE_ACTION_LIST,
+<script lang="ts" setup>
+import { computed, reactive, ref } from "vue";
+import { isEmpty } from "lodash-es";
+import { useI18n } from "vue-i18n";
+import type { TaskStatusTransition } from "@/utils";
+import { allTaskList, applicableTaskTransition, isDBAOrOwner } from "@/utils";
+import type {
Issue,
IssueCreate,
IssueStatusTransition,
IssueStatusTransitionType,
- ISSUE_STATUS_TRANSITION_LIST,
- ONBOARDING_ISSUE_ID,
Principal,
- SYSTEM_BOT_ID,
Task,
+ TaskCreate,
+} from "@/types";
+import {
+ ASSIGNEE_APPLICABLE_ACTION_LIST,
+ CREATOR_APPLICABLE_ACTION_LIST,
+ SYSTEM_BOT_ID,
UNKNOWN_ID,
-} from "../../types";
-import { IssueTemplate } from "../../plugins";
-import isEmpty from "lodash-es/isEmpty";
-import { useI18n } from "vue-i18n";
-import { BBContextMenu } from "../../bbkit";
+ ISSUE_STATUS_TRANSITION_LIST,
+ ONBOARDING_ISSUE_ID,
+} from "@/types";
+import { BBContextMenu } from "@/bbkit";
import { useCurrentUser } from "@/store";
+import StatusTransitionForm from "./StatusTransitionForm.vue";
+import {
+ flattenTaskList,
+ IssueTypeWithStatement,
+ TaskTypeWithStatement,
+ useIssueLogic,
+} from "./logic";
+
+export type IssueContext = {
+ currentUser: Principal;
+ create: boolean;
+ issue: Issue | IssueCreate;
+};
interface UpdateStatusModalState {
mode: "ISSUE" | "TASK";
@@ -150,298 +159,239 @@ interface UpdateStatusModalState {
payload?: Task;
}
-export type IssueContext = {
- currentUser: Principal;
- create: boolean;
- issue: Issue | IssueCreate;
-};
-
-export default defineComponent({
- name: "IssueStatusTransitionButtonGroup",
- components: {
- StatusTransitionForm,
- },
- props: {
- create: {
- required: true,
- type: Boolean,
- },
- issue: {
- required: true,
- type: Object as PropType<Issue | IssueCreate>,
- },
- issueTemplate: {
- required: true,
- type: Object as PropType<IssueTemplate>,
- },
- },
- emits: ["create", "change-issue-status", "change-task-status"],
-
- setup(props, { emit }) {
- const { t } = useI18n();
- const menu = ref<InstanceType<typeof BBContextMenu>>();
+const emit = defineEmits(["change-issue-status", "change-task-status"]);
- const updateStatusModalState = reactive<UpdateStatusModalState>({
- mode: "ISSUE",
- show: false,
- style: "INFO",
- okText: "OK",
- title: "",
- });
+const { t } = useI18n();
+const menu = ref<InstanceType<typeof BBContextMenu>>();
- const currentUser = useCurrentUser();
+const {
+ create,
+ issue,
+ template: issueTemplate,
+ activeTaskOfPipeline,
+ doCreate,
+} = useIssueLogic();
- const issueContext = computed((): IssueContext => {
- return {
- currentUser: currentUser.value,
- create: props.create,
- issue: props.issue,
- };
- });
-
- const applicableTaskStatusTransitionList = computed(
- (): TaskStatusTransition[] => {
- if ((props.issue as Issue).id == ONBOARDING_ISSUE_ID) {
- return [];
- }
- switch ((props.issue as Issue).status) {
- case "DONE":
- case "CANCELED":
- return [];
- case "OPEN": {
- let list: TaskStatusTransition[] = [];
-
- // Allow assignee, or assignee is the system bot and current user is DBA or owner
- if (
- currentUser.value.id === (props.issue as Issue).assignee?.id ||
- ((props.issue as Issue).assignee?.id == SYSTEM_BOT_ID &&
- isDBAOrOwner(currentUser.value.role))
- ) {
- list = applicableTaskTransition((props.issue as Issue).pipeline);
- }
+const updateStatusModalState = reactive<UpdateStatusModalState>({
+ mode: "ISSUE",
+ show: false,
+ style: "INFO",
+ okText: "OK",
+ title: "",
+});
- return list;
- }
- }
- return []; // Only to make eslint happy. Should never reach this line.
- }
- );
+const currentUser = useCurrentUser();
- const tryStartTaskStatusTransition = (transition: TaskStatusTransition) => {
- updateStatusModalState.mode = "TASK";
- updateStatusModalState.okText = t(transition.buttonName);
- const task = currentTask.value;
- switch (transition.type) {
- case "RUN":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = `${t("common.run")} '${task.name}'?`;
- break;
- case "APPROVE":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = `${t("common.approve")} '${
- task.name
- }'?`;
- break;
- case "RETRY":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = `${t("common.retry")} '${task.name}'?`;
- break;
- case "CANCEL":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = `${t("common.cancel")} '${
- task.name
- }'?`;
- break;
- case "SKIP":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = `${t("common.skip")} '${task.name}'?`;
- break;
- }
- updateStatusModalState.transition = transition;
- updateStatusModalState.payload = task;
- updateStatusModalState.show = true;
- };
+const issueContext = computed((): IssueContext => {
+ return {
+ currentUser: currentUser.value,
+ create: create.value,
+ issue: issue.value,
+ };
+});
- const doTaskStatusTransition = (
- transition: TaskStatusTransition,
- task: Task,
- comment: string
- ) => {
- emit("change-task-status", task, transition.to, comment);
- };
+const applicableTaskStatusTransitionList = computed(
+ (): TaskStatusTransition[] => {
+ const issueEntity = issue.value as Issue;
+ if (issueEntity.id == ONBOARDING_ISSUE_ID) {
+ return [];
+ }
+ switch (issueEntity.status) {
+ case "DONE":
+ case "CANCELED":
+ return [];
+ case "OPEN": {
+ let list: TaskStatusTransition[] = [];
- const applicableIssueStatusTransitionList = computed(
- (): IssueStatusTransition[] => {
- if ((props.issue as Issue).id == ONBOARDING_ISSUE_ID) {
- return [];
- }
- const list: IssueStatusTransitionType[] = [];
// Allow assignee, or assignee is the system bot and current user is DBA or owner
if (
- currentUser.value.id === (props.issue as Issue).assignee?.id ||
- ((props.issue as Issue).assignee?.id == SYSTEM_BOT_ID &&
+ currentUser.value.id === issueEntity.assignee?.id ||
+ (issueEntity.assignee?.id == SYSTEM_BOT_ID &&
isDBAOrOwner(currentUser.value.role))
) {
- list.push(
- ...ASSIGNEE_APPLICABLE_ACTION_LIST.get(
- (props.issue as Issue).status
- )!
- );
- }
- if (currentUser.value.id === (props.issue as Issue).creator.id) {
- CREATOR_APPLICABLE_ACTION_LIST.get(
- (props.issue as Issue).status
- )!.forEach((item) => {
- if (list.indexOf(item) == -1) {
- list.push(item);
- }
- });
+ list = applicableTaskTransition(issueEntity.pipeline);
}
- return list
- .filter((item) => {
- const pipeline = (props.issue as Issue).pipeline;
- // Disallow any issue status transition if the active task is in RUNNING state.
- if (currentTask.value.status == "RUNNING") {
- return false;
- }
-
- const taskList = allTaskList(pipeline);
- // Don't display the Resolve action if the last task is NOT in DONE status.
- if (
- item == "RESOLVE" &&
- taskList.length > 0 &&
- (currentTask.value.id != taskList[taskList.length - 1].id ||
- currentTask.value.status != "DONE")
- ) {
- return false;
- }
-
- return true;
- })
- .map(
- (type: IssueStatusTransitionType) =>
- ISSUE_STATUS_TRANSITION_LIST.get(type)!
- )
- .reverse();
+ return list;
}
- );
+ }
+ return []; // Only to make eslint happy. Should never reach this line.
+ }
+);
- const currentTask = computed(() => {
- return activeTask((props.issue as Issue).pipeline);
- });
+const tryStartTaskStatusTransition = (transition: TaskStatusTransition) => {
+ updateStatusModalState.mode = "TASK";
+ updateStatusModalState.okText = t(transition.buttonName);
+ const task = currentTask.value;
+ switch (transition.type) {
+ case "RUN":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = `${t("common.run")} '${task.name}'?`;
+ break;
+ case "APPROVE":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = `${t("common.approve")} '${task.name}'?`;
+ break;
+ case "RETRY":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = `${t("common.retry")} '${task.name}'?`;
+ break;
+ case "CANCEL":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = `${t("common.cancel")} '${task.name}'?`;
+ break;
+ case "SKIP":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = `${t("common.skip")} '${task.name}'?`;
+ break;
+ }
+ updateStatusModalState.transition = transition;
+ updateStatusModalState.payload = task;
+ updateStatusModalState.show = true;
+};
+
+const doTaskStatusTransition = (
+ transition: TaskStatusTransition,
+ task: Task,
+ comment: string
+) => {
+ emit("change-task-status", task, transition.to, comment);
+};
- const allowIssueStatusTransition = (
- transition: IssueStatusTransition
- ): boolean => {
- if (transition.type == "RESOLVE") {
- // Returns false if any of the required output fields is not provided.
- for (let i = 0; i < props.issueTemplate.outputFieldList.length; i++) {
- const field = props.issueTemplate.outputFieldList[i];
- if (!field.resolved(issueContext.value)) {
- return false;
+const applicableIssueStatusTransitionList = computed(
+ (): IssueStatusTransition[] => {
+ const issueEntity = issue.value as Issue;
+ if (issueEntity.id == ONBOARDING_ISSUE_ID) {
+ return [];
+ }
+ const list: IssueStatusTransitionType[] = [];
+ // Allow assignee, or assignee is the system bot and current user is DBA or owner
+ if (
+ currentUser.value.id === issueEntity.assignee?.id ||
+ (issueEntity.assignee?.id == SYSTEM_BOT_ID &&
+ isDBAOrOwner(currentUser.value.role))
+ ) {
+ list.push(...ASSIGNEE_APPLICABLE_ACTION_LIST.get(issueEntity.status)!);
+ }
+ if (currentUser.value.id === issueEntity.creator.id) {
+ CREATOR_APPLICABLE_ACTION_LIST.get(issueEntity.status)!.forEach(
+ (item) => {
+ if (list.indexOf(item) == -1) {
+ list.push(item);
}
}
- return true;
- }
- return true;
- };
+ );
+ }
- const tryStartIssueStatusTransition = (
- transition: IssueStatusTransition
- ) => {
- updateStatusModalState.mode = "ISSUE";
- updateStatusModalState.okText = t(transition.buttonName);
- switch (transition.type) {
- case "RESOLVE":
- updateStatusModalState.style = "SUCCESS";
- updateStatusModalState.title = t(
- "issue.status-transition.modal.resolve"
- );
- break;
- case "CANCEL":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = t(
- "issue.status-transition.modal.cancel"
- );
- break;
- case "REOPEN":
- updateStatusModalState.style = "INFO";
- updateStatusModalState.title = t(
- "issue.status-transition.modal.reopen"
- );
- break;
- }
- updateStatusModalState.transition = transition;
- updateStatusModalState.show = true;
- };
+ return list
+ .filter((item) => {
+ const pipeline = issueEntity.pipeline;
+ // Disallow any issue status transition if the active task is in RUNNING state.
+ if (currentTask.value.status == "RUNNING") {
+ return false;
+ }
- const doIssueStatusTransition = (
- transition: IssueStatusTransition,
- comment: string
- ) => {
- emit("change-issue-status", transition.to, comment);
- };
+ const taskList = allTaskList(pipeline);
+ // Don't display the Resolve action if the last task is NOT in DONE status.
+ if (
+ item == "RESOLVE" &&
+ taskList.length > 0 &&
+ (currentTask.value.id != taskList[taskList.length - 1].id ||
+ currentTask.value.status != "DONE")
+ ) {
+ return false;
+ }
- const allowCreate = computed(() => {
- const newIssue = props.issue as IssueCreate;
- if (isEmpty(newIssue.name)) {
- return false;
- }
+ return true;
+ })
+ .map(
+ (type: IssueStatusTransitionType) =>
+ ISSUE_STATUS_TRANSITION_LIST.get(type)!
+ )
+ .reverse();
+ }
+);
+
+const currentTask = computed(() => {
+ return activeTaskOfPipeline((issue.value as Issue).pipeline);
+});
- if (newIssue.assigneeId == UNKNOWN_ID) {
+const allowIssueStatusTransition = (
+ transition: IssueStatusTransition
+): boolean => {
+ if (transition.type == "RESOLVE") {
+ const template = issueTemplate.value;
+ // Returns false if any of the required output fields is not provided.
+ for (let i = 0; i < template.outputFieldList.length; i++) {
+ const field = template.outputFieldList[i];
+ if (!field.resolved(issueContext.value)) {
return false;
}
+ }
+ return true;
+ }
+ return true;
+};
- if (
- newIssue.type == "bb.issue.database.create" ||
- newIssue.type == "bb.issue.database.schema.update" ||
- newIssue.type == "bb.issue.database.data.update"
- ) {
- for (const stage of newIssue.pipeline.stageList) {
- for (const task of stage.taskList) {
- if (
- task.type == "bb.task.database.create" ||
- task.type == "bb.task.database.schema.update" ||
- task.type == "bb.task.database.data.update"
- ) {
- if (isEmpty(task.statement)) {
- return false;
- }
- }
- }
- }
- }
+const tryStartIssueStatusTransition = (transition: IssueStatusTransition) => {
+ updateStatusModalState.mode = "ISSUE";
+ updateStatusModalState.okText = t(transition.buttonName);
+ switch (transition.type) {
+ case "RESOLVE":
+ updateStatusModalState.style = "SUCCESS";
+ updateStatusModalState.title = t("issue.status-transition.modal.resolve");
+ break;
+ case "CANCEL":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = t("issue.status-transition.modal.cancel");
+ break;
+ case "REOPEN":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = t("issue.status-transition.modal.reopen");
+ break;
+ }
+ updateStatusModalState.transition = transition;
+ updateStatusModalState.show = true;
+};
- for (const field of props.issueTemplate.inputFieldList) {
- if (
- field.type != "Boolean" && // Switch is boolean value which always is present
- !field.resolved(issueContext.value)
- ) {
+const doIssueStatusTransition = (
+ transition: IssueStatusTransition,
+ comment: string
+) => {
+ emit("change-issue-status", transition.to, comment);
+};
+
+const allowCreate = computed(() => {
+ const newIssue = issue.value as IssueCreate;
+
+ if (isEmpty(newIssue.name)) {
+ return false;
+ }
+
+ if (newIssue.assigneeId == UNKNOWN_ID) {
+ return false;
+ }
+
+ if (IssueTypeWithStatement.includes(newIssue.type)) {
+ const allTaskList = flattenTaskList<TaskCreate>(newIssue);
+ for (const task of allTaskList) {
+ if (TaskTypeWithStatement.includes(task.type)) {
+ if (isEmpty(task.statement)) {
return false;
}
}
- return true;
- });
-
- const doCreate = () => {
- emit("create");
- };
+ }
+ }
- return {
- menu,
- updateStatusModalState,
- applicableTaskStatusTransitionList,
- tryStartTaskStatusTransition,
- doTaskStatusTransition,
- applicableIssueStatusTransitionList,
- currentTask,
- allowIssueStatusTransition,
- tryStartIssueStatusTransition,
- doIssueStatusTransition,
- allowCreate,
- doCreate,
- };
- },
+ const template = issueTemplate.value;
+ for (const field of template.inputFieldList) {
+ if (
+ field.type !== "Boolean" && // Switch is boolean value which always is present
+ !field.resolved(issueContext.value)
+ ) {
+ return false;
+ }
+ }
+ return true;
});
</script>
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
index 35ad635979..e9d765b6fd 100644
--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
@@ -1,6 +1,8 @@
<template>
- <div class="flex justify-between">
- <div class="flex space-x-4">
+ <div
+ class="flex flex-col md:flex-row md:justify-between md:items-center gap-2 md:gap-4"
+ >
+ <div class="flex space-x-4 flex-1">
<div
class="text-sm font-medium"
:class="isEmpty(state.editStatement) ? 'text-red-600' : 'text-control'"
@@ -10,13 +12,11 @@
<span v-if="sqlHint" class="text-accent">{{ `(${sqlHint})` }}</span>
</div>
<button
- v-if="showApplyStatement"
+ v-if="allowApplyStatementToOtherStages"
:disabled="isEmpty(state.editStatement)"
type="button"
class="btn-small"
- @click.prevent="
- $emit('apply-statement-to-other-stages', state.editStatement)
- "
+ @click.prevent="applyStatementToOtherStages(state.editStatement)"
>
{{ $t("issue.apply-to-other-stages") }}
</button>
@@ -35,7 +35,7 @@
</template>
<template v-else>
<button
- v-if="allowEdit && !state.editing"
+ v-if="allowEditStatement && !state.editing"
type="button"
class="btn-icon"
@click.prevent="beginEdit"
@@ -86,9 +86,9 @@
@input="
(e) => {
sizeToFit(e.target as HTMLTextAreaElement);
- // When creating the issue, we will emit the event on keystroke to update the in-memory state.
+ // When creating the issue, we update the in-memory state.
if (create) {
- $emit('update-statement', state.editStatement);
+ updateStatement( state.editStatement);
}
}
"
@@ -124,8 +124,9 @@ import {
defineComponent,
computed,
} from "vue";
-import { sizeToFit } from "../../utils";
+import { sizeToFit } from "@/utils";
import { useUIStateStore } from "@/store";
+import { useIssueLogic } from "./logic";
interface LocalState {
editing: boolean;
@@ -135,37 +136,29 @@ interface LocalState {
export default defineComponent({
name: "IssueTaskStatementPanel",
props: {
- statement: {
- required: true,
- type: String,
- },
- create: {
- required: true,
- type: Boolean,
- },
- allowEdit: {
- required: true,
- type: Boolean,
- },
- showApplyStatement: {
- required: true,
- type: Boolean,
- },
sqlHint: {
required: false,
type: String,
default: undefined,
},
},
- emits: ["update-statement", "apply-statement-to-other-stages"],
setup(props, { emit }) {
+ const {
+ create,
+ allowEditStatement,
+ selectedStatement: statement,
+ updateStatement,
+ allowApplyStatementToOtherStages,
+ applyStatementToOtherStages,
+ } = useIssueLogic();
+
const editStatementTextArea = ref();
const uiStateStore = useUIStateStore();
const state = reactive<LocalState>({
editing: false,
- editStatement: props.statement,
+ editStatement: statement.value,
});
const formatOnSave = computed({
@@ -182,7 +175,7 @@ export default defineComponent({
onMounted(() => {
window.addEventListener("resize", resizeTextAreaHandler);
- if (props.create) {
+ if (create.value) {
state.editing = true;
nextTick(() => {
sizeToFit(editStatementTextArea.value);
@@ -195,25 +188,19 @@ export default defineComponent({
});
// Reset the edit state after creating the issue.
- watch(
- () => props.create,
- (curNew, prevNew) => {
- if (!curNew && prevNew) {
- state.editing = false;
- }
+ watch(create, (curNew, prevNew) => {
+ if (!curNew && prevNew) {
+ state.editing = false;
}
- );
+ });
- watch(
- () => props.statement,
- (cur) => {
- state.editStatement = cur;
- nextTick(() => sizeToFit(editStatementTextArea.value));
- }
- );
+ watch(statement, (cur) => {
+ state.editStatement = cur;
+ nextTick(() => sizeToFit(editStatementTextArea.value));
+ });
const beginEdit = () => {
- state.editStatement = props.statement;
+ state.editStatement = statement.value;
state.editing = true;
nextTick(() => {
sizeToFit(editStatementTextArea.value);
@@ -222,17 +209,23 @@ export default defineComponent({
};
const saveEdit = () => {
- emit("update-statement", state.editStatement, () => {
+ updateStatement(state.editStatement, () => {
state.editing = false;
});
};
const cancelEdit = () => {
- state.editStatement = props.statement;
+ state.editStatement = statement.value;
state.editing = false;
};
return {
+ create,
+ allowEditStatement,
+ statement,
+ updateStatement,
+ allowApplyStatementToOtherStages,
+ applyStatementToOtherStages,
editStatementTextArea,
formatOnSave,
state,
diff --git a/frontend/src/components/Issue/PipelineGhostFlow.vue b/frontend/src/components/Issue/PipelineGhostFlow.vue
index 5d7d1f203c..91dde9333d 100644
--- a/frontend/src/components/Issue/PipelineGhostFlow.vue
+++ b/frontend/src/components/Issue/PipelineGhostFlow.vue
@@ -87,7 +87,7 @@ import TaskStatusIcon from "./TaskStatusIcon.vue";
import { useDatabaseStore } from "@/store";
import { BBProgressPie } from "@/bbkit";
import PipelineStageList from "./PipelineStageList.vue";
-import { useIssueContext } from "./context";
+import { useIssueLogic } from "./logic";
const { t } = useI18n();
const databaseStore = useDatabaseStore();
@@ -99,7 +99,7 @@ const {
selectedStage,
selectedTask,
selectStageOrTask,
-} = useIssueContext();
+} = useIssueLogic();
const pipeline = computed(() => issue.value.pipeline!);
diff --git a/frontend/src/components/Issue/PipelineSimpleFlow.vue b/frontend/src/components/Issue/PipelineSimpleFlow.vue
index a83b729bf5..bf321c693d 100644
--- a/frontend/src/components/Issue/PipelineSimpleFlow.vue
+++ b/frontend/src/components/Issue/PipelineSimpleFlow.vue
@@ -11,9 +11,9 @@
<script lang="ts" setup>
import type { Stage, StageCreate } from "@/types";
import { activeTaskInStage } from "@/utils";
-import { useIssueContext } from "./context";
+import { useIssueLogic } from "./logic";
-const { create } = useIssueContext();
+const { create } = useIssueLogic();
const taskNameOfStage = (stage: Stage | StageCreate) => {
if (create.value) {
diff --git a/frontend/src/components/Issue/PipelineStageList.vue b/frontend/src/components/Issue/PipelineStageList.vue
index 88da17f456..38c26ee8c2 100644
--- a/frontend/src/components/Issue/PipelineStageList.vue
+++ b/frontend/src/components/Issue/PipelineStageList.vue
@@ -35,7 +35,7 @@
<!-- Arrow separator -->
<div
- v-if="i < issue.pipeline?.stageList.length - 1"
+ v-if="i < issue.pipeline!.stageList.length - 1"
class="hidden lg:block absolute top-0 bottom-0 right-0 w-5 pointer-events-none"
aria-hidden="true"
>
@@ -61,7 +61,7 @@
import { NPopover } from "naive-ui";
import { Issue, Stage, StageCreate } from "@/types";
import TaskStatusIcon from "./TaskStatusIcon.vue";
-import { useIssueContext } from "./context";
+import { useIssueLogic } from "./logic";
const {
create,
@@ -72,7 +72,7 @@ const {
activeTaskOfStage,
taskStatusOfStage,
selectStageOrTask,
-} = useIssueContext();
+} = useIssueLogic();
const isSelectedStage = (stage: Stage | StageCreate): boolean => {
return stage === selectedStage.value;
diff --git a/frontend/src/components/Issue/PipelineTenantFlow.vue b/frontend/src/components/Issue/PipelineTenantFlow.vue
index eae2925901..b4e6a36b67 100644
--- a/frontend/src/components/Issue/PipelineTenantFlow.vue
+++ b/frontend/src/components/Issue/PipelineTenantFlow.vue
@@ -52,7 +52,7 @@ import {
import { activeTask, activeTaskInStage, taskSlug } from "@/utils";
import TaskStatusIcon from "./TaskStatusIcon.vue";
import { useDatabaseStore } from "@/store";
-import { useIssueContext } from "./context";
+import { useIssueLogic } from "./logic";
const {
create,
@@ -61,7 +61,7 @@ const {
selectedStage,
selectedTask,
selectStageOrTask,
-} = useIssueContext();
+} = useIssueLogic();
const pipeline = computed(() => issue.value.pipeline!);
diff --git a/frontend/src/components/Issue/context/IssueContext.ts b/frontend/src/components/Issue/context/IssueContext.ts
deleted file mode 100644
index b83afa24eb..0000000000
--- a/frontend/src/components/Issue/context/IssueContext.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import {
- Issue,
- IssueCreate,
- Pipeline,
- Project,
- Stage,
- StageCreate,
- Task,
- TaskCreate,
- TaskStatus,
-} from "@/types";
-import { Ref } from "vue";
-
-type IssueContext = {
- // base params
- create: Ref<boolean>;
- project: Ref<Project>;
- issue: Ref<Issue | IssueCreate>;
-
- // states
- selectedStage: Ref<Stage | StageCreate>;
- selectedTask: Ref<Task | TaskCreate>;
-
- // logic functions
- isValidStage: (stage: Stage | StageCreate, index: number) => boolean;
- activeStageOfPipeline: (pipeline: Pipeline) => Stage;
- activeTaskOfPipeline: (pipeline: Pipeline) => Task;
- activeTaskOfStage: (stage: Stage) => Task;
- taskStatusOfStage: (stage: Stage | StageCreate, index: number) => TaskStatus;
-
- // event handlers
- selectStageOrTask: (
- stageIdOrIndex: number,
- taskSlug?: string | undefined
- ) => void;
-};
-
-export default IssueContext;
diff --git a/frontend/src/components/Issue/context/index.ts b/frontend/src/components/Issue/context/index.ts
deleted file mode 100644
index 9d977cc6c3..0000000000
--- a/frontend/src/components/Issue/context/index.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { inject, provide, InjectionKey } from "vue";
-import IssueContext from "./IssueContext";
-
-export const KEY = Symbol(
- "bb.issue.ui-state-context"
-) as InjectionKey<IssueContext>;
-
-export const useIssueContext = () => {
- return inject(KEY)!;
-};
-
-export const provideIssueContext = (
- context: Partial<IssueContext>,
- root = false
-) => {
- if (!root) {
- const parentContext = useIssueContext();
- context = {
- ...parentContext,
- ...context,
- };
- }
- provide(KEY, context as IssueContext);
-};
diff --git a/frontend/src/components/Issue/logic/GhostModeProvider.ts b/frontend/src/components/Issue/logic/GhostModeProvider.ts
new file mode 100644
index 0000000000..27a50d38de
--- /dev/null
+++ b/frontend/src/components/Issue/logic/GhostModeProvider.ts
@@ -0,0 +1,70 @@
+import { computed, defineComponent } from "vue";
+import { provideIssueLogic, useIssueLogic } from "./index";
+import { maybeFormatStatementOnSave, useCommonLogic } from "./common";
+import {
+ IssueCreate,
+ Task,
+ TaskCreate,
+ TaskDatabaseSchemaUpdateGhostSyncPayload,
+ UpdateSchemaGhostContext,
+} from "@/types";
+import { useDatabaseStore } from "@/store";
+
+export default defineComponent({
+ name: "GhostModeProvider",
+ setup() {
+ const { create, issue, selectedTask } = useIssueLogic();
+ const databaseStore = useDatabaseStore();
+
+ // In gh-ost mode, each stage can own its SQL statement
+ // But only for task.type === "bb.task.database.schema.update.ghost.sync"
+ const selectedStatement = computed(() => {
+ const task = selectedTask.value;
+ if (task.type === "bb.task.database.schema.update.ghost.sync") {
+ if (create.value) {
+ return (task as TaskCreate).statement;
+ } else {
+ const payload = (task as Task)
+ .payload as TaskDatabaseSchemaUpdateGhostSyncPayload;
+ return payload.statement;
+ }
+ } else {
+ return "";
+ }
+ });
+
+ const doCreate = () => {
+ const issueCreate = issue.value as IssueCreate;
+
+ // for gh-ost mode, copy user edited tasks back to issue.createContext
+ // only the first subtask (bb.task.database.schema.update.ghost.sync) has statement
+ const stageList = issueCreate.pipeline!.stageList;
+ const createContext =
+ issueCreate.createContext as UpdateSchemaGhostContext;
+ const detailList = createContext.updateSchemaDetailList;
+ stageList.forEach((stage, i) => {
+ const detail = detailList[i];
+ const syncTask = stage.taskList.find(
+ (task) => task.type === "bb.task.database.schema.update.ghost.sync"
+ )!;
+ const db = databaseStore.getDatabaseById(syncTask.databaseId!);
+
+ detail.databaseId = syncTask.databaseId!;
+ detail.databaseName = syncTask.databaseName!;
+ detail.statement = maybeFormatStatementOnSave(syncTask.statement, db);
+ detail.earliestAllowedTs = syncTask.earliestAllowedTs;
+ });
+ };
+
+ const logic = {
+ ...useCommonLogic(),
+ selectedStatement,
+ doCreate,
+ };
+ provideIssueLogic(logic);
+ return logic;
+ },
+ render() {
+ return this.$slots.default?.();
+ },
+});
diff --git a/frontend/src/components/Issue/logic/IssueLogic.ts b/frontend/src/components/Issue/logic/IssueLogic.ts
new file mode 100644
index 0000000000..4a3c136e15
--- /dev/null
+++ b/frontend/src/components/Issue/logic/IssueLogic.ts
@@ -0,0 +1,68 @@
+import { IssueTemplate } from "@/plugins";
+import {
+ Issue,
+ IssueCreate,
+ IssuePatch,
+ Pipeline,
+ Project,
+ Stage,
+ StageCreate,
+ Task,
+ TaskCreate,
+ TaskId,
+ TaskPatch,
+ TaskStatus,
+} from "@/types";
+import { Ref } from "vue";
+
+type IssueLogic = {
+ // base params
+ create: Ref<boolean>;
+ project: Ref<Project>;
+ issue: Ref<Issue | IssueCreate>;
+ template: Ref<IssueTemplate>;
+
+ // states
+ selectedStage: Ref<Stage | StageCreate>;
+ selectedTask: Ref<Task | TaskCreate>;
+
+ // ui state logic
+ isTenantMode: Ref<boolean>;
+ isGhostMode: Ref<boolean>;
+ isValidStage: (stage: Stage | StageCreate, index: number) => boolean;
+ activeStageOfPipeline: (pipeline: Pipeline) => Stage;
+ activeTaskOfPipeline: (pipeline: Pipeline) => Task;
+ activeTaskOfStage: (stage: Stage) => Task;
+ taskStatusOfStage: (stage: Stage | StageCreate, index: number) => TaskStatus;
+
+ // api endpoint
+ patchTask: (
+ taskId: TaskId,
+ taskPatch: TaskPatch,
+ postUpdated?: (updatedTask: Task) => void
+ ) => any;
+ patchIssue: (
+ issuePatch: IssuePatch,
+ postUpdated?: (updatedIssue: Issue) => void
+ ) => any;
+ createIssue: (issueCreate: IssueCreate) => any;
+
+ // edit logic
+ allowEditStatement: Ref<boolean>;
+ selectedStatement: Ref<string>;
+ updateStatement: (
+ newStatement: string,
+ postUpdated?: (updatedTask: Task) => void
+ ) => any;
+ allowApplyStatementToOtherStages: Ref<boolean>;
+ applyStatementToOtherStages: (statement: string) => any;
+ doCreate(): any;
+
+ // events
+ selectStageOrTask: (
+ stageIdOrIndex: number,
+ taskSlug?: string | undefined
+ ) => void;
+};
+
+export default IssueLogic;
diff --git a/frontend/src/components/Issue/logic/StandardModeProvider.ts b/frontend/src/components/Issue/logic/StandardModeProvider.ts
new file mode 100644
index 0000000000..d36d97aa5d
--- /dev/null
+++ b/frontend/src/components/Issue/logic/StandardModeProvider.ts
@@ -0,0 +1,16 @@
+import { defineComponent } from "vue";
+import { provideIssueLogic } from "./index";
+import { useCommonLogic } from "./common";
+
+export default defineComponent({
+ name: "StandardModeProvider",
+ setup() {
+ const common = useCommonLogic();
+
+ provideIssueLogic(common);
+ return common;
+ },
+ render() {
+ return this.$slots.default?.();
+ },
+});
diff --git a/frontend/src/components/Issue/logic/TenantModeProvider.ts b/frontend/src/components/Issue/logic/TenantModeProvider.ts
new file mode 100644
index 0000000000..acb0190022
--- /dev/null
+++ b/frontend/src/components/Issue/logic/TenantModeProvider.ts
@@ -0,0 +1,100 @@
+import { computed, defineComponent } from "vue";
+import { cloneDeep } from "lodash-es";
+import { useDatabaseStore } from "@/store";
+import {
+ Issue,
+ IssueCreate,
+ TaskCreate,
+ TaskDatabaseSchemaUpdatePayload,
+ UpdateSchemaContext,
+} from "@/types";
+import {
+ errorAssertion,
+ flattenTaskList,
+ maybeFormatStatementOnSave,
+ useCommonLogic,
+} from "./common";
+import { provideIssueLogic, useIssueLogic } from "./index";
+
+export default defineComponent({
+ name: "TenantModeProvider",
+ setup() {
+ const { create, issue, createIssue } = useIssueLogic();
+ const databaseStore = useDatabaseStore();
+
+ const allowEditStatement = computed(() => {
+ if (create.value) {
+ return true;
+ }
+ // Once a tenant-mode issue created, its statement can never be changed.
+ return false;
+ });
+
+ // In tenant mode, the entire issue shares only one SQL statement
+ const selectedStatement = computed(() => {
+ if (create.value) {
+ const issueCreate = issue.value as IssueCreate;
+ const context = issueCreate.createContext as UpdateSchemaContext;
+ return context.updateSchemaDetailList[0].statement;
+ } else {
+ const issueEntity = issue.value as Issue;
+ const task = issueEntity.pipeline.stageList[0].taskList[0];
+ const payload = task.payload as TaskDatabaseSchemaUpdatePayload;
+ return payload.statement;
+ }
+ });
+
+ const updateStatement = (newStatement: string) => {
+ if (create.value) {
+ // For tenant deploy mode, we apply the statement to all stages and all tasks
+ const allTaskList = flattenTaskList<TaskCreate>(issue.value);
+ allTaskList.forEach((task) => {
+ task.statement = newStatement;
+ });
+
+ const issueCreate = issue.value as IssueCreate;
+ const context = issueCreate.createContext as UpdateSchemaContext;
+ // We also apply it back to the CreateContext
+ context.updateSchemaDetailList.forEach(
+ (detail) => (detail.statement = newStatement)
+ );
+ } else {
+ // But not editable in non-create mode
+ errorAssertion();
+ }
+ };
+
+ // We are never allowed to "apply statement to other stages" in tenant mode.
+ const allowApplyStatementToOtherStages = computed(() => false);
+
+ const doCreate = () => {
+ const issueCreate = cloneDeep(issue.value as IssueCreate);
+
+ // for multi-tenancy issue pipeline (M * N)
+ // createContext is up-to-date already
+ // so we just format the statement if needed
+ const context = issueCreate.createContext as UpdateSchemaContext;
+ context.updateSchemaDetailList.forEach((detail) => {
+ const db = databaseStore.getDatabaseById(detail.databaseId!);
+ detail.statement = maybeFormatStatementOnSave(detail.statement, db);
+ });
+
+ createIssue(issueCreate);
+ };
+
+ const logic = {
+ ...useCommonLogic(),
+ allowEditStatement,
+ selectedStatement,
+ updateStatement,
+ allowApplyStatementToOtherStages,
+ applyStatementToOtherStages: errorAssertion,
+ doCreate,
+ };
+ provideIssueLogic(logic);
+ return logic;
+ },
+ render() {
+ return this.$slots.default?.();
+ },
+});
diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.ts
new file mode 100644
index 0000000000..b25e9e8928
--- /dev/null
+++ b/frontend/src/components/Issue/logic/common.ts
@@ -0,0 +1,242 @@
+import { computed } from "vue";
+import { cloneDeep } from "lodash-es";
+import formatSQL from "@/components/MonacoEditor/sqlFormatter";
+import { useCurrentUser, useDatabaseStore, useUIStateStore } from "@/store";
+import {
+ Database,
+ Issue,
+ IssueCreate,
+ IssueType,
+ SQLDialect,
+ Task,
+ TaskCreate,
+ TaskDatabaseCreatePayload,
+ TaskDatabaseDataUpdatePayload,
+ TaskDatabaseSchemaUpdatePayload,
+ TaskGeneralPayload,
+ TaskType,
+ UpdateSchemaDetail,
+} from "@/types";
+import { useIssueLogic } from "./index";
+import { isDev } from "@/utils";
+
+export const useCommonLogic = () => {
+ const { create, issue, selectedTask, patchTask, createIssue } =
+ useIssueLogic();
+ const currentUser = useCurrentUser();
+ const databaseStore = useDatabaseStore();
+
+ const allowEditStatement = computed(() => {
+ // if creating an issue, it's editable
+ if (create.value) {
+ return true;
+ }
+
+ const issueEntity = issue.value as Issue;
+
+ // For Create DB issues ,statement is not editable.
+ // Since the server-side seems won't do a patch really.
+ if (issueEntity.type === "bb.issue.database.create") {
+ return false;
+ }
+
+ // if not creating, we are allowed to edit sql statement only when:
+ // 1. issue.status is OPEN
+ // 2. AND currentUser is the creator
+ // 3. AND workflowType is UI
+ if (issueEntity.status !== "OPEN") {
+ return false;
+ }
+ if (issueEntity.creator.id !== currentUser.value.id) {
+ return false;
+ }
+ if (issueEntity.project.workflowType !== "UI") {
+ return false;
+ }
+
+ // check `selectedTask`, expected to be PENDING or PENDING_APPROVAL or FAILED
+ const checkTask = (task: Task) => {
+ return (
+ task.status == "PENDING" ||
+ task.status == "PENDING_APPROVAL" ||
+ task.status == "FAILED"
+ );
+ };
+ return checkTask(selectedTask.value as Task);
+ });
+
+ const selectedStatement = computed((): string => {
+ const task = selectedTask.value;
+ if (create.value) {
+ return (task as TaskCreate).statement;
+ }
+
+ // Extract statement from different types of payloads
+ return statementOfTask(task as Task);
+ });
+
+ const updateStatement = (
+ newStatement: string,
+ postUpdated?: (updatedTask: Task) => void
+ ) => {
+ if (create.value) {
+ const task = selectedTask.value as TaskCreate;
+ task.statement = newStatement;
+ } else {
+ // otherwise, patch the task
+ const task = selectedTask.value as Task;
+ patchTask(
+ task.id,
+ {
+ statement: maybeFormatStatementOnSave(newStatement, task.database),
+ },
+ postUpdated
+ );
+ }
+ };
+
+ const applyStatementToOtherStages = (statement: string) => {
+ const taskList = flattenTaskList<TaskCreate>(issue.value);
+
+ for (const task of taskList) {
+ if (TaskTypeWithStatement.includes(task.type)) {
+ task.statement = statement;
+ }
+ }
+ };
+
+ const allowApplyStatementToOtherStages = computed(() => {
+ if (!create.value) {
+ return false;
+ }
+
+ const stageList = issue.value.pipeline?.stageList || [];
+ if (stageList.length <= 1) {
+ // Only available for multi-stage pipeline
+ return false;
+ }
+ const taskList = flattenTaskList<TaskCreate>(issue.value);
+ const count = taskList.filter((task) =>
+ TaskTypeWithStatement.includes(task.type)
+ ).length;
+
+ return count > 1;
+ });
+
+ const doCreate = () => {
+ const issueCreate = cloneDeep(issue.value as IssueCreate);
+ // for standard issue pipeline (1 * 1 or M * 1)
+ // copy user edited tasks back to issue.createContext
+ const taskList = issueCreate.pipeline!.stageList.map(
+ (stage) => stage.taskList[0]
+ );
+ const detailList: UpdateSchemaDetail[] = taskList.map((task) => {
+ const db = databaseStore.getDatabaseById(task.databaseId!);
+ return {
+ databaseId: task.databaseId!,
+ databaseName: task.databaseName!,
+ statement: maybeFormatStatementOnSave(task.statement, db),
+ earliestAllowedTs: task.earliestAllowedTs,
+ };
+ });
+ issueCreate.createContext = {
+ migrationType: taskList[0].migrationType!,
+ updateSchemaDetailList: detailList,
+ };
+
+ createIssue(issueCreate);
+ };
+
+ return {
+ patchTask,
+ allowEditStatement,
+ selectedStatement,
+ updateStatement,
+ allowApplyStatementToOtherStages,
+ applyStatementToOtherStages,
+ doCreate,
+ };
+};
+
+export const TaskTypeWithStatement: TaskType[] = [
+ "bb.task.general",
+ "bb.task.database.create",
+ "bb.task.database.schema.update",
+ "bb.task.database.schema.update.ghost.sync",
+ "bb.task.database.data.update",
+];
+
+export const IssueTypeWithStatement: IssueType[] = [
+ "bb.issue.database.create",
+ "bb.issue.database.schema.update",
+ "bb.issue.database.data.update",
+ "bb.issue.database.schema.update.ghost",
+];
+
+export const flattenTaskList = <T extends Task | TaskCreate>(
+ issue: Issue | IssueCreate
+) => {
+ const taskList = issue.pipeline?.stageList.flatMap(
+ (stage) => stage.taskList as T[]
+ );
+ return taskList || [];
+};
+
+export const maybeFormatStatementOnSave = (
+ statement: string,
+ database?: Database
+): string => {
+ const uiStateStore = useUIStateStore();
+ if (!uiStateStore.issueFormatStatementOnSave) {
+ // Don't format if user disabled this feature
+ return statement;
+ }
+
+ // Default to use mysql dialect but use postgresql dialect if needed
+ let dialect: SQLDialect = "mysql";
+ if (database && database.instance.engine === "POSTGRES") {
+ dialect = "postgresql";
+ }
+
+ const result = formatSQL(statement, dialect);
+ if (!result.error) {
+ return result.data;
+ }
+
+ // Fallback to the input statement if error occurs while formatting
+ return statement;
+};
+
+// To let us know if we reaches a logic branch unexpectedly.
+export const errorAssertion = () => {
+ if (isDev()) {
+ throw new Error("should never reach here");
+ }
+};
+
+const statementOfTask = (task: Task) => {
+ switch (task.type) {
+ case "bb.task.general":
+ return ((task as Task).payload as TaskGeneralPayload).statement || "";
+ case "bb.task.database.create":
+ return (
+ ((task as Task).payload as TaskDatabaseCreatePayload).statement || ""
+ );
+ case "bb.task.database.schema.update":
+ return (
+ ((task as Task).payload as TaskDatabaseSchemaUpdatePayload).statement ||
+ ""
+ );
+ case "bb.task.database.data.update":
+ return (
+ ((task as Task).payload as TaskDatabaseDataUpdatePayload).statement ||
+ ""
+ );
+ case "bb.task.database.restore":
+ return "";
+ case "bb.task.database.schema.update.ghost.sync":
+ case "bb.task.database.schema.update.ghost.cutover":
+ case "bb.task.database.schema.update.ghost.drop-original-table":
+ return ""; // should never reach here
+ }
+};
diff --git a/frontend/src/components/Issue/logic/index.ts b/frontend/src/components/Issue/logic/index.ts
new file mode 100644
index 0000000000..d6a503e340
--- /dev/null
+++ b/frontend/src/components/Issue/logic/index.ts
@@ -0,0 +1,31 @@
+import { inject, provide, InjectionKey } from "vue";
+import type IssueLogic from "./IssueLogic";
+import TenantModeProvider from "./TenantModeProvider";
+import GhostModeProvider from "./GhostModeProvider";
+import StandardModeProvider from "./StandardModeProvider";
+
+export * from "./common";
+
+export {
+ IssueLogic,
+ TenantModeProvider,
+ GhostModeProvider,
+ StandardModeProvider,
+};
+
+export const KEY = Symbol("bb.issue.logic") as InjectionKey<IssueLogic>;
+
+export const useIssueLogic = () => {
+ return inject(KEY)!;
+};
+
+export const provideIssueLogic = (logic: Partial<IssueLogic>, root = false) => {
+ if (!root) {
+ const parent = useIssueLogic();
+ logic = {
+ ...parent,
+ ...logic,
+ };
+ }
+ provide(KEY, logic as IssueLogic);
+};
diff --git a/frontend/src/plugins/issue/logic/initialize/index.ts b/frontend/src/plugins/issue/logic/initialize/index.ts
index be6ed16a5d..c98ecb8e5f 100644
--- a/frontend/src/plugins/issue/logic/initialize/index.ts
+++ b/frontend/src/plugins/issue/logic/initialize/index.ts
@@ -1,6 +1,6 @@
import { computed, ref, Ref, watch } from "vue";
import { useRoute } from "vue-router";
-import { Issue, IssueCreate, IssueType } from "@/types";
+import { IssueCreate, IssueType } from "@/types";
import { pushNotification, useIssueStore } from "@/store";
import { idFromSlug } from "@/utils";
import { defaultTemplate, templateForType } from "@/plugins";
@@ -13,7 +13,14 @@ export function useInitializeIssue(issueSlug: Ref<string>) {
const issueStore = useIssueStore();
const create = computed(() => issueSlug.value.toLowerCase() == "new");
const route = useRoute();
- const issue = ref<Issue | IssueCreate | undefined>();
+ const issueCreate = ref<IssueCreate | undefined>();
+
+ const issue = computed(() => {
+ return create.value
+ ? issueCreate.value
+ : issueStore.getIssueById(idFromSlug(issueSlug.value));
+ });
+
const template = computed(() => {
// Find proper IssueTemplate from route.query.template
const issueType = route.query.template as IssueType;
@@ -38,11 +45,9 @@ export function useInitializeIssue(issueSlug: Ref<string>) {
watch(
issueSlug,
async () => {
- issue.value = undefined;
+ issueCreate.value = undefined;
if (create.value) {
- issue.value = await buildNewIssue({ template, route });
- } else {
- issue.value = issueStore.getIssueById(idFromSlug(issueSlug.value));
+ issueCreate.value = await buildNewIssue({ template, route });
}
},
{ immediate: true }