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(tenancy): label group-by selector UI updated (#398)
Liu Ji60b508e6ecc1
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vueindex 7c959f3c0a..ecf84e0bc1 100644--- a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue@@ -34,41 +34,48 @@</template></i18n-t></div>- <NCollapse- v-else- display-directive="if"- accordion- :expanded-names="state.selectedDatabaseName"- @update:expanded-names="- (names) => (state.selectedDatabaseName = names[0])- "- >- <NCollapseItem- v-for="{ name, list } in databaseListGroupByName"- :key="name"- :title="name"- :name="name"+ <template v-else>+ <YAxisRadioGroup+ v-model:label="label"+ :label-list="labelList"+ class="text-sm pt-2 pb-1"+ />+ <NCollapse+ display-directive="if"+ accordion+ :expanded-names="state.selectedDatabaseName"+ @update:expanded-names="+ (names) => (state.selectedDatabaseName = names[0])+ ">- <template #header>- <span class="text-base">{{ name }}</span>- <span v-if="name === state.selectedDatabaseName">- <heroicons-outline:check class="w-5 h-5 ml-2 text-success" />- </span>- </template>- <template #header-extra>- <span class="text-control-placeholder">- {{ $t("deployment-config.n-databases", list.length) }}- </span>- </template>-- <DeployDatabaseTable- :database-list="list"- :label-list="labelList"- :environment-list="environmentList"- :deployment="deployment!"- />- </NCollapseItem>- </NCollapse>+ <NCollapseItem+ v-for="{ name, list } in databaseListGroupByName"+ :key="name"+ :title="name"+ :name="name"+ >+ <template #header>+ <span class="text-base">{{ name }}</span>+ <span v-if="name === state.selectedDatabaseName">+ <heroicons-outline:check class="w-5 h-5 ml-2 text-success" />+ </span>+ </template>+ <template #header-extra>+ <span class="text-control-placeholder">+ {{ $t("deployment-config.n-databases", list.length) }}+ </span>+ </template>++ <DeployDatabaseTable+ :database-list="list"+ :label="label"+ :label-list="labelList"+ :environment-list="environmentList"+ :deployment="deployment!"+ />+ </NCollapseItem>+ </NCollapse>+ </template></template></template></div>@@ -77,13 +84,21 @@<script lang="ts" setup>/* eslint-disable vue/no-mutating-props */-import { computed, defineProps, defineEmits, watchEffect, watch } from "vue";+import {+ computed,+ defineProps,+ defineEmits,+ watchEffect,+ watch,+ ref,+} from "vue";import { useStore } from "vuex";import {Database,DeploymentConfig,Environment,Label,+ LabelKeyType,Project,UNKNOWN_ID,} from "../../types";@@ -120,6 +135,7 @@ const fetchData = () => {watchEffect(fetchData);+const label = ref<LabelKeyType>("bb.environment");const labelList = computed(() => store.getters["label/labelList"]() as Label[]);const deployment = computed(() => {diff --git a/frontend/src/components/DatabaseLabels/DatabaseLabel.vue b/frontend/src/components/DatabaseLabels/DatabaseLabel.vueindex 35b21fd6d1..87297a4b66 100644--- a/frontend/src/components/DatabaseLabels/DatabaseLabel.vue+++ b/frontend/src/components/DatabaseLabels/DatabaseLabel.vue@@ -2,13 +2,14 @@<!-- eslint-disable vue/no-mutating-props --><div class="database-label" :class="{ editable }"><div class="select key">- <span>{{ hidePrefix(label.key) }}</span>+ <span class="capitalize">{{ hidePrefix(label.key) }}</span><span v-if="editable" class="dropdown-icon"><heroicons-solid:selector class="h-4 w-4 text-control-light" /></span><select v-if="editable" v-model="label.key"><option v-for="(key, i) in keys" :key="i" :value="key">- {{ hidePrefix(key) }}+ <!-- not available to use <span class="capitalize"> here -->+ {{ capitalize(hidePrefix(key)) }}</option></select></div>@@ -36,6 +37,7 @@import { computed, defineComponent, PropType, watch } from "vue";import { DatabaseLabel, Label } from "../../types";import { hidePrefix } from "../../utils";+import { capitalize } from "lodash-es";export default defineComponent({name: "DatabaseLabel",@@ -84,6 +86,7 @@ export default defineComponent({keys,values,hidePrefix,+ capitalize,};},});diff --git a/frontend/src/components/DeploymentConfigTool/LabelSelect.vue b/frontend/src/components/DeploymentConfigTool/LabelSelect.vueindex b9c6f0470b..0e61320d24 100644--- a/frontend/src/components/DeploymentConfigTool/LabelSelect.vue+++ b/frontend/src/components/DeploymentConfigTool/LabelSelect.vue@@ -8,7 +8,9 @@<template v-if="Array.isArray(state.value)"><ResponsiveTags :tags="state.value" /></template>- <span v-else>{{ modifier(state.value) }}</span>+ <span v-else :class="{ capitalize }">+ {{ modifier(state.value) }}+ </span></slot></template><template v-else>@@ -61,7 +63,7 @@class="flex items-center text-main hover:text-main-text hover:bg-main-hover cursor-default select-none relative py-2 px-3"@click="toggleSelection(item)">- <span class="flex-1">+ <span class="flex-1" :class="{ capitalize }">{{ modifier(item) }}</span><span@@ -128,6 +130,10 @@ export default defineComponent({type: Function as PropType<(str: string) => string>,default: (str: string) => str,},+ capitalize: {+ type: Boolean,+ default: false,+ },},emits: ["update:value"],setup(props, { emit }) {diff --git a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue b/frontend/src/components/DeploymentConfigTool/SelectorItem.vueindex 22eb5ba708..083a61d06e 100644--- a/frontend/src/components/DeploymentConfigTool/SelectorItem.vue+++ b/frontend/src/components/DeploymentConfigTool/SelectorItem.vue@@ -6,6 +6,7 @@:options="keys":disabled="!editable":modifier="hidePrefix"+ :capitalize="true"class="select key"/><LabelSelectdiff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vueindex 87c22bd75c..d26863c168 100644--- a/frontend/src/components/ProjectOverviewPanel.vue+++ b/frontend/src/components/ProjectOverviewPanel.vue@@ -44,12 +44,27 @@:style="`INFO`":title="$t('project.overview.info-slot-content')"/>++ <YAxisRadioGroup+ v-if="isTenantProject && state.yAxisLabel"+ v-model:label="state.yAxisLabel"+ :label-list="selectableLabelList"+ class="text-sm font-normal py-1"+ />+<template v-if="databaseList.length > 0">- <TenantDatabaseTable- v-if="isTenantProject"- :database-list="databaseList"- :filter="state.databaseNameFilter"- />+ <template v-if="isTenantProject">+ <TenantDatabaseTable+ v-if="state.yAxisLabel"+ :database-list="filteredDatabaseList"+ :x-axis-label="state.xAxisLabel"+ :y-axis-label="state.yAxisLabel"+ :label-list="labelList"+ />+ <div v-else class="w-full h-40 flex justify-center items-center">+ <NSpin />+ </div>+ </template><DatabaseTable v-else :mode="'PROJECT'" :database-list="databaseList" /></template><div v-else class="text-center textinfolabel">@@ -106,7 +121,7 @@ import {import { useStore } from "vuex";import ActivityTable from "../components/ActivityTable.vue";import DatabaseTable from "../components/DatabaseTable.vue";-import TenantDatabaseTable from "./TenantDatabaseTable";+import TenantDatabaseTable, { YAxisRadioGroup } from "./TenantDatabaseTable";import { IssueTable } from "../components/Issue";import {Activity,@@ -114,7 +129,11 @@ import {Issue,Project,DEFAULT_PROJECT_ID,+ Label,+ LabelKeyType,} from "../types";+import { findDefaultGroupByLabel } from "../utils";+import { NSpin } from "naive-ui";// Show at most 5 activityconst ACTIVITY_LIMIT = 5;@@ -124,6 +143,8 @@ interface LocalState {progressIssueList: Issue[];closedIssueList: Issue[];databaseNameFilter: string;+ xAxisLabel: LabelKeyType;+ yAxisLabel: LabelKeyType | undefined;}export default defineComponent({@@ -133,6 +154,8 @@ export default defineComponent({DatabaseTable,TenantDatabaseTable,IssueTable,+ YAxisRadioGroup,+ NSpin,},props: {project: {@@ -152,6 +175,8 @@ export default defineComponent({progressIssueList: [],closedIssueList: [],databaseNameFilter: "",+ xAxisLabel: "bb.environment",+ yAxisLabel: undefined,});const prepareActivityList = () => {@@ -165,8 +190,6 @@ export default defineComponent({});};- watchEffect(prepareActivityList);-const prepareIssueList = () => {store.dispatch("issue/fetchIssueList", {@@ -188,16 +211,56 @@ export default defineComponent({});};- watchEffect(prepareIssueList);-const isTenantProject = computed((): boolean => {return props.project.tenantMode === "TENANT";});+ const prepareLabelList = () => {+ if (!isTenantProject.value) return;+ store.dispatch("label/fetchLabelList");+ };++ const prepare = () => {+ prepareActivityList();+ prepareIssueList();+ prepareLabelList();+ };++ watchEffect(prepare);++ const labelList = computed(+ () => store.getters["label/labelList"]() as Label[]+ );++ const filteredDatabaseList = computed(() => {+ const filter = state.databaseNameFilter.toLocaleLowerCase();+ if (!filter) return props.databaseList;++ return props.databaseList.filter((database) =>+ database.name.toLowerCase().includes(filter)+ );+ });++ // make "bb.environment" non-selectable because it was already specified to the x-axis+ const selectableLabelList = computed(() => {+ const excludes = new Set([state.xAxisLabel]);+ return labelList.value.filter((label) => !excludes.has(label.key));+ });++ watchEffect(() => {+ state.yAxisLabel = findDefaultGroupByLabel(+ selectableLabelList.value,+ filteredDatabaseList.value+ );+ });+return {DEFAULT_PROJECT_ID,state,isTenantProject,+ filteredDatabaseList,+ labelList,+ selectableLabelList,};},});diff --git a/frontend/src/components/TenantDatabaseTable/DatabaseMatrix.vue b/frontend/src/components/TenantDatabaseTable/DatabaseMatrix.vueindex bffbc6120c..67d8b27f2b 100644--- a/frontend/src/components/TenantDatabaseTable/DatabaseMatrix.vue+++ b/frontend/src/components/TenantDatabaseTable/DatabaseMatrix.vue@@ -15,12 +15,8 @@><template #header><tr>- <BBTableHeaderCell compact class="w-1/12 pl-3 pr-2">- <YAxisSwitch- v-if="yAxisLabel"- v-model:label="yAxisLabel"- :label-list="selectableLabelList"- />+ <BBTableHeaderCell compact class="w-1/12 pl-4 pr-2 capitalize">+ {{ hidePrefix(yAxisLabel) }}</BBTableHeaderCell><BBTableHeaderCell@@ -75,8 +71,7 @@ import {} from "../../types";import DatabaseMatrixItem from "./DatabaseMatrixItem.vue";import { groupBy } from "lodash-es";-import { findDefaultGroupByLabel, getLabelValue } from "../../utils";-import YAxisSwitch from "./YAxisSwitch.vue";+import { hidePrefix, getLabelValue } from "../../utils";type DatabaseMatrix = {labelValue: LabelValueType;@@ -85,7 +80,7 @@ type DatabaseMatrix = {export default defineComponent({name: "TenantDatabaseMatrix",- components: { DatabaseMatrixItem, YAxisSwitch },+ components: { DatabaseMatrixItem },props: {bordered: {default: true,@@ -115,37 +110,26 @@ export default defineComponent({type: Array as PropType<Label[]>,required: true,},+ xAxisLabel: {+ type: String as PropType<LabelKeyType>,+ required: true,+ },+ yAxisLabel: {+ type: String as PropType<LabelKeyType>,+ required: true,+ },},emits: ["select-database"],setup(props) {- // make "bb.environment" non-selectable because it was already specified to the x-axis- const selectableLabelList = computed(() => {- const excludes = new Set(["bb.environment"]);- return props.labelList.filter((label) => !excludes.has(label.key));- });-/*** databases are grouped by `yAxisLabel` then by `xAxisLabel`* for now, `xAxisLabel` will always be 'bb.environment'*/- const yAxisLabel = ref<LabelKeyType>();- const xAxisLabel = ref<LabelKeyType>("bb.environment");-const filteredXAxisValueList = ref<LabelValueType[]>([]);const filteredMatrixList = ref<DatabaseMatrix[]>([]);-- // find the default label key to firstBy (y-axis)- watchEffect(() => {- // "bb.environment" is excluded because it was specified to the x-axis- yAxisLabel.value = findDefaultGroupByLabel(- selectableLabelList.value,- props.databaseList- );- });-// pre-filtered y-axis valuesconst yAxisValueList = computed((): string[] => {- const key = yAxisLabel.value;+ const key = props.yAxisLabel;if (!key) {// y-axis is undefinedreturn [];@@ -162,7 +146,7 @@ export default defineComponent({const xAxisValueList = computed(() => {// order based on label.valueList// plus one more "<empty value>"- const key = xAxisLabel.value;+ const key = props.xAxisLabel;const label = props.labelList.find((label) => label.key === key);if (!label) return [];return [...label.valueList, ""];@@ -170,7 +154,7 @@ export default defineComponent({// first, group databases by `yAxisLabel` into some rowsconst groupedRowList = computed(() => {- const key = yAxisLabel.value;+ const key = props.yAxisLabel;if (!key) {// y-axis is undefinedreturn [];@@ -188,7 +172,7 @@ export default defineComponent({// then, group each row by `xAxisLabel` into some columns// now the `matrices` is pre-filtered (with empty rows or columns)const matrixList = computed((): DatabaseMatrix[] => {- const key = xAxisLabel.value;+ const key = props.xAxisLabel;return groupedRowList.value.map(({ labelValue: yValue, databaseList }) => {const databaseMatrix: Database[][] = xAxisValueList.value.map(@@ -245,8 +229,7 @@ export default defineComponent({});return {- selectableLabelList,- yAxisLabel,+ hidePrefix,yAxisValueList,xAxisValueList,filteredXAxisValueList,diff --git a/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue b/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vueindex adb11cdd56..3c721ed428 100644--- a/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue+++ b/frontend/src/components/TenantDatabaseTable/DeployDatabaseTable.vue@@ -8,8 +8,8 @@><template #header><tr>- <BBTableHeaderCell compact class="w-1/12 pl-3 pr-2">- <YAxisSwitch v-model:label="state.label" :label-list="labelList" />+ <BBTableHeaderCell compact class="w-1/12 pl-3 pr-2 capitalize">+ {{ hidePrefix(label) }}</BBTableHeaderCell><BBTableHeaderCell@@ -101,21 +101,26 @@<script lang="ts" setup>import { groupBy } from "lodash-es";-import { computed, defineProps, reactive, withDefaults } from "vue";+import { computed, defineProps, withDefaults } from "vue";import type {Database,DeploymentConfig,Environment,Label,+ LabelKeyType,} from "../../types";-import { getLabelValue, getPipelineFromDeploymentSchedule } from "../../utils";+import {+ hidePrefix,+ getLabelValue,+ getPipelineFromDeploymentSchedule,+} from "../../utils";import { NPopover } from "naive-ui";import { DeploymentStage } from "../DeploymentConfigTool";-import YAxisSwitch from "./YAxisSwitch.vue";const props = withDefaults(defineProps<{databaseList: Database[];+ label: LabelKeyType;labelList: Label[];environmentList: Environment[];deployment: DeploymentConfig;@@ -128,14 +133,10 @@ const props = withDefaults(});-const state = reactive({- label: "bb.environment",-});-const yAxisValueList = computed(() => {// order based on label.valueList// plus one more "<empty value>"- const key = state.label;+ const key = props.label;const label = props.labelList.find((label) => label.key === key);if (!label) return [];return [...label.valueList, ""];@@ -147,7 +148,7 @@ const xAxisValueList = computed(() => {});const databaseGroupList = computed(() => {- const key = state.label;+ const key = props.label;const dict = groupBy(props.databaseList, (db) => getLabelValue(db, key));const rows = yAxisValueList.value.map((labelValue) => {const databaseList = dict[labelValue] || [];diff --git a/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue b/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vueindex 7b9c98961a..7054618d3e 100644--- a/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue+++ b/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue@@ -7,6 +7,8 @@:database-list="dbGroup.databaseList":environment-list="environmentList":label-list="labelList"+ :x-axis-label="xAxisLabel"+ :y-axis-label="yAxisLabel"/></div></template>@@ -14,7 +16,7 @@<script lang="ts">import { computed, defineComponent, PropType, watchEffect } from "vue";import { useStore } from "vuex";-import { Database, Environment, Label } from "../../types";+import { Database, Environment, Label, LabelKeyType } from "../../types";import { groupBy } from "lodash-es";import DatabaseMatrix from "./DatabaseMatrix.vue";@@ -41,13 +43,21 @@ export default defineComponent({default: false,type: Boolean,},+ labelList: {+ type: Array as PropType<Label[]>,+ required: true,+ },databaseList: {type: Object as PropType<Database[]>,required: true,},- filter: {- type: String,- default: "",+ xAxisLabel: {+ type: String as PropType<LabelKeyType>,+ required: true,+ },+ yAxisLabel: {+ type: String as PropType<LabelKeyType>,+ required: true,},},emits: ["select-database"],@@ -56,27 +66,15 @@ export default defineComponent({const prepareList = () => {store.dispatch("environment/fetchEnvironmentList");- store.dispatch("label/fetchLabelList");};watchEffect(prepareList);- const labelList = computed(- () => store.getters["label/labelList"]() as Label[]- );const environmentList = computed(() => store.getters["environment/environmentList"]() as Environment[]);- const filteredDatabaseList = computed(() => {- if (!props.filter) return props.databaseList;-- return props.databaseList.filter((database) =>- database.name.toLowerCase().includes(props.filter.toLowerCase())- );- });-const databaseListGroupByName = computed((): DatabaseGroupByName[] => {- const dict = groupBy(filteredDatabaseList.value, "name");+ const dict = groupBy(props.databaseList, "name");return Object.keys(dict).map((name) => ({name,databaseList: dict[name],@@ -84,7 +82,6 @@ export default defineComponent({});return {- labelList,environmentList,databaseListGroupByName,};diff --git a/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vuenew file mode 100644index 0000000000..a1b55d1491--- /dev/null+++ b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue@@ -0,0 +1,41 @@+<template>+ <div v-if="label" class="flex items-center space-x-2">+ <slot name="title">+ <label for="group-by">Group by</label>+ </slot>++ <label v-for="lbl in labelList" :key="lbl.key">+ <input+ type="radio"+ :value="lbl.key"+ :checked="lbl.key === label"+ @change="onChange"+ />+ <span class="capitalize ml-1">+ {{ hidePrefix(lbl.key) }}+ </span>+ </label>+ </div>+</template>++<script lang="ts" setup>+import { defineProps, defineEmits } from "vue";+import { Label, LabelKeyType } from "../../types";+import { hidePrefix } from "../../utils";++defineProps<{+ label: LabelKeyType;+ labelList: Label[];+}>();++const emit = defineEmits<{+ (event: "update:label", label: LabelKeyType): void;+}>();++const onChange = (e: Event) => {+ const target = e.target as HTMLInputElement;+ if (target.checked) {+ emit("update:label", target.value);+ }+};+</script>diff --git a/frontend/src/components/TenantDatabaseTable/YAxisSwitch.vue b/frontend/src/components/TenantDatabaseTable/YAxisSwitch.vuedeleted file mode 100644index e10866d953..0000000000--- a/frontend/src/components/TenantDatabaseTable/YAxisSwitch.vue+++ /dev/null@@ -1,46 +0,0 @@-<template>- <div- class="pl-1 py-1 relative rounded inline-flex items-center hover:bg-control-bg-hover cursor-pointer select-none"- @click="switchValue"- >- <span>{{ hidePrefix(label) }}</span>- <heroicons-solid:selector class="h-4 w-4 text-control-light" />- <select- v-if="labelList.length > 2"- :value="label"- class="absolute w-full h-full inset-0 opacity-0"- @change="(e: any) => $emit('update:label', e.target.value)"- >- <option v-for="opt in labelList" :key="opt.key" :value="opt.key">- {{ hidePrefix(opt.key) }}- </option>- </select>- </div>-</template>--<script lang="ts" setup>-import { defineProps, defineEmits } from "vue";-import { Label, LabelKeyType } from "../../types";-import { hidePrefix } from "../../utils";--const props = defineProps<{- label: LabelKeyType;- labelList: Label[];-}>();--const emit = defineEmits<{- (event: "update:label", label: LabelKeyType): void;-}>();--const switchValue = () => {- const list = props.labelList;- if (list.length === 0) return;- if (list.length === 1) return;- if (list.length > 2) return;-- const index = list.findIndex((label) => label.key === props.label);- if (index < 0) return;- const next = (index + 1) % list.length;- emit("update:label", list[next].key);-};-</script>diff --git a/frontend/src/components/TenantDatabaseTable/index.ts b/frontend/src/components/TenantDatabaseTable/index.tsindex b00de02976..3478475d45 100644--- a/frontend/src/components/TenantDatabaseTable/index.ts+++ b/frontend/src/components/TenantDatabaseTable/index.ts@@ -1,7 +1,13 @@import TenantDatabaseTable from "./TenantDatabaseTable.vue";import DatabaseMatrix from "./DatabaseMatrix.vue";import DeployDatabaseTable from "./DeployDatabaseTable.vue";+import YAxisRadioGroup from "./YAxisRadioGroup.vue";export default TenantDatabaseTable;-export { TenantDatabaseTable, DatabaseMatrix, DeployDatabaseTable };+export {+ TenantDatabaseTable,+ DatabaseMatrix,+ DeployDatabaseTable,+ YAxisRadioGroup,+};diff --git a/frontend/src/views/SettingWorkspaceLabel.vue b/frontend/src/views/SettingWorkspaceLabel.vueindex afabd02c49..346b7a23da 100644--- a/frontend/src/views/SettingWorkspaceLabel.vue+++ b/frontend/src/views/SettingWorkspaceLabel.vue@@ -10,6 +10,10 @@><template #body="{ rowData: label }"><BBTableCell :left-padding="4" class="w-36 table-cell">+ <!-- will not capitalize label.key here due to it may be editable in the future -->+ <!-- capitalizing editable things may be confusing -->+ <!-- capitalizing only bb.prefixed things makes it inconsistent with others -->+ <!-- so just capitalize none of them -->{{ hidePrefix(label.key) }}</BBTableCell><BBTableCell class="whitespace-nowrap">