Skip to content

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

chore: migrate `DatabaseV1Table` from `BBGrid` to `NDataTable` (#11685)

boojack197fa4fb52c4
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 7e798cc798..9b9af4c97d 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -150,55 +150,12 @@
:placement="'left-start'"
/>
</div>
- <DatabaseV1Table
+ <DatabaseDataTable
mode="ALL_SHORT"
- table-class="border"
- :custom-click="true"
- :database-list="selectableDatabaseList"
- :show-selection-column="true"
:show-sql-editor-button="false"
- :show-placeholder="true"
- @select-database="
- (db: ComposedDatabase) =>
- toggleDatabasesSelection(
- [db as ComposedDatabase],
- !isDatabaseSelected(db)
- )
- "
- >
- <template
- #selection-all="{ databaseList: selectedDatabaseList }"
- >
- <NCheckbox
- v-if="selectedDatabaseList.length > 0"
- class="h-4 w-4 text-accent rounded disabled:cursor-not-allowed border-control-border focus:ring-accent"
- v-bind="
- getAllSelectionState(
- selectedDatabaseList as ComposedDatabase[]
- )
- "
- @update:checked="
- toggleDatabasesSelection(
- selectedDatabaseList as ComposedDatabase[],
- $event
- )
- "
- />
- </template>
- <template #selection="{ database }">
- <NCheckbox
- :checked="
- isDatabaseSelected(database as ComposedDatabase)
- "
- @update:checked="
- toggleDatabasesSelection(
- [database as ComposedDatabase],
- $event
- )
- "
- />
- </template>
- </DatabaseV1Table>
+ :database-list="selectableDatabaseList"
+ @update:selected-databases="handleDatabasesSelectionChanged"
+ />
<SchemalessDatabaseTable
v-if="isEditSchema"
mode="ALL"
@@ -299,10 +256,10 @@
/>
<DatabaseGroupPrevEditorModal
- v-if="state.selectedDatabaseGroup"
+ v-if="state.showDatabaseGroupPrevModal"
:issue-type="type"
- :database-group="state.selectedDatabaseGroup"
- @close="state.selectedDatabaseGroup = undefined"
+ :database-group-name="state.selectedDatabaseGroupName!"
+ @close="state.showDatabaseGroupPrevModal = false"
/>
</template>
@@ -315,12 +272,12 @@ import {
NRadio,
NInputGroup,
NInputGroupLabel,
- NCheckbox,
} from "naive-ui";
import type { PropType } from "vue";
import { computed, reactive, ref, watch, watchEffect, h } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
import FeatureBadge from "@/components/FeatureGuard/FeatureBadge.vue";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import {
@@ -351,7 +308,7 @@ import {
extractInstanceResourceName,
extractProjectResourceName,
} from "@/utils";
-import { DatabaseLabelFilter, DatabaseV1Table, DrawerContent } from "../v2";
+import { DatabaseLabelFilter, DrawerContent } from "../v2";
import DatabaseGroupPrevEditorModal from "./DatabaseGroupPrevEditorModal.vue";
import ProjectStandardView from "./ProjectStandardView.vue";
import ProjectTenantView from "./ProjectTenantView.vue";
@@ -364,12 +321,11 @@ type LocalState = {
alterType: "MULTI_DB" | "TENANT";
databaseSelectedTab: "DATABASE" | "DATABASE_GROUP";
showSchemaLessDatabaseList: boolean;
- showSchemaEditorModal: boolean;
- selectedDatabaseGroupName?: string;
- // Using to display the database group prev editor.
- selectedDatabaseGroup?: ComposedDatabaseGroup;
selectedLabels: { key: string; value: string }[];
selectedDatabaseUidList: Set<string>;
+ showSchemaEditorModal: boolean;
+ selectedDatabaseGroupName?: string;
+ showDatabaseGroupPrevModal: boolean;
params: SearchParams;
};
@@ -413,6 +369,7 @@ const state = reactive<LocalState>({
showSchemaLessDatabaseList: false,
showSchemaEditorModal: false,
selectedLabels: [],
+ showDatabaseGroupPrevModal: false,
params: {
query: "",
scopes: [],
@@ -616,10 +573,7 @@ const generateMultiDb = async () => {
state.databaseSelectedTab === "DATABASE_GROUP" &&
state.selectedDatabaseGroupName
) {
- const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
- state.selectedDatabaseGroupName
- );
- state.selectedDatabaseGroup = databaseGroup;
+ state.showDatabaseGroupPrevModal = true;
return;
}
@@ -675,33 +629,14 @@ const allowGenerateTenant = computed(() => {
return true;
});
-const getAllSelectionState = (
- databaseList: ComposedDatabase[]
-): { checked: boolean; indeterminate: boolean } => {
- const set = state.selectedDatabaseUidList;
-
- const checked = set.size > 0 && databaseList.every((db) => set.has(db.uid));
- const indeterminate = !checked && databaseList.some((db) => set.has(db.uid));
-
- return {
- checked,
- indeterminate,
- };
-};
-
-const toggleDatabasesSelection = (
- databaseList: ComposedDatabase[],
- on: boolean
-): void => {
- if (on) {
- databaseList.forEach((db) => {
- state.selectedDatabaseUidList.add(db.uid);
- });
- } else {
- databaseList.forEach((db) => {
- state.selectedDatabaseUidList.delete(db.uid);
- });
- }
+const handleDatabasesSelectionChanged = (
+ selectedDatabaseNameList: Set<string>
+) => {
+ state.selectedDatabaseUidList = new Set(
+ Array.from(selectedDatabaseNameList).map(
+ (name) => databaseV1Store.getDatabaseByName(name)?.uid
+ )
+ );
};
const selectDatabaseGroup = async (
@@ -716,26 +651,16 @@ const selectDatabaseGroup = async (
state.selectedDatabaseGroupName = databaseGroupName;
if (showModal) {
- const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
- state.selectedDatabaseGroupName
- );
- state.selectedDatabaseGroup = databaseGroup;
+ state.showDatabaseGroupPrevModal = true;
}
};
-const isDatabaseSelected = (database: ComposedDatabase): boolean => {
- return state.selectedDatabaseUidList.has(database.uid);
-};
-
const generateTenant = async () => {
if (
state.databaseSelectedTab === "DATABASE_GROUP" &&
state.selectedDatabaseGroupName
) {
- const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
- state.selectedDatabaseGroupName
- );
- state.selectedDatabaseGroup = databaseGroup;
+ state.showDatabaseGroupPrevModal = true;
return;
}
diff --git a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
index a508299413..7fe90946fa 100644
--- a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
@@ -76,8 +76,8 @@ interface LocalState {
}
const props = defineProps({
- databaseGroup: {
- type: Object as PropType<ComposedDatabaseGroup>,
+ databaseGroupName: {
+ type: Object as PropType<string>,
required: true,
},
issueType: {
@@ -100,6 +100,12 @@ const state = reactive<LocalState>({
showActionConfirmModal: false,
});
+const databaseGroup = computed(() => {
+ return dbGroupStore.getDBGroupByName(
+ props.databaseGroupName
+ ) as ComposedDatabaseGroup;
+});
+
const allowPreviewIssue = computed(() => {
return state.editStatement !== "";
});
@@ -115,7 +121,7 @@ const title = computed(() => {
onMounted(async () => {
const schemaGroupList =
await dbGroupStore.getOrFetchSchemaGroupListByDBGroupName(
- props.databaseGroup.name
+ databaseGroup.value.name
);
// Initial statement with schema group list;
state.editStatement = generateReferenceStatement(schemaGroupList);
@@ -148,7 +154,7 @@ const dismissModal = () => {
const handlePreviewIssue = async () => {
const issueRoute = generateDatabaseGroupIssueRoute(
props.issueType,
- props.databaseGroup,
+ databaseGroup.value,
state.editStatement
);
router.push(issueRoute);
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue b/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
index 460b290e0f..d525d34f90 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemalessDatabaseTable.vue
@@ -5,14 +5,13 @@
{{ $t("database.show-schemaless-databases") }}
</NCheckbox>
</div>
- <DatabaseV1Table
+ <DatabaseDataTable
v-if="expand"
:mode="`${mode}_SHORT`"
- class="overflow-y-auto mt-2"
- table-class="border"
:schemaless="true"
- :row-clickable="false"
:database-list="databaseList"
+ :show-selection="false"
+ :show-sql-editor-button="false"
/>
</div>
</template>
@@ -20,8 +19,8 @@
<script setup lang="ts">
import { NCheckbox } from "naive-ui";
import { ref } from "vue";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
import type { ComposedDatabase } from "@/types";
-import { DatabaseV1Table } from "../v2/";
defineProps<{
databaseList: ComposedDatabase[];
diff --git a/frontend/src/components/AlterSchemaPrepForm/SelectDatabaseGroupTable.vue b/frontend/src/components/AlterSchemaPrepForm/SelectDatabaseGroupTable.vue
index 6be41f4c40..f6f329565c 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SelectDatabaseGroupTable.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SelectDatabaseGroupTable.vue
@@ -25,7 +25,7 @@
{{ dbGroup.databasePlaceholder }}
</div>
<div class="bb-grid-cell">
- <ProjectCol :project="dbGroup.project" :show-tenant-icon="true" />
+ <ProjectCol :project="dbGroup.projectEntity" :show-tenant-icon="true" />
</div>
</template>
</BBGrid>
diff --git a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
index 59051def22..13417d70a3 100644
--- a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
+++ b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
@@ -26,27 +26,13 @@
:placement="'left-start'"
/>
</div>
- <DatabaseV1Table
+ <DatabaseDataTable
mode="ALL_SHORT"
- table-class="border"
- :custom-click="true"
- :database-list="selectableDatabaseList"
- :show-selection-column="true"
+ :database-list="filteredDatabaseList"
:show-sql-editor-button="false"
- :show-placeholder="true"
- @select-database="handleSelectedDatabaseChange"
- >
- <template #selection="{ database }">
- <NRadio
- :checked="isDatabaseSelected(database as ComposedDatabase)"
- :value="(database as ComposedDatabase).uid"
- @click="
- () =>
- handleSelectedDatabaseChange(database as ComposedDatabase)
- "
- />
- </template>
- </DatabaseV1Table>
+ :single-selection="true"
+ @update:selected-databases="handleDatabasesSelectionChanged"
+ />
</div>
</div>
<div
@@ -79,9 +65,10 @@
</template>
<script lang="ts" setup>
-import { NButton, NRadio } from "naive-ui";
+import { NButton } from "naive-ui";
import { computed, reactive } from "vue";
import { useRouter } from "vue-router";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import {
useCurrentUserV1,
@@ -101,7 +88,7 @@ import {
generateIssueName,
extractProjectResourceName,
} from "@/utils";
-import { DatabaseLabelFilter, DatabaseV1Table, DrawerContent } from "../v2";
+import { DatabaseLabelFilter, DrawerContent } from "../v2";
type LocalState = {
label: string;
@@ -211,16 +198,15 @@ const filteredDatabaseList = computed(() => {
return sortDatabaseV1List(list);
});
-const selectableDatabaseList = computed(() => {
- return filteredDatabaseList.value;
-});
-
-const handleSelectedDatabaseChange = (database: ComposedDatabase) => {
- state.selectedDatabaseUid = database.uid;
-};
-
-const isDatabaseSelected = (database: ComposedDatabase): boolean => {
- return state.selectedDatabaseUid === database.uid;
+const handleDatabasesSelectionChanged = (
+ selectedDatabaseNameList: Set<string>
+): void => {
+ if (selectedDatabaseNameList.size !== 1) {
+ return;
+ }
+ state.selectedDatabaseUid = databaseV1Store.getDatabaseByName(
+ Array.from(selectedDatabaseNameList)[0]
+ )?.uid;
};
const navigateToIssuePage = async () => {
@@ -228,7 +214,7 @@ const navigateToIssuePage = async () => {
return;
}
- const selectedDatabase = selectableDatabaseList.value.find(
+ const selectedDatabase = filteredDatabaseList.value.find(
(db) => db.uid === state.selectedDatabaseUid
) as ComposedDatabase;
diff --git a/frontend/src/components/DatabaseDataTable/DatabaseDataTable.vue b/frontend/src/components/DatabaseDataTable/DatabaseDataTable.vue
new file mode 100644
index 0000000000..bddd6609b1
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/DatabaseDataTable.vue
@@ -0,0 +1,208 @@
+<template>
+ <div>
+ <NDataTable
+ size="small"
+ :columns="columnList"
+ :data="data"
+ :striped="true"
+ :bordered="bordered"
+ :loading="loading"
+ :row-key="(data: ComposedDatabase) => data.name"
+ :checked-row-keys="Array.from(state.selectedDatabaseNameList)"
+ :row-props="rowProps"
+ :pagination="{ pageSize: 20 }"
+ @update:checked-row-keys="
+ (val) => (state.selectedDatabaseNameList = new Set(val as string[]))
+ "
+ ></NDataTable>
+ </div>
+</template>
+
+<script setup lang="tsx">
+import { NDataTable, type DataTableColumn } from "naive-ui";
+import { computed, reactive } from "vue";
+import { watch } from "vue";
+import { useI18n } from "vue-i18n";
+import type { ComposedDatabase } from "@/types";
+import { EnvironmentV1Name, InstanceV1Name } from "../v2";
+import { DatabaseNameCell, ProjectNameCell, DatabaseLabelsCell } from "./cells";
+
+interface LocalState {
+ // The selected database name list.
+ selectedDatabaseNameList: Set<string>;
+}
+
+type DatabaseDataTableColumn = DataTableColumn<ComposedDatabase> & {
+ hide?: boolean;
+};
+
+export type Mode =
+ | "ALL"
+ | "ALL_SHORT"
+ | "ALL_TINY"
+ | "INSTANCE"
+ | "PROJECT"
+ | "PROJECT_SHORT";
+
+const props = withDefaults(
+ defineProps<{
+ mode: Mode;
+ databaseList: ComposedDatabase[];
+ bordered?: boolean;
+ loading?: boolean;
+ showSelection?: boolean;
+ singleSelection?: boolean;
+ schemaless?: boolean;
+ customClick?: boolean;
+ showSqlEditorButton?: boolean;
+ }>(),
+ {
+ mode: "ALL",
+ bordered: true,
+ showSelection: true,
+ showSqlEditorButton: true,
+ }
+);
+
+const emit = defineEmits<{
+ (event: "row-click", e: MouseEvent, val: ComposedDatabase): void;
+ (event: "update:selected-databases", val: Set<string>): void;
+}>();
+
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ selectedDatabaseNameList: new Set(),
+});
+
+const columnList = computed((): DatabaseDataTableColumn[] => {
+ const SELECTION: DatabaseDataTableColumn = {
+ type: "selection",
+ multiple: !props.singleSelection,
+ hide: !props.showSelection,
+ cellProps: () => {
+ return {
+ onClick: (e: MouseEvent) => {
+ e.stopPropagation();
+ },
+ };
+ },
+ };
+ const NAME: DatabaseDataTableColumn = {
+ key: "title",
+ title: t("common.name"),
+ resizable: true,
+ render: (data) => {
+ return (
+ <DatabaseNameCell
+ database={data as ComposedDatabase}
+ showSQLEditorButton={props.showSqlEditorButton}
+ />
+ );
+ },
+ };
+ const ENVIRONMENT: DatabaseDataTableColumn = {
+ key: "environment",
+ title: t("common.environment"),
+ resizable: true,
+ render: (data) => (
+ <EnvironmentV1Name
+ environment={(data as ComposedDatabase).effectiveEnvironmentEntity}
+ link={false}
+ tag="div"
+ />
+ ),
+ };
+ const SCHEMA_VERSION: DatabaseDataTableColumn = {
+ key: "schema-version",
+ title: t("common.schema-version"),
+ resizable: true,
+ hide: props.schemaless,
+ render: (data) => (data as ComposedDatabase).schemaVersion || "-",
+ };
+ const PROJECT: DatabaseDataTableColumn = {
+ key: "project",
+ title: t("common.project"),
+ resizable: true,
+ render: (data) => (
+ <ProjectNameCell project={data.projectEntity} mode={props.mode} />
+ ),
+ };
+ const INSTANCE: DatabaseDataTableColumn = {
+ key: "instance",
+ title: t("common.instance"),
+ resizable: true,
+ render: (data) => (
+ <InstanceV1Name
+ instance={(data as ComposedDatabase).instanceEntity}
+ link={false}
+ tag="div"
+ />
+ ),
+ };
+ const DATABASE_LABELS: DatabaseDataTableColumn = {
+ key: "labels",
+ title: t("common.labels"),
+ resizable: true,
+ render: (data) => (
+ <DatabaseLabelsCell
+ labels={(data as ComposedDatabase).labels}
+ showCount={1}
+ placeholder="-"
+ />
+ ),
+ };
+
+ const columnsMap = new Map<Mode, DatabaseDataTableColumn[]>([
+ [
+ "ALL",
+ [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, INSTANCE, DATABASE_LABELS],
+ ],
+ ["ALL_SHORT", [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, INSTANCE]],
+ ["ALL_TINY", [NAME, ENVIRONMENT, PROJECT, INSTANCE]],
+ ["INSTANCE", [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, DATABASE_LABELS]],
+ ["PROJECT", [NAME, ENVIRONMENT, SCHEMA_VERSION, INSTANCE, DATABASE_LABELS]],
+ ["PROJECT_SHORT", [NAME, ENVIRONMENT, SCHEMA_VERSION, INSTANCE]],
+ ]);
+
+ return [SELECTION, ...(columnsMap.get(props.mode) || [])].filter(
+ (column) => !column.hide
+ );
+});
+
+const data = computed(() => {
+ return [...props.databaseList];
+});
+
+const rowProps = (database: ComposedDatabase) => {
+ return {
+ style: "cursor: pointer;",
+ onClick: (e: MouseEvent) => {
+ if (props.customClick) {
+ emit("row-click", e, database);
+ return;
+ }
+
+ if (props.singleSelection) {
+ state.selectedDatabaseNameList = new Set([database.name]);
+ } else {
+ const selectedDatabaseNameList = new Set(
+ Array.from(state.selectedDatabaseNameList)
+ );
+ if (selectedDatabaseNameList.has(database.name)) {
+ selectedDatabaseNameList.delete(database.name);
+ } else {
+ selectedDatabaseNameList.add(database.name);
+ }
+ state.selectedDatabaseNameList = selectedDatabaseNameList;
+ }
+ },
+ };
+};
+
+watch(
+ () => state.selectedDatabaseNameList,
+ () => {
+ emit("update:selected-databases", state.selectedDatabaseNameList);
+ }
+);
+</script>
diff --git a/frontend/src/components/DatabaseDataTable/cells/DatabaseLabelsCell.vue b/frontend/src/components/DatabaseDataTable/cells/DatabaseLabelsCell.vue
new file mode 100644
index 0000000000..e58f51eed6
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/cells/DatabaseLabelsCell.vue
@@ -0,0 +1,45 @@
+<template>
+ <NTooltip :disabled="Object.keys(labels).length <= minimumShowCount">
+ <template #trigger>
+ <div
+ v-if="Object.entries(labels).length > 0"
+ class="flex items-center space-x-1"
+ >
+ <div
+ v-for="[key, label] in Object.entries(labels).slice(
+ 0,
+ minimumShowCount
+ )"
+ :key="key"
+ class="rounded-lg bg-gray-100 group-hover:bg-gray-200 py-0.5 px-2 text-sm"
+ >
+ {{ `${key}:${label}` }}
+ </div>
+ <span v-if="Object.keys(labels).length > minimumShowCount">...</span>
+ </div>
+ <div v-else>{{ placeholder }}</div>
+ </template>
+ <div class="text-sm flex flex-col space-y-1">
+ <div v-for="[key, label] in Object.entries(labels)" :key="key">
+ {{ `${key}:${label}` }}
+ </div>
+ </div>
+ </NTooltip>
+</template>
+
+<script setup lang="ts">
+const props = withDefaults(
+ defineProps<{
+ labels: {
+ [key: string]: string;
+ };
+ showCount: number;
+ placeholder?: string;
+ }>(),
+ {
+ placeholder: "",
+ }
+);
+
+const minimumShowCount = Math.max(1, props.showCount);
+</script>
diff --git a/frontend/src/components/DatabaseDataTable/cells/DatabaseNameCell.vue b/frontend/src/components/DatabaseDataTable/cells/DatabaseNameCell.vue
new file mode 100644
index 0000000000..92ba1d2b3c
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/cells/DatabaseNameCell.vue
@@ -0,0 +1,40 @@
+<template>
+ <div class="flex items-center space-x-2">
+ <SQLEditorButtonV1
+ v-if="showSQLEditorButton"
+ :database="database"
+ :disabled="!allowQuery"
+ :tooltip="true"
+ @failed="handleGotoSQLEditorFailed"
+ />
+ <DatabaseV1Name :database="database" :link="false" tag="span" />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { defineProps } from "vue";
+import SQLEditorButtonV1 from "@/components/DatabaseDetail/SQLEditorButtonV1.vue";
+import { DatabaseV1Name } from "@/components/v2";
+import { pushNotification, useCurrentUserV1 } from "@/store";
+import type { ComposedDatabase } from "@/types";
+import { isDatabaseV1Queryable } from "@/utils";
+
+const props = defineProps<{
+ database: ComposedDatabase;
+ showSQLEditorButton: boolean;
+}>();
+
+const currentUser = useCurrentUserV1();
+
+const allowQuery = () => {
+ return isDatabaseV1Queryable(props.database, currentUser.value);
+};
+
+const handleGotoSQLEditorFailed = () => {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: `Failed to go to SQL editor for database ${props.database.name}`,
+ });
+};
+</script>
diff --git a/frontend/src/components/DatabaseDataTable/cells/ProjectNameCell.vue b/frontend/src/components/DatabaseDataTable/cells/ProjectNameCell.vue
new file mode 100644
index 0000000000..d69034ac19
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/cells/ProjectNameCell.vue
@@ -0,0 +1,62 @@
+<template>
+ <div class="flex flex-row space-x-2 items-center">
+ <ProjectV1Name :project="project" :link="false" tag="div" />
+ <NTooltip
+ v-if="
+ showTenantIcon && project.tenantMode === TenantMode.TENANT_MODE_ENABLED
+ "
+ >
+ <template #trigger>
+ <TenantIcon class="text-control" />
+ </template>
+ <span class="whitespace-nowrap">
+ {{ $t("project.mode.batch") }}
+ </span>
+ </NTooltip>
+
+ <NTooltip v-if="project.workflow === Workflow.VCS">
+ <template #trigger>
+ <GitIcon class="w-4 h-4 text-control" />
+ </template>
+ <span v-if="mode === 'ALL_SHORT'" class="w-40">
+ {{ $t("alter-schema.vcs-info") }}
+ </span>
+ <span v-else class="tooltip whitespace-nowrap">
+ {{ $t("database.gitops-enabled") }}
+ </span>
+ </NTooltip>
+
+ <NTooltip v-if="project.state === State.DELETED">
+ <template #trigger>
+ <heroicons-outline:archive class="w-4 h-4 text-control" />
+ </template>
+ <span class="whitespace-nowrap">
+ {{ $t("common.archived") }}
+ </span>
+ </NTooltip>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { NTooltip } from "naive-ui";
+import { computed } from "vue";
+import { ProjectV1Name } from "@/components/v2";
+import { State } from "@/types/proto/v1/common";
+import type { Project } from "@/types/proto/v1/project_service";
+import { TenantMode, Workflow } from "@/types/proto/v1/project_service";
+import type { Mode } from "../DatabaseDataTable.vue";
+
+const props = withDefaults(
+ defineProps<{
+ project: Project;
+ mode?: Mode;
+ }>(),
+ {
+ mode: "ALL",
+ }
+);
+
+const showTenantIcon = computed(() => {
+ return ["ALL", "ALL_SHORT", "INSTANCE"].includes(props.mode);
+});
+</script>
diff --git a/frontend/src/components/DatabaseDataTable/cells/index.ts b/frontend/src/components/DatabaseDataTable/cells/index.ts
new file mode 100644
index 0000000000..a16be98eb0
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/cells/index.ts
@@ -0,0 +1,5 @@
+import DatabaseLabelsCell from "./DatabaseLabelsCell.vue";
+import DatabaseNameCell from "./DatabaseNameCell.vue";
+import ProjectNameCell from "./ProjectNameCell.vue";
+
+export { DatabaseNameCell, ProjectNameCell, DatabaseLabelsCell };
diff --git a/frontend/src/components/DatabaseDataTable/index.ts b/frontend/src/components/DatabaseDataTable/index.ts
new file mode 100644
index 0000000000..aeac279140
--- /dev/null
+++ b/frontend/src/components/DatabaseDataTable/index.ts
@@ -0,0 +1,3 @@
+import DatabaseDataTable from "./DatabaseDataTable.vue";
+
+export default DatabaseDataTable;
diff --git a/frontend/src/components/IssueV1/components/IssueTableV1.vue b/frontend/src/components/IssueV1/components/IssueTableV1.vue
index a41e37c6d2..a8bf1772fb 100644
--- a/frontend/src/components/IssueV1/components/IssueTableV1.vue
+++ b/frontend/src/components/IssueV1/components/IssueTableV1.vue
@@ -1,5 +1,4 @@
<template>
- <!-- eslint-disable vue/no-v-html -->
<div
v-if="title"
class="text-left pl-4 pt-4 pb-2 py-text-base leading-6 font-medium text-gray-900"
@@ -185,7 +184,6 @@ const columnList = computed((): DataTableColumn<ComposedIssue>[] => {
});
interface LocalState {
- dataSource: any[];
selectedIssueIdList: Set<string>;
}
@@ -212,7 +210,6 @@ const props = withDefaults(
const router = useRouter();
const state = reactive<LocalState>({
- dataSource: [],
selectedIssueIdList: new Set(),
});
const currentUserV1 = useCurrentUserV1();
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 82c8cb74ac..159c0bdff2 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -24,73 +24,22 @@
:databases="selectedDatabases"
/>
- <DatabaseV1Table
+ <DatabaseDataTable
mode="PROJECT"
- table-class="border"
- :show-selection-column="true"
- :show-placeholder="true"
- :custom-click="isStandaloneMode"
:database-list="filteredDatabaseList"
- @select-database="
- (db: ComposedDatabase) =>
- toggleDatabasesSelection(
- [db as ComposedDatabase],
- !isDatabaseSelected(db)
- )
- "
- >
- <template #selection-all="{ databaseList: selectedDatabaseList }">
- <NCheckbox
- v-if="selectedDatabaseList.length > 0"
- v-bind="
- getAllSelectionState(selectedDatabaseList as ComposedDatabase[])
- "
- @update:checked="
- toggleDatabasesSelection(
- selectedDatabaseList as ComposedDatabase[],
- $event
- )
- "
- />
- </template>
- <template #selection="{ database }">
- <NCheckbox
- :checked="isDatabaseSelected(database as ComposedDatabase)"
- @update:checked="
- toggleDatabasesSelection([database as ComposedDatabase], $event)
- "
- />
- </template>
- <template v-if="databaseList.length === 0" #placeholder>
- <div class="p-8 text-center textinfolabel">
- <i18n-t
- v-if="showEmptyActions"
- keypath="project.overview.no-db-prompt"
- tag="p"
- >
- <template #newDb>
- <span class="text-main font-bold">{{
- $t("quick-action.new-db")
- }}</span>
- </template>
- <template #transferInDb>
- <span class="text-main font-bold">{{
- $t("quick-action.transfer-in-db")
- }}</span>
- </template>
- </i18n-t>
- <i18n-t v-else keypath="common.no-data" tag="p"></i18n-t>
- </div>
- </template>
- </DatabaseV1Table>
+ :custom-click="true"
+ @row-click="handleDatabaseClick"
+ @update:selected-databases="handleDatabasesSelectionChanged"
+ />
</div>
</div>
</template>
<script lang="ts" setup>
-import { NCheckbox } from "naive-ui";
import { reactive, computed } from "vue";
-import { useFilterStore, usePageMode } from "@/store";
+import { useRouter } from "vue-router";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
+import { useDatabaseV1Store, useFilterStore, usePageMode } from "@/store";
import type { ComposedDatabase, ComposedProject } from "@/types";
import { UNKNOWN_ID } from "@/types";
import type { SearchParams } from "@/utils";
@@ -99,8 +48,9 @@ import {
CommonFilterScopeIdList,
extractEnvironmentResourceName,
extractInstanceResourceName,
+ databaseV1Url,
} from "@/utils";
-import { DatabaseV1Table, DatabaseOperations, DatabaseLabelFilter } from "./v2";
+import { DatabaseOperations, DatabaseLabelFilter } from "./v2";
interface LocalState {
selectedDatabaseIds: Set<string>;
@@ -113,8 +63,10 @@ const props = defineProps<{
databaseList: ComposedDatabase[];
}>();
+const router = useRouter();
const pageMode = usePageMode();
const { filter } = useFilterStore();
+const databaseV1Store = useDatabaseV1Store();
const state = reactive<LocalState>({
selectedDatabaseIds: new Set(),
@@ -125,8 +77,6 @@ const state = reactive<LocalState>({
},
});
-const isStandaloneMode = computed(() => pageMode.value === "STANDALONE");
-
const selectedInstance = computed(() => {
return (
state.params.scopes.find((scope) => scope.id === "instance")?.value ??
@@ -187,45 +137,6 @@ const showDatabaseOperations = computed(() => {
return true;
});
-const showEmptyActions = computed(() => {
- return pageMode.value === "BUNDLED";
-});
-
-const getAllSelectionState = (
- databaseList: ComposedDatabase[]
-): { checked: boolean; indeterminate: boolean } => {
- const checked =
- state.selectedDatabaseIds.size > 0 &&
- databaseList.every((db) => state.selectedDatabaseIds.has(db.uid));
- const indeterminate =
- !checked &&
- databaseList.some((db) => state.selectedDatabaseIds.has(db.uid));
-
- return {
- checked,
- indeterminate,
- };
-};
-
-const toggleDatabasesSelection = (
- databaseList: ComposedDatabase[],
- on: boolean
-): void => {
- if (on) {
- databaseList.forEach((db) => {
- state.selectedDatabaseIds.add(db.uid);
- });
- } else {
- databaseList.forEach((db) => {
- state.selectedDatabaseIds.delete(db.uid);
- });
- }
-};
-
-const isDatabaseSelected = (database: ComposedDatabase): boolean => {
- return state.selectedDatabaseIds.has((database as ComposedDatabase).uid);
-};
-
const selectedDatabases = computed((): ComposedDatabase[] => {
return filteredDatabaseList.value.filter((db) =>
state.selectedDatabaseIds.has(db.uid)
@@ -233,4 +144,23 @@ const selectedDatabases = computed((): ComposedDatabase[] => {
});
const supportOptionIdList = computed(() => [...CommonFilterScopeIdList]);
+
+const handleDatabasesSelectionChanged = (
+ selectedDatabaseNameList: Set<string>
+): void => {
+ state.selectedDatabaseIds = new Set(
+ Array.from(selectedDatabaseNameList).map(
+ (name) => databaseV1Store.getDatabaseByName(name)?.uid
+ )
+ );
+};
+
+const handleDatabaseClick = (event: MouseEvent, database: ComposedDatabase) => {
+ const url = databaseV1Url(database);
+ if (event.ctrlKey || event.metaKey) {
+ window.open(url, "_blank");
+ } else {
+ router.push(url);
+ }
+};
</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseGroupTableRow.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseGroupTableRow.vue
deleted file mode 100644
index a145ff2020..0000000000
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseGroupTableRow.vue
+++ /dev/null
@@ -1,54 +0,0 @@
-<template>
- <div v-if="showSelectionColumn" class="bb-grid-cell !px-2">
- <slot name="selection" :database="databaseGroup" />
- </div>
- <div class="bb-grid-cell">
- <div class="flex items-center space-x-2">
- <SQLEditorButtonV1 :disabled="true" :tooltip="true" />
- <span>{{ databaseGroup.databasePlaceholder }}</span>
- <BBBadge text="GROUP" :can-remove="false" class="text-xs" />
- </div>
- </div>
- <div class="bb-grid-cell">-</div>
- <div class="bb-grid-cell">
- <!-- schema version -->
- <span>-</span>
- </div>
- <div class="bb-grid-cell">
- <!-- project -->
- <ProjectCol
- :project="databaseGroup.project"
- :mode="mode"
- :show-tenant-icon="showTenantIcon"
- />
- </div>
- <div class="bb-grid-cell">
- <!-- instance -->
- <span>-</span>
- </div>
- <div v-if="showLabelsColumn" class="bb-grid-cell">
- <!-- labels -->
- <span>-</span>
- </div>
-</template>
-
-<script lang="ts" setup>
-import BBBadge from "@/bbkit/BBBadge.vue";
-import { SQLEditorButtonV1 } from "@/components/DatabaseDetail";
-import type { ComposedDatabaseGroup } from "@/types";
-import ProjectCol from "./ProjectCol.vue";
-import type { Mode } from "./utils";
-
-defineProps<{
- databaseGroup: ComposedDatabaseGroup;
- mode: Mode;
- showSelectionColumn: boolean;
- showMiscColumn: boolean;
- showSchemaVersionColumn: boolean;
- showProjectColumn: boolean;
- showTenantIcon: boolean;
- showEnvironmentColumn: boolean;
- showInstanceColumn: boolean;
- showLabelsColumn: boolean;
-}>();
-</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue
deleted file mode 100644
index 12cbbeb5af..0000000000
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseTableRow.vue
+++ /dev/null
@@ -1,81 +0,0 @@
-<template>
- <div
- v-if="showSelectionColumn"
- class="bb-grid-cell !px-2"
- @click.stop.prevent
- >
- <slot name="selection" :database="database" />
- </div>
- <div class="bb-grid-cell">
- <div class="flex items-center space-x-2">
- <SQLEditorButtonV1
- v-if="showSqlEditorButton"
- :database="database"
- :disabled="!allowQuery"
- :tooltip="true"
- @failed="$emit('goto-sql-editor-failed')"
- />
- <DatabaseV1Name :database="database" :link="false" tag="span" />
- </div>
- </div>
- <div v-if="showEnvironmentColumn" class="bb-grid-cell">
- <EnvironmentV1Name
- :environment="environment ?? database.effectiveEnvironmentEntity"
- :link="false"
- tag="div"
- />
- </div>
- <div v-if="showSchemaVersionColumn" class="hidden lg:bb-grid-cell">
- {{ database.schemaVersion }}
- </div>
- <div v-if="showProjectColumn" class="bb-grid-cell">
- <ProjectCol
- :project="database.projectEntity"
- :mode="mode"
- :show-tenant-icon="showTenantIcon"
- />
- </div>
- <div v-if="showInstanceColumn" class="bb-grid-cell">
- <InstanceV1Name
- :instance="database.instanceEntity"
- :link="false"
- tag="div"
- />
- </div>
- <div v-if="showLabelsColumn" class="bb-grid-cell !py-1">
- <LabelsColumn :labels="database.labels" :show-count="1" placeholder="-" />
- </div>
-</template>
-
-<script lang="ts" setup>
-import { computed } from "vue";
-import { InstanceV1Name, EnvironmentV1Name } from "@/components/v2";
-import { useEnvironmentV1Store } from "@/store";
-import type { ComposedDatabase } from "@/types";
-import LabelsColumn from "./LabelsColumn.vue";
-import ProjectCol from "./ProjectCol.vue";
-import type { Mode } from "./utils";
-
-const props = defineProps<{
- database: ComposedDatabase;
- mode: Mode;
- showSelectionColumn: boolean;
- showMiscColumn: boolean;
- showSchemaVersionColumn: boolean;
- showProjectColumn: boolean;
- showTenantIcon: boolean;
- showEnvironmentColumn: boolean;
- showInstanceColumn: boolean;
- showLabelsColumn: boolean;
- showSqlEditorButton: boolean;
- allowQuery: boolean;
-}>();
-
-defineEmits(["goto-sql-editor-failed"]);
-
-const environment = computed(() => {
- return useEnvironmentV1Store().getEnvironmentByName(
- props.database.environment
- );
-});
-</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue b/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue
deleted file mode 100644
index 258c8fd1c2..0000000000
--- a/frontend/src/components/v2/Model/DatabaseV1Table/DatabaseV1Table.vue
+++ /dev/null
@@ -1,429 +0,0 @@
-<template>
- <div ref="wrapper" rule="database-table" v-bind="$attrs">
- <BBGrid
- :column-list="columnList"
- :data-source="pagedDataSource"
- :custom-header="true"
- :class="tableClass"
- :row-clickable="rowClickable"
- :show-placeholder="showPlaceholder"
- @click-row="clickDatabase"
- >
- <template #header>
- <div role="table-row" class="bb-grid-row bb-grid-header-row group">
- <div
- v-for="(column, index) in columnList"
- :key="index"
- role="table-cell"
- class="bb-grid-header-cell capitalize"
- :class="[column.class]"
- >
- <template v-if="showSelectionColumn && index === 0">
- <slot name="selection-all" :database-list="mixedDataList" />
- </template>
- <template v-else>{{ column.title }}</template>
- </div>
- </div>
- </template>
-
- <template
- #item="{
- item: database,
- }: {
- item: ComposedDatabase | ComposedDatabaseGroup;
- }"
- >
- <template v-if="isDatabase(database)">
- <DatabaseTableRow
- :database="database as ComposedDatabase"
- :mode="mode"
- :show-selection-column="showSelectionColumn"
- :show-misc-column="showMiscColumn"
- :show-schema-version-column="showSchemaVersionColumn"
- :show-project-column="showProjectColumn"
- :show-environment-column="showEnvironmentColumn"
- :show-tenant-icon="showTenantIcon"
- :show-instance-column="showInstanceColumn"
- :show-labels-column="showLabelsColumn"
- :show-sql-editor-button="showSQLEditorButton"
- :allow-query="allowQuery(database as ComposedDatabase)"
- @goto-sql-editor-failed="
- handleGotoSQLEditorFailed(database as ComposedDatabase)
- "
- >
- <template v-if="showSelectionColumn" #selection>
- <slot name="selection" :database="database" />
- </template>
- </DatabaseTableRow>
- </template>
- <template v-else>
- <DatabaseGroupTableRow
- :database-group="database as ComposedDatabaseGroup"
- :mode="mode"
- :show-selection-column="showSelectionColumn"
- :show-misc-column="showMiscColumn"
- :show-schema-version-column="showSchemaVersionColumn"
- :show-project-column="showProjectColumn"
- :show-environment-column="showEnvironmentColumn"
- :show-tenant-icon="showTenantIcon"
- :show-instance-column="showInstanceColumn"
- :show-labels-column="showLabelsColumn"
- >
- <template v-if="showSelectionColumn" #selection>
- <slot name="selection" :database="database" />
- </template>
- </DatabaseGroupTableRow>
- </template>
- </template>
-
- <template #placeholder-content>
- <slot name="placeholder"></slot>
- </template>
- </BBGrid>
- </div>
-
- <div
- v-if="showPagination"
- class="flex justify-end !mt-2"
- :class="paginationClass"
- >
- <NPagination
- :item-count="table.getCoreRowModel().rows.length"
- :page="table.getState().pagination.pageIndex + 1"
- :page-size="table.getState().pagination.pageSize"
- :show-quick-jumper="true"
- @update-page="handleChangePage"
- @update-page-size="table.setPageSize($event)"
- />
- </div>
-
- <BBModal
- v-if="state.showIncorrectProjectModal"
- :title="$t('common.warning')"
- @close="handleIncorrectProjectModalCancel"
- >
- <div class="col-span-1 w-96">
- {{ $t("database.incorrect-project-warning") }}
- </div>
- <div class="pt-6 flex justify-end space-x-3">
- <NButton @click.prevent="handleIncorrectProjectModalCancel">
- {{ $t("common.cancel") }}
- </NButton>
- <NButton
- type="primary"
- @click.prevent="handleIncorrectProjectModalConfirm"
- >
- {{ $t("database.go-to-transfer") }}
- </NButton>
- </div>
- </BBModal>
-</template>
-
-<script lang="ts" setup>
-import type { ColumnDef } from "@tanstack/vue-table";
-import { sortBy } from "lodash-es";
-import cloneDeep from "lodash-es/cloneDeep";
-import { NPagination } from "naive-ui";
-import type { PropType } from "vue";
-import { computed, reactive, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import type { BBGridColumn } from "@/bbkit/types";
-import { PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL } from "@/router/dashboard/projectV1";
-import { usePageMode, useCurrentUserV1 } from "@/store";
-import { getProjectNameAndDatabaseGroupName } from "@/store/modules/v1/common";
-import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
-import type { VueClass } from "@/utils";
-import { databaseV1Url, getScrollParent, isDatabaseV1Queryable } from "@/utils";
-import DatabaseGroupTableRow from "./DatabaseGroupTableRow.vue";
-import DatabaseTableRow from "./DatabaseTableRow.vue";
-import type { Mode } from "./utils";
-import { isDatabase } from "./utils";
-
-const { getCoreRowModel, getPaginationRowModel, useVueTable } = await import(
- "@tanstack/vue-table"
-);
-
-interface LocalState {
- showIncorrectProjectModal: boolean;
- warningDatabase?: ComposedDatabase;
-}
-
-const props = defineProps({
- bordered: {
- default: true,
- type: Boolean,
- },
- tableClass: {
- type: [String, Array, Object] as PropType<VueClass>,
- default: undefined,
- },
- paginationClass: {
- type: [String, Array, Object] as PropType<VueClass>,
- default: undefined,
- },
- mode: {
- default: "ALL",
- type: String as PropType<Mode>,
- },
- singleInstance: {
- default: true,
- type: Boolean,
- },
-
- showSelectionColumn: {
- type: Boolean,
- default: false,
- },
- rowClickable: {
- default: true,
- type: Boolean,
- },
- customClick: {
- default: false,
- type: Boolean,
- },
- databaseList: {
- required: true,
- type: Object as PropType<ComposedDatabase[]>,
- },
- databaseGroupList: {
- required: false,
- type: Object as PropType<ComposedDatabaseGroup[]>,
- default: undefined,
- },
- pageSize: {
- type: Number,
- default: 20,
- },
- scrollOnPageChange: {
- type: Boolean,
- default: true,
- },
- schemaless: {
- type: Boolean,
- default: false,
- },
- showPlaceholder: {
- type: Boolean,
- default: undefined,
- },
- showSqlEditorButton: {
- required: false,
- type: Boolean,
- default: true,
- },
-});
-
-const emit = defineEmits(["select-database"]);
-
-const router = useRouter();
-const currentUserV1 = useCurrentUserV1();
-const { t } = useI18n();
-const state = reactive<LocalState>({
- showIncorrectProjectModal: false,
-});
-const pageMode = usePageMode();
-const wrapper = ref<HTMLElement>();
-
-const regularDatabaseList = computed(() => props.databaseList);
-
-const mixedDataList = computed(() => {
- const dataList: (ComposedDatabase | ComposedDatabaseGroup)[] = [
- ...regularDatabaseList.value,
- ];
- if (props.databaseGroupList) {
- dataList.push(...props.databaseGroupList);
- }
- return sortBy(dataList, (d) => {
- if (isDatabase(d)) {
- return (d as ComposedDatabase).effectiveEnvironment;
- } else {
- return (d as ComposedDatabaseGroup).name;
- }
- });
-});
-
-const columnListMap = computed(() => {
- const NAME = {
- title: t("common.name"),
- width: "minmax(min-content, auto)",
- };
- const SCHEMA_VERSION = props.schemaless
- ? undefined
- : {
- title: t("common.schema-version"),
- width: { lg: "minmax(min-content, auto)" },
- class: "hidden lg:flex",
- };
- const PROJECT = {
- title: t("common.project"),
- width: "minmax(min-content, auto)",
- };
- const ENVIRONMENT = {
- title: t("common.environment"),
- width: "minmax(min-content, auto)",
- };
- const INSTANCE = {
- title: t("common.instance"),
- width: "minmax(min-content, auto)",
- };
- const LABELS = {
- title: t("common.labels"),
- width: "minmax(max-content, auto)",
- class: "items-center",
- };
- return new Map<Mode, (BBGridColumn | undefined)[]>([
- ["ALL", [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, INSTANCE, LABELS]],
- ["ALL_SHORT", [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, INSTANCE]],
- ["ALL_TINY", [NAME, ENVIRONMENT, PROJECT, INSTANCE]],
- ["INSTANCE", [NAME, ENVIRONMENT, SCHEMA_VERSION, PROJECT, LABELS]],
- ["PROJECT", [NAME, ENVIRONMENT, SCHEMA_VERSION, INSTANCE, LABELS]],
- ["PROJECT_SHORT", [NAME, ENVIRONMENT, SCHEMA_VERSION, INSTANCE]],
- ]);
-});
-
-const showSchemaVersionColumn = computed(() => {
- return props.mode !== "ALL_TINY" && !props.schemaless;
-});
-
-const showInstanceColumn = computed(() => {
- return props.mode != "INSTANCE";
-});
-
-const showProjectColumn = computed(() => {
- return props.mode != "PROJECT" && props.mode != "PROJECT_SHORT";
-});
-
-const showLabelsColumn = computed(() => {
- return (
- props.mode == "PROJECT" || props.mode == "ALL" || props.mode == "INSTANCE"
- );
-});
-
-const showEnvironmentColumn = computed(() => {
- return true;
-});
-
-const showMiscColumn = computed(() => {
- if (
- props.mode === "ALL_SHORT" ||
- props.mode === "ALL_TINY" ||
- props.mode === "PROJECT_SHORT"
- ) {
- return false;
- }
- return true;
-});
-
-const showSQLEditorButton = computed(() => {
- return pageMode.value === "BUNDLED" && props.showSqlEditorButton;
-});
-
-const columnList = computed(() => {
- const list = cloneDeep(columnListMap.value.get(props.mode)!).filter(Boolean);
- if (props.showSelectionColumn) {
- list.unshift({
- title: "",
- width: "minmax(auto, 2rem)",
- class: "items-center !px-2",
- });
- }
- return list as BBGridColumn[];
-});
-
-const table = useVueTable<ComposedDatabase | ComposedDatabaseGroup>({
- get data() {
- return mixedDataList.value;
- },
- get columns() {
- return columnList.value.map<
- ColumnDef<ComposedDatabase | ComposedDatabaseGroup>
- >((col, index) => ({
- header: col.title!,
- }));
- },
- getCoreRowModel: getCoreRowModel(),
- getPaginationRowModel: getPaginationRowModel(),
-});
-
-const pagedDataSource = computed(() => {
- return table.getRowModel().rows.map((row) => row.original);
-});
-
-const showPagination = computed(() => {
- return mixedDataList.value.length > props.pageSize;
-});
-
-const handleChangePage = (page: number) => {
- table.setPageIndex(page - 1);
- if (props.scrollOnPageChange && wrapper.value) {
- const parent = getScrollParent(wrapper.value);
- parent.scrollTo(0, 0);
- }
-};
-watch(
- () => props.pageSize,
- (ps) => {
- table.setPageSize(ps);
- },
- { immediate: true }
-);
-
-const allowQuery = (database: ComposedDatabase) => {
- return isDatabaseV1Queryable(database, currentUserV1.value);
-};
-
-const showTenantIcon = computed(() => {
- return ["ALL", "ALL_SHORT", "INSTANCE"].includes(props.mode);
-});
-
-const handleGotoSQLEditorFailed = (database: ComposedDatabase) => {
- state.warningDatabase = database;
- state.showIncorrectProjectModal = true;
-};
-
-const handleIncorrectProjectModalConfirm = () => {
- if (state.warningDatabase) {
- router.push(databaseV1Url(state.warningDatabase));
- }
-};
-
-const handleIncorrectProjectModalCancel = () => {
- state.showIncorrectProjectModal = false;
- state.warningDatabase = undefined;
-};
-
-const clickDatabase = (
- database: ComposedDatabase | ComposedDatabaseGroup,
- section: number,
- row: number,
- e: MouseEvent
-) => {
- if (!props.rowClickable) return;
-
- if (props.customClick) {
- emit("select-database", database);
- } else {
- if (isDatabase(database)) {
- const url = databaseV1Url(database as ComposedDatabase);
- if (e.ctrlKey || e.metaKey) {
- window.open(url, "_blank");
- } else {
- router.push(url);
- }
- } else {
- const [projectId, databaseGroupName] = getProjectNameAndDatabaseGroupName(
- database.name
- );
- router.push({
- name: PROJECT_V1_ROUTE_DATABASE_GROUP_DETAIL,
- params: {
- projectId,
- databaseGroupName,
- },
- });
- }
- }
-};
-</script>
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/ProjectCol.vue b/frontend/src/components/v2/Model/DatabaseV1Table/ProjectCol.vue
index 22096ee548..c934df1ce5 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/ProjectCol.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/ProjectCol.vue
@@ -40,10 +40,10 @@
<script setup lang="ts">
import { NTooltip } from "naive-ui";
+import type { Mode } from "@/components/DatabaseDataTable/DatabaseDataTable.vue";
import { State } from "@/types/proto/v1/common";
import type { Project } from "@/types/proto/v1/project_service";
import { TenantMode, Workflow } from "@/types/proto/v1/project_service";
-import type { Mode } from "./utils";
withDefaults(
defineProps<{
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/index.ts b/frontend/src/components/v2/Model/DatabaseV1Table/index.ts
index 3452f8691c..0f81cf3d12 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table/index.ts
+++ b/frontend/src/components/v2/Model/DatabaseV1Table/index.ts
@@ -1,7 +1,4 @@
import DatabaseLabelFilter from "./DatabaseLabelFilter.vue";
import DatabaseOperations from "./DatabaseOperations.vue";
-import DatabaseV1Table from "./DatabaseV1Table.vue";
-export default DatabaseV1Table;
-
-export { DatabaseV1Table, DatabaseOperations, DatabaseLabelFilter };
+export { DatabaseOperations, DatabaseLabelFilter };
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table/utils.ts b/frontend/src/components/v2/Model/DatabaseV1Table/utils.ts
deleted file mode 100644
index 3a9320be56..0000000000
--- a/frontend/src/components/v2/Model/DatabaseV1Table/utils.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { has } from "lodash-es";
-import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
-
-export type Mode =
- | "ALL"
- | "ALL_SHORT"
- | "ALL_TINY"
- | "INSTANCE"
- | "PROJECT"
- | "PROJECT_SHORT";
-
-export const isDatabase = (
- data: ComposedDatabase | ComposedDatabaseGroup
-): boolean => {
- return has(data, "uid");
-};
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index c1f336b843..e1e87692e9 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -61,7 +61,7 @@ const batchComposeDatabaseGroup = async (
...databaseGroup,
databaseGroupName,
projectName,
- project,
+ projectEntity: project,
simpleExpr: emptySimpleExpr(),
});
diff --git a/frontend/src/types/dbGroup.ts b/frontend/src/types/dbGroup.ts
index 61446c3860..ed1794d14e 100644
--- a/frontend/src/types/dbGroup.ts
+++ b/frontend/src/types/dbGroup.ts
@@ -1,8 +1,7 @@
import type { ConditionGroupExpr } from "@/plugins/cel";
-import type { ComposedDatabase } from "@/types";
+import type { ComposedDatabase, ComposedProject } from "@/types";
import type {
DatabaseGroup,
- Project,
SchemaGroup,
SchemaGroup_Table,
} from "./proto/v1/project_service";
@@ -10,7 +9,7 @@ import type {
export interface ComposedDatabaseGroup extends DatabaseGroup {
databaseGroupName: string;
projectName: string;
- project: Project;
+ projectEntity: ComposedProject;
simpleExpr: ConditionGroupExpr;
}
diff --git a/frontend/src/utils/databaseGroup/issue.ts b/frontend/src/utils/databaseGroup/issue.ts
index fe28972dd3..38bfc364da 100644
--- a/frontend/src/utils/databaseGroup/issue.ts
+++ b/frontend/src/utils/databaseGroup/issue.ts
@@ -21,7 +21,7 @@ export const generateDatabaseGroupIssueRoute = (
template: type,
batch: "1",
name: issueNameParts.join(" "),
- project: databaseGroup.project.uid,
+ project: databaseGroup.projectEntity.uid,
databaseGroupName: databaseGroup.name,
sql,
};
@@ -29,7 +29,7 @@ export const generateDatabaseGroupIssueRoute = (
return {
name: PROJECT_V1_ROUTE_ISSUE_DETAIL,
params: {
- projectId: extractProjectResourceName(databaseGroup.project.name),
+ projectId: extractProjectResourceName(databaseGroup.projectEntity.name),
issueSlug: "create",
},
query,
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index a54e36c585..c4c673d7c4 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -19,40 +19,13 @@
<div class="space-y-2">
<DatabaseOperations :databases="selectedDatabases" />
- <DatabaseV1Table
- pagination-class="mb-4"
- table-class="border-y"
+ <DatabaseDataTable
+ mode="ALL"
:database-list="filteredDatabaseList"
- :database-group-list="filteredDatabaseGroupList"
- :show-placeholder="true"
- :show-selection-column="true"
- :custom-click="isStandaloneMode"
- @select-database="
- (db: ComposedDatabase) =>
- toggleDatabasesSelection(
- [db as ComposedDatabase],
- !isDatabaseSelected(db)
- )
- "
- >
- <template #selection-all="{ databaseList }">
- <NCheckbox
- v-if="databaseList.length > 0"
- v-bind="getAllSelectionState(databaseList)"
- @update:checked="toggleDatabasesSelection(databaseList, $event)"
- />
- </template>
- <template #selection="{ database }">
- <NCheckbox
- v-if="isDatabase(database)"
- :checked="isDatabaseSelected(database as ComposedDatabase)"
- @update:checked="toggleDatabasesSelection([database], $event)"
- />
- <div v-else class="text-control-light cursor-not-allowed ml-auto">
- -
- </div>
- </template>
- </DatabaseV1Table>
+ :custom-click="true"
+ @row-click="handleDatabaseClick"
+ @update:selected-databases="handleDatabasesSelectionChanged"
+ />
</div>
<div
@@ -65,25 +38,17 @@
</template>
<script lang="ts" setup>
-import { NCheckbox } from "naive-ui";
-import { computed, watchEffect, onMounted, reactive, watch } from "vue";
+import { computed, onMounted, reactive, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
-import { DatabaseV1Table } from "@/components/v2";
-import { isDatabase } from "@/components/v2/Model/DatabaseV1Table/utils";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
import {
- useCurrentUserV1,
- useDBGroupStore,
useDatabaseV1Store,
usePageMode,
useProjectV1List,
useUIStateStore,
} from "@/store";
-import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
-import {
- UNKNOWN_ID,
- UNKNOWN_USER_NAME,
- DEFAULT_PROJECT_V1_NAME,
-} from "@/types";
+import type { ComposedDatabase } from "@/types";
+import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";
import type { SearchScopeId, SearchParams } from "@/utils";
import {
filterDatabaseV1ByKeyword,
@@ -94,10 +59,10 @@ import {
extractProjectResourceName,
buildSearchTextBySearchParams,
buildSearchParamsBySearchText,
+ databaseV1Url,
} from "@/utils";
interface LocalState {
- databaseGroupList: ComposedDatabaseGroup[];
loading: boolean;
selectedDatabaseIds: Set<string>;
params: SearchParams;
@@ -127,7 +92,6 @@ const initializeSearchParamsFromQuery = () => {
};
const state = reactive<LocalState>({
- databaseGroupList: [],
loading: false,
selectedDatabaseIds: new Set(),
params: initializeSearchParamsFromQuery(),
@@ -149,9 +113,7 @@ watch(
{ deep: true }
);
-const currentUserV1 = useCurrentUserV1();
const databaseV1Store = useDatabaseV1Store();
-const dbGroupStore = useDBGroupStore();
const isStandaloneMode = computed(() => pageMode.value === "STANDALONE");
@@ -198,24 +160,6 @@ const databaseV1List = computed(() => {
);
});
-const prepareDatabaseGroupList = async () => {
- if (currentUserV1.value.name !== UNKNOWN_USER_NAME) {
- state.databaseGroupList = (
- await dbGroupStore.fetchAllDatabaseGroupList()
- ).filter((dbGroup) =>
- projectList.value
- .map((project) => project.name)
- .includes(dbGroup.project.name)
- );
- }
-};
-
-watchEffect(async () => {
- state.loading = true;
- await prepareDatabaseGroupList();
- state.loading = false;
-});
-
const filteredDatabaseList = computed(() => {
let list = databaseV1List.value;
if (selectedEnvironment.value !== `${UNKNOWN_ID}`) {
@@ -270,65 +214,9 @@ const filteredDatabaseList = computed(() => {
return list;
});
-const filteredDatabaseGroupList = computed(() => {
- let list = [...state.databaseGroupList];
- const keyword = state.params.query.trim().toLowerCase();
- if (keyword) {
- list = list.filter(
- (dbGroup) =>
- dbGroup.name.includes(keyword) ||
- dbGroup.databasePlaceholder.includes(keyword)
- );
- }
- return list;
-});
-
-const getAllSelectionState = (
- databaseList: (ComposedDatabase | ComposedDatabaseGroup)[]
-): { checked: boolean; indeterminate: boolean } => {
- const filteredDatabases = databaseList.filter((db) =>
- isDatabase(db)
- ) as ComposedDatabase[];
-
- const checked =
- state.selectedDatabaseIds.size > 0 &&
- filteredDatabases.every((db) => state.selectedDatabaseIds.has(db.uid));
- const indeterminate =
- !checked &&
- filteredDatabases.some((db) => state.selectedDatabaseIds.has(db.uid));
-
- return {
- checked,
- indeterminate,
- };
-};
-
-const toggleDatabasesSelection = (
- databaseList: (ComposedDatabase | ComposedDatabaseGroup)[],
- on: boolean
-): void => {
- if (on) {
- databaseList.forEach((db) => {
- if (isDatabase(db)) {
- state.selectedDatabaseIds.add((db as ComposedDatabase).uid);
- }
- });
- } else {
- databaseList.forEach((db) => {
- if (isDatabase(db)) {
- state.selectedDatabaseIds.delete((db as ComposedDatabase).uid);
- }
- });
- }
-};
-
-const isDatabaseSelected = (database: ComposedDatabase): boolean => {
- return state.selectedDatabaseIds.has((database as ComposedDatabase).uid);
-};
-
const selectedDatabases = computed((): ComposedDatabase[] => {
- return filteredDatabaseList.value.filter(
- (db) => isDatabase(db) && state.selectedDatabaseIds.has(db.uid)
+ return filteredDatabaseList.value.filter((db) =>
+ state.selectedDatabaseIds.has(db.uid)
);
});
@@ -337,4 +225,23 @@ const supportOptionIdList = computed((): SearchScopeId[] => [
"project",
"project-assigned",
]);
+
+const handleDatabasesSelectionChanged = (
+ selectedDatabaseNameList: Set<string>
+): void => {
+ state.selectedDatabaseIds = new Set(
+ Array.from(selectedDatabaseNameList).map(
+ (name) => databaseV1Store.getDatabaseByName(name)?.uid
+ )
+ );
+};
+
+const handleDatabaseClick = (event: MouseEvent, database: ComposedDatabase) => {
+ const url = databaseV1Url(database);
+ if (event.ctrlKey || event.metaKey) {
+ window.open(url, "_blank");
+ } else {
+ router.push(url);
+ }
+};
</script>
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index 44899384e1..79e083f521 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -118,7 +118,7 @@
<DatabaseGroupPrevEditorModal
v-if="issueType"
:issue-type="issueType"
- :database-group="databaseGroup"
+ :database-group-name="databaseGroup.name"
@close="issueType = undefined"
/>
</template>
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 1b71597017..d8d907517c 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -35,19 +35,14 @@
<InstanceForm class="-mt-2" :instance="instance" />
</NTabPane>
<NTabPane name="DATABASES" :tab="$t('common.databases')">
- <DatabaseV1Table
+ <DatabaseDataTable
mode="INSTANCE"
- class="mt-2"
- table-class="border"
- :scroll-on-page-change="false"
+ :show-selection="false"
:database-list="databaseV1List"
/>
</NTabPane>
<NTabPane name="USERS" :tab="$t('instance.users')">
- <InstanceRoleTable
- class="mt-2"
- :instance-role-list="instanceRoleList"
- />
+ <InstanceRoleTable :instance-role-list="instanceRoleList" />
</NTabPane>
</NTabs>
</div>
@@ -72,9 +67,10 @@ import { computed, reactive, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import ArchiveBanner from "@/components/ArchiveBanner.vue";
import { CreateDatabasePrepPanel } from "@/components/CreateDatabasePrepForm";
+import DatabaseDataTable from "@/components/DatabaseDataTable";
import { EngineIcon } from "@/components/Icon";
import InstanceForm from "@/components/InstanceForm/";
-import { InstanceRoleTable, DatabaseV1Table, Drawer } from "@/components/v2";
+import { InstanceRoleTable, Drawer } from "@/components/v2";
import {
pushNotification,
useDBSchemaV1Store,