Skip to content

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

Use DatabaseTable to choose database

天舟2ba2f01cea09
diff --git a/frontend/src/components/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm.vue
index f638fcb9c1..df6c650527 100644
--- a/frontend/src/components/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm.vue
@@ -1,86 +1,12 @@
<template>
- <form class="mx-4 space-y-6 divide-y divide-block-border">
- <div class="grid gap-y-6 gap-x-4 grid-cols-2">
- <template v-if="state.singleEnvironment">
- <div class="col-span-2 col-start-1 w-64">
- <label for="environment" class="textlabel">
- Environment <span style="color: red">*</span>
- </label>
- <EnvironmentSelect
- class="mt-1 w-full"
- id="environment"
- name="environment"
- :selectedId="state.singleStageConfig.environmentId"
- @select-environment-id="
- (environmentId) => {
- state.singleStageConfig.environmentId = environmentId;
- }
- "
- />
- </div>
-
- <!-- If project is supplied, we put ProjectSelect before DatabaseSelect,
- Otherwise, we put it after. This is based on the assumption that
- it's relatively easy to directly select the database instead of selecting
- project and then selecting database in that project -->
- <div v-if="projectId != UNKNOWN_ID" class="col-span-2 col-start-1 w-64">
- <label for="project" class="textlabel">
- Project <span style="color: red">*</span>
- </label>
- <!-- Disable the selection if having preset project -->
- <ProjectSelect
- class="mt-1"
- id="project"
- name="project"
- :disabled="true"
- :selectedId="state.project.id"
- @select-project-id="
- (projectId) => {
- changeProjectId(projectId);
- }
- "
- />
- </div>
-
- <div class="col-span-2 col-start-1 w-64">
- <label for="database" class="textlabel">
- Database <span style="color: red">*</span>
- </label>
- <DatabaseSelect
- class="mt-1 w-full"
- id="database"
- name="database"
- :selectedId="state.singleStageConfig.databaseId"
- :environmentId="state.singleStageConfig.environmentId"
- :projectId="state.project.id"
- :mode="'USER'"
- @select-database-id="
- (databaseId) => {
- changeDatabaseId(databaseId);
- }
- "
- />
- </div>
-
- <div v-if="projectId == UNKNOWN_ID" class="col-span-2 col-start-1 w-64">
- <label for="project" class="textlabel">
- Project <span style="color: red">*</span>
- </label>
- <!-- Disable the selection if having preset project -->
- <ProjectSelect
- class="mt-1"
- id="project"
- name="project"
- :selectedId="state.project.id"
- @select-project-id="
- (projectId) => {
- changeProjectId(projectId);
- }
- "
- />
- </div>
- </template>
- </div>
+ <div class="mx-4 space-y-6 w-160 divide-y divide-block-border">
+ <DatabaseTable
+ :mode="projectId == UNKNOWN_ID ? 'ALL_SHORT' : 'PROJECT_SHORT'"
+ :bordered="true"
+ :customClick="true"
+ :databaseList="databaseList"
+ @select-database-id="selectDatabaseId"
+ />
<!-- Create button group -->
<div class="pt-4 flex justify-end">
<button
@@ -90,43 +16,19 @@
>
Cancel
</button>
- <button
- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
- :disabled="!allowNext"
- @click.prevent="goNext"
- >
- Next
- </button>
</div>
- </form>
+ </div>
</template>
<script lang="ts">
import { computed, reactive, onMounted, onUnmounted, PropType } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
-import ProjectSelect from "../components/ProjectSelect.vue";
-import DatabaseSelect from "../components/DatabaseSelect.vue";
-import EnvironmentSelect from "../components/EnvironmentSelect.vue";
-import {
- Database,
- DatabaseId,
- EnvironmentId,
- Project,
- ProjectId,
- UNKNOWN_ID,
-} from "../types";
-
-type StageConfig = {
- environmentId: EnvironmentId;
- databaseId: DatabaseId;
-};
+import DatabaseTable from "../components/DatabaseTable.vue";
+import { Database, DatabaseId, Project, ProjectId, UNKNOWN_ID } from "../types";
interface LocalState {
project: Project;
- singleEnvironment: boolean;
- singleStageConfig: StageConfig;
- stageConfigList: StageConfig[];
}
export default {
@@ -138,11 +40,15 @@ export default {
type: Number as PropType<ProjectId>,
},
},
- components: { ProjectSelect, DatabaseSelect, EnvironmentSelect },
+ components: {
+ DatabaseTable,
+ },
setup(props, { emit }) {
const store = useStore();
const router = useRouter();
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
const keyboardHandler = (e: KeyboardEvent) => {
if (e.code == "Escape") {
cancel();
@@ -159,79 +65,77 @@ export default {
const state = reactive<LocalState>({
project: store.getters["project/projectById"](props.projectId),
- singleEnvironment: true,
- singleStageConfig: {
- environmentId: UNKNOWN_ID,
- databaseId: UNKNOWN_ID,
- },
- stageConfigList: [],
});
- const allowNext = computed(() => {
- if (state.singleEnvironment) {
- return (
- state.project.id != UNKNOWN_ID &&
- state.singleStageConfig.environmentId != UNKNOWN_ID &&
- state.singleStageConfig.databaseId != UNKNOWN_ID
- );
- }
- return true;
+ const environmentList = computed(() => {
+ return store.getters["environment/environmentList"]([
+ "NORMAL",
+ "ARCHIVED",
+ ]);
});
- const changeProjectId = (projectId: ProjectId) => {
- state.project = store.getters["project/projectById"](projectId);
- if (state.singleEnvironment) {
+ const databaseList = computed(() => {
+ var list;
+ if (props.projectId == UNKNOWN_ID) {
+ list = store.getters["database/databaseListByPrincipalId"](
+ currentUser.value.id
+ );
} else {
- state.stageConfigList = [];
- }
- };
-
- const changeDatabaseId = (databaseId: DatabaseId) => {
- state.singleStageConfig.databaseId = databaseId;
-
- if (databaseId != UNKNOWN_ID) {
- const database: Database = store.getters["database/databaseById"](
- state.singleStageConfig.databaseId
+ list = store.getters["database/databaseListByProjectId"](
+ props.projectId
);
- state.project = database.project;
}
- };
- const cancel = () => {
- emit("dismiss");
- };
+ // Sort the list to put prod items first.
+ return list.sort((a: Database, b: Database) => {
+ var aEnvIndex = -1;
+ var bEnvIndex = -1;
+
+ for (var i = 0; i < environmentList.value.length; i++) {
+ if (environmentList.value[i].id == a.instance.environment.id) {
+ aEnvIndex = i;
+ }
+ if (environmentList.value[i].id == b.instance.environment.id) {
+ bEnvIndex = i;
+ }
+
+ if (aEnvIndex != -1 && bEnvIndex != -1) {
+ break;
+ }
+ }
+ return bEnvIndex - aEnvIndex;
+ });
+ });
- const goNext = () => {
+ const selectDatabaseId = (databaseId: DatabaseId) => {
emit("dismiss");
- if (state.singleEnvironment) {
- const database = store.getters["database/databaseById"](
- state.singleStageConfig.databaseId
- );
+ const database = store.getters["database/databaseById"](databaseId);
+
+ router.push({
+ name: "workspace.issue.detail",
+ params: {
+ issueSlug: "new",
+ },
+ query: {
+ template: "bb.issue.db.schema.update",
+ name: `[${database.name}] Alter schema`,
+ project: state.project.id,
+ databaseList: database.id,
+ },
+ });
+ };
- router.push({
- name: "workspace.issue.detail",
- params: {
- issueSlug: "new",
- },
- query: {
- template: "bb.issue.db.schema.update",
- name: `[${database.name}] Alter schema`,
- project: state.project.id,
- databaseList: database.id,
- },
- });
- }
+ const cancel = () => {
+ emit("dismiss");
};
return {
UNKNOWN_ID,
state,
- allowNext,
- changeProjectId,
- changeDatabaseId,
+ databaseList,
+ selectDatabaseId,
cancel,
- goNext,
};
},
};
diff --git a/frontend/src/components/DatabaseTable.vue b/frontend/src/components/DatabaseTable.vue
index cc6a5e0386..0d9b625276 100644
--- a/frontend/src/components/DatabaseTable.vue
+++ b/frontend/src/components/DatabaseTable.vue
@@ -23,16 +23,16 @@
<BBTableCell v-if="showInstanceColumn" class="w-24">
{{ instanceName(database.instance) }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell v-if="showMiscColumn" class="w-8">
{{ database.characterSet }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell v-if="showMiscColumn" class="w-8">
{{ database.collation }}
</BBTableCell>
<BBTableCell class="w-8">
{{ database.syncStatus }}
</BBTableCell>
- <BBTableCell class="w-16">
+ <BBTableCell v-if="showMiscColumn" class="w-16">
{{ humanizeTs(database.lastSuccessfulSyncTs) }}
</BBTableCell>
</template>
@@ -47,116 +47,166 @@ import { databaseSlug, isDBAOrOwner } from "../utils";
import { Database } from "../types";
import { BBTableColumn } from "../bbkit/types";
-type Mode = "ALL" | "INSTANCE" | "PROJECT";
+type Mode = "ALL" | "ALL_SHORT" | "INSTANCE" | "PROJECT" | "PROJECT_SHORT";
-const columnListMap: Map<Mode | "ALL_HIDE_INSTANCE", BBTableColumn[]> = new Map(
+const columnListMap: Map<
+ Mode | "ALL_HIDE_INSTANCE" | "ALL_HIDE_INSTANCE_SHORT",
+ BBTableColumn[]
+> = new Map([
+ [
+ "ALL",
+ [
+ {
+ title: "Project",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
+ {
+ title: "Instance",
+ },
+ {
+ title: "Character set",
+ },
+ {
+ title: "Collation",
+ },
+ {
+ title: "Sync status",
+ },
+ {
+ title: "Last successful sync",
+ },
+ ],
+ ],
[
+ "ALL_SHORT",
[
- "ALL",
- [
- {
- title: "Project",
- },
- {
- title: "Name",
- },
- {
- title: "Environment",
- },
- {
- title: "Instance",
- },
- {
- title: "Character set",
- },
- {
- title: "Collation",
- },
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
- ],
+ {
+ title: "Project",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
+ {
+ title: "Instance",
+ },
+ {
+ title: "Sync status",
+ },
],
+ ],
+ [
+ "ALL_HIDE_INSTANCE",
[
- "ALL_HIDE_INSTANCE",
- [
- {
- title: "Project",
- },
- {
- title: "Name",
- },
- {
- title: "Environment",
- },
- {
- title: "Character set",
- },
- {
- title: "Collation",
- },
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
- ],
+ {
+ title: "Project",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
+ {
+ title: "Character set",
+ },
+ {
+ title: "Collation",
+ },
+ {
+ title: "Sync status",
+ },
+ {
+ title: "Last successful sync",
+ },
],
+ ],
+ [
+ "ALL_HIDE_INSTANCE_SHORT",
[
- "INSTANCE",
- [
- {
- title: "Project",
- },
- {
- title: "Name",
- },
- {
- title: "Character set",
- },
- {
- title: "Collation",
- },
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
- ],
+ {
+ title: "Project",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
],
+ ],
+ [
+ "INSTANCE",
[
- "PROJECT",
- [
- {
- title: "Name",
- },
- {
- title: "Environment",
- },
- {
- title: "Character set",
- },
- {
- title: "Collation",
- },
- {
- title: "Sync status",
- },
- {
- title: "Last successful sync",
- },
- ],
+ {
+ title: "Project",
+ },
+ {
+ title: "Name",
+ },
+ {
+ title: "Character set",
+ },
+ {
+ title: "Collation",
+ },
+ {
+ title: "Sync status",
+ },
+ {
+ title: "Last successful sync",
+ },
],
- ]
-);
+ ],
+ [
+ "PROJECT",
+ [
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
+ {
+ title: "Character set",
+ },
+ {
+ title: "Collation",
+ },
+ {
+ title: "Sync status",
+ },
+ {
+ title: "Last successful sync",
+ },
+ ],
+ ],
+ [
+ "PROJECT_SHORT",
+ [
+ {
+ title: "Name",
+ },
+ {
+ title: "Environment",
+ },
+ {
+ title: "Sync status",
+ },
+ ],
+ ],
+]);
export default {
name: "DatabaseTable",
+ emits: ["select-database-id"],
components: {},
props: {
bordered: {
@@ -171,19 +221,23 @@ export default {
default: true,
type: Boolean,
},
+ customClick: {
+ default: false,
+ type: Boolean,
+ },
databaseList: {
required: true,
type: Object as PropType<Database[]>,
},
},
- setup(props, ctx) {
+ setup(props, { emit, attrs }) {
const store = useStore();
const router = useRouter();
const currentUser = computed(() => store.getters["auth/currentUser"]());
const showProjectColumn = computed(() => {
- return props.mode != "PROJECT";
+ return props.mode != "PROJECT" && props.mode != "PROJECT_SHORT";
});
const showEnvironmentColumn = computed(() => {
@@ -191,25 +245,42 @@ export default {
});
const showInstanceColumn = computed(() => {
- return props.mode == "ALL" && isDBAOrOwner(currentUser.value.role);
+ return (
+ (props.mode == "ALL" || props.mode == "ALL_SHORT") &&
+ isDBAOrOwner(currentUser.value.role)
+ );
+ });
+
+ const showMiscColumn = computed(() => {
+ return props.mode != "ALL_SHORT" && props.mode != "PROJECT_SHORT";
});
const columnList = computed(() => {
- if (props.mode == "ALL" && !showInstanceColumn.value) {
- return columnListMap.get("ALL_HIDE_INSTANCE");
+ if (
+ (props.mode == "ALL" || props.mode == "ALL_SHORT") &&
+ !showInstanceColumn.value
+ ) {
+ return props.mode == "ALL"
+ ? columnListMap.get("ALL_HIDE_INSTANCE")
+ : columnListMap.get("ALL_HIDE_INSTANCE_SHORT");
}
return columnListMap.get(props.mode);
});
const clickDatabase = function (section: number, row: number) {
const database = props.databaseList[row];
- router.push(`/db/${databaseSlug(database)}`);
+ if (props.customClick) {
+ emit("select-database-id", database.id);
+ } else {
+ router.push(`/db/${databaseSlug(database)}`);
+ }
};
return {
showProjectColumn,
showEnvironmentColumn,
showInstanceColumn,
+ showMiscColumn,
columnList,
clickDatabase,
};
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 6415995191..d937097464 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -447,7 +447,7 @@ export default {
const alterSchema = () => {
state.modalTitle = "Alter schema";
- state.modalSubtitle = "Task 1 - choose database";
+ state.modalSubtitle = "Choose database";
state.quickActionType = "quickaction.bb.database.schema.update";
state.showModal = true;
};