Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Extract EnvironmentTabFilter
Tianzhou Chen8ce30ab4e20f
diff --git a/frontend/src/bbkit/BBTable/BBTableTabFilter.vue b/frontend/src/bbkit/BBTable/BBTableTabFilter.vueindex d9f8708e52..94840ac39c 100644--- a/frontend/src/bbkit/BBTable/BBTableTabFilter.vue+++ b/frontend/src/bbkit/BBTable/BBTableTabFilter.vue@@ -12,40 +12,40 @@"><option- v-for="(item, index) in itemList"+ v-for="(item, index) in tabList":key="index":value="index":selected="index == selectedIndex">- {{ item.title }}+ {{ item }}</option></select></div><div class="hidden sm:block"><div class="flex space-x-4" aria-label="Tabs"><button- v-for="(item, index) in itemList"+ v-for="(item, index) in tabList":key="index"class="px-3 py-1 rounded-md text-normal-text font-normal text-sm focus:outline-none":class="buttonClass(index == selectedIndex)"@click.prevent="$emit('select-index', index)">- {{ item.title }}+ {{ item }}</button></div></div></template><script lang="ts">-import { computed, reactive } from "vue";+import { PropType } from "vue";export default {name: "BBTableTabFilter",emits: ["select-index"],props: {- itemList: {+ tabList: {required: true,- type: Array,+ type: Object as PropType<String[]>,},selectedIndex: {required: true,diff --git a/frontend/src/components/EnvironmentTabFilter.vue b/frontend/src/components/EnvironmentTabFilter.vuenew file mode 100644index 0000000000..45ec09a9d5--- /dev/null+++ b/frontend/src/components/EnvironmentTabFilter.vue@@ -0,0 +1,67 @@+<template>+ <BBTableTabFilter+ :tabList="state.tabList"+ :selectedIndex="state.selectedIndex"+ @select-index="+ (index) => {+ state.selectedIndex = index;+ $emit(+ 'select-environment',+ index == 0 ? null : state.environmentList[index - 1]+ );+ }+ "+ />+</template>++<script lang="ts">+import { watchEffect, reactive } from "vue";+import { useStore } from "vuex";+import { Environment } from "../types";++interface LocalState {+ environmentList: Environment[];+ tabList: string[];+ selectedIndex: number;+}++export default {+ name: "EnvironmentTabFilter",+ emits: ["select-environment"],+ components: {},+ props: {},+ setup(props, ctx) {+ const state = reactive<LocalState>({+ environmentList: [],+ tabList: [],+ selectedIndex: 0,+ });+ const store = useStore();++ const prepareEnvironmentList = () => {+ store+ .dispatch("environment/fetchEnvironmentList")+ .then((list: Environment[]) => {+ // Usually env is ordered by ascending importantance, thus we rervese the order to put+ // more important ones first.+ state.environmentList = list.reverse();+ state.tabList = [+ "All",+ ...list.map((environment) => {+ return environment.attributes.name;+ }),+ ];+ })+ .catch((error) => {+ console.log(error);+ });+ };++ watchEffect(prepareEnvironmentList);++ return {+ state,+ };+ },+};+</script>diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex fa24ce7ca3..4b563b95b1 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -4,11 +4,7 @@<QuickActionPanel /></div><div class="px-2 py-1 border-t">- <BBTableTabFilter- :itemList="state.environmentFilterList"- :selectedIndex="state.selectedFilterIndex"- @select-index="selectFilter"- />+ <EnvironmentTabFilter @select-environment="selectEnvironment" /></div><PipelineTable:pipelineSectionList="[@@ -36,31 +32,26 @@</template><script lang="ts">-import { watchEffect, computed, inject, reactive, PropType } from "vue";+import { watchEffect, inject, reactive } from "vue";+import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import PipelineTable from "../components/PipelineTable.vue";import QuickActionPanel from "../components/QuickActionPanel.vue";import { useStore } from "vuex";import { useRouter } from "vue-router";import { UserStateSymbol } from "../components/ProvideUser.vue";import { User, Environment, Pipeline } from "../types";-import environment from "../store/modules/environment";--interface EnvironmentFilter {- id: string;- title: string;-}interface LocalState {attentionList: Pipeline[];subscribeList: Pipeline[];closeList: Pipeline[];- environmentFilterList: EnvironmentFilter[];- selectedFilterIndex: number;+ selectedEnvironment?: Environment;}export default {name: "Home",components: {+ EnvironmentTabFilter,PipelineTable,QuickActionPanel,},@@ -70,8 +61,6 @@ export default {attentionList: [],subscribeList: [],closeList: [],- environmentFilterList: [],- selectedFilterIndex: 0,});const store = useStore();const router = useRouter();@@ -113,57 +102,28 @@ export default {});};- const prepareEnvironmentList = () => {- store- .dispatch("environment/fetchEnvironmentList")- .then((list: Environment[]) => {- state.environmentFilterList = [- {- id: "",- title: "All",- },- ...list- .map((environment) => {- return {- id: environment.id,- title: environment.attributes.name,- };- })- // Usually env is ordered by ascending importantance, thus we rervese the order to put- // more important ones first.- .reverse(),- ];- })- .catch((error) => {- console.log(error);- });- };-- const selectFilter = (index: number) => {- state.selectedFilterIndex = index;+ const selectEnvironment = (environment: Environment) => {+ state.selectedEnvironment = environment;};const filteredList = (list: Pipeline[]) => {- if (state.selectedFilterIndex == 0) {+ if (!state.selectedEnvironment) {// Select "All"return list;}return list.filter((pipeline) => {return (- pipeline.attributes.currentStageId ==- state.environmentFilterList[state.selectedFilterIndex].id+ pipeline.attributes.currentStageId == state.selectedEnvironment!.id);});};watchEffect(preparePipelineList);- watchEffect(prepareEnvironmentList);-return {state,filteredList,- selectFilter,+ selectEnvironment,};},};diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vueindex 8524a228b5..3b273c6155 100644--- a/frontend/src/views/InstanceDashboard.vue+++ b/frontend/src/views/InstanceDashboard.vue@@ -4,49 +4,37 @@<QuickActionPanel /></div><div class="px-2 py-1 border-t">- <BBTableTabFilter- :itemList="state.environmentFilterList"- :selectedIndex="state.selectedFilterIndex"- @select-index="selectFilter"- />+ <EnvironmentTabFilter @select-environment="selectEnvironment" /></div><InstanceTable :instanceList="filteredList(state.instanceList)" /></div></template><script lang="ts">-import { watchEffect, computed, reactive, PropType } from "vue";+import { watchEffect, reactive } from "vue";+import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import InstanceTable from "../components/InstanceTable.vue";import QuickActionPanel from "../components/QuickActionPanel.vue";import { useStore } from "vuex";-import { useRouter } from "vue-router";import { Environment, Instance } from "../types";-interface EnvironmentFilter {- id: string;- title: string;-}-interface LocalState {instanceList: Instance[];- environmentFilterList: EnvironmentFilter[];- selectedFilterIndex: number;+ selectedEnvironment?: Environment;}export default {name: "InstanceDashboard",components: {+ EnvironmentTabFilter,InstanceTable,QuickActionPanel,},setup(props, ctx) {const state = reactive<LocalState>({instanceList: [],- environmentFilterList: [],- selectedFilterIndex: 0,});const store = useStore();- const router = useRouter();const prepareInstanceList = () => {store@@ -59,57 +47,29 @@ export default {});};- const prepareEnvironmentList = () => {- store- .dispatch("environment/fetchEnvironmentList")- .then((list: Environment[]) => {- state.environmentFilterList = [- {- id: "",- title: "All",- },- ...list- .map((environment) => {- return {- id: environment.id,- title: environment.attributes.name,- };- })- // Usually env is ordered by ascending importantance, thus we rervese the order to put- // more important ones first.- .reverse(),- ];- })- .catch((error) => {- console.log(error);- });- };-- const selectFilter = (index: number) => {- state.selectedFilterIndex = index;+ const selectEnvironment = (environment: Environment) => {+ state.selectedEnvironment = environment;};const filteredList = (list: Instance[]) => {- if (state.selectedFilterIndex == 0) {+ if (!state.selectedEnvironment) {// Select "All"return list;}return list.filter((instance) => {return (instance.attributes.environmentName ==- state.environmentFilterList[state.selectedFilterIndex].title+ state.selectedEnvironment!.attributes.name);});};watchEffect(prepareInstanceList);- watchEffect(prepareEnvironmentList);-return {state,filteredList,- selectFilter,+ selectEnvironment,};},};