Skip to content

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

Introduce overview tab to database detail view.

spinningbot23105b80af6c
diff --git a/frontend/src/components/DatabaseOverviewPanel.vue b/frontend/src/components/DatabaseOverviewPanel.vue
new file mode 100644
index 0000000000..480f556d5c
--- /dev/null
+++ b/frontend/src/components/DatabaseOverviewPanel.vue
@@ -0,0 +1,403 @@
+<template>
+ <div class="mt-6">
+ <div
+ class="max-w-6xl mx-auto px-6 space-y-6 divide-y divide-block-border"
+ >
+ <!-- Description list -->
+ <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
+ <div class="col-span-1 col-start-1">
+ <dt class="text-sm font-medium text-control-light">
+ Character set
+ </dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ database.characterSet }}
+ </dd>
+ </div>
+
+ <div class="col-span-1">
+ <dt class="text-sm font-medium text-control-light">Collation</dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ database.collation }}
+ </dd>
+ </div>
+
+ <div class="col-span-1 col-start-1">
+ <dt class="text-sm font-medium text-control-light">
+ Sync status
+ </dt>
+ <dd class="mt-1 text-sm text-main">
+ <span>{{ database.syncStatus }}</span>
+ </dd>
+ </div>
+
+ <div class="col-span-1">
+ <dt class="text-sm font-medium text-control-light">
+ Last successful sync
+ </dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ humanizeTs(database.lastSuccessfulSyncTs) }}
+ </dd>
+ </div>
+
+ <div class="col-span-1 col-start-1">
+ <dt class="text-sm font-medium text-control-light">Updated</dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ humanizeTs(database.updatedTs) }}
+ </dd>
+ </div>
+
+ <div class="col-span-1">
+ <dt class="text-sm font-medium text-control-light">Created</dt>
+ <dd class="mt-1 text-sm text-main">
+ {{ humanizeTs(database.createdTs) }}
+ </dd>
+ </div>
+ </dl>
+
+ <div class="pt-6">
+ <div class="text-lg leading-6 font-medium text-main mb-4">
+ Tables
+ </div>
+ <TableTable
+ :mode="'TABLE'"
+ :tableList="tableList.filter((item) => item.type == 'BASE TABLE')"
+ />
+
+ <div class="mt-6 text-lg leading-6 font-medium text-main mb-4">
+ Views
+ </div>
+ <TableTable
+ :mode="'VIEW'"
+ :tableList="tableList.filter((item) => item.type == 'VIEW')"
+ />
+ <div class="mt-6 text-lg leading-6 font-medium text-main mb-4">
+ Migration History
+ </div>
+ <MigrationHistoryTable
+ v-if="state.migrationSetupStatus == 'OK'"
+ :historyList="migrationHistoryList"
+ />
+ <BBAttention
+ v-else
+ :title="attentionTitle"
+ :actionText="'Config instance'"
+ @click-action="configInstance"
+ />
+ </div>
+
+ <!-- Hide data source list for now, as we don't allow adding new data source after creating the database. -->
+ <div v-if="false" class="pt-6">
+ <DataSourceTable
+ :instance="database.instance"
+ :database="database"
+ />
+ </div>
+
+ <template v-if="allowViewDataSource">
+ <template
+ v-for="(item, index) of [
+ { type: 'RW', list: readWriteDataSourceList },
+ { type: 'RO', list: readonlyDataSourceList },
+ ]"
+ :key="index"
+ >
+ <div v-if="item.list.length" class="pt-6">
+ <div
+ v-if="hasDataSourceFeature"
+ class="text-lg leading-6 font-medium text-main mb-4"
+ >
+ <span v-data-source-type>{{ item.type }}</span>
+ </div>
+ <div class="space-y-4">
+ <div v-for="(ds, index) of item.list" :key="index">
+ <div v-if="hasDataSourceFeature" class="relative mb-2">
+ <div
+ class="absolute inset-0 flex items-center"
+ aria-hidden="true"
+ >
+ <div class="w-full border-t border-gray-300"></div>
+ </div>
+ <div class="relative flex justify-start">
+ <router-link
+ :to="`/db/${databaseSlug}/datasource/${dataSourceSlug(
+ ds
+ )}`"
+ class="pr-3 bg-white font-medium normal-link"
+ >
+ {{ ds.name }}
+ </router-link>
+ </div>
+ </div>
+ <div
+ v-if="allowChangeDataSource"
+ class="flex justify-end space-x-3"
+ >
+ <template v-if="isEditingDataSource(ds)">
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="cancelEditDataSource"
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ class="btn-normal"
+ :disabled="!allowSaveDataSource"
+ @click.prevent="saveEditDataSource"
+ >
+ <!-- Heroicon name: solid/save -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"
+ ></path>
+ </svg>
+ <span>Save</span>
+ </button>
+ </template>
+ <template v-else>
+ <button
+ type="button"
+ class="btn-normal"
+ @click.prevent="editDataSource(ds)"
+ >
+ <!-- Heroicon name: solid/pencil -->
+ <svg
+ class="-ml-1 mr-2 h-5 w-5 text-control-light"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
+ ></path>
+ </svg>
+ <span>Edit</span>
+ </button>
+ </template>
+ </div>
+ <DataSourceConnectionPanel
+ :editing="isEditingDataSource(ds)"
+ :dataSource="
+ isEditingDataSource(ds) ? state.editingDataSource : ds
+ "
+ />
+ </div>
+ </div>
+ </div>
+ </template>
+ </template>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, reactive, watchEffect, PropType } from "vue";
+import { useStore } from "vuex";
+import { useRouter } from "vue-router";
+import DataSourceTable from "../components/DataSourceTable.vue";
+import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
+import TableTable from "../components/TableTable.vue";
+import MigrationHistoryTable from "../components/MigrationHistoryTable.vue";
+import {
+ idFromSlug,
+ instanceSlug,
+ isDBAOrOwner,
+} from "../utils";
+import {
+ Database,
+ DataSource,
+ DataSourcePatch,
+ MigrationSchemaStatus,
+ InstanceMigration,
+} from "../types";
+import { cloneDeep, isEmpty, isEqual } from "lodash";
+
+interface LocalState {
+ editingDataSource?: DataSource;
+ migrationSetupStatus: MigrationSchemaStatus;
+}
+
+export default {
+ name: "DatabaseOverviewPanel",
+ props: {
+ database: {
+ required: true,
+ type: Object as PropType<Database>,
+ },
+ },
+ components: {
+ DataSourceConnectionPanel,
+ DataSourceTable,
+ TableTable,
+ MigrationHistoryTable,
+ },
+ setup(props, ctx) {
+ const store = useStore();
+ const router = useRouter();
+
+ const state = reactive<LocalState>({
+ migrationSetupStatus: "OK",
+ });
+
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const database = props.database;
+
+ const prepareTableList = () => {
+ store.dispatch(
+ "table/fetchTableListByDatabaseId",
+ database.id
+ );
+ };
+
+ watchEffect(prepareTableList);
+
+ const prepareMigrationHistoryList = () => {
+ store
+ .dispatch("instance/checkMigrationSetup", database.instance.id)
+ .then((migration: InstanceMigration) => {
+ state.migrationSetupStatus = migration.status;
+ if (state.migrationSetupStatus == "OK") {
+ store.dispatch("instance/migrationHistory", {
+ instanceId: database.instance.id,
+ databaseName: database.name,
+ });
+ }
+ });
+ };
+
+ watchEffect(prepareMigrationHistoryList);
+
+ const hasDataSourceFeature = computed(() =>
+ store.getters["plan/feature"]("bb.data-source")
+ );
+
+ const tableList = computed(() => {
+ return store.getters["table/tableListByDatabaseId"](
+ database.id
+ );
+ });
+
+ const attentionTitle = computed((): string => {
+ if (state.migrationSetupStatus == "NOT_EXIST") {
+ return `Missing migration history schema on instance "${database.instance.name}"`;
+ } else if (state.migrationSetupStatus == "UNKNOWN") {
+ return `Unable to connect instance "${database.instance.name}" to retrieve migration history`;
+ }
+ return "";
+ });
+
+ const migrationHistoryList = computed(() => {
+ return store.getters[
+ "instance/migrationHistoryListByInstanceIdAndDatabaseName"
+ ](database.instance.id, database.name);
+ });
+
+ const isCurrentUserDBAOrOwner = computed((): boolean => {
+ return isDBAOrOwner(currentUser.value.role);
+ });
+
+ const allowViewDataSource = computed(() => {
+ if (isCurrentUserDBAOrOwner.value) {
+ return true;
+ }
+
+ for (const member of database.project.memberList) {
+ if (member.principal.id == currentUser.value.id) {
+ return true;
+ }
+ }
+
+ return false;
+ });
+
+ const allowChangeDataSource = computed(() => {
+ return isCurrentUserDBAOrOwner.value;
+ });
+
+ const dataSourceList = computed(() => {
+ return database.dataSourceList;
+ });
+
+ const readWriteDataSourceList = computed(() => {
+ return dataSourceList.value.filter((dataSource: DataSource) => {
+ return dataSource.type == "RW";
+ });
+ });
+
+ const readonlyDataSourceList = computed(() => {
+ return dataSourceList.value.filter((dataSource: DataSource) => {
+ return dataSource.type == "RO";
+ });
+ });
+
+ const isEditingDataSource = (dataSource: DataSource) => {
+ return (
+ state.editingDataSource && state.editingDataSource.id == dataSource.id
+ );
+ };
+
+ const allowSaveDataSource = computed(() => {
+ for (const dataSource of dataSourceList.value) {
+ if (dataSource.id == state.editingDataSource!.id) {
+ return !isEqual(dataSource, state.editingDataSource);
+ }
+ }
+ return false;
+ });
+
+ const editDataSource = (dataSource: DataSource) => {
+ state.editingDataSource = cloneDeep(dataSource);
+ };
+
+ const cancelEditDataSource = () => {
+ state.editingDataSource = undefined;
+ };
+
+ const saveEditDataSource = () => {
+ const dataSourcePatch: DataSourcePatch = {
+ username: state.editingDataSource?.username,
+ password: state.editingDataSource?.password,
+ };
+ store
+ .dispatch("dataSource/patchDataSource", {
+ databaseId: state.editingDataSource!.database.id,
+ dataSourceId: state.editingDataSource!.id,
+ dataSource: dataSourcePatch,
+ })
+ .then(() => {
+ state.editingDataSource = undefined;
+ });
+ };
+
+ const configInstance = () => {
+ router.push(`/instance/${instanceSlug(database.instance)}`);
+ };
+
+ return {
+ state,
+ database,
+ tableList,
+ attentionTitle,
+ migrationHistoryList,
+ hasDataSourceFeature,
+ allowViewDataSource,
+ allowChangeDataSource,
+ readWriteDataSourceList,
+ readonlyDataSourceList,
+ isEditingDataSource,
+ allowSaveDataSource,
+ editDataSource,
+ cancelEditDataSource,
+ saveEditDataSource,
+ configInstance,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index db1d7fae23..955a232cb6 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -1,12 +1,11 @@
<template>
<div class="flex-1 overflow-auto focus:outline-none" tabindex="0">
- <main class="flex-1 relative pb-8 overflow-y-auto">
+ <main class="flex-1 relative overflow-y-auto">
<!-- Highlight Panel -->
<div
class="
px-4
pb-4
- border-b border-block-border
md:flex md:items-center md:justify-between
"
>
@@ -121,202 +120,6 @@
<span>Transfer Project</span>
</button>
</div>
-
- <div class="mt-6">
- <div
- class="max-w-6xl mx-auto px-6 space-y-6 divide-y divide-block-border"
- >
- <!-- Description list -->
- <dl class="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
- <div class="col-span-1 col-start-1">
- <dt class="text-sm font-medium text-control-light">
- Character set
- </dt>
- <dd class="mt-1 text-sm text-main">
- {{ database.characterSet }}
- </dd>
- </div>
-
- <div class="col-span-1">
- <dt class="text-sm font-medium text-control-light">Collation</dt>
- <dd class="mt-1 text-sm text-main">
- {{ database.collation }}
- </dd>
- </div>
-
- <div class="col-span-1 col-start-1">
- <dt class="text-sm font-medium text-control-light">
- Sync status
- </dt>
- <dd class="mt-1 text-sm text-main">
- <span>{{ database.syncStatus }}</span>
- </dd>
- </div>
-
- <div class="col-span-1">
- <dt class="text-sm font-medium text-control-light">
- Last successful sync
- </dt>
- <dd class="mt-1 text-sm text-main">
- {{ humanizeTs(database.lastSuccessfulSyncTs) }}
- </dd>
- </div>
-
- <div class="col-span-1 col-start-1">
- <dt class="text-sm font-medium text-control-light">Updated</dt>
- <dd class="mt-1 text-sm text-main">
- {{ humanizeTs(database.updatedTs) }}
- </dd>
- </div>
-
- <div class="col-span-1">
- <dt class="text-sm font-medium text-control-light">Created</dt>
- <dd class="mt-1 text-sm text-main">
- {{ humanizeTs(database.createdTs) }}
- </dd>
- </div>
- </dl>
-
- <div class="pt-6">
- <div class="text-lg leading-6 font-medium text-main mb-4">
- Tables
- </div>
- <TableTable
- :mode="'TABLE'"
- :tableList="tableList.filter((item) => item.type == 'BASE TABLE')"
- />
-
- <div class="mt-6 text-lg leading-6 font-medium text-main mb-4">
- Views
- </div>
- <TableTable
- :mode="'VIEW'"
- :tableList="tableList.filter((item) => item.type == 'VIEW')"
- />
- <div class="mt-6 text-lg leading-6 font-medium text-main mb-4">
- Migration History
- </div>
- <MigrationHistoryTable
- v-if="state.migrationSetupStatus == 'OK'"
- :historyList="migrationHistoryList"
- />
- <BBAttention
- v-else
- :title="attentionTitle"
- :actionText="'Config instance'"
- @click-action="configInstance"
- />
- </div>
-
- <!-- Hide data source list for now, as we don't allow adding new data source after creating the database. -->
- <div v-if="false" class="pt-6">
- <DataSourceTable
- :instance="database.instance"
- :database="database"
- />
- </div>
-
- <template v-if="allowViewDataSource">
- <template
- v-for="(item, index) of [
- { type: 'RW', list: readWriteDataSourceList },
- { type: 'RO', list: readonlyDataSourceList },
- ]"
- :key="index"
- >
- <div v-if="item.list.length" class="pt-6">
- <div
- v-if="hasDataSourceFeature"
- class="text-lg leading-6 font-medium text-main mb-4"
- >
- <span v-data-source-type>{{ item.type }}</span>
- </div>
- <div class="space-y-4">
- <div v-for="(ds, index) of item.list" :key="index">
- <div v-if="hasDataSourceFeature" class="relative mb-2">
- <div
- class="absolute inset-0 flex items-center"
- aria-hidden="true"
- >
- <div class="w-full border-t border-gray-300"></div>
- </div>
- <div class="relative flex justify-start">
- <router-link
- :to="`/db/${databaseSlug}/datasource/${dataSourceSlug(
- ds
- )}`"
- class="pr-3 bg-white font-medium normal-link"
- >
- {{ ds.name }}
- </router-link>
- </div>
- </div>
- <div
- v-if="allowChangeDataSource"
- class="flex justify-end space-x-3"
- >
- <template v-if="isEditingDataSource(ds)">
- <button
- type="button"
- class="btn-normal"
- @click.prevent="cancelEditDataSource"
- >
- Cancel
- </button>
- <button
- type="button"
- class="btn-normal"
- :disabled="!allowSaveDataSource"
- @click.prevent="saveEditDataSource"
- >
- <!-- Heroicon name: solid/save -->
- <svg
- class="-ml-1 mr-2 h-5 w-5 text-control-light"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- d="M7.707 10.293a1 1 0 10-1.414 1.414l3 3a1 1 0 001.414 0l3-3a1 1 0 00-1.414-1.414L11 11.586V6h5a2 2 0 012 2v7a2 2 0 01-2 2H4a2 2 0 01-2-2V8a2 2 0 012-2h5v5.586l-1.293-1.293zM9 4a1 1 0 012 0v2H9V4z"
- ></path>
- </svg>
- <span>Save</span>
- </button>
- </template>
- <template v-else>
- <button
- type="button"
- class="btn-normal"
- @click.prevent="editDataSource(ds)"
- >
- <!-- Heroicon name: solid/pencil -->
- <svg
- class="-ml-1 mr-2 h-5 w-5 text-control-light"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- d="M13.586 3.586a2 2 0 112.828 2.828l-.793.793-2.828-2.828.793-.793zM11.379 5.793L3 14.172V17h2.828l8.38-8.379-2.83-2.828z"
- ></path>
- </svg>
- <span>Edit</span>
- </button>
- </template>
- </div>
- <DataSourceConnectionPanel
- :editing="isEditingDataSource(ds)"
- :dataSource="
- isEditingDataSource(ds) ? state.editingDataSource : ds
- "
- />
- </div>
- </div>
- </div>
- </template>
- </template>
- </div>
- </div>
</main>
</div>
<BBModal
@@ -362,18 +165,31 @@
</button>
</div>
</BBModal>
+ <BBTabFilter
+ class="px-1 pb-2 border-b border-block-border"
+ :responsive="false"
+ :tabList="databaseTabItemList.map((item) => item.name)"
+ :selectedIndex="state.selectedIndex"
+ @select-index="
+ (index) => {
+ selectTab(index);
+ }
+ "
+ />
+ <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
+ <template v-if="state.selectedIndex == OVERVIEW_TAB">
+ <DatabaseOverviewPanel id="overview" :database="database" />
+ </template>
+ </div>
</template>
<script lang="ts">
-import { computed, reactive, watchEffect } from "vue";
+import { computed, onMounted, reactive, watch } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
-import DataSourceTable from "../components/DataSourceTable.vue";
-import DataSourceConnectionPanel from "../components/DataSourceConnectionPanel.vue";
-import TableTable from "../components/TableTable.vue";
-import MigrationHistoryTable from "../components/MigrationHistoryTable.vue";
import MemberSelect from "../components/MemberSelect.vue";
import ProjectSelect from "../components/ProjectSelect.vue";
+import DatabaseOverviewPanel from "../components/DatabaseOverviewPanel.vue";
import {
databaseConsoleLink,
idFromSlug,
@@ -381,21 +197,27 @@ import {
isDBAOrOwner,
} from "../utils";
import {
- DataSource,
ProjectId,
- DataSourcePatch,
UNKNOWN_ID,
DEFAULT_PROJECT_ID,
- MigrationSchemaStatus,
- InstanceMigration,
} from "../types";
-import { cloneDeep, isEmpty, isEqual } from "lodash";
+import { isEmpty } from "lodash";
+
+const OVERVIEW_TAB = 0;
+
+type DatabaseTabItem = {
+ name: string;
+ hash: string;
+};
+
+const databaseTabItemList: DatabaseTabItem[] = [
+ { name: "Overview", hash: "overview" },
+];
interface LocalState {
- editingDataSource?: DataSource;
showModal: boolean;
editingProjectId: ProjectId;
- migrationSetupStatus: MigrationSchemaStatus;
+ selectedIndex: number;
}
export default {
@@ -407,12 +229,9 @@ export default {
},
},
components: {
- DataSourceConnectionPanel,
- DataSourceTable,
- TableTable,
- MigrationHistoryTable,
MemberSelect,
ProjectSelect,
+ DatabaseOverviewPanel,
},
setup(props, ctx) {
const store = useStore();
@@ -421,7 +240,7 @@ export default {
const state = reactive<LocalState>({
showModal: false,
editingProjectId: UNKNOWN_ID,
- migrationSetupStatus: "OK",
+ selectedIndex: OVERVIEW_TAB,
});
const currentUser = computed(() => store.getters["auth/currentUser"]());
@@ -432,31 +251,6 @@ export default {
);
});
- const prepareTableList = () => {
- store.dispatch(
- "table/fetchTableListByDatabaseId",
- idFromSlug(props.databaseSlug)
- );
- };
-
- watchEffect(prepareTableList);
-
- const prepareMigrationHistoryList = () => {
- store
- .dispatch("instance/checkMigrationSetup", database.value.instance.id)
- .then((migration: InstanceMigration) => {
- state.migrationSetupStatus = migration.status;
- if (state.migrationSetupStatus == "OK") {
- store.dispatch("instance/migrationHistory", {
- instanceId: database.value.instance.id,
- databaseName: database.value.name,
- });
- }
- });
- };
-
- watchEffect(prepareMigrationHistoryList);
-
const consoleLink = computed(() => {
const consoleURL = store.getters["setting/settingByName"](
"bb.console.database"
@@ -467,31 +261,6 @@ export default {
return "";
});
- const hasDataSourceFeature = computed(() =>
- store.getters["plan/feature"]("bb.data-source")
- );
-
- const tableList = computed(() => {
- return store.getters["table/tableListByDatabaseId"](
- idFromSlug(props.databaseSlug)
- );
- });
-
- const attentionTitle = computed((): string => {
- if (state.migrationSetupStatus == "NOT_EXIST") {
- return `Missing migration history schema on instance "${database.value.instance.name}"`;
- } else if (state.migrationSetupStatus == "UNKNOWN") {
- return `Unable to connect instance "${database.value.instance.name}" to retrieve migration history`;
- }
- return "";
- });
-
- const migrationHistoryList = computed(() => {
- return store.getters[
- "instance/migrationHistoryListByInstanceIdAndDatabaseName"
- ](database.value.instance.id, database.value.name);
- });
-
const isCurrentUserDBAOrOwner = computed((): boolean => {
return isDBAOrOwner(currentUser.value.role);
});
@@ -521,40 +290,6 @@ export default {
return false;
});
- const allowViewDataSource = computed(() => {
- if (isCurrentUserDBAOrOwner.value) {
- return true;
- }
-
- for (const member of database.value.project.memberList) {
- if (member.principal.id == currentUser.value.id) {
- return true;
- }
- }
-
- return false;
- });
-
- const allowChangeDataSource = computed(() => {
- return isCurrentUserDBAOrOwner.value;
- });
-
- const dataSourceList = computed(() => {
- return database.value.dataSourceList;
- });
-
- const readWriteDataSourceList = computed(() => {
- return dataSourceList.value.filter((dataSource: DataSource) => {
- return dataSource.type == "RW";
- });
- });
-
- const readonlyDataSourceList = computed(() => {
- return dataSourceList.value.filter((dataSource: DataSource) => {
- return dataSource.type == "RO";
- });
- });
-
const tryTransferProject = () => {
state.editingProjectId = database.value.project.id;
state.showModal = true;
@@ -576,70 +311,53 @@ export default {
});
};
- const isEditingDataSource = (dataSource: DataSource) => {
- return (
- state.editingDataSource && state.editingDataSource.id == dataSource.id
- );
+ const selectTab = (index: number) => {
+ state.selectedIndex = index;
+ router.replace({
+ name: "workspace.database.detail",
+ hash: "#" + databaseTabItemList[index].hash,
+ });
};
- const allowSaveDataSource = computed(() => {
- for (const dataSource of dataSourceList.value) {
- if (dataSource.id == state.editingDataSource!.id) {
- return !isEqual(dataSource, state.editingDataSource);
+ const selectDatabaseTabOnHash = () => {
+ if (router.currentRoute.value.hash) {
+ for (let i = 0; i < databaseTabItemList.length; i++) {
+ if (
+ databaseTabItemList[i].hash ==
+ router.currentRoute.value.hash.slice(1)
+ ) {
+ selectTab(i);
+ break;
+ }
}
+ } else {
+ selectTab(OVERVIEW_TAB);
}
- return false;
- });
-
- const editDataSource = (dataSource: DataSource) => {
- state.editingDataSource = cloneDeep(dataSource);
- };
-
- const cancelEditDataSource = () => {
- state.editingDataSource = undefined;
};
- const saveEditDataSource = () => {
- const dataSourcePatch: DataSourcePatch = {
- username: state.editingDataSource?.username,
- password: state.editingDataSource?.password,
- };
- store
- .dispatch("dataSource/patchDataSource", {
- databaseId: state.editingDataSource!.database.id,
- dataSourceId: state.editingDataSource!.id,
- dataSource: dataSourcePatch,
- })
- .then(() => {
- state.editingDataSource = undefined;
- });
- };
+ onMounted(() => {
+ selectDatabaseTabOnHash();
+ });
- const configInstance = () => {
- router.push(`/instance/${instanceSlug(database.value.instance)}`);
- };
+ watch(
+ () => router.currentRoute.value.hash,
+ () => {
+ if (router.currentRoute.value.name == "workspace.database.detail") {
+ selectDatabaseTabOnHash();
+ }
+ }
+ );
return {
+ OVERVIEW_TAB,
state,
database,
- tableList,
- attentionTitle,
- migrationHistoryList,
consoleLink,
- hasDataSourceFeature,
allowChangeProject,
- allowViewDataSource,
- allowChangeDataSource,
- readWriteDataSourceList,
- readonlyDataSourceList,
tryTransferProject,
updateProject,
- isEditingDataSource,
- allowSaveDataSource,
- editDataSource,
- cancelEditDataSource,
- saveEditDataSource,
- configInstance,
+ selectTab,
+ databaseTabItemList,
};
},
};