Skip to content

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

Create BBSpin to show action in progress and use it in creating instance

天舟4dbb5144f59f
diff --git a/frontend/src/bbkit/BBSpin.vue b/frontend/src/bbkit/BBSpin.vue
new file mode 100644
index 0000000000..7e3c0fa911
--- /dev/null
+++ b/frontend/src/bbkit/BBSpin.vue
@@ -0,0 +1,41 @@
+<template>
+ <div class="flex flex-row items-center text-control">
+ <svg
+ class="animate-spin h-5 w-5 mr-1 text-blue-600"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ >
+ <circle
+ class="opacity-25"
+ cx="12"
+ cy="12"
+ r="10"
+ stroke="currentColor"
+ stroke-width="4"
+ ></circle>
+ <path
+ class="opacity-75"
+ fill="currentColor"
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
+ ></path>
+ </svg>
+ {{ title }}
+ </div>
+</template>
+
+<script lang="ts">
+export default {
+ name: "BBSpin",
+ components: {},
+ props: {
+ title: {
+ required: true,
+ type: String,
+ },
+ },
+ setup(props, {}) {
+ return {};
+ },
+};
+</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 9aa9f56d24..96285838cd 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -8,20 +8,21 @@ import BBContextMenu from "./BBContextMenu.vue";
import BBModal from "./BBModal.vue";
import BBNotification from "./BBNotification.vue";
import BBOutline from "./BBOutline.vue";
-import BBSwitch from "./BBSwitch.vue";
import BBSelect from "./BBSelect.vue";
+import BBSpin from "./BBSpin.vue";
import BBStepBar from "./BBStepBar.vue";
import BBStepTab from "./BBStepTab.vue";
+import BBSwitch from "./BBSwitch.vue";
import BBTab from "./BBTab.vue";
-import BBTabPanel from "./BBTabPanel.vue";
import BBTabFilter from "./BBTabFilter.vue";
-import BBTextField from "./BBTextField.vue";
import {
BBTable,
BBTableCell,
BBTableHeaderCell,
BBTableSearch,
} from "./BBTable";
+import BBTabPanel from "./BBTabPanel.vue";
+import BBTextField from "./BBTextField.vue";
export {
BBAlert,
@@ -35,6 +36,7 @@ export {
BBNotification,
BBOutline,
BBSelect,
+ BBSpin,
BBStepBar,
BBStepTab,
BBSwitch,
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 0e46b126c4..c31561516d 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -272,22 +272,28 @@ input[type="number"] {
<!-- Action Button Group -->
<div class="pt-4">
<!-- Create button group -->
- <div v-if="create" class="flex justify-end">
- <button
- type="button"
- class="btn-normal py-2 px-4"
- @click.prevent="cancel"
- >
- Cancel
- </button>
- <button
- type="button"
- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
- :disabled="!allowCreate"
- @click.prevent="tryCreate"
- >
- Create
- </button>
+ <div v-if="create" class="flex justify-between">
+ <div>
+ <BBSpin v-if="state.creating" :title="'Creating...'" />
+ </div>
+ <div>
+ <button
+ type="button"
+ class="btn-normal py-2 px-4"
+ :disabled="state.creating"
+ @click.prevent="cancel"
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!allowCreate || state.creating"
+ @click.prevent="tryCreate"
+ >
+ Create
+ </button>
+ </div>
</div>
<!-- Update button group -->
<div v-else class="flex justify-end">
@@ -351,6 +357,7 @@ interface LocalState {
showCreateInstanceWarningModal: boolean;
createInstanceWarning: string;
showCreateUserExample: boolean;
+ creating: boolean;
}
export default {
@@ -394,6 +401,7 @@ export default {
showCreateInstanceWarningModal: false,
createInstanceWarning: "",
showCreateUserExample: props.create,
+ creating: false,
});
const allowCreate = computed(() => {
@@ -460,9 +468,11 @@ export default {
// stored in that data source object instead of in the instance self.
// Conceptually, data source is the proper place to store connnection info (thinking of DSN)
const doCreate = () => {
+ state.creating = true;
store
.dispatch("instance/createInstance", state.instance)
.then((createdInstance) => {
+ state.creating = false;
emit("dismiss");
router.push(`/instance/${instanceSlug(createdInstance)}`);
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 631a76abc1..b98c080cbd 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -17,6 +17,7 @@ import {
BBNotification,
BBOutline,
BBSelect,
+ BBSpin,
BBStepBar,
BBStepTab,
BBSwitch,
@@ -170,6 +171,7 @@ Promise.all([
.component("BBModal", BBModal)
.component("BBNotification", BBNotification)
.component("BBOutline", BBOutline)
+ .component("BBSpin", BBSpin)
.component("BBSelect", BBSelect)
.component("BBStepBar", BBStepBar)
.component("BBStepTab", BBStepTab)
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 76c423824b..d89e78500f 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -20,6 +20,9 @@ import {
} from "../../types";
import { InstanceUser } from "../../types/InstanceUser";
+// Create migration schema might take a while (e.g TiDB)
+const CREATE_MIGRATION_SCHEMA_TIMEOUT = 30000;
+
function convert(
instance: ResourceObject,
includedList: ResourceObject[],
@@ -190,12 +193,18 @@ const actions = {
newInstance: InstanceCreate
) {
const data = (
- await axios.post(`/api/instance`, {
- data: {
- type: "InstanceCreate",
- attributes: newInstance,
+ await axios.post(
+ `/api/instance`,
+ {
+ data: {
+ type: "InstanceCreate",
+ attributes: newInstance,
+ },
},
- })
+ {
+ timeout: CREATE_MIGRATION_SCHEMA_TIMEOUT,
+ }
+ )
).data;
const createdInstance = convert(data.data, data.included, rootGetters);
@@ -278,8 +287,11 @@ const actions = {
{ rootGetters }: any,
instanceId: InstanceId
): Promise<SqlResultSet> {
- const data = (await axios.post(`/api/instance/${instanceId}/migration`))
- .data.data;
+ const data = (
+ await axios.post(`/api/instance/${instanceId}/migration`, undefined, {
+ timeout: CREATE_MIGRATION_SCHEMA_TIMEOUT,
+ })
+ ).data.data;
return rootGetters["sql/convert"](data);
},