Skip to content

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

chore: allow to select multi table for exporter (#7491)

boojack13e9e8076069
diff --git a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue b/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
index 674d3c2c4c..f96239dc30 100644
--- a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
+++ b/frontend/src/components/Issue/form/GrantRequestExporterForm.vue
@@ -8,9 +8,7 @@
</span>
<DatabaseResourceTable
class="w-full"
- :database-resource-list="
- selectedDatabaseResource ? [selectedDatabaseResource] : []
- "
+ :database-resource-list="selectedDatabaseResources"
/>
</div>
<div
@@ -25,7 +23,6 @@
:value="state.statement"
:auto-focus="false"
:language="'sql'"
- :dialect="dialect"
/>
</div>
</div>
@@ -58,26 +55,15 @@
<script lang="ts" setup>
import dayjs from "dayjs";
-import { head } from "lodash-es";
import { computed, onMounted, reactive, ref } from "vue";
import MonacoEditor from "@/components/MonacoEditor";
-import { useDatabaseV1Store } from "@/store";
-import {
- GrantRequestPayload,
- Issue,
- PresetRoleType,
- SQLDialect,
- UNKNOWN_ID,
- dialectOfEngineV1,
-} from "@/types";
+import { GrantRequestPayload, Issue, PresetRoleType } from "@/types";
import { DatabaseResource } from "@/types";
-import { Engine } from "@/types/proto/v1/common";
import { convertFromCELString } from "@/utils/issue/cel";
import { useIssueLogic } from "../logic";
import DatabaseResourceTable from "../table/DatabaseResourceTable.vue";
interface LocalState {
- databaseId?: string;
maxRowCount: number;
exportFormat: "CSV" | "JSON";
statement: string;
@@ -85,30 +71,18 @@ interface LocalState {
}
const { issue } = useIssueLogic();
-const databaseStore = useDatabaseV1Store();
const state = reactive<LocalState>({
maxRowCount: 1000,
exportFormat: "CSV",
statement: "",
expiredAt: "",
});
-const selectedDatabaseResource = ref<DatabaseResource | undefined>(undefined);
-
-const selectedDatabase = computed(() => {
- return databaseStore.getDatabaseByName(
- selectedDatabaseResource.value?.databaseName ?? String(UNKNOWN_ID)
- );
-});
+const selectedDatabaseResources = ref<DatabaseResource[]>([]);
const exportMethod = computed(() => {
return state.statement === "" ? "DATABASE" : "SQL";
});
-const dialect = computed((): SQLDialect => {
- const db = selectedDatabase.value;
- return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);
-});
-
onMounted(async () => {
const payload = ((issue.value as Issue).payload as any)
.grantRequest as GrantRequestPayload;
@@ -123,14 +97,7 @@ onMounted(async () => {
conditionExpression.databaseResources !== undefined &&
conditionExpression.databaseResources.length > 0
) {
- const resource = head(conditionExpression.databaseResources);
- if (resource) {
- const database = await databaseStore.getOrFetchDatabaseByName(
- resource.databaseName
- );
- state.databaseId = database.uid;
- selectedDatabaseResource.value = resource;
- }
+ selectedDatabaseResources.value = conditionExpression.databaseResources;
}
if (conditionExpression.expiredTime !== undefined) {
state.expiredAt = dayjs(new Date(conditionExpression.expiredTime)).format(
diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue
index 1ee859a9a9..584655c22f 100644
--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue
+++ b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/DatabaseResourceSelector.vue
@@ -14,7 +14,6 @@
</template>
<script setup lang="ts">
-import { last } from "lodash-es";
import {
NTransfer,
TransferRenderSourceList,
@@ -55,8 +54,6 @@ const selectedValueList = ref<string[]>(
);
if (databaseResource.table !== undefined) {
return `t-${database.uid}-${databaseResource.schema}-${databaseResource.table}`;
- } else if (databaseResource.schema !== undefined) {
- return `s-${database.uid}-${databaseResource.schema}`;
} else {
return "";
}
@@ -137,12 +134,7 @@ const renderSourceList: TransferRenderSourceList = ({ onCheck, pattern }) => {
checkedKeys: selectedValueList.value,
showIrrelevantNodes: false,
onUpdateCheckedKeys: (checkedKeys: string[]) => {
- // NOTE: we only allow to select one resource(table).
- if (checkedKeys.length > 0) {
- onCheck([last(checkedKeys)!]);
- } else {
- onCheck([]);
- }
+ onCheck(checkedKeys);
},
});
};
@@ -173,6 +165,14 @@ const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {
});
};
+// Clear selectedValueList when projectId changed.
+watch(
+ () => props.projectId,
+ () => {
+ selectedValueList.value = [];
+ }
+);
+
watch(
() => [props.projectId, props.databaseId],
() => {
diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
index 5ccb36480b..221789be95 100644
--- a/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
+++ b/frontend/src/components/Issue/panel/RequestExportPanel/ExportResourceForm/index.vue
@@ -156,12 +156,6 @@ const handleStatementChange = (value: string) => {
const handleTableResourceUpdate = (
databaseResourceList: DatabaseResource[]
) => {
- if (databaseResourceList.length > 1) {
- throw new Error("Only one table can be selected");
- } else if (databaseResourceList.length === 0) {
- state.databaseResources = [];
- } else {
- state.databaseResources = databaseResourceList;
- }
+ state.databaseResources = databaseResourceList;
};
</script>
diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
index d2f635be6b..a43a2c5795 100644
--- a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue
@@ -93,6 +93,7 @@
class="grid-cols-6"
:options="expireDaysOptions"
:value="state.expireDays"
+ @update="state.expireDays = $event"
/>
</div>
<div class="w-full flex flex-col justify-start items-start">
@@ -341,15 +342,18 @@ const generateIssueName = () => {
if (state.databaseResources.length === 0) {
return `Request data export for "${database.databaseName} (${database.instanceEntity.title})"`;
} else {
- const tableResource = state.databaseResources[0] as DatabaseResource;
- const nameList = [database.databaseName];
- if (tableResource.schema) {
- nameList.push(tableResource.schema);
+ const sections: string[] = [];
+ for (const databaseResource of state.databaseResources) {
+ const nameList = [database.databaseName];
+ if (databaseResource.schema) {
+ nameList.push(databaseResource.schema);
+ }
+ if (databaseResource.table) {
+ nameList.push(databaseResource.table);
+ }
+ sections.push(nameList.join("."));
}
- if (tableResource.table) {
- nameList.push(tableResource.table);
- }
- return `Request data export for "${nameList.join(".")} (${
+ return `Request data export for "${sections.join(".")} (${
database.instanceEntity.title
})"`;
}
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
index 696e02b42d..7bd67d0b47 100644
--- a/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
@@ -46,7 +46,6 @@ const emit = defineEmits<{
const databaseStore = useDatabaseV1Store();
const dbSchemaStore = useDBSchemaV1Store();
-
const selectedValueList = ref<string[]>(
props.databaseResources.map((databaseResource) => {
const database = databaseStore.getDatabaseByName(
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
index aef065dc70..012c5b721f 100644
--- a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
@@ -44,6 +44,7 @@
class="grid-cols-4"
:options="expireDaysOptions"
:value="state.expireDays"
+ @update="state.expireDays = $event"
/>
</div>
<div class="w-full flex flex-col justify-start items-start">
diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vue
index 8e59fbd663..6a2910cfff 100644
--- a/frontend/src/views/ExportCenter/index.vue
+++ b/frontend/src/views/ExportCenter/index.vue
@@ -57,7 +57,6 @@
</template>
<script lang="ts" setup>
-import { head } from "lodash-es";
import { NButton, NInputGroup } from "naive-ui";
import { computed, reactive, watchEffect } from "vue";
import { useRoute, useRouter } from "vue-router";
@@ -160,8 +159,11 @@ watchEffect(async () => {
}
const conditionExpr = convertFromExpr(binding.parsedExpr.expr);
- const databaseResource = head(conditionExpr.databaseResources);
- if (databaseResource) {
+ if (!conditionExpr.databaseResources) {
+ continue;
+ }
+
+ for (const databaseResource of conditionExpr.databaseResources) {
const description = binding.condition?.description || "";
const issueId = description.match(issueDescriptionRegexp)?.[1];
const database = await databaseStore.getOrFetchDatabaseByName(