Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: implement request export panel (#6633)
boojack37ac6ca48f15
diff --git a/frontend/src/components/Issue/IssueHighlightPanel.vue b/frontend/src/components/Issue/IssueHighlightPanel.vueindex da13667497..1e4c9d7d21 100644--- a/frontend/src/components/Issue/IssueHighlightPanel.vue+++ b/frontend/src/components/Issue/IssueHighlightPanel.vue@@ -23,7 +23,6 @@<div class="mt-4 flex space-x-3 md:mt-0 md:ml-4"><IssueReviewButtonGroup v-if="showReviewButton" />- <ExportDataButton v-if="showExportButton" /><CombinedRolloutButtonGroup v-if="showRolloutButton" /></div></div>@@ -94,7 +93,6 @@ import { head } from "lodash-es";import IssueStatusIcon from "./IssueStatusIcon.vue";import {activeTask,- extractUserUID,isDatabaseRelatedIssueType,isGrantRequestIssueType,} from "@/utils";@@ -103,14 +101,10 @@ import {TaskDatabaseDataUpdatePayload,Issue,VCSPushEvent,- GrantRequestPayload,- PresetRoleType,} from "@/types";-import { useCurrentUserV1 } from "@/store";import { useExtraIssueLogic, useIssueLogic } from "./logic";import { IssueReviewButtonGroup } from "./review";import { useIssueReviewContext } from "@/plugins/issue/logic/review/context";-import ExportDataButton from "./action/ExportDataButton.vue";import { CombinedRolloutButtonGroup } from "./StatusTransitionButtonGroup";interface LocalState {@@ -119,7 +113,6 @@ interface LocalState {}const logic = useIssueLogic();-const currentUserV1 = useCurrentUserV1();const create = logic.create;const issue = logic.issue as Ref<Issue>;const { allowEditNameAndDescription, updateName } = useExtraIssueLogic();@@ -145,25 +138,6 @@ const showRolloutButton = computed(() => {return reviewDone.value;});-const showExportButton = computed(() => {- if (create.value) return false;- if (!isGrantRequestIssueType(issue.value.type)) return false;- if (showReviewButton.value) return false;- // Don't show export button when issue is closed or done.- if (issue.value.status !== "OPEN") return false;-- const issuePayload = (issue.value.payload as any)- .grantRequest as GrantRequestPayload;- if (- issuePayload.role !== PresetRoleType.EXPORTER ||- extractUserUID(currentUserV1.value.name) !== String(issue.value.creator.id)- ) {- return false;- }-- return true;-});-const issueTaskStatus = computed(() => {// For grant request issue, we always show the status as "PENDING_APPROVAL" as task status.if (!isDatabaseRelatedIssueType(issue.value.type)) {diff --git a/frontend/src/components/Issue/action/ExportDataButton.vue b/frontend/src/components/Issue/action/ExportDataButton.vuedeleted file mode 100644index 3990c75a7f..0000000000--- a/frontend/src/components/Issue/action/ExportDataButton.vue+++ /dev/null@@ -1,161 +0,0 @@-<template>- <button- class="btn-primary flex flex-row justify-center items-center"- @click="state.showConfirmModal = true"- >- <heroicons-outline:document-download class="w-4 h-auto mr-0.5" />- {{ $t("common.export") }}- </button>-- <BBModal- v-if="state.showConfirmModal"- :title="$t('common.export')"- header-class="overflow-hidden"- @confirm="handleExport"- @close="state.showConfirmModal = false"- >- <div class="w-128 mb-6">- {{ $t("issue.grant-request.data-export-attention") }}- </div>- <div class="w-full flex items-center justify-end mt-2 space-x-3 pr-1 pb-1">- <button- type="button"- class="btn-cancel"- @click="state.showConfirmModal = false"- >- {{ $t("common.cancel") }}- </button>- <button- class="btn-primary"- :disabled="state.isRequesting"- @click="handleExport"- >- <BBSpin v-if="state.isRequesting" class="mr-2" color="text-white" />- {{ $t("common.confirm") }}- </button>- </div>- </BBModal>-</template>--<script lang="ts" setup>-import dayjs from "dayjs";-import { head } from "lodash-es";-import { onMounted, reactive } from "vue";-import { useExtraIssueLogic, useIssueLogic } from "../logic";-import {- GrantRequestPayload,- Issue,- PresetRoleType,- UNKNOWN_ID,-} from "@/types";-import {- getExportRequestFormat,- pushNotification,- useDatabaseV1Store,- useProjectIamPolicyStore,- useSQLStore,-} from "@/store";-import { BBSpin } from "@/bbkit";-import { convertFromCELString } from "@/utils/issue/cel";--interface LocalState {- databaseId: string;- statement: string;- maxRowCount: number;- exportFormat: "CSV" | "JSON";- showConfirmModal: boolean;- isRequesting: boolean;-}--const { changeIssueStatus } = useExtraIssueLogic();-const { issue } = useIssueLogic();-const databaseStore = useDatabaseV1Store();-const sqlStore = useSQLStore();-const projectIamPolicyStore = useProjectIamPolicyStore();-const state = reactive<LocalState>({- databaseId: String(UNKNOWN_ID),- statement: "",- maxRowCount: 1000,- exportFormat: "CSV",- showConfirmModal: false,- isRequesting: false,-});--onMounted(async () => {- const payload = ((issue.value as Issue).payload as any)- .grantRequest as GrantRequestPayload;- if (payload.role !== PresetRoleType.EXPORTER) {- throw "Only support EXPORTER role";- }- const conditionExpression = await convertFromCELString(- payload.condition.expression- );- if (- 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;- }- }- if (conditionExpression.statement !== undefined) {- state.statement = conditionExpression.statement;- }- if (conditionExpression.rowLimit !== undefined) {- state.maxRowCount = conditionExpression.rowLimit;- }- if (conditionExpression.exportFormat !== undefined) {- state.exportFormat = conditionExpression.exportFormat as "CSV" | "JSON";- }-});--const handleExport = async () => {- if (state.isRequesting) {- return;- }- state.isRequesting = true;-- const database = databaseStore.getDatabaseByUID(state.databaseId);- if (database.uid === String(UNKNOWN_ID)) {- throw "Database not found";- }-- try {- const { content } = await sqlStore.exportData({- name: database.instance,- connectionDatabase: database.databaseName,- statement: state.statement,- limit: state.maxRowCount,- format: getExportRequestFormat(state.exportFormat),- });- const blob = new Blob([content], {- type: state.exportFormat === "CSV" ? "text/csv" : "application/json",- });- const url = window.URL.createObjectURL(blob);- const fileFormat = state.exportFormat.toLowerCase();- const formattedDateString = dayjs(new Date()).format("YYYY-MM-DDTHH-mm-ss");- const filename = `export-data-${formattedDateString}`;- const link = document.createElement("a");- link.download = `${filename}.${fileFormat}`;- link.href = url;- link.click();- // Fetch the latest iam policy.- await projectIamPolicyStore.fetchProjectIamPolicy(database.project, true);- state.isRequesting = false;- state.showConfirmModal = false;- } catch (error) {- pushNotification({- module: "bytebase",- style: "CRITICAL",- title: `Failed to export data`,- description: JSON.stringify(error),- });- }- // After data exported successfully, we change the issue status to DONE automatically.- changeIssueStatus("DONE", "");-};-</script>diff --git a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue b/frontend/src/components/Issue/form/GrantRequestExporterForm.vueindex 5b73742aa5..5b1451ee2f 100644--- a/frontend/src/components/Issue/form/GrantRequestExporterForm.vue+++ b/frontend/src/components/Issue/form/GrantRequestExporterForm.vue@@ -1,153 +1,74 @@<template><div- class="w-full mx-auto flex flex-col justify-start items-start space-y-4 my-8 gap-4"+ class="w-full mx-auto flex flex-col justify-start items-start mb-4 space-y-4">- <div v-if="create" class="w-full flex flex-row justify-start items-center">- <span class="flex w-40 items-center textlabel !leading-6">- {{ $t("common.project") }}- <RequiredStar />- </span>- <ProjectSelect- class="!w-60 shrink-0"- :only-userself="false"- :selected-id="projectId"- @select-project-id="handleProjectSelect"- />- </div>- <div class="w-full flex flex-row justify-start items-center">- <span class="flex w-40 items-center shrink-0 textlabel !leading-6">- {{ $t("common.database") }}- <RequiredStar />- </span>- <div v-if="create" class="flex flex-row justify-start items-center">- <EnvironmentSelect- class="!w-60 mr-4 shrink-0"- name="environment"- :select-default="false"- :selected-id="state.environmentId"- @select-environment-id="handleEnvironmentSelect"- />- <DatabaseSelect- class="!w-128"- :selected-id="state.databaseId ?? String(UNKNOWN_ID)"- :mode="'ALL'"- :environment-id="state.environmentId"- :project-id="state.projectId"- :sync-status="'OK'"- :customize-item="true"- @select-database-id="handleDatabaseSelect"- >- <template #customizeItem="{ database }">- <div class="flex items-center">- <InstanceV1EngineIcon :instance="database.instanceEntity" />- <span class="mx-2">{{ database.databaseName }}</span>- <span class="text-gray-400">- ({{ instanceV1Name(database.instanceEntity) }})- </span>- </div>- </template>- </DatabaseSelect>- </div>- <div- v-else-if="selectedDatabase"- class="flex flex-row justify-start items-center"- >- <InstanceV1EngineIcon- :instance="selectedDatabase.instanceEntity"- :link="false"- class="mr-1"- />- {{ selectedDatabase.databaseName }}+ <template v-if="exportMethod === 'SQL'">+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("common.database") }}+ </span>+ <div class="flex flex-row justify-start items-center">+ <InstanceV1EngineIcon+ :instance="selectedDatabase.instanceEntity"+ :link="false"+ class="mr-1"+ />+ {{ selectedDatabase.databaseName }}+ </div></div>- </div>- <div class="w-full flex flex-row justify-start items-start">- <span class="flex w-40 items-start textlabel !leading-6">- {{- create- ? $t("issue.grant-request.expire-days")- : $t("issue.grant-request.expired-at")- }}- <RequiredStar />- </span>- <div v-if="create">- <NRadioGroup- v-model:value="state.expireDays"- class="!grid grid-cols-6 gap-4"- name="radiogroup"- >- <div- v-for="day in expireDaysOptions"- :key="day.value"- class="col-span-1 flex flex-row justify-start items-center"- >- <NRadio :value="day.value" :label="day.label" />- </div>- <div class="col-span-2 flex flex-row justify-start items-center">- <NRadio :value="-1" :label="$t('issue.grant-request.customize')" />- <NInputNumber- v-model:value="state.customDays"- class="!w-24 ml-2"- :disabled="state.expireDays !== -1"- :min="1"- :show-button="false"- :placeholder="''"- >- <template #suffix>{{ $t("common.date.days") }}</template>- </NInputNumber>- </div>- </NRadioGroup>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">SQL</span>+ <div class="w-full border rounded">+ <MonacoEditor+ class="w-full h-[300px] py-2"+ readonly+ :value="state.statement"+ :auto-focus="false"+ :language="'sql'"+ :dialect="dialect"+ />+ </div></div>- <div v-else>- {{ state.expiredAt }}+ </template>+ <template v-else>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("common.database") }}+ </span>+ <DatabaseResourceTable+ class="w-full"+ :database-resource-list="+ selectedDatabaseResource ? [selectedDatabaseResource] : []+ "+ /></div>- </div>- <div class="w-full flex flex-row justify-start items-center">- <span class="flex w-40 items-center textlabel !leading-6">+ </template>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">{{ $t("issue.grant-request.export-rows") }}- <RequiredStar /></span><inputv-model="state.maxRowCount"- required+ readonlytype="number"class="textfield"- :readonly="!create"placeholder="Max row count"/></div>- <div class="w-full flex flex-row justify-start items-start">- <span class="flex w-40 items-center textlabel !leading-6">+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">{{ $t("issue.grant-request.export-format") }}- <RequiredStar /></span>- <div v-if="create">- <NRadioGroup- v-model:value="state.exportFormat"- class="w-full !flex flex-row justify-start items-center gap-4"- name="radiogroup"- >- <NRadio :value="'CSV'" label="CSV" />- <NRadio :value="'JSON'" label="JSON" />- </NRadioGroup>- </div>- <div v-else class="flex flex-row justify-start items-start gap-4">+ <div class="flex flex-row justify-start items-start gap-4">{{ state.exportFormat }}</div></div>- <div class="w-full flex flex-row justify-start items-start">- <span class="flex w-40 items-center shrink-0 textlabel !leading-6 mt-4"- >SQL<RequiredStar- /></span>- <div class="whitespace-pre-wrap w-full overflow-hidden border">- <MonacoEditor- class="w-full h-[360px] py-2"- :value="state.statement"- :auto-focus="false"- :language="'sql'"- :dialect="dialect"- :readonly="!create"- @change="handleStatementChange"- />+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("issue.grant-request.expired-at") }}+ </span>+ <div>+ {{ state.expiredAt }}</div></div></div>@@ -155,84 +76,50 @@<script lang="ts" setup>import { head } from "lodash-es";-import { NRadioGroup, NRadio, NInputNumber } from "naive-ui";-import { computed, onMounted, reactive, watch } from "vue";-import { useI18n } from "vue-i18n";+import { computed, onMounted, reactive, ref } from "vue";import { useIssueLogic } from "../logic";import {- GrantRequestContext,GrantRequestPayload,Issue,- IssueCreate,PresetRoleType,SQLDialect,UNKNOWN_ID,dialectOfEngineV1,} from "@/types";-import { extractUserUID, instanceV1Name, memberListInProjectV1 } from "@/utils";-import { useDatabaseV1Store, useProjectV1Store } from "@/store";+import { useDatabaseV1Store } from "@/store";import MonacoEditor from "@/components/MonacoEditor";-import RequiredStar from "@/components/RequiredStar.vue";import { convertFromCELString } from "@/utils/issue/cel";import { InstanceV1EngineIcon } from "@/components/v2";-import DatabaseSelect from "@/components/DatabaseSelect.vue";import { Engine } from "@/types/proto/v1/common";+import dayjs from "dayjs";+import DatabaseResourceTable from "../table/DatabaseResourceTable.vue";+import { DatabaseResource } from "./SelectDatabaseResourceForm/common";interface LocalState {- // For creating- projectId?: string;- environmentId?: string;databaseId?: string;- expireDays: number;- customDays: number;maxRowCount: number;exportFormat: "CSV" | "JSON";statement: string;- // For reviewingexpiredAt: string;}-const { t } = useI18n();-const { create, issue } = useIssueLogic();+const { issue } = useIssueLogic();const databaseStore = useDatabaseV1Store();const state = reactive<LocalState>({- expireDays: 1,- customDays: 7,maxRowCount: 1000,exportFormat: "CSV",statement: "",expiredAt: "",});--const projectId = computed(() => {- return create.value ? state.projectId : (issue.value as Issue).project.id;-});+const selectedDatabaseResource = ref<DatabaseResource | undefined>(undefined);const selectedDatabase = computed(() => {- if (!state.databaseId || state.databaseId === String(UNKNOWN_ID)) {- return undefined;- }- return databaseStore.getDatabaseByUID(state.databaseId);+ return databaseStore.getDatabaseByUID(state.databaseId ?? String(UNKNOWN_ID));});-const expireDaysOptions = computed(() => [- {- value: 1,- label: t("common.date.days", { days: 1 }),- },- {- value: 3,- label: t("common.date.days", { days: 3 }),- },- {- value: 7,- label: t("common.date.days", { days: 7 }),- },- {- value: 15,- label: t("common.date.days", { days: 15 }),- },-]);+const exportMethod = computed(() => {+ return state.statement === "" ? "DATABASE" : "SQL";+});const dialect = computed((): SQLDialect => {const db = selectedDatabase.value;@@ -240,157 +127,43 @@ const dialect = computed((): SQLDialect => {});onMounted(async () => {- if (create.value) {- const projectId = String((issue.value as IssueCreate).projectId);- if (projectId && projectId !== String(UNKNOWN_ID)) {- handleProjectSelect(projectId);- }- const context = (issue.value as IssueCreate)- .createContext as GrantRequestContext;- if (context.statement) {- state.statement = context.statement;- }- if (context.databaseResources && context.databaseResources.length > 0) {- const databaseName = String(context.databaseResources[0].databaseName);- const database = await databaseStore.getOrFetchDatabaseByName(- databaseName- );- state.databaseId = database.uid;- state.environmentId = database.instanceEntity.environmentEntity.uid;- }- }-});--const handleProjectSelect = async (projectId: string) => {- if (!create.value) {- return;- }-- const issueCreate = issue.value as IssueCreate;- state.projectId = projectId;- issueCreate.projectId = parseInt(projectId, 10);- // update issue assignee- const project = await useProjectV1Store().getOrFetchProjectByUID(projectId);- const memberList = memberListInProjectV1(project, project.iamPolicy);- const ownerList = memberList.filter((member) =>- member.roleList.includes(PresetRoleType.OWNER)- );- const projectOwner = head(ownerList);- if (projectOwner) {- const userUID = extractUserUID(projectOwner.user.name);- issueCreate.assigneeId = Number(userUID);+ const payload = ((issue.value as Issue).payload as any)+ .grantRequest as GrantRequestPayload;+ if (payload.role !== PresetRoleType.EXPORTER) {+ throw "Only support EXPORTER role";}-};-const handleEnvironmentSelect = (environmentId: string) => {- state.environmentId = environmentId;- const database = databaseStore.getDatabaseByUID(- state.databaseId || String(UNKNOWN_ID)+ const conditionExpression = await convertFromCELString(+ payload.condition.expression);- // Unselect database if it doesn't belong to the newly selected environment.if (- database &&- database.uid !== String(UNKNOWN_ID) &&- database.instanceEntity.environmentEntity.uid !== state.environmentId+ conditionExpression.databaseResources !== undefined &&+ conditionExpression.databaseResources.length > 0) {- state.databaseId = undefined;+ const resource = head(conditionExpression.databaseResources);+ if (resource) {+ const database = await databaseStore.getOrFetchDatabaseByName(+ resource.databaseName+ );+ state.databaseId = database.uid;+ selectedDatabaseResource.value = resource;+ }}-};--const handleDatabaseSelect = (databaseId: string) => {- state.databaseId = databaseId;- const database = databaseStore.getDatabaseByUID(- state.databaseId || String(UNKNOWN_ID)- );- if (database && database.uid !== String(UNKNOWN_ID)) {- state.environmentId = database.instanceEntity.environmentEntity.uid;- handleProjectSelect(database.projectEntity.uid);+ if (conditionExpression.expiredTime !== undefined) {+ state.expiredAt = dayjs(new Date(conditionExpression.expiredTime)).format(+ "LLL"+ );+ } else {+ state.expiredAt = "-";}-};--const handleStatementChange = (value: string) => {- state.statement = value;-};--watch(- () => [- state.databaseId,- state.expireDays,- state.customDays,- state.maxRowCount,- state.exportFormat,- state.statement,- ],- () => {- if (create.value) {- const context = (issue.value as IssueCreate)- .createContext as GrantRequestContext;- if (selectedDatabase.value) {- context.databaseResources = [- {- databaseName: selectedDatabase.value.name,- },- ];- } else {- context.databaseResources = [];- }- if (state.expireDays === -1) {- context.expireDays = state.customDays;- } else {- context.expireDays = state.expireDays;- }- context.maxRowCount = state.maxRowCount;- context.exportFormat = state.exportFormat;- context.statement = state.statement;- }+ if (conditionExpression.statement !== undefined) {+ state.statement = conditionExpression.statement;}-);--watch(- create,- async () => {- if (!create.value) {- const payload = ((issue.value as Issue).payload as any)- .grantRequest as GrantRequestPayload;- if (payload.role !== PresetRoleType.EXPORTER) {- throw "Only support EXPORTER role";- }-- const conditionExpression = await convertFromCELString(- payload.condition.expression- );- if (- 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;- }- }- if (conditionExpression.expiredTime !== undefined) {- state.expiredAt = new Date(- conditionExpression.expiredTime- ).toLocaleString();- } else {- state.expiredAt = "-";- }- if (conditionExpression.statement !== undefined) {- state.statement = conditionExpression.statement;- }- if (conditionExpression.rowLimit !== undefined) {- state.maxRowCount = conditionExpression.rowLimit;- }- if (conditionExpression.exportFormat !== undefined) {- state.exportFormat = conditionExpression.exportFormat as "CSV" | "JSON";- }- }- },- {- immediate: true,+ if (conditionExpression.rowLimit !== undefined) {+ state.maxRowCount = conditionExpression.rowLimit;}-);+ if (conditionExpression.exportFormat !== undefined) {+ state.exportFormat = conditionExpression.exportFormat as "CSV" | "JSON";+ }+});</script>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/Label.vue b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/Label.vuenew file mode 100644index 0000000000..ced0b9d4b1--- /dev/null+++ b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/Label.vue@@ -0,0 +1,77 @@+<template>+ <div class="flex items-center gap-x-1">+ <span v-if="environment" class="text-gray-400">+ (<EnvironmentV1Name :environment="environment" :link="false" />)+ </span>+ <Prefix />+ <!-- eslint-disable-next-line vue/no-v-html -->+ <span class="truncate" v-html="optionName" />+ <span v-if="database" class="ml-1 text-gray-500 flex flex-row items-center">+ (<InstanceV1Name+ :instance="database.instanceEntity"+ :link="false"+ class="whitespace-nowrap"+ />)+ </span>+ </div>+</template>++<script setup lang="ts">+import { escape } from "lodash-es";+import { computed, h } from "vue";+import { DatabaseTreeOption } from "./common";+import { useDatabaseV1Store } from "@/store";+import { getHighlightHTMLByRegExp } from "@/utils";+import { EnvironmentV1Name, InstanceV1Name } from "@/components/v2";+import DatabaseIcon from "~icons/heroicons-outline/circle-stack";+import SchemaIcon from "~icons/heroicons-outline/view-columns";+import TableIcon from "~icons/heroicons-outline/table-cells";++const props = defineProps<{+ option: DatabaseTreeOption;+ keyword?: string;+}>();++const option = computed(() => props.option);++const database = computed(() => {+ const { option } = props;+ if (option.level !== "database") return undefined;+ const databaseId = option.value.replace("d-", "");+ return useDatabaseV1Store().getDatabaseByUID(databaseId);+});++const environment = computed(() => {+ const { option } = props;+ if (option.level !== "database") return undefined;+ return database.value?.instanceEntity.environmentEntity;+});++const Prefix = () => {+ if (option.value.level === "database") {+ return h(DatabaseIcon, {+ class: "w-4 h-auto text-gray-400",+ });+ } else if (option.value.level === "schema") {+ return h(SchemaIcon, {+ class: "w-4 h-auto text-gray-400",+ });+ } else if (option.value.level === "table") {+ return h(TableIcon, {+ class: "w-4 h-auto text-gray-400",+ });+ }+ return null;+};++const optionName = computed(() => {+ const name = option.value?.label ?? "";+ const keyword = (props.keyword ?? "").trim();++ return getHighlightHTMLByRegExp(+ escape(name),+ escape(keyword),+ false /* !caseSensitive */+ );+});+</script>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/common.ts b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/common.tsnew file mode 100644index 0000000000..f0791e25e1--- /dev/null+++ b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/common.ts@@ -0,0 +1,115 @@+import { flatten } from "lodash-es";+import { TransferOption, TreeOption } from "naive-ui";+import { useDBSchemaV1Store } from "@/store";+import { ComposedDatabase } from "@/types";+import { hasSchemaProperty } from "@/utils";++export interface DatabaseResource {+ databaseName: string;+ schema?: string;+ table?: string;+}++export interface DatabaseTreeOption<L = "database" | "schema" | "table">+ extends TreeOption {+ level: L;+ value: string;+}++export const mapTreeOptions = (+ databaseList: ComposedDatabase[],+ filterValueList?: string[]+) => {+ const dbSchemaStore = useDBSchemaV1Store();+ const databaseNodes: DatabaseTreeOption<"database">[] = [];+ for (const database of databaseList) {+ const databaseMetadata = dbSchemaStore.getDatabaseMetadata(database.name);+ const databaseNode: DatabaseTreeOption<"database"> = {+ level: "database",+ value: `d-${database.uid}`,+ label: database.databaseName,+ checkboxDisabled: true,+ };++ if (hasSchemaProperty(database.instanceEntity.engine)) {+ const schemaNodes = databaseMetadata.schemas.map(+ (schema): DatabaseTreeOption<"schema"> => {+ const schemaNode: DatabaseTreeOption<"schema"> = {+ level: "schema",+ value: `s-${database.uid}-${schema.name}`,+ label: schema.name,+ checkboxDisabled: true,+ };+ const tableNodes = schema.tables.map(+ (table): DatabaseTreeOption<"table"> => {+ return {+ level: "table",+ value: `t-${database.uid}-${schema.name}-${table.name}`,+ label: table.name,+ };+ }+ );+ if (tableNodes.length > 0) {+ schemaNode.children = filterValueList+ ? tableNodes.filter(+ (node) =>+ (node.children && node.children?.length > 0) ||+ filterValueList.includes(node.value)+ )+ : tableNodes;+ }+ return schemaNode;+ }+ );+ if (schemaNodes.length > 0) {+ databaseNode.children = filterValueList+ ? schemaNodes.filter(+ (node) =>+ (node.children && node.children?.length > 0) ||+ filterValueList.includes(node.value)+ )+ : schemaNodes;+ }+ } else {+ const tableNodes = flatten(+ databaseMetadata.schemas.map((schema) => schema.tables)+ ).map((table): DatabaseTreeOption<"table"> => {+ return {+ level: "table",+ value: `t-${database.uid}--${table.name}`,+ label: table.name,+ };+ });+ if (tableNodes.length > 0) {+ databaseNode.children = filterValueList+ ? tableNodes.filter(+ (node) =>+ (node.children && node.children?.length > 0) ||+ filterValueList.includes(node.value)+ )+ : tableNodes;+ }+ }+ databaseNodes.push(databaseNode);+ }+ return filterValueList+ ? databaseNodes.filter(+ (node) =>+ (node.children && node.children?.length > 0) ||+ filterValueList.includes(node.value)+ )+ : databaseNodes;+};++export const flattenTreeOptions = (+ options: DatabaseTreeOption[]+): TransferOption[] => {+ return options.flatMap((option) => {+ return [+ option as TransferOption,+ ...flattenTreeOptions(+ (option.children as DatabaseTreeOption[] | undefined) ?? []+ ),+ ];+ });+};diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/index.vuenew file mode 100644index 0000000000..cb16f968a8--- /dev/null+++ b/frontend/src/components/Issue/panel/RequestExportPanel/SelectTableForm/index.vue@@ -0,0 +1,190 @@+<template>+ <div class="w-[60rem] space-y-2">+ <NTransfer+ v-if="!loading"+ v-model:value="selectedValueList"+ class="select-table-transfer"+ :options="sourceTransferOptions"+ :render-source-list="renderSourceList"+ :render-target-list="renderTargetList"+ :source-filterable="true"+ :source-filter-placeholder="$t('database.search-database-name')"+ />+ </div>+</template>++<script setup lang="ts">+import { last } from "lodash-es";+import {+ NTransfer,+ TransferRenderSourceList,+ NTree,+ TreeOption,+} from "naive-ui";+import { computed, h, onMounted, ref, watch } from "vue";+import {+ useDatabaseV1Store,+ useDBSchemaV1Store,+ useProjectV1Store,+} from "@/store";+import {+ flattenTreeOptions,+ mapTreeOptions,+ DatabaseTreeOption,+ DatabaseResource,+} from "./common";+import Label from "./Label.vue";++const props = defineProps<{+ projectId: string;+ databaseId: string;+}>();++const emit = defineEmits<{+ (e: "update", databaseResourceList: DatabaseResource[]): void;+}>();++const databaseStore = useDatabaseV1Store();+const dbSchemaStore = useDBSchemaV1Store();+const selectedValueList = ref<string[]>([]);+const databaseResourceMap = ref<Map<string, DatabaseResource>>(new Map());+const loading = ref(false);++onMounted(async () => {+ const project = await useProjectV1Store().getOrFetchProjectByUID(+ props.projectId+ );+ const databaseList = await databaseStore.fetchDatabaseList({+ parent: "instances/-",+ filter: `project == "${project.name}"`,+ });++ for (const database of databaseList) {+ const databaseMetadata = await dbSchemaStore.getOrFetchDatabaseMetadata(+ database.name+ );+ databaseResourceMap.value.set(`d-${database.uid}`, {+ databaseName: database.name,+ });+ for (const schema of databaseMetadata.schemas) {+ databaseResourceMap.value.set(`s-${database.uid}-${schema.name}`, {+ databaseName: database.name,+ schema: schema.name,+ });+ for (const table of schema.tables) {+ databaseResourceMap.value.set(+ `t-${database.uid}-${schema.name}-${table.name}`,+ {+ databaseName: database.name,+ schema: schema.name,+ table: table.name,+ }+ );+ }+ }+ }+ loading.value = false;+});++const databaseList = computed(() => {+ const project = useProjectV1Store().getProjectByUID(props.projectId);+ const list = databaseStore.databaseListByProject(project.name);+ return props.databaseId+ ? list.filter((item) => item.uid === props.databaseId)+ : list;+});++const sourceTreeOptions = computed(() => {+ return mapTreeOptions(databaseList.value);+});++const sourceTransferOptions = computed(() => {+ const options = flattenTreeOptions(sourceTreeOptions.value);+ return options;+});++const renderSourceList: TransferRenderSourceList = ({ onCheck, pattern }) => {+ return h(NTree, {+ keyField: "value",+ checkable: true,+ selectable: false,+ virtualScroll: true,+ data: sourceTreeOptions.value,+ defaultExpandAll: true,+ renderLabel: ({ option }: { option: TreeOption }) => {+ return h(Label, {+ option: option as DatabaseTreeOption,+ keyword: pattern,+ });+ },+ 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([]);+ }+ },+ });+};++const targetTreeOptions = computed(() => {+ return mapTreeOptions(databaseList.value, selectedValueList.value);+});++const renderTargetList: TransferRenderSourceList = ({ onCheck }) => {+ return h(NTree, {+ keyField: "value",+ checkable: true,+ selectable: false,+ checkOnClick: true,+ virtualScroll: true,+ defaultExpandAll: true,+ data: targetTreeOptions.value,+ renderLabel: ({ option }: { option: TreeOption }) => {+ return h(Label, {+ option: option as DatabaseTreeOption,+ });+ },+ checkedKeys: selectedValueList.value,+ showIrrelevantNodes: false,+ onUpdateCheckedKeys: (checkedKeys: string[]) => {+ onCheck(checkedKeys);+ },+ });+};++watch(+ () => [props.projectId, props.databaseId],+ () => {+ if (!props.databaseId) {+ selectedValueList.value = [];+ return;+ }+ const database = databaseStore.getDatabaseByUID(props.databaseId);+ selectedValueList.value = selectedValueList.value.filter((key) =>+ key.startsWith(`t-${database.databaseName}`)+ );+ }+);++watch(selectedValueList, () => {+ emit(+ "update",+ selectedValueList.value.map((key) => databaseResourceMap.value.get(key)!)+ );+});+</script>++<style>+/* Hide the select all button in NTransfer */+.select-table-transfer+ > .n-transfer-list--source+ > .n-transfer-list-header+ > .n-transfer-list-header__button {+ @apply hidden;+}+</style>diff --git a/frontend/src/components/Issue/panel/RequestExportPanel/index.vue b/frontend/src/components/Issue/panel/RequestExportPanel/index.vuenew file mode 100644index 0000000000..1dbdb44bde--- /dev/null+++ b/frontend/src/components/Issue/panel/RequestExportPanel/index.vue@@ -0,0 +1,482 @@+<template>+ <NDrawer+ :show="true"+ width="auto"+ :auto-focus="false"+ @update:show="(show: boolean) => !show && $emit('close')"+ >+ <NDrawerContent+ :title="$t('quick-action.request-export')"+ :closable="true"+ class="w-[50rem] max-w-[100vw] relative"+ >+ <div class="w-full mx-auto space-y-4">+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("common.project") }}+ <RequiredStar />+ </span>+ <ProjectSelect+ class="!w-60 shrink-0"+ :only-userself="false"+ :selected-id="state.projectId"+ @select-project-id="handleProjectSelect"+ />+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("common.database") }}+ <RequiredStar />+ </span>+ <div class="flex flex-row justify-start items-center">+ <EnvironmentSelect+ class="!w-60 mr-4 shrink-0"+ name="environment"+ :select-default="false"+ :selected-id="state.environmentId"+ @select-environment-id="handleEnvironmentSelect"+ />+ <DatabaseSelect+ class="!w-96"+ :selected-id="state.databaseId ?? String(UNKNOWN_ID)"+ :mode="'ALL'"+ :environment-id="state.environmentId"+ :project-id="state.projectId"+ :sync-status="'OK'"+ :customize-item="true"+ @select-database-id="handleDatabaseSelect"+ >+ <template #customizeItem="{ database }">+ <div class="flex items-center">+ <InstanceV1EngineIcon :instance="database.instanceEntity" />+ <span class="mx-2">{{ database.databaseName }}</span>+ <span class="text-gray-400">+ ({{ instanceV1Name(database.instanceEntity) }})+ </span>+ </div>+ </template>+ </DatabaseSelect>+ </div>+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("issue.grant-request.export-method") }}+ <RequiredStar />+ </span>+ <div class="w-full mb-2">+ <NRadioGroup+ v-model:value="state.exportMethod"+ class="w-full !flex flex-row justify-start items-center gap-4"+ name="export-method"+ >+ <NRadio :value="'SQL'" label="SQL" />+ <NTooltip :disabled="allowSelectTableResource">+ <template #trigger>+ <NRadio+ :disabled="!allowSelectTableResource"+ :value="'DATABASE'"+ :label="$t('common.database')"+ />+ </template>+ {{ $t("issue.grant-request.please-select-database-first") }}+ </NTooltip>+ </NRadioGroup>+ </div>+ <div+ v-show="state.exportMethod === 'SQL'"+ class="w-full h-[300px] border rounded"+ >+ <MonacoEditor+ class="w-full h-full py-2"+ :value="state.statement"+ :auto-focus="false"+ :language="'sql'"+ :dialect="dialect"+ @change="handleStatementChange"+ />+ </div>+ <div+ v-if="state.exportMethod === 'DATABASE'"+ class="w-full flex flex-row justify-start items-center"+ >+ <SelectTableForm+ :project-id="state.projectId"+ :database-id="state.databaseId"+ :selected-database-resource-list="+ selectedTableResource ? [selectedTableResource] : []+ "+ @update="handleTableResourceUpdate"+ />+ </div>+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("issue.grant-request.export-rows") }}+ <RequiredStar />+ </span>+ <input+ v-model="state.maxRowCount"+ required+ type="number"+ class="textfield"+ placeholder="Max row count"+ />+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">+ {{ $t("issue.grant-request.export-format") }}+ <RequiredStar />+ </span>+ <div>+ <NRadioGroup+ v-model:value="state.exportFormat"+ class="w-full !flex flex-row justify-start items-center gap-4"+ name="export-format"+ >+ <NRadio :value="'CSV'" label="CSV" />+ <NRadio :value="'JSON'" label="JSON" />+ <NRadio :value="'SQL'" label="SQL" />+ </NRadioGroup>+ </div>+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-start textlabel mb-2">+ {{ $t("issue.grant-request.expire-days") }}+ <RequiredStar />+ </span>+ <div>+ <NRadioGroup+ v-model:value="state.expireDays"+ class="!grid grid-cols-6 gap-4"+ name="radiogroup"+ >+ <div+ v-for="day in expireDaysOptions"+ :key="day.value"+ class="col-span-1 flex flex-row justify-start items-center"+ >+ <NRadio :value="day.value" :label="day.label" />+ </div>+ <div class="col-span-2 flex flex-row justify-start items-center">+ <NRadio+ :value="-1"+ :label="$t('issue.grant-request.customize')"+ />+ <NInputNumber+ v-model:value="state.customDays"+ class="!w-24 ml-2"+ :disabled="state.expireDays !== -1"+ :min="1"+ :show-button="false"+ :placeholder="''"+ >+ <template #suffix>{{ $t("common.date.days") }}</template>+ </NInputNumber>+ </div>+ </NRadioGroup>+ </div>+ </div>+ <div class="w-full flex flex-col justify-start items-start">+ <span class="flex items-center textlabel mb-2">{{+ $t("common.reason")+ }}</span>+ <NInput+ v-model:value="state.description"+ type="textarea"+ class="w-full"+ placeholder=""+ />+ </div>+ </div>+ <template #footer>+ <div class="flex items-center justify-end gap-x-2">+ <NButton @click="$emit('close')">{{ $t("common.cancel") }}</NButton>+ <NButton+ type="primary"+ :disabled="!allowCreate"+ @click="doCreateIssue"+ >+ {{ $t("common.ok") }}+ </NButton>+ </div>+ </template>+ </NDrawerContent>+ </NDrawer>+</template>++<script lang="ts" setup>+import {+ NDrawer,+ NDrawerContent,+ NRadioGroup,+ NRadio,+ NInputNumber,+ NInput,+ NTooltip,+} from "naive-ui";+import { computed, onMounted, reactive, ref } from "vue";+import { useI18n } from "vue-i18n";+import {+ IssueCreate,+ PresetRoleType,+ SQLDialect,+ SYSTEM_BOT_ID,+ UNKNOWN_ID,+ dialectOfEngineV1,+} from "@/types";+import {+ extractUserUID,+ instanceV1Name,+ issueSlug,+ memberListInProjectV1,+} from "@/utils";+import {+ useCurrentUserV1,+ useDatabaseV1Store,+ useIssueStore,+ useProjectV1Store,+} from "@/store";+import MonacoEditor from "@/components/MonacoEditor";+import RequiredStar from "@/components/RequiredStar.vue";+import { InstanceV1EngineIcon } from "@/components/v2";+import DatabaseSelect from "@/components/DatabaseSelect.vue";+import { Engine } from "@/types/proto/v1/common";+import { head } from "lodash-es";+import { useRouter } from "vue-router";+import SelectTableForm from "./SelectTableForm/index.vue";+import { DatabaseResource } from "./SelectTableForm/common";+import dayjs from "dayjs";+import { stringifyDatabaseResources } from "@/utils/issue/cel";++interface LocalState {+ projectId?: string;+ environmentId?: string;+ databaseId?: string;+ expireDays: number;+ customDays: number;+ maxRowCount: number;+ exportMethod: "SQL" | "DATABASE";+ exportFormat: "CSV" | "JSON" | "SQL";+ statement: string;+ description: string;+}++const props = defineProps<{+ databaseId?: string;+ statement?: string;+}>();++defineEmits<{+ (event: "close"): void;+}>();++const { t } = useI18n();+const router = useRouter();+const currentUser = useCurrentUserV1();+const databaseStore = useDatabaseV1Store();+const state = reactive<LocalState>({+ expireDays: 1,+ customDays: 7,+ maxRowCount: 1000,+ exportMethod: "SQL",+ exportFormat: "CSV",+ statement: "",+ description: "",+});+const selectedTableResource = ref<DatabaseResource>();++const selectedDatabase = computed(() => {+ if (!state.databaseId || state.databaseId === String(UNKNOWN_ID)) {+ return undefined;+ }+ return databaseStore.getDatabaseByUID(state.databaseId);+});++const expireDaysOptions = computed(() => [+ {+ value: 1,+ label: t("common.date.days", { days: 1 }),+ },+ {+ value: 3,+ label: t("common.date.days", { days: 3 }),+ },+ {+ value: 7,+ label: t("common.date.days", { days: 7 }),+ },+ {+ value: 15,+ label: t("common.date.days", { days: 15 }),+ },+]);++const allowCreate = computed(() => {+ if (!state.databaseId) {+ return false;+ }++ if (state.exportMethod === "SQL") {+ return state.statement && state.statement !== "";+ } else {+ return selectedTableResource.value !== undefined;+ }+});++const allowSelectTableResource = computed(() => {+ return state.databaseId !== undefined;+});++const dialect = computed((): SQLDialect => {+ const db = selectedDatabase.value;+ return dialectOfEngineV1(db?.instanceEntity.engine ?? Engine.MYSQL);+});++onMounted(async () => {+ if (props.databaseId) {+ handleDatabaseSelect(props.databaseId);+ }+ if (props.statement) {+ state.statement = props.statement;+ }+});++const handleProjectSelect = async (projectId: string) => {+ state.projectId = projectId;+};++const handleEnvironmentSelect = (environmentId: string) => {+ state.environmentId = environmentId;+ const database = databaseStore.getDatabaseByUID(+ state.databaseId || String(UNKNOWN_ID)+ );+ // Unselect database if it doesn't belong to the newly selected environment.+ if (+ database &&+ database.uid !== String(UNKNOWN_ID) &&+ database.instanceEntity.environmentEntity.uid !== state.environmentId+ ) {+ state.databaseId = undefined;+ }+};++const handleDatabaseSelect = (databaseId: string) => {+ state.databaseId = databaseId;+ const database = databaseStore.getDatabaseByUID(+ state.databaseId || String(UNKNOWN_ID)+ );+ if (database && database.uid !== String(UNKNOWN_ID)) {+ handleProjectSelect(database.projectEntity.uid);+ handleEnvironmentSelect(database.instanceEntity.environmentEntity.uid);+ }+};++const handleTableResourceUpdate = (+ databaseResourceList: DatabaseResource[]+) => {+ if (databaseResourceList.length > 1) {+ throw new Error("Only one table can be selected");+ } else if (databaseResourceList.length === 0) {+ selectedTableResource.value = undefined;+ } else {+ selectedTableResource.value = databaseResourceList[0];+ }+};++const handleStatementChange = (value: string) => {+ state.statement = value;+};++const doCreateIssue = async () => {+ if (!allowCreate.value) {+ return;+ }++ const newIssue: IssueCreate = {+ name: generateIssueName(),+ type: "bb.issue.grant.request",+ description: state.description,+ projectId: Number(state.projectId),+ assigneeId: SYSTEM_BOT_ID,+ createContext: {},+ payload: {},+ };++ // update issue's assignee to first project owner.+ const project = await useProjectV1Store().getOrFetchProjectByUID(+ state.projectId!+ );+ const memberList = memberListInProjectV1(project, project.iamPolicy);+ const ownerList = memberList.filter((member) =>+ member.roleList.includes(PresetRoleType.OWNER)+ );+ const projectOwner = head(ownerList);+ if (projectOwner) {+ const userUID = extractUserUID(projectOwner.user.name);+ newIssue.assigneeId = Number(userUID);+ }++ const expression: string[] = [];+ const expireDays =+ state.expireDays === -1 ? state.customDays : state.expireDays;+ expression.push(+ `request.time < timestamp("${dayjs()+ .add(expireDays, "days")+ .toISOString()}")`+ );+ expression.push(`request.export_format == "${state.exportFormat}"`);+ expression.push(`request.row_limit == ${state.maxRowCount}`);+ if (state.exportMethod === "SQL") {+ expression.push(`request.statement == "${btoa(state.statement)}"`);+ const cel = stringifyDatabaseResources([+ {+ databaseName: selectedDatabase.value!.name,+ },+ ]);+ expression.push(cel);+ } else {+ if (!selectedTableResource.value) {+ throw new Error("No table selected");+ }+ const cel = stringifyDatabaseResources([selectedTableResource.value]);+ expression.push(cel);+ }++ const celExpressionString = expression.join(" && ");+ newIssue.payload = {+ grantRequest: {+ role: "roles/EXPORTER",+ user: currentUser.value.name,+ condition: {+ expression: celExpressionString,+ },+ },+ };++ const issue = await useIssueStore().createIssue(newIssue);+ router.push(`/issue/${issueSlug(issue.name, issue.id)}`);+};++const generateIssueName = () => {+ const database = selectedDatabase.value;+ if (!database) {+ throw new Error("No database selected");+ }++ if (state.exportMethod === "SQL") {+ return `Request data export for "${database.databaseName} (${database.instanceEntity.title})"`;+ } else {+ const tableResource = selectedTableResource.value as DatabaseResource;+ const nameList = [database.databaseName];+ if (tableResource.schema) {+ nameList.push(tableResource.schema);+ }+ if (tableResource.table) {+ nameList.push(tableResource.table);+ }+ return `Request data export for "${nameList.join(".")} (${+ database.instanceEntity.title+ })"`;+ }+};+</script>diff --git a/frontend/src/components/Issue/table/DatabaseResourceTable.vue b/frontend/src/components/Issue/table/DatabaseResourceTable.vuenew file mode 100644index 0000000000..3db992051c--- /dev/null+++ b/frontend/src/components/Issue/table/DatabaseResourceTable.vue@@ -0,0 +1,105 @@+<template>+ <BBGrid+ :column-list="COLUMN_LIST"+ :data-source="databaseResourceList"+ :row-clickable="true"+ row-key="name"+ class="border"+ >+ <template #item="{ item }">+ <div class="bb-grid-cell">+ {{ extractDatabaseName(item) }}+ </div>+ <div class="bb-grid-cell">+ {{ extractTableName(item) }}+ </div>+ <div class="bb-grid-cell">+ <EnvironmentV1Name+ :environment="+ extractComposedDatabase(item).instanceEntity.environmentEntity+ "+ />+ </div>+ <div class="bb-grid-cell">+ <InstanceV1Name+ :instance="extractComposedDatabase(item).instanceEntity"+ />+ </div>+ </template>+ </BBGrid>+</template>++<script lang="ts" setup>+import { computed } from "vue";+import { useI18n } from "vue-i18n";+import { BBGridColumn } from "@/bbkit";+import { DatabaseGroup } from "@/types/proto/v1/project_service";+import { DatabaseResource } from "../panel/RequestExportPanel/SelectTableForm/common";+import { watch } from "vue";+import { useDatabaseV1Store } from "@/store";+import { EnvironmentV1Name, InstanceV1Name } from "@/components/v2";++const props = defineProps<{+ databaseResourceList: DatabaseResource[];+}>();++defineEmits<{+ (event: "edit", databaseGroup: DatabaseGroup): void;+}>();++const { t } = useI18n();+const databaseStore = useDatabaseV1Store();++const extractDatabaseName = (databaseResource: DatabaseResource) => {+ const database = databaseStore.getDatabaseByName(+ String(databaseResource.databaseName)+ );+ return database.databaseName;+};++const extractTableName = (databaseResource: DatabaseResource) => {+ const nameList = [];+ if (databaseResource.schema) {+ nameList.push(databaseResource.schema);+ }+ if (databaseResource.table) {+ nameList.push(databaseResource.table);+ }+ return nameList.join(".") ?? "*";+};++const extractComposedDatabase = (databaseResource: DatabaseResource) => {+ const database = databaseStore.getDatabaseByName(+ String(databaseResource.databaseName)+ );+ return database;+};++watch(+ () => props.databaseResourceList,+ async () => {+ for (const databaseResource of props.databaseResourceList) {+ await databaseStore.getOrFetchDatabaseByName(+ databaseResource.databaseName+ );+ }+ },+ {+ immediate: true,+ }+);++const COLUMN_LIST = computed(() => {+ const columns: BBGridColumn[] = [+ { title: t("common.database"), width: "1fr" },+ { title: t("common.table"), width: "1fr" },+ {+ title: t("common.environment"),+ width: "1fr",+ },+ { title: t("common.instance"), width: "1fr" },+ ];++ return columns;+});+</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex fda8c18762..7da939b8fc 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -779,7 +779,9 @@"all-databases-tip": "All current and future databases in this project.","manually-select": "Manually select","customize": "Customize",- "data-export-attention": "The data will be exported to a file and downloaded to your local machine. And you can only do the export action once."+ "data-export-attention": "The data will be exported to a file and downloaded to your local machine. And you can only do the export action once.",+ "export-method": "Export method",+ "please-select-database-first": "Please select database first"},"review-sent-back": "Review sent back"},diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex d16a6ca8f4..8ca05fcb40 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -772,7 +772,9 @@"all-databases-tip": "Todas las bases de datos actuales y futuras de este proyecto.","manually-select": "selección manual","customize": "personalice",- "data-export-attention": "Los datos se exportarán a un archivo y se descargarán en su computadora local. Y solo puede realizar la acción de exportación una vez."+ "data-export-attention": "Los datos se exportarán a un archivo y se descargarán en su computadora local. Y solo puede realizar la acción de exportación una vez.",+ "export-method": "Método de exportación",+ "please-select-database-first": "Por favor, seleccione primero la base de datos"},"review-sent-back": "Revisión devuelta"},diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 233a98fb41..ebac6c4da8 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -776,7 +776,9 @@"all-databases-tip": "所有当前和未来属于这个项目的数据库。","manually-select": "手动选择","customize": "自定义",- "data-export-attention": "数据将被导出到一个文件并自动下载。而且您只能完成一次导出操作。"+ "data-export-attention": "数据将被导出到一个文件并自动下载。而且您只能完成一次导出操作。",+ "export-method": "导出方式",+ "please-select-database-first": "请先选择数据库"},"review-sent-back": "审核被退回"},diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vueindex c50c6fef3e..0a92ec4aae 100644--- a/frontend/src/views/ExportCenter/index.vue+++ b/frontend/src/views/ExportCenter/index.vue@@ -23,7 +23,7 @@</NInputGroup></div><div>- <NButton @click="createExportDataIssue">+ <NButton @click="state.showRequestExportPanel = true">{{ $t("quick-action.request-export") }}</NButton></div>@@ -32,13 +32,17 @@<ExportRecordTable :export-records="filterExportRecords" /></div></div>++ <RequestExportPanel+ v-if="state.showRequestExportPanel"+ @close="state.showRequestExportPanel = false"+ /></template><script lang="ts" setup>import { head } from "lodash-es";import { NButton, NInputGroup } from "naive-ui";import { computed, reactive, watchEffect } from "vue";-import { useRouter } from "vue-router";import { UNKNOWN_ID } from "@/types";import { FilterParams, ExportRecord } from "./types";import {@@ -52,15 +56,16 @@ import {import { ProjectSelect, InstanceSelect, DatabaseSelect } from "@/components/v2";import { convertFromExpr } from "@/utils/issue/cel";import ExportRecordTable from "./ExportRecordTable.vue";+import RequestExportPanel from "@/components/Issue/panel/RequestExportPanel/index.vue";interface LocalState {filterParams: FilterParams;exportRecords: ExportRecord[];+ showRequestExportPanel: boolean;}const issueDescriptionRegexp = /^#(\d+)$/;-const router = useRouter();const currentUser = useCurrentUserV1();const projectIamPolicyStore = useProjectIamPolicyStore();const databaseStore = useDatabaseV1Store();@@ -72,6 +77,7 @@ const state = reactive<LocalState>({database: undefined,},exportRecords: [],+ showRequestExportPanel: false,});const filterExportRecords = computed(() => {@@ -162,19 +168,4 @@ const changeDatabaseId = (uid: string | undefined) => {state.filterParams.database = undefined;}};--const createExportDataIssue = () => {- const routeInfo = {- name: "workspace.issue.detail",- params: {- issueSlug: "new",- },- query: {- template: "bb.issue.grant.request",- role: "EXPORTER",- name: "New grant exporter request",- },- };- router.push(routeInfo);-};</script>