Skip to content

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

chore: import files/zip from local to release (#14253)

boojack35393dd5c698
diff --git a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
index dd3ce2593f..5766d8c3ed 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/NavBar/ImportButton.vue
@@ -1,15 +1,9 @@
<template>
- <NUpload
- v-model:file-list="uploadFileList"
- abstract
- accept="application/x-zip,.zip,application/sql,.sql"
- :multiple="false"
- @change="handleFileChange"
- >
- <NUploadTrigger #="{ handleClick }" abstract>
+ <UploadFilesButton @update="onUploadFiles">
+ <template #trigger="{ onClick }">
<NTooltip>
<template #trigger>
- <NButton icon style="--n-padding: 0 10px" @click="handleClick">
+ <NButton icon style="--n-padding: 0 10px" @click="onClick">
<template #icon>
<UploadIcon class="w-4 h-4" />
</template>
@@ -21,121 +15,37 @@
</div>
</template>
</NTooltip>
- </NUploadTrigger>
- </NUpload>
-
- <BBModal
- :show="state.showModal"
- :title="$t('sql-editor.select-encoding')"
- class="shadow-inner outline outline-gray-200"
- @close="closeModal"
- >
- <div class="w-80">
- <div class="w-full flex flex-row justify-start items-center gap-2">
- <span class="textinfolabel">{{ $t("common.encoding") }}</span>
- <NSelect
- v-model:value="state.encoding"
- class="!w-24"
- filterable
- :options="encodingOptions"
- :consistent-menu-width="false"
- />
- </div>
- <div>
- <NUpload :file-list="uploadFileList" disabled trigger-class="!hidden">
- </NUpload>
- </div>
- </div>
- <div class="w-full flex items-center justify-end mt-2 space-x-3">
- <NButton @click="closeModal">
- {{ $t("common.cancel") }}
- </NButton>
- <NButton type="primary" @click="save">
- {{ $t("common.save") }}
- </NButton>
- </div>
- </BBModal>
+ </template>
+ </UploadFilesButton>
</template>
<script setup lang="ts">
import { UploadIcon } from "lucide-vue-next";
-import {
- NButton,
- NSelect,
- NTooltip,
- NUpload,
- NUploadTrigger,
- type UploadFileInfo,
-} from "naive-ui";
-import { computed, reactive, ref } from "vue";
+import { NButton, NTooltip } from "naive-ui";
import { useI18n } from "vue-i18n";
-import BBModal from "@/bbkit/BBModal.vue";
+import UploadFilesButton from "@/components/Release/ReleaseCreate/FileToCreateTable/UploadFilesButton.vue";
import { pushNotification, useChangelistStore, useSheetV1Store } from "@/store";
import {
Changelist_Change as Change,
Changelist,
} from "@/types/proto/v1/changelist_service";
-import { Engine } from "@/types/proto/v1/common";
import { Sheet } from "@/types/proto/v1/sheet_service";
-import { ENCODINGS, setSheetStatement, type Encoding } from "@/utils";
+import { setSheetStatement } from "@/utils";
import { fallbackVersionForChange } from "../../common";
-import { readUpload, type ParsedFile } from "../../import";
import { useChangelistDetailContext } from "../context";
-interface LocalState {
- encoding: Encoding;
- files: ParsedFile[];
- showModal: boolean;
-}
-
const { t } = useI18n();
-const { changelist, project, isUpdating } = useChangelistDetailContext();
-const state = reactive<LocalState>({
- encoding: "utf-8",
- files: [],
- showModal: false,
-});
-const uploadFileList = ref<UploadFileInfo[]>([]);
-
-const encodingOptions = computed(() =>
- ENCODINGS.map((encoding) => ({
- label: encoding,
- value: encoding,
- }))
-);
-
-const cleanup = () => {
- isUpdating.value = false;
- uploadFileList.value = [];
- state.files = [];
-};
-
-const handleFileChange = async (options: { file: UploadFileInfo }) => {
- isUpdating.value = true;
- const files = await readUpload(options.file);
- if (files.length === 0) {
- pushNotification({
- module: "bytebase",
- style: "WARN",
- title: t("changelist.import.no-file-to-upload"),
- });
- uploadFileList.value = [];
- }
- state.files = files;
- state.showModal = true;
-};
+const { changelist, project } = useChangelistDetailContext();
-const save = async () => {
- isUpdating.value = true;
+const onUploadFiles = async (
+ statementMap: { filename: string; statement: string }[]
+) => {
const createdSheets = await Promise.all(
- state.files.map(async (f) => {
- const { name, arrayBuffer } = f;
+ statementMap.map(async (m) => {
const sheet = Sheet.fromPartial({
- title: name,
- engine: Engine.ENGINE_UNSPECIFIED, // TODO(jim)
+ title: m.filename,
});
- const content = new TextDecoder(state.encoding).decode(arrayBuffer);
- setSheetStatement(sheet, content);
+ setSheetStatement(sheet, m.statement);
const created = await useSheetV1Store().createSheet(
project.value.name,
sheet
@@ -154,16 +64,10 @@ const save = async () => {
changes: [...changelist.value.changes, ...newChanges],
});
await useChangelistStore().patchChangelist(changelistPatch, ["changes"]);
- closeModal();
pushNotification({
module: "bytebase",
style: "SUCCESS",
title: t("common.updated"),
});
};
-
-const closeModal = () => {
- state.showModal = false;
- cleanup();
-};
</script>
diff --git a/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/CreateReleaseFilesPanel.vue b/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/CreateReleaseFilesPanel.vue
index c4d6c0edfd..70894f8e62 100644
--- a/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/CreateReleaseFilesPanel.vue
+++ b/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/CreateReleaseFilesPanel.vue
@@ -26,12 +26,25 @@
</NButton>
</div>
</div>
- <div v-if="isCreating" class="w-full flex flex-row justify-end mt-4">
+ <div
+ v-if="isCreating"
+ class="w-full flex flex-row justify-end mt-4 gap-2"
+ >
+ <UploadFilesButton @update="onUploadFiles">
+ <template #trigger="{ onClick }">
+ <NButton size="small" @click="onClick">
+ <template #icon>
+ <UploadIcon class="w-4 h-4" />
+ </template>
+ {{ $t("common.upload") }}
+ </NButton>
+ </template>
+ </UploadFilesButton>
<NButton size="small" @click="onAddFile">
<template #icon>
- <PlusIcon />
+ <PlusIcon class="w-4 h-4" />
</template>
- {{ $t("release.actions.new-file") }}
+ {{ $t("common.new") }}
</NButton>
</div>
</template>
@@ -72,12 +85,13 @@
<script lang="ts" setup>
import { uniqueId } from "lodash-es";
-import { TrashIcon, XIcon, PlusIcon } from "lucide-vue-next";
+import { TrashIcon, XIcon, PlusIcon, UploadIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { computed, reactive, watch } from "vue";
import { Drawer, DrawerContent, ErrorTipsButton } from "@/components/v2";
import { useReleaseCreateContext, type FileToCreate } from "../context";
import ReleaseFileDetailPanel from "./ReleaseFileDetailPanel.vue";
+import UploadFilesButton from "./UploadFilesButton.vue";
interface LocalState {
files: FileToCreate[];
@@ -138,6 +152,18 @@ const onDeletePropsFile = () => {
}
};
+const onUploadFiles = (
+ statementMap: { filename: string; statement: string }[]
+) => {
+ const files: FileToCreate[] = statementMap.map(({ filename, statement }) => ({
+ id: uniqueId(),
+ version: "",
+ path: filename,
+ statement,
+ }));
+ state.files = [...state.files, ...files];
+};
+
const onConfirm = () => {
if (!isCreating.value) {
context.files.value = context.files.value.map((file) =>
diff --git a/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/UploadFilesButton.vue b/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/UploadFilesButton.vue
new file mode 100644
index 0000000000..5a346f406b
--- /dev/null
+++ b/frontend/src/components/Release/ReleaseCreate/FileToCreateTable/UploadFilesButton.vue
@@ -0,0 +1,126 @@
+<template>
+ <NUpload
+ v-model:file-list="uploadFileList"
+ abstract
+ accept="application/x-zip,.zip,application/sql,.sql"
+ :multiple="false"
+ v-bind="$attrs"
+ @change="handleFileChange"
+ >
+ <NUploadTrigger #="{ handleClick }" abstract>
+ <slot name="trigger" @click="handleClick" />
+ </NUploadTrigger>
+ </NUpload>
+
+ <BBModal
+ :show="state.showModal"
+ :title="$t('sql-editor.select-encoding')"
+ @close="closeModal"
+ >
+ <div class="w-96">
+ <div class="w-full flex flex-row justify-start items-center gap-2">
+ <span class="textlabel">{{ $t("common.encoding") }}</span>
+ <NSelect
+ v-model:value="state.encoding"
+ size="small"
+ filterable
+ :options="encodingOptions"
+ :consistent-menu-width="false"
+ />
+ </div>
+ <NUpload :file-list="uploadFileList" disabled trigger-class="!hidden">
+ </NUpload>
+ </div>
+ <div class="w-full flex items-center justify-end mt-4 space-x-2">
+ <NButton quaternary @click="closeModal">
+ {{ $t("common.cancel") }}
+ </NButton>
+ <NButton type="primary" @click="onConfirm">
+ {{ $t("common.confirm") }}
+ </NButton>
+ </div>
+ </BBModal>
+</template>
+
+<script setup lang="ts">
+import {
+ NButton,
+ NSelect,
+ NUpload,
+ NUploadTrigger,
+ type UploadFileInfo,
+} from "naive-ui";
+import { computed, reactive, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import BBModal from "@/bbkit/BBModal.vue";
+import { readUpload } from "@/components/Changelist/import";
+import { pushNotification } from "@/store";
+import { ENCODINGS, type Encoding } from "@/utils";
+
+type ParsedFile = {
+ name: string;
+ arrayBuffer: ArrayBuffer;
+};
+
+interface LocalState {
+ encoding: Encoding;
+ files: ParsedFile[];
+ showModal: boolean;
+}
+
+const emit = defineEmits<{
+ (event: "update", value: { filename: string; statement: string }[]): void;
+}>();
+
+const { t } = useI18n();
+const state = reactive<LocalState>({
+ encoding: "utf-8",
+ files: [],
+ showModal: false,
+});
+const uploadFileList = ref<UploadFileInfo[]>([]);
+
+const encodingOptions = computed(() =>
+ ENCODINGS.map((encoding) => ({
+ label: encoding,
+ value: encoding,
+ }))
+);
+
+const cleanup = () => {
+ uploadFileList.value = [];
+ state.files = [];
+};
+
+const handleFileChange = async (options: { file: UploadFileInfo }) => {
+ const files = await readUpload(options.file);
+ if (files.length === 0) {
+ pushNotification({
+ module: "bytebase",
+ style: "WARN",
+ title: t("changelist.import.no-file-to-upload"),
+ });
+ uploadFileList.value = [];
+ }
+ state.files = files;
+ state.showModal = true;
+};
+
+const onConfirm = async () => {
+ emit(
+ "update",
+ state.files.map((f) => {
+ return {
+ filename: f.name,
+ statement: new TextDecoder(state.encoding).decode(f.arrayBuffer),
+ };
+ })
+ );
+ closeModal();
+};
+
+const closeModal = () => {
+ state.showModal = false;
+ cleanup();
+};
+</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 37e8f266d9..8ad4156d3d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -228,6 +228,7 @@
"will-override-current-data": "Will override current data.",
"roll-out": "Roll out",
"uploading": "Uploading",
+ "upload": "Upload",
"active": "Active",
"added": "Added",
"revoke": "Revoke",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 7ae6224b58..7be5df610d 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -228,6 +228,7 @@
"will-override-current-data": "Se sobrescribirán los datos actuales.",
"roll-out": "Implementar",
"uploading": "Subiendo",
+ "upload": "Subir",
"active": "Activo",
"added": "Agregado",
"revoke": "Revocar",
@@ -3844,4 +3845,4 @@
"setup": {
"self": "Configuración"
}
-}
\ No newline at end of file
+}
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index c31b656a08..e86027d9eb 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -228,6 +228,7 @@
"will-override-current-data": "現在のデータは上書きされます。",
"roll-out": "リリース",
"uploading": "アップロードする",
+ "upload": "アップロード",
"active": "オンにする",
"added": "作成した",
"revoke": "キャンセル",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index af931da65f..cd0d166a26 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -228,6 +228,7 @@
"will-override-current-data": "将会覆盖当前数据。",
"roll-out": "发布",
"uploading": "上传中",
+ "upload": "上传",
"active": "开启",
"added": "已创建",
"revoke": "撤销",
@@ -3844,4 +3845,4 @@
"setup": {
"self": "设置"
}
-}
\ No newline at end of file
+}