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(frontend): filter improvements (#5596)
Liu Ji321d245cf26f
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex 8e5b24fa4b..c9a9e14422 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -3,8 +3,7 @@<divclass="text-lg font-medium leading-7 text-main flex items-center justify-between">- <div class="flex items-center gap-x-6">- <h3>{{ $t("common.database") }}</h3>+ <div class="flex items-center"><EnvironmentTabFilter:environment="state.environment":include-all="true"@@ -16,6 +15,7 @@:instance="state.instance":include-all="true":filter="filterInstance"+ :environment="state.environment"@update:instance="state.instance = $event ?? UNKNOWN_ID"/><SearchBoxdiff --git a/frontend/src/components/v2/Form/SearchBox.vue b/frontend/src/components/v2/Form/SearchBox.vueindex 1c70660780..3fbb082006 100644--- a/frontend/src/components/v2/Form/SearchBox.vue+++ b/frontend/src/components/v2/Form/SearchBox.vue@@ -1,7 +1,8 @@<template><NInput+ ref="inputRef":value="value"- :clearable="true"+ :clearable="!!value":placeholder="placeholder"style="width: 12rem"@update:value="$emit('update:value', $event)"@@ -13,16 +14,18 @@</template><script lang="ts" setup>-import { computed, useAttrs } from "vue";+import { computed, onMounted, ref, useAttrs } from "vue";import { useI18n } from "vue-i18n";import { NInput } from "naive-ui";-withDefaults(+const props = withDefaults(defineProps<{value?: string;+ autofocus?: boolean;}>(),{value: "",+ autofocus: false,});@@ -30,10 +33,17 @@ defineEmits<{(event: "update:value", value: string): void;}>();+const inputRef = ref<InstanceType<typeof NInput>>();const attrs = useAttrs();const { t } = useI18n();const placeholder = computed(() => {return (attrs.placeholder as string) ?? t("common.search");});++onMounted(() => {+ if (props.autofocus) {+ inputRef.value?.inputElRef?.focus();+ }+});</script>diff --git a/frontend/src/components/v2/Select/DatabaseSelect.vue b/frontend/src/components/v2/Select/DatabaseSelect.vueindex 6f4f0543fe..25eb211787 100644--- a/frontend/src/components/v2/Select/DatabaseSelect.vue+++ b/frontend/src/components/v2/Select/DatabaseSelect.vue@@ -4,6 +4,8 @@:options="options":placeholder="$t('database.select')":virtual-scroll="true"+ :filter="filterByName"+ :filterable="true"style="width: 12rem"@update:value="$emit('update:database', $event)"/>@@ -28,6 +30,11 @@ import {unknown,} from "@/types";+interface DatabaseSelectOption extends SelectOption {+ value: DatabaseId;+ database: Database;+}+const props = withDefaults(defineProps<{database: DatabaseId | undefined;@@ -102,14 +109,20 @@ const combinedDatabaseList = computed(() => {});const options = computed(() => {- return combinedDatabaseList.value.map<SelectOption>((database) => {+ return combinedDatabaseList.value.map<DatabaseSelectOption>((database) => {return {+ database,value: database.id,label: database.name,};});});+const filterByName = (pattern: string, option: SelectOption) => {+ const { database } = option as DatabaseSelectOption;+ return database.name.toLowerCase().includes(pattern.toLowerCase());+};+// The database list might change if environment changes, and the previous selected id// might not exist in the new list. In such case, we need to invalidate the selection// and emit the event.diff --git a/frontend/src/components/v2/Select/InstanceSelect.vue b/frontend/src/components/v2/Select/InstanceSelect.vueindex 7a6748fa33..9037706c67 100644--- a/frontend/src/components/v2/Select/InstanceSelect.vue+++ b/frontend/src/components/v2/Select/InstanceSelect.vue@@ -3,6 +3,12 @@:value="instance":options="options":placeholder="$t('instance.select')"+ :render-label="renderLabel"+ :filter="filterByName"+ :filterable="true"+ :virtual-scroll="true"+ :fallback-option="false"+ class="bb-instance-select"style="width: 12rem"@update:value="$emit('update:instance', $event)"/>@@ -18,13 +24,18 @@ import {InstanceId,EnvironmentId,Instance,- UNKNOWN_ID,- unknown,EngineType,+ unknown,EngineTypeList,+ UNKNOWN_ID,} from "@/types";import InstanceEngineIcon from "@/components/InstanceEngineIcon.vue";+interface InstanceSelectOption extends SelectOption {+ value: InstanceId;+ instance: Instance;+}+const props = withDefaults(defineProps<{instance: InstanceId | undefined;@@ -92,28 +103,40 @@ const combinedInstanceList = computed(() => {return list;});+const renderLabel = (option: SelectOption) => {+ const { instance } = option as InstanceSelectOption;+ if (instance.id === UNKNOWN_ID) {+ return t("instance.all");+ }+ const icon = h(InstanceEngineIcon, {+ instance,+ class: "bb-instance-select--engine-icon shrink-0",+ });+ const text = h("span", {}, instance.name);+ return h(+ "div",+ {+ class: "flex items-center gap-x-2",+ },+ [icon, text]+ );+};+const options = computed(() => {- return combinedInstanceList.value.map<SelectOption>((instance) => {+ return combinedInstanceList.value.map<InstanceSelectOption>((instance) => {return {+ instance,value: instance.id,- label: () => {- if (instance.id === UNKNOWN_ID) {- return t("instance.all");- }- const icon = h(InstanceEngineIcon, { instance, class: "shrink-0" });- const text = h("span", {}, instance.name);- return h(- "div",- {- class: "flex items-center gap-x-2",- },- [icon, text]- );- },+ label: instance.name,};});});+const filterByName = (pattern: string, option: SelectOption) => {+ const { instance } = option as InstanceSelectOption;+ return instance.name.toLowerCase().includes(pattern.toLowerCase());+};+// The instance list might change if environment changes, and the previous selected id// might not exist in the new list. In such case, we need to reset the selection// and emit the event.@@ -131,3 +154,9 @@ watch([() => props.instance, combinedInstanceList], resetInvalidSelection, {immediate: true,});</script>++<style>+.bb-instance-select .n-base-selection--active .bb-instance-select--engine-icon {+ opacity: 0.3;+}+</style>diff --git a/frontend/src/components/v2/Select/PrincipalSelect.vue b/frontend/src/components/v2/Select/PrincipalSelect.vuenew file mode 100644index 0000000000..ce1147fd0e--- /dev/null+++ b/frontend/src/components/v2/Select/PrincipalSelect.vue@@ -0,0 +1,209 @@+<template>+ <NSelect+ :value="principal"+ :options="options"+ :filterable="true"+ :filter="filterByName"+ :virtual-scroll="true"+ :render-label="renderLabel"+ :fallback-option="false"+ :placeholder="$t('principal.select')"+ class="bb-principal-select"+ style="width: 12rem"+ @update:value="$emit('update:principal', $event)"+ />+</template>++<script lang="ts" setup>+import { computed, watch, watchEffect, h } from "vue";+import { NSelect, SelectOption } from "naive-ui";+import { useI18n } from "vue-i18n";+import UserIcon from "~icons/heroicons-outline/user";++import { useMemberStore, usePrincipalStore, useProjectStore } from "@/store";+import {+ Principal,+ PrincipalId,+ ProjectId,+ ProjectRoleType,+ RoleType,+ SYSTEM_BOT_ID,+ UNKNOWN_ID,+ unknown,+} from "@/types";+import PrincipalAvatar from "@/components/PrincipalAvatar.vue";++interface PrincipalSelectOption extends SelectOption {+ value: PrincipalId;+ principal: Principal;+}++const props = withDefaults(+ defineProps<{+ principal: PrincipalId | undefined;+ project?: ProjectId;+ includeAll?: boolean;+ includeSystemBot?: boolean;+ includeServiceAccount?: boolean;+ allowedRoleList?: RoleType[];+ allowedProjectMemberRoleList?: ProjectRoleType[];+ autoReset?: boolean;+ filter?: (principal: Principal, index: number) => boolean;+ }>(),+ {+ project: undefined,+ includeAll: false,+ includeSystemBot: false,+ includeServiceAccount: false,+ allowedRoleList: () => ["DEVELOPER", "DBA", "OWNER"],+ allowedProjectMemberRoleList: () => ["DEVELOPER", "OWNER"],+ autoReset: true,+ filter: undefined,+ }+);++const emit = defineEmits<{+ (event: "update:principal", value: PrincipalId | undefined): void;+}>();++const { t } = useI18n();+const projectStore = useProjectStore();+const memberStore = useMemberStore();+const principalStore = usePrincipalStore();++const prepare = () => {+ if (props.project && props.project !== UNKNOWN_ID) {+ projectStore.getOrFetchProjectById(props.project);+ } else {+ // Need not to fetch the entire member list since it's done in+ // root component+ }+};+watchEffect(prepare);++const getPrincipalListFromProject = (project: ProjectId) => {+ return projectStore+ .getProjectById(project)+ .memberList.filter((member) => {+ return props.allowedProjectMemberRoleList.includes(member.role);+ })+ .map((member) => member.principal);+};+const getPrincipalListFromWorkspace = () => {+ return memberStore.memberList+ .filter((member) => {+ return props.allowedRoleList.includes(member.role);+ })+ .map((member) => member.principal);+};++const rawPrincipalList = computed(() => {+ const list =+ props.project && props.project !== UNKNOWN_ID+ ? getPrincipalListFromProject(props.project)+ : getPrincipalListFromWorkspace();++ return list.filter((principal) => {+ if (principal.type === "SERVICE_ACCOUNT" && !props.includeServiceAccount) {+ return false;+ }++ return true;+ });+});++const combinedPrincipalList = computed(() => {+ let list = [...rawPrincipalList.value];++ if (props.filter) {+ list = list.filter(props.filter);+ }++ if (props.principal === SYSTEM_BOT_ID || props.includeSystemBot) {+ list.unshift(principalStore.principalById(SYSTEM_BOT_ID));+ }+ if (props.principal === UNKNOWN_ID || props.includeAll) {+ const dummyAll = unknown("PRINCIPAL");+ dummyAll.name = t("common.all");+ list.unshift(dummyAll);+ }++ return list;+});++const renderAvatar = (principal: Principal) => {+ if (principal.id === UNKNOWN_ID) {+ return h(+ "div",+ {+ class:+ "bb-principal-select--avatar w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white",+ },+ h(UserIcon, {+ class: "w-4 h-4 text-main text-current",+ })+ );+ } else {+ return h(PrincipalAvatar, {+ class: "bb-principal-select--avatar",+ principal,+ size: "SMALL",+ });+ }+};++const renderLabel = (option: SelectOption) => {+ const { principal } = option as PrincipalSelectOption;+ const avatar = renderAvatar(principal);+ const text = h("span", { class: "truncate" }, principal.name);+ return h(+ "div",+ {+ class: "flex items-center gap-x-2",+ },+ [avatar, text]+ );+};++const options = computed(() => {+ return combinedPrincipalList.value.map<PrincipalSelectOption>((principal) => {+ return {+ principal,+ value: principal.id,+ label: principal.name,+ };+ });+});++const filterByName = (pattern: string, option: SelectOption) => {+ const { principal } = option as PrincipalSelectOption;+ pattern = pattern.toLowerCase();+ return (+ principal.name.toLowerCase().includes(pattern) ||+ principal.email.includes(pattern.toLowerCase())+ );+};++// The user list might change if props change, and the previous selected id+// might not exist in the new list. In such case, we need to invalidate the selection+// and emit the event.+const resetInvalidSelection = () => {+ if (!props.autoReset) return;+ if (+ props.principal &&+ !combinedPrincipalList.value.find((item) => item.id === props.principal)+ ) {+ emit("update:principal", undefined);+ }+};++watch([() => props.principal, combinedPrincipalList], resetInvalidSelection, {+ immediate: true,+});+</script>++<style>+.bb-principal-select .n-base-selection--active .bb-principal-select--avatar {+ opacity: 0.3;+}+</style>diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vueindex 3ba4655ba2..efb7a6b250 100644--- a/frontend/src/components/v2/Select/ProjectSelect.vue+++ b/frontend/src/components/v2/Select/ProjectSelect.vue@@ -3,6 +3,8 @@:value="project":options="options":placeholder="$t('project.select')"+ :filterable="true"+ :filter="filterByName"style="width: 12rem"@update:value="$emit('update:project', $event)"/>@@ -16,6 +18,7 @@ import { NSelect, SelectOption } from "naive-ui";import { useCurrentUser, useProjectStore } from "@/store";import {DEFAULT_PROJECT_ID,+ Project,ProjectId,ProjectRoleType,ProjectTenantMode,@@ -25,6 +28,11 @@ import {} from "@/types";import { memberInProject } from "@/utils";+interface ProjectSelectOption extends SelectOption {+ value: ProjectId;+ project: Project;+}+const props = withDefaults(defineProps<{project: ProjectId | undefined; // UNKNOWN_ID(-1) to "ALL"@@ -127,8 +135,9 @@ const combinedProjectList = computed(() => {});const options = computed(() => {- return combinedProjectList.value.map<SelectOption>((project) => {+ return combinedProjectList.value.map<ProjectSelectOption>((project) => {return {+ project,value: project.id,label:project.id === DEFAULT_PROJECT_ID@@ -140,5 +149,14 @@ const options = computed(() => {});});+const filterByName = (pattern: string, option: SelectOption) => {+ const { project } = option as ProjectSelectOption;+ pattern = pattern.toLowerCase();+ return (+ project.name.toLowerCase().includes(pattern) ||+ project.key.toLowerCase().includes(pattern)+ );+};+watchEffect(prepare);</script>diff --git a/frontend/src/components/v2/Select/index.ts b/frontend/src/components/v2/Select/index.tsindex 6e664ec6e4..b2c14ea71f 100644--- a/frontend/src/components/v2/Select/index.ts+++ b/frontend/src/components/v2/Select/index.ts@@ -1,5 +1,6 @@import InstanceSelect from "./InstanceSelect.vue";import DatabaseSelect from "./DatabaseSelect.vue";import ProjectSelect from "./ProjectSelect.vue";+import PrincipalSelect from "./PrincipalSelect.vue";-export { InstanceSelect, DatabaseSelect, ProjectSelect };+export { InstanceSelect, DatabaseSelect, ProjectSelect, PrincipalSelect };diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 44c15217e1..7687f6d6a5 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2274,5 +2274,8 @@"attention-description": "Logging and analyzing slow queries for {versions}.\nBytebase will periodically sync slow query logs from instances.","sync-job-started": "Sync jobs started. Please wait for the jobs to complete.","detail": "Slow Query Detail"+ },+ "principal": {+ "select": "Select user"}}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 5d42b15d86..aacb1fe3d9 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2271,5 +2271,8 @@"attention-description": "为 {versions} 记录和分析慢查询。\nBytebase 会定期从实例上同步慢查询日志。","sync-job-started": "同步作业已启动。请等待同步完成。","detail": "慢查询详情"+ },+ "principal": {+ "select": "选择用户"}}diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vueindex 634896a108..c3b6b3af01 100644--- a/frontend/src/views/DatabaseDashboard.vue+++ b/frontend/src/views/DatabaseDashboard.vue@@ -2,8 +2,9 @@<div class="flex flex-col relative"><div class="px-5 py-2 flex justify-between items-center"><EnvironmentTabFilter- :selected-id="state.selectedEnvironment?.id"- @select-environment="selectEnvironment"+ :include-all="true"+ :environment="selectedEnvironment?.id ?? UNKNOWN_ID"+ @update:environment="changeEnvironmentId"/><div class="flex items-center space-x-4">@@ -27,11 +28,21 @@{{ $t("quick-action.default-db-hint") }}</div></NTooltip>- <BBTableSearch- ref="searchField"- :placeholder="$t('database.search-database')"- @change-text="(text: string) => changeSearchText(text)"- />++ <NInputGroup style="width: auto">+ <InstanceSelect+ :instance="state.instanceFilter"+ :include-all="true"+ :environment="selectedEnvironment?.id"+ @update:instance="state.instanceFilter = $event ?? UNKNOWN_ID"+ />+ <SearchBox+ :value="state.searchText"+ :placeholder="$t('database.search-database')"+ :autofocus="true"+ @update:value="changeSearchText($event)"+ />+ </NInputGroup></div></div>@@ -46,157 +57,134 @@</div></template>-<script lang="ts">+<script lang="ts" setup>+import { computed, watchEffect, onMounted, reactive } from "vue";+import { useRoute, useRouter } from "vue-router";+import { NInputGroup, NTooltip } from "naive-ui";+import { cloneDeep } from "lodash-es";+import {- computed,- watchEffect,- onMounted,- reactive,- ref,- defineComponent,-} from "vue";-import { useRouter } from "vue-router";-import { NTooltip } from "naive-ui";-import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";+ EnvironmentTabFilter,+ InstanceSelect,+ SearchBox,+} from "@/components/v2";import DatabaseTable from "../components/DatabaseTable.vue";import {- Environment,- Database,+ type Database,+ type EnvironmentId,UNKNOWN_ID,DEFAULT_PROJECT_ID,+ InstanceId,} from "../types";import {filterDatabaseByKeyword,hasWorkspacePermission,sortDatabaseList,} from "../utils";-import { cloneDeep } from "lodash-es";import {useCurrentUser,useDatabaseStore,- useEnvironmentList,useEnvironmentStore,useUIStateStore,} from "@/store";interface LocalState {+ instanceFilter: InstanceId;searchText: string;databaseList: Database[];- selectedEnvironment?: Environment;loading: boolean;}-export default defineComponent({- name: "DatabaseDashboard",- components: {- NTooltip,- EnvironmentTabFilter,- DatabaseTable,- },- setup() {- const searchField = ref();-- const uiStateStore = useUIStateStore();- const router = useRouter();-- const state = reactive<LocalState>({- searchText: "",- databaseList: [],- selectedEnvironment: router.currentRoute.value.query.environment- ? useEnvironmentStore().getEnvironmentById(- parseInt(router.currentRoute.value.query.environment as string, 10)- )- : undefined,- loading: false,- });+const uiStateStore = useUIStateStore();+const environmentStore = useEnvironmentStore();+const router = useRouter();+const route = useRoute();- const currentUser = useCurrentUser();+const state = reactive<LocalState>({+ instanceFilter: UNKNOWN_ID,+ searchText: "",+ databaseList: [],+ loading: false,+});- const environmentList = useEnvironmentList(["NORMAL"]);+const currentUser = useCurrentUser();- const canVisitUnassignedDatabases = computed(() => {- return hasWorkspacePermission(- "bb.permission.workspace.manage-database",- currentUser.value.role- );- });+const selectedEnvironment = computed(() => {+ const { environment } = route.query;+ return environment+ ? environmentStore.getEnvironmentById(parseInt(environment as string, 10))+ : undefined;+});- onMounted(() => {- // Focus on the internal search field when mounted- searchField.value.$el.querySelector("#search").focus();+const canVisitUnassignedDatabases = computed(() => {+ return hasWorkspacePermission(+ "bb.permission.workspace.manage-database",+ currentUser.value.role+ );+});- if (!uiStateStore.getIntroStateByKey("database.visit")) {- uiStateStore.saveIntroStateByKey({- key: "database.visit",- newState: true,- });- }+onMounted(() => {+ if (!uiStateStore.getIntroStateByKey("database.visit")) {+ uiStateStore.saveIntroStateByKey({+ key: "database.visit",+ newState: true,});+ }+});- const prepareDatabaseList = () => {- // It will also be called when user logout- if (currentUser.value.id != UNKNOWN_ID) {- state.loading = true;- useDatabaseStore()- .fetchDatabaseList()- .then((list) => {- state.databaseList = sortDatabaseList(- cloneDeep(list),- environmentList.value- );- })- .finally(() => {- state.loading = false;- });- }- };-- watchEffect(prepareDatabaseList);-- const selectEnvironment = (environment: Environment) => {- state.selectedEnvironment = environment;- if (environment) {- router.replace({- name: "workspace.database",- query: { environment: environment.id },- });- } else {- router.replace({ name: "workspace.database" });- }- };-- const changeSearchText = (searchText: string) => {- state.searchText = searchText;- };-- const filteredList = computed(() => {- const { databaseList, selectedEnvironment, searchText } = state;- let list = [...databaseList];- if (selectedEnvironment) {- list = list.filter(- (db) => db.instance.environment.id === selectedEnvironment.id+const prepareDatabaseList = () => {+ // It will also be called when user logout+ if (currentUser.value.id != UNKNOWN_ID) {+ state.loading = true;+ useDatabaseStore()+ .fetchDatabaseList()+ .then((list) => {+ state.databaseList = sortDatabaseList(+ cloneDeep(list),+ environmentStore.getEnvironmentList());- }- list = list.filter((db) =>- filterDatabaseByKeyword(db, searchText, [- "name",- "environment",- "instance",- "project",- ])- );- return list;+ })+ .finally(() => {+ state.loading = false;+ });+ }+};++watchEffect(prepareDatabaseList);++const changeEnvironmentId = (environment: EnvironmentId | undefined) => {+ if (environment && environment !== UNKNOWN_ID) {+ router.replace({+ name: "workspace.database",+ query: { environment },});-- return {- DEFAULT_PROJECT_ID,- searchField,- state,- filteredList,- selectEnvironment,- changeSearchText,- canVisitUnassignedDatabases,- };- },+ } else {+ router.replace({ name: "workspace.database" });+ }+};++const changeSearchText = (searchText: string) => {+ state.searchText = searchText;+};++const filteredList = computed(() => {+ const { databaseList, searchText } = state;+ let list = [...databaseList];+ const environment = selectedEnvironment.value;+ if (environment && environment.id !== UNKNOWN_ID) {+ list = list.filter((db) => db.instance.environment.id === environment.id);+ }+ if (state.instanceFilter !== UNKNOWN_ID) {+ list = list.filter((db) => db.instance.id === state.instanceFilter);+ }+ list = list.filter((db) =>+ filterDatabaseByKeyword(db, searchText, [+ "name",+ "environment",+ "instance",+ "project",+ ])+ );+ return list;});</script>diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex ccbb82fa8d..b5b3b0b484 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -1,15 +1,16 @@<template><div class="flex flex-col"><div class="px-4 py-2 flex justify-between items-center">- <!-- eslint-disable vue/attribute-hyphenation --><EnvironmentTabFilter- :selectedId="selectedEnvironment?.id"- @select-environment="selectEnvironment"+ :include-all="true"+ :environment="selectedEnvironment?.id ?? UNKNOWN_ID"+ @update:environment="changeEnvironmentId"/>- <BBTableSearch- ref="searchField"+ <SearchBox+ :value="state.searchText":placeholder="$t('issue.search-issue-name')"- @change-text="(text: string) => changeSearchText(text)"+ :autofocus="true"+ @update:value="changeSearchText($event)"/></div>@@ -186,11 +187,11 @@</template><script lang="ts" setup>-import { onMounted, reactive, ref, computed } from "vue";+import { reactive, computed } from "vue";import { useRoute, useRouter } from "vue-router";-import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import { activeEnvironment } from "../utils";-import { Environment, Issue, planTypeToString } from "../types";+import { UNKNOWN_ID, Issue, planTypeToString, EnvironmentId } from "../types";+import { EnvironmentTabFilter, SearchBox } from "@/components/v2";import {useCurrentUser,useEnvironmentStore,@@ -212,8 +213,6 @@ interface LocalState {const OPEN_ISSUE_LIST_PAGE_SIZE = 10;const MAX_CLOSED_ISSUE = 5;-const searchField = ref();-const environmentStore = useEnvironmentStore();const subscriptionStore = useSubscriptionStore();const onboardingStateStore = useOnboardingStateStore();@@ -250,7 +249,10 @@ const selectedEnvironment = computed(() => {});const keywordAndEnvironmentFilter = (issue: Issue) => {- if (selectedEnvironment.value) {+ if (+ selectedEnvironment.value &&+ selectedEnvironment.value.id !== UNKNOWN_ID+ ) {if (activeEnvironment(issue.pipeline).id !== selectedEnvironment.value.id) {return false;}@@ -263,13 +265,14 @@ const keywordAndEnvironmentFilter = (issue: Issue) => {}return true;};-const selectEnvironment = (environment: Environment) => {- if (environment) {++const changeEnvironmentId = (environment: EnvironmentId | undefined) => {+ if (environment && environment !== UNKNOWN_ID) {router.replace({name: "workspace.home",query: {...route.query,- environment: environment.id,+ environment,},});} else {@@ -286,9 +289,4 @@ const selectEnvironment = (environment: Environment) => {const changeSearchText = (searchText: string) => {state.searchText = searchText;};--onMounted(() => {- // Focus on the internal search field when mounted- searchField.value.$el.querySelector("#search").focus();-});</script>diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vueindex 13e15f64b1..bc2d8295f9 100644--- a/frontend/src/views/IssueDashboard.vue+++ b/frontend/src/views/IssueDashboard.vue@@ -1,33 +1,30 @@<template>- <!-- This example requires Tailwind CSS v2.0+ --><div class="flex flex-col"><div class="px-4 py-2 flex justify-between items-center">- <!-- eslint-disable vue/attribute-hyphenation --><EnvironmentTabFilter- :selectedId="selectedEnvironment?.id"- @select-environment="selectEnvironment"+ :include-all="true"+ :environment="selectedEnvironment?.id ?? UNKNOWN_ID"+ @update:environment="changeEnvironmentId($event)"/><div class="flex flex-row space-x-4">- <button- v-if="project"- class="px-4 cursor-pointer rounded-md text-control text-sm bg-link-hover focus:outline-none hover:underline"- @click.prevent="goProject"- >+ <NButton v-if="project" @click="goProject">{{ project.key }}- </button>- <!-- eslint-disable vue/attribute-hyphenation -->- <MemberSelect- class="w-72"- :show-all="true"- :show-system-bot="true"- :selected-id="selectedPrincipalId"- @select-principal-id="selectPrincipal"- />- <BBTableSearch- ref="searchField"- :placeholder="$t('issue.search-issue-name')"- @change-text="(text: string) => changeSearchText(text)"- />+ </NButton>++ <NInputGroup style="width: auto">+ <PrincipalSelect+ :principal="selectedPrincipalId"+ :include-system-bot="true"+ :include-all="allowSelectAllUsers"+ @update:principal="changePrincipalId"+ />+ <SearchBox+ :value="state.searchText"+ :placeholder="$t('issue.search-issue-name')"+ :autofocus="true"+ @update:value="changeSearchText($event)"+ />+ </NInputGroup></div></div>@@ -37,7 +34,10 @@session-key="dashboard-open":issue-find="{statusList: ['OPEN'],- principalId: selectedPrincipalId > 0 ? selectedPrincipalId : undefined,+ principalId:+ selectedPrincipalId && selectedPrincipalId !== UNKNOWN_ID+ ? selectedPrincipalId+ : undefined,projectId: selectedProjectId,}":page-size="10"@@ -61,7 +61,10 @@session-key="dashboard-closed":issue-find="{statusList: ['DONE', 'CANCELED'],- principalId: selectedPrincipalId > 0 ? selectedPrincipalId : undefined,+ principalId:+ selectedPrincipalId && selectedPrincipalId !== UNKNOWN_ID+ ? selectedPrincipalId+ : undefined,projectId: selectedProjectId,}":page-size="10"@@ -83,12 +86,24 @@</template><script lang="ts" setup>+import { reactive, computed } from "vue";import { useRoute, useRouter } from "vue-router";-import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";+import { NInputGroup, NButton } from "naive-ui";++import {+ EnvironmentTabFilter,+ PrincipalSelect,+ SearchBox,+} from "@/components/v2";import { IssueTable } from "../components/Issue";-import MemberSelect from "../components/MemberSelect.vue";-import { EMPTY_ID, Environment, Issue, PrincipalId, ProjectId } from "../types";-import { reactive, ref, computed, onMounted } from "vue";+import {+ type Environment,+ type EnvironmentId,+ type Issue,+ type PrincipalId,+ type ProjectId,+ UNKNOWN_ID,+} from "../types";import {activeEnvironment,hasWorkspacePermission,@@ -101,8 +116,6 @@ interface LocalState {searchText: string;}-const searchField = ref();-const router = useRouter();const route = useRoute();@@ -125,16 +138,20 @@ const showClosed = computed(() => statusList.value.length === 0 || statusList.value.includes("closed"));+const allowSelectAllUsers = computed(() => {+ return hasWorkspacePermission(+ "bb.permission.workspace.manage-issue",+ currentUser.value.role+ );+});+const selectedPrincipalId = computed((): PrincipalId => {const id = parseInt(route.query.user as string, 10);if (id >= 0) {return id;}- return hasWorkspacePermission(- "bb.permission.workspace.manage-issue",- currentUser.value.role- )- ? EMPTY_ID // default to 'All' if current user is owner or DBA+ return allowSelectAllUsers.value+ ? UNKNOWN_ID // default to 'All' if current user is owner or DBA: currentUser.value.id; // default to current user otherwise});@@ -150,11 +167,6 @@ const selectedProjectId = computed((): ProjectId | undefined => {return project ? parseInt(project as string, 10) : undefined;});-onMounted(() => {- // Focus on the internal search field when mounted- searchField.value.$el.querySelector("#search").focus();-});-const project = computed(() => {if (selectedProjectId.value) {return projectStore.getProjectById(selectedProjectId.value);@@ -177,13 +189,13 @@ const filter = (issue: Issue) => {return true;};-const selectEnvironment = (environment: Environment) => {- if (environment) {+const changeEnvironmentId = (environment: EnvironmentId | undefined) => {+ if (environment && environment !== UNKNOWN_ID) {router.replace({name: "workspace.issue",query: {...route.query,- environment: environment.id,+ environment,},});} else {@@ -197,12 +209,15 @@ const selectEnvironment = (environment: Environment) => {}};-const selectPrincipal = (principalId: PrincipalId) => {+const changePrincipalId = (user: PrincipalId | undefined) => {+ if (user === UNKNOWN_ID) {+ user = undefined;+ }router.replace({name: "workspace.issue",query: {...route.query,- user: principalId,+ user,},});};diff --git a/frontend/src/views/ProjectDashboard.vue b/frontend/src/views/ProjectDashboard.vueindex 13fffd5033..4b4553fa5e 100644--- a/frontend/src/views/ProjectDashboard.vue+++ b/frontend/src/views/ProjectDashboard.vue@@ -1,10 +1,12 @@<template><div class="flex flex-col"><div class="px-2 py-2 flex justify-between items-center">- <BBTableSearch- ref="searchField"+ <SearchBox+ :value="state.searchText":placeholder="$t('project.dashboard.search-bar-placeholder')"- @change-text="(text: string) => changeSearchText(text)"+ :autofocus="true"+ style="width: 12rem"+ @update:value="changeSearchText($event)"/></div><ProjectTable@@ -15,9 +17,11 @@</div></template>-<script lang="ts">+<script lang="ts" setup>+import { watchEffect, onMounted, reactive } from "vue";+import { useCurrentUser, useUIStateStore, useProjectStore } from "@/store";-import { watchEffect, onMounted, reactive, ref, defineComponent } from "vue";+import { SearchBox } from "@/components/v2";import ProjectTable from "../components/ProjectTable.vue";import { Project, UNKNOWN_ID } from "../types";@@ -26,74 +30,55 @@ interface LocalState {searchText: string;}-export default defineComponent({- name: "ProjectDashboard",- components: {- ProjectTable,- },- setup() {- const searchField = ref();-- const uiStateStore = useUIStateStore();- const currentUser = useCurrentUser();- const projectStore = useProjectStore();+const uiStateStore = useUIStateStore();+const currentUser = useCurrentUser();+const projectStore = useProjectStore();- const state = reactive<LocalState>({- projectList: [],- searchText: "",- });-- onMounted(() => {- // Focus on the internal search field when mounted- searchField.value.$el.querySelector("#search").focus();+const state = reactive<LocalState>({+ projectList: [],+ searchText: "",+});- if (!uiStateStore.getIntroStateByKey("project.visit")) {- uiStateStore.saveIntroStateByKey({- key: "project.visit",- newState: true,- });- }+onMounted(() => {+ if (!uiStateStore.getIntroStateByKey("project.visit")) {+ uiStateStore.saveIntroStateByKey({+ key: "project.visit",+ newState: true,});+ }+});- const prepareProjectList = () => {- // It will also be called when user logout- if (currentUser.value.id != UNKNOWN_ID) {- projectStore- .fetchProjectListByUser({- userId: currentUser.value.id,- rowStatusList: ["NORMAL"],- })- .then((projectList: Project[]) => {- state.projectList = projectList;- });- }- };+const prepareProjectList = () => {+ // It will also be called when user logout+ if (currentUser.value.id != UNKNOWN_ID) {+ projectStore+ .fetchProjectListByUser({+ userId: currentUser.value.id,+ rowStatusList: ["NORMAL"],+ })+ .then((projectList: Project[]) => {+ state.projectList = projectList;+ });+ }+};- watchEffect(prepareProjectList);+watchEffect(prepareProjectList);- const changeSearchText = (searchText: string) => {- state.searchText = searchText;- };+const changeSearchText = (searchText: string) => {+ state.searchText = searchText;+};- const filteredList = (list: Project[]) => {- if (!state.searchText) {- // Select "All"- return list;- }- return list.filter((issue) => {- return (- !state.searchText ||- issue.name.toLowerCase().includes(state.searchText.toLowerCase())- );- });- };-- return {- searchField,- state,- filteredList,- changeSearchText,- };- },-});+const filteredList = (list: Project[]) => {+ const keyword = state.searchText.trim().toLowerCase();+ if (!keyword) {+ // Select "All"+ return list;+ }+ return list.filter((project) => {+ return (+ project.name.toLowerCase().includes(keyword) ||+ project.key.toLowerCase().includes(keyword)+ );+ });+};</script>