Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
UI support for environment reorder
Tianzhou Chen2a23be4e62f9
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex 10c5605dd8..2107d42db8 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -177,20 +177,94 @@</button><h3 class="mt-1 text-center text-base font-normal text-accent">Ticket</h3></div>++ <div+ v-if="quickActionList.includes('environment.add')"+ class="flex flex-col items-center w-28"+ >+ <button class="btn-icon">+ <span+ class="inline-flex items-center justify-center p-3 bg-blue-600 hover:bg-blue-700 rounded-full"+ @click.prevent="addEnvironment"+ >+ <svg+ class="w-6 h-6 text-white"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M12 6v6m0 0v6m0-6h6m-6 0H6"+ ></path>+ </svg>+ </span>+ </button>+ <h3 class="mt-1 text-center text-base font-normal text-accent">New</h3>+ </div>++ <div+ v-if="quickActionList.includes('environment.reorder')"+ class="flex flex-col items-center w-28"+ >+ <button class="btn-icon">+ <span+ class="inline-flex items-center justify-center p-3 bg-blue-600 hover:bg-blue-700 rounded-full"+ @click.prevent="reorderEnvironment"+ >+ <svg+ class="transform rotate-90 w-6 h-6 text-white"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M8 9l4-4 4 4m0 6l-4 4-4-4"+ ></path>+ </svg>+ </span>+ </button>+ <h3 class="mt-1 text-center text-base font-normal text-accent">+ Reorder+ </h3>+ </div></div></template><script lang="ts">import { PropType } from "vue";+import { useStore } from "vuex";export default {name: "QuickActionPanel",- setup() {},props: {quickActionList: {required: true,type: Object as PropType<String[]>,},},+ setup() {+ const store = useStore();++ const addEnvironment = () => {+ store.dispatch("command/dispatchCommand", "bytebase.environment.add");+ };++ const reorderEnvironment = () => {+ store.dispatch("command/dispatchCommand", "bytebase.environment.reorder");+ };++ return {+ addEnvironment,+ reorderEnvironment,+ };+ },};</script>diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 4641291c95..c44bf00ef8 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -198,7 +198,10 @@ const routes: Array<RouteRecordRaw> = [{path: "environment",name: "workspace.environment",- meta: { title: () => "Environment" },+ meta: {+ title: () => "Environment",+ quickActionList: ["environment.add", "environment.reorder"],+ },components: {content: defineAsyncComponent(() => import("../views/EnvironmentDashboard.vue")diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vueindex 0398c2387b..aa5e4e7d91 100644--- a/frontend/src/views/EnvironmentDashboard.vue+++ b/frontend/src/views/EnvironmentDashboard.vue@@ -1,20 +1,36 @@<template><div><BBTab- :itemList="tabItemList"- :selectedId="state.selectedId"- allowReorder- @create-item="createEnvironment"- @reorder-item="redorderEnvironment"- @select-item="selectEnvironment"+ :tabTitleList="tabTitleList"+ :selectedIndex="state.selectedIndex"+ :reorderModel="state.reorder ? 'ALWAYS' : 'NEVER'"+ @reorder-index="reorderEnvironment"+ @select-index="selectEnvironment"><BBTabPanel- v-for="item in environmentList"+ v-for="(item, index) in environmentList":key="item.id":id="item.id"- :active="item.id == state.selectedId"+ :active="index == state.selectedIndex">- <EnvironmentDetail :environment="item" @delete="deleteEnvironment" />+ <div v-if="state.reorder" class="flex justify-center pt-5">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="discardReorder"+ >+ Cancel+ </button>+ <button+ type="submit"+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"+ :disabled="!orderChanged"+ @click.prevent="doReorder"+ >+ Apply new order+ </button>+ </div>+ <EnvironmentDetail v-else :environment="item" @delete="doDelete" /></BBTabPanel></BBTab></div>@@ -25,22 +41,25 @@><EnvironmentForm:create="true"- @submit="tryCreate"+ @submit="doCreate"@cancel="state.showCreateModal = false"/></BBModal></template><script lang="ts">-import { watchEffect, computed, inject, reactive, readonly } from "vue";+import { onMounted, onUnmounted, watchEffect, computed, reactive } from "vue";import { useStore } from "vuex";+import { array_swap } from "../utils";import EnvironmentForm from "../components/EnvironmentForm.vue";import EnvironmentDetail from "../views/EnvironmentDetail.vue";import { Environment, NewEnvironment } from "../types";interface LocalState {- selectedId: string;+ reorderedEnvironmentList: Environment[];+ selectedIndex: number;showCreateModal: boolean;+ reorder: boolean;}export default {@@ -54,8 +73,38 @@ export default {const store = useStore();const state = reactive<LocalState>({- selectedId: "",+ reorderedEnvironmentList: [],+ selectedIndex: -1,showCreateModal: false,+ reorder: false,+ });++ onMounted(() => {+ store.dispatch("command/registerCommand", {+ id: "bytebase.environment.add",+ registerId: "environment.dashboard",+ run: () => {+ createEnvironment();+ },+ });+ store.dispatch("command/registerCommand", {+ id: "bytebase.environment.reorder",+ registerId: "environment.dashboard",+ run: () => {+ startReorder();+ },+ });+ });++ onUnmounted(() => {+ store.dispatch("command/unregisterCommand", {+ id: "bytebase.environment.add",+ registerId: "environment.dashboard",+ });+ store.dispatch("command/unregisterCommand", {+ id: "bytebase.environment.reorder",+ registerId: "environment.dashboard",+ });});const prepareEnvironmentList = () => {@@ -63,7 +112,7 @@ export default {.dispatch("environment/fetchEnvironmentList").then((list) => {if (list.length > 0) {- selectEnvironment(list[0].id);+ selectEnvironment(0);}}).catch((error) => {@@ -77,54 +126,90 @@ export default {return store.getters["environment/environmentList"]();});- const tabItemList = computed(() => {+ const tabTitleList = computed(() => {if (environmentList.value) {- return environmentList.value?.map((item: Environment) => ({- id: item.id,- name: item.attributes.name,- }));+ if (state.reorder) {+ return state.reorderedEnvironmentList.map(+ (item: Environment) => item.attributes.name+ );+ }+ return environmentList.value.map(+ (item: Environment) => item.attributes.name+ );}- return new Array();+ return [];});- const tryCreate = (newEnvironment: NewEnvironment) => {+ const createEnvironment = () => {+ stopReorder();+ state.showCreateModal = true;+ };++ const doCreate = (newEnvironment: NewEnvironment) => {store.dispatch("environment/createEnvironment", {newEnvironment,}).then((createdEnvironment) => {state.showCreateModal = false;- selectEnvironment(createdEnvironment.id);+ selectEnvironment(environmentList.value.length - 1);}).catch((error) => {console.log(error);});};- const createEnvironment = () => {- state.showCreateModal = true;+ const startReorder = () => {+ state.reorderedEnvironmentList = [...environmentList.value];+ state.reorder = true;};- const redorderEnvironment = (sourceIndex: number, targetIndex: number) => {+ const stopReorder = () => {+ state.reorder = false;+ state.reorderedEnvironmentList = [];+ };++ const reorderEnvironment = (sourceIndex: number, targetIndex: number) => {+ array_swap(state.reorderedEnvironmentList, sourceIndex, targetIndex);+ };++ const orderChanged = computed(() => {+ for (let i = 0; i < state.reorderedEnvironmentList.length; i++) {+ if (+ state.reorderedEnvironmentList[i].id != environmentList.value[i].id+ ) {+ return true;+ }+ }+ return false;+ });++ const discardReorder = () => {+ stopReorder();+ };++ const doReorder = () => {store- .dispatch("environment/reorderEnvironmentList", {- sourceIndex,- targetIndex,+ .dispatch(+ "environment/reorderEnvironmentList",+ state.reorderedEnvironmentList+ )+ .then(() => {+ stopReorder();})- .then((list) => {}).catch((error) => {console.log(error);});};- const deleteEnvironment = (environment: Environment) => {+ const doDelete = (environment: Environment) => {store.dispatch("environment/deleteEnvironmentById", {id: environment.id,}).then(() => {- if (tabItemList.value.length > 0) {- selectEnvironment(tabItemList.value[0].id);+ if (environmentList.value.length > 0) {+ selectEnvironment(0);}}).catch((error) => {@@ -132,8 +217,8 @@ export default {});};- const selectEnvironment = (id: string) => {- state.selectedId = id;+ const selectEnvironment = (index: number) => {+ state.selectedIndex = index;};const tabClass = computed(() => "w-1/" + environmentList.value.length);@@ -141,11 +226,14 @@ export default {return {state,environmentList,- tabItemList,- tryCreate,+ tabTitleList,createEnvironment,- redorderEnvironment,- deleteEnvironment,+ doCreate,+ reorderEnvironment,+ orderChanged,+ discardReorder,+ doReorder,+ doDelete,selectEnvironment,tabClass,};