Skip to content

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

refactor(frontend): ship to project V1 API (part.4) (#5974)

Liu Jid732543d97b5
diff --git a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
index 3d1ad7b843..915e96f668 100644
--- a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
+++ b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
@@ -36,19 +36,12 @@
<script lang="ts" setup>
import { computed, reactive } from "vue";
-import {
- Project,
- DeploymentConfig,
- Environment,
- Database,
- LabelKeyType,
-} from "@/types";
+import { DeploymentConfig, Environment, Database, LabelKeyType } from "@/types";
import { DeployDatabaseTable } from "../TenantDatabaseTable";
import { filterDatabaseByKeyword } from "@/utils";
const props = withDefaults(
defineProps<{
- project: Project;
deployment: DeploymentConfig;
environmentList: Environment[];
databaseList: Database[];
diff --git a/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
index e4b81018c2..08c67c3265 100644
--- a/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/Project/ProjectSetting/ProjectGeneralSettingPanel.vue
@@ -150,7 +150,7 @@ const allowSave = computed((): boolean => {
const save = () => {
const projectPatch = cloneDeep(props.project);
- const updateMask: Array<keyof Project> = [];
+ const updateMask: string[] = [];
if (state.title !== props.project.title) {
projectPatch.title = state.title;
updateMask.push("title");
@@ -168,7 +168,7 @@ const save = () => {
}
}
projectPatch.tenantMode = state.tenantMode;
- updateMask.push("tenantMode");
+ updateMask.push("tenant_mode");
}
projectV1Store.updateProject(projectPatch, updateMask).then((updated) => {
pushNotification({
diff --git a/frontend/src/components/ProjectActivityPanel.vue b/frontend/src/components/ProjectActivityPanel.vue
index f96a2174b8..6814559e35 100644
--- a/frontend/src/components/ProjectActivityPanel.vue
+++ b/frontend/src/components/ProjectActivityPanel.vue
@@ -7,7 +7,7 @@
<PagedActivityTableVue
:activity-find="{
typePrefix: ['bb.project.', 'bb.database.'],
- container: project.id,
+ container: project.uid,
order: 'DESC',
}"
session-key="project-activity-panel"
@@ -21,20 +21,16 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent, PropType } from "vue";
-import { Project } from "../types";
+<script lang="ts" setup>
+import { PropType } from "vue";
import ActivityTable from "../components/ActivityTable.vue";
import PagedActivityTableVue from "@/components/PagedActivityTable.vue";
+import { Project } from "@/types/proto/v1/project_service";
-export default defineComponent({
- name: "ProjectActivityPanel",
- components: { ActivityTable, PagedActivityTableVue },
- props: {
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
+defineProps({
+ project: {
+ required: true,
+ type: Object as PropType<Project>,
},
});
</script>
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index c9a9e14422..790ff80d7e 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -56,7 +56,6 @@ import {
EnvironmentId,
Instance,
InstanceId,
- Project,
UNKNOWN_ID,
} from "../types";
import { filterDatabaseByKeyword } from "@/utils";
@@ -70,10 +69,6 @@ interface LocalState {
}
const props = defineProps({
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
databaseList: {
required: true,
type: Object as PropType<Database[]>,
diff --git a/frontend/src/components/ProjectDeploymentConfigPanel.vue b/frontend/src/components/ProjectDeploymentConfigPanel.vue
index a17389b66d..df13ece189 100644
--- a/frontend/src/components/ProjectDeploymentConfigPanel.vue
+++ b/frontend/src/components/ProjectDeploymentConfigPanel.vue
@@ -144,7 +144,6 @@ import { cloneDeep, isEqual } from "lodash-es";
import { useI18n } from "vue-i18n";
import { NPopover, useDialog } from "naive-ui";
import {
- Project,
DeploymentConfig,
EMPTY_ID,
DeploymentConfigPatch,
@@ -157,8 +156,9 @@ import {
pushNotification,
useDeploymentStore,
useEnvironmentList,
- useProjectStore,
+ useProjectV1Store,
} from "@/store";
+import { Project } from "@/types/proto/v1/project_service";
type LocalState = {
deployment: DeploymentConfig | undefined;
@@ -217,7 +217,7 @@ export default defineComponent({
watchEffect(async () => {
const dep = await deploymentStore.fetchDeploymentConfigByProjectId(
- props.project.id
+ props.project.uid
);
// We clone the saved deployment-config
// <DeploymentConfigTool /> will mutate `state.deployment` directly
@@ -281,7 +281,7 @@ export default defineComponent({
payload: JSON.stringify(state.deployment.schedule),
};
await deploymentStore.patchDeploymentConfigByProjectId({
- projectId: props.project.id,
+ projectId: props.project.uid,
deploymentConfigPatch,
});
pushNotification({
@@ -326,12 +326,10 @@ export default defineComponent({
const confirmEditDBNameTemplate = async () => {
try {
- await useProjectStore().patchProject({
- projectId: props.project.id,
- projectPatch: {
- dbNameTemplate: state.dbNameTemplate,
- },
- });
+ const projectPatch = cloneDeep(props.project);
+ projectPatch.dbNameTemplate = state.dbNameTemplate;
+ const updateMask = ["db_name_template"];
+ await useProjectV1Store().updateProject(projectPatch, updateMask);
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/ProjectMigrationHistoryPanel.vue b/frontend/src/components/ProjectMigrationHistoryPanel.vue
index 2cb471d89e..5ef06466a3 100644
--- a/frontend/src/components/ProjectMigrationHistoryPanel.vue
+++ b/frontend/src/components/ProjectMigrationHistoryPanel.vue
@@ -25,15 +25,10 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent, PropType, reactive, ref, watchEffect } from "vue";
+<script lang="ts" setup>
+import { PropType, reactive, watchEffect } from "vue";
import MigrationHistoryTable from "../components/MigrationHistoryTable.vue";
-import {
- Database,
- InstanceMigration,
- MigrationHistory,
- Project,
-} from "../types";
+import { Database, InstanceMigration, MigrationHistory } from "../types";
import { BBTableSectionDataSource } from "../bbkit/types";
import { fullDatabasePath } from "../utils";
import { useInstanceStore } from "@/store";
@@ -46,79 +41,63 @@ interface LocalState {
migrationHistorySectionList: BBTableSectionDataSource<MigrationHistory>[];
}
-export default defineComponent({
- name: "ProjectMigrationHistoryPanel",
- components: { MigrationHistoryTable },
- props: {
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
- databaseList: {
- required: true,
- type: Object as PropType<Database[]>,
- },
+const props = defineProps({
+ databaseList: {
+ required: true,
+ type: Object as PropType<Database[]>,
},
- setup(props) {
- const searchField = ref();
+});
- const instanceStore = useInstanceStore();
+const instanceStore = useInstanceStore();
- const state = reactive<LocalState>({
- databaseSectionList: [],
- migrationHistorySectionList: [],
- });
+const state = reactive<LocalState>({
+ databaseSectionList: [],
+ migrationHistorySectionList: [],
+});
- const fetchMigrationHistory = (databaseList: Database[]) => {
- state.databaseSectionList = [];
- state.migrationHistorySectionList = [];
- for (const database of databaseList) {
- instanceStore
- .checkMigrationSetup(database.instance.id)
- .then((migration: InstanceMigration) => {
- if (migration.status == "OK") {
- instanceStore
- .fetchMigrationHistory({
- instanceId: database.instance.id,
- databaseName: database.name,
- limit: MAX_MIGRATION_HISTORY_COUNT,
- })
- .then((migrationHistoryList: MigrationHistory[]) => {
- if (migrationHistoryList.length > 0) {
- state.databaseSectionList.push(database);
+const fetchMigrationHistory = (databaseList: Database[]) => {
+ state.databaseSectionList = [];
+ state.migrationHistorySectionList = [];
+ for (const database of databaseList) {
+ instanceStore
+ .checkMigrationSetup(database.instance.id)
+ .then((migration: InstanceMigration) => {
+ if (migration.status == "OK") {
+ instanceStore
+ .fetchMigrationHistory({
+ instanceId: database.instance.id,
+ databaseName: database.name,
+ limit: MAX_MIGRATION_HISTORY_COUNT,
+ })
+ .then((migrationHistoryList: MigrationHistory[]) => {
+ if (migrationHistoryList.length > 0) {
+ state.databaseSectionList.push(database);
- const title = `${database.name} (${database.instance.environment.name})`;
- const index = state.migrationHistorySectionList.findIndex(
- (item: BBTableSectionDataSource<MigrationHistory>) => {
- return item.title == title;
- }
- );
- const newItem = {
- title: title,
- link: `${fullDatabasePath(database)}#change-history`,
- list: migrationHistoryList,
- };
- if (index >= 0) {
- state.migrationHistorySectionList[index] = newItem;
- } else {
- state.migrationHistorySectionList.push(newItem);
- }
+ const title = `${database.name} (${database.instance.environment.name})`;
+ const index = state.migrationHistorySectionList.findIndex(
+ (item: BBTableSectionDataSource<MigrationHistory>) => {
+ return item.title == title;
}
- });
- }
- });
- }
- };
-
- const prepareMigrationHistoryList = () => {
- fetchMigrationHistory(props.databaseList);
- };
- watchEffect(prepareMigrationHistoryList);
+ );
+ const newItem = {
+ title: title,
+ link: `${fullDatabasePath(database)}#change-history`,
+ list: migrationHistoryList,
+ };
+ if (index >= 0) {
+ state.migrationHistorySectionList[index] = newItem;
+ } else {
+ state.migrationHistorySectionList.push(newItem);
+ }
+ }
+ });
+ }
+ });
+ }
+};
- return {
- searchField,
- state,
- };
- },
-});
+const prepareMigrationHistoryList = () => {
+ fetchMigrationHistory(props.databaseList);
+};
+watchEffect(prepareMigrationHistoryList);
</script>
diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vue
index 8ee621f679..3cfcdc1a98 100644
--- a/frontend/src/components/ProjectOverviewPanel.vue
+++ b/frontend/src/components/ProjectOverviewPanel.vue
@@ -10,7 +10,7 @@
<PagedActivityTableVue
:activity-find="{
typePrefix: ['bb.project.', 'bb.database.'],
- container: project.id,
+ container: project.uid,
order: 'DESC',
}"
session-key="project-activity"
@@ -50,7 +50,7 @@
session-key="project-waiting-approval"
:issue-find="{
statusList: ['OPEN'],
- projectId: project.id,
+ projectId: project.uid,
}"
>
<template #table="{ issueList, loading }">
@@ -67,7 +67,7 @@
session-key="project-open"
:issue-find="{
statusList: ['OPEN'],
- projectId: project.id,
+ projectId: project.uid,
}"
:page-size="10"
>
@@ -88,7 +88,7 @@
session-key="project-closed"
:issue-find="{
statusList: ['DONE', 'CANCELED'],
- projectId: project.id,
+ projectId: project.uid,
}"
:page-size="5"
:hide-load-more="true"
@@ -106,7 +106,7 @@
<div class="w-full flex justify-end mt-2 px-4">
<router-link
- :to="`/issue?status=closed&project=${project.id}`"
+ :to="`/issue?status=closed&project=${project.uid}`"
class="normal-link"
>
{{ $t("project.overview.view-all-closed") }}
@@ -117,93 +117,33 @@
</div>
</template>
-<script lang="ts">
-import {
- reactive,
- watchEffect,
- PropType,
- computed,
- defineComponent,
-} from "vue";
+<script lang="ts" setup>
+import { reactive, PropType } from "vue";
import ActivityTable from "../components/ActivityTable.vue";
import { IssueTable } from "../components/Issue";
-import { Database, Issue, Project, LabelKeyType } from "../types";
-import { findDefaultGroupByLabel } from "../utils";
+import { Issue } from "../types";
import PagedIssueTable from "@/components/Issue/table/PagedIssueTable.vue";
import PagedActivityTableVue from "./PagedActivityTable.vue";
import { featureToRef } from "@/store";
-
-// Show at most 5 activity
-const ACTIVITY_LIMIT = 5;
+import { Project } from "@/types/proto/v1/project_service";
interface LocalState {
isFetchingActivityList: boolean;
progressIssueList: Issue[];
closedIssueList: Issue[];
- databaseNameFilter: string;
- xAxisLabel: LabelKeyType;
- yAxisLabel: LabelKeyType | undefined;
}
-export default defineComponent({
- name: "ProjectOverviewPanel",
- components: {
- ActivityTable,
- IssueTable,
- PagedIssueTable,
- PagedActivityTableVue,
- },
- props: {
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
- databaseList: {
- required: true,
- type: Object as PropType<Database[]>,
- },
+defineProps({
+ project: {
+ required: true,
+ type: Object as PropType<Project>,
},
- setup(props) {
- const state = reactive<LocalState>({
- isFetchingActivityList: false,
- progressIssueList: [],
- closedIssueList: [],
- databaseNameFilter: "",
- xAxisLabel: "bb.environment",
- yAxisLabel: undefined,
- });
- const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
-
- const isTenantProject = computed((): boolean => {
- return props.project.tenantMode === "TENANT";
- });
-
- const filteredDatabaseList = computed(() => {
- const filter = state.databaseNameFilter.toLocaleLowerCase();
- if (!filter) return props.databaseList;
-
- return props.databaseList.filter((database) =>
- database.name.toLowerCase().includes(filter)
- );
- });
-
- const excludedKeyList = computed(() => [state.xAxisLabel]);
-
- watchEffect(() => {
- state.yAxisLabel = findDefaultGroupByLabel(
- filteredDatabaseList.value,
- excludedKeyList.value
- );
- });
+});
- return {
- state,
- hasCustomApprovalFeature,
- isTenantProject,
- filteredDatabaseList,
- excludedKeyList,
- ACTIVITY_LIMIT,
- };
- },
+const state = reactive<LocalState>({
+ isFetchingActivityList: false,
+ progressIssueList: [],
+ closedIssueList: [],
});
+const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
</script>
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index 3509720a47..ccf6126f45 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -75,10 +75,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {
await upsertProjectMap([created]);
return created;
};
- const updateProject = async (
- project: Project,
- updateMask: Array<keyof Project>
- ) => {
+ const updateProject = async (project: Project, updateMask: string[]) => {
const updated = await projectServiceClient.updateProject({
project,
updateMask,
diff --git a/frontend/src/utils/v1/project.ts b/frontend/src/utils/v1/project.ts
index a5656ad657..c9d4470d32 100644
--- a/frontend/src/utils/v1/project.ts
+++ b/frontend/src/utils/v1/project.ts
@@ -9,7 +9,7 @@ import {
} from "../role";
export const extractProjectResourceName = (name: string) => {
- const pattern = /(?:^|\/)project\/([^/]+)(?:$|\/)/;
+ const pattern = /(?:^|\/)projects\/([^/]+)(?:$|\/)/;
const matches = name.match(pattern);
return matches?.[1] ?? "";
};
diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vue
index 552c0a99db..556a17846f 100644
--- a/frontend/src/views/ProjectDetail.vue
+++ b/frontend/src/views/ProjectDetail.vue
@@ -2,7 +2,7 @@
<template v-if="hash === 'overview'">
<ProjectOverviewPanel
id="overview"
- :project="project"
+ :project="projectV1"
:database-list="databaseList"
/>
</template>
@@ -10,20 +10,15 @@
<ProjectDeploymentConfigPanel
v-if="isTenantProject"
id="deployment-config"
- :project="project"
+ :project="projectV1"
:database-list="databaseList"
:allow-edit="allowEdit"
/>
- <ProjectDatabasesPanel
- v-else
- :project="project"
- :database-list="databaseList"
- />
+ <ProjectDatabasesPanel v-else :database-list="databaseList" />
</template>
<template v-if="hash === 'change-history'">
<ProjectMigrationHistoryPanel
id="change-history"
- :project="project"
:database-list="databaseList"
/>
</template>
@@ -31,7 +26,7 @@
<ProjectSlowQueryPanel :project="project" />
</template>
<template v-if="hash === 'activity'">
- <ProjectActivityPanel id="activity" :project="project" />
+ <ProjectActivityPanel id="activity" :project="projectV1" />
</template>
<template v-if="project.id !== DEFAULT_PROJECT_ID && hash === 'gitops'">
<ProjectVersionControlPanel