Skip to content

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

feat(frontend): The user filter on the "Issues" page supports and defaults to "All" (#1789)

Liu Ji583e6fb8c151
diff --git a/frontend/src/components/MemberSelect.vue b/frontend/src/components/MemberSelect.vue
index 706e30204c..c753ee2521 100644
--- a/frontend/src/components/MemberSelect.vue
+++ b/frontend/src/components/MemberSelect.vue
@@ -19,7 +19,15 @@
The specific value and breakpoint is to make it align with other select in the issue sidebar.
-->
<span class="flex lg:40 xl:w-44 items-center space-x-2">
- <PrincipalAvatar :principal="item" :size="'SMALL'" />
+ <!-- Show a special avatar for "All" -->
+ <div
+ v-if="showAll && item.id === EMPTY_ID"
+ class="w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white"
+ >
+ <heroicons-outline:user class="w-4 h-4 text-main" />
+ </div>
+ <!-- Show the initial letters by default -->
+ <PrincipalAvatar v-else :principal="item" :size="'SMALL'" />
<span class="truncate">{{ item.name }}</span>
</span>
</template>
@@ -42,15 +50,18 @@
import { reactive, computed, watch, PropType, defineComponent } from "vue";
import PrincipalAvatar from "./PrincipalAvatar.vue";
import {
+ empty,
Member,
Principal,
PrincipalId,
RoleType,
SYSTEM_BOT_ID,
+ EMPTY_ID,
} from "../types";
import { isDBA, isDeveloper, isOwner } from "../utils";
import { BBComboBox } from "../bbkit";
import { useMemberStore, usePrincipalStore } from "@/store";
+import { useI18n } from "vue-i18n";
interface LocalState {
selectedId: PrincipalId | undefined;
@@ -69,6 +80,10 @@ export default defineComponent({
default: false,
type: Boolean,
},
+ showAll: {
+ type: Boolean,
+ default: false,
+ },
allowedRoleList: {
default: () => ["OWNER", "DBA", "DEVELOPER"],
type: Array as PropType<RoleType[]>,
@@ -90,6 +105,7 @@ export default defineComponent({
});
const memberStore = useMemberStore();
const principalStore = usePrincipalStore();
+ const { t } = useI18n();
const principalList = computed((): Principal[] => {
const list = memberStore.memberList
@@ -104,6 +120,12 @@ export default defineComponent({
if (props.selectedId == SYSTEM_BOT_ID) {
list.unshift(principalStore.principalById(SYSTEM_BOT_ID));
}
+ // If `showAll` is true, we insert a virtual user before the list.
+ if (props.showAll) {
+ const all = empty("PRINCIPAL");
+ all.name = t("common.all");
+ list.unshift(all);
+ }
return list.filter((item: Principal) => {
// The previously selected item might no longer be applicable.
// e.g. The select limits to DBA only and the selected principal is no longer a DBA
@@ -148,6 +170,7 @@ export default defineComponent({
};
return {
+ EMPTY_ID,
state,
principalList,
selectedPrincipal,
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index 7b34dd52ee..8b738c1246 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -19,7 +19,8 @@
<MemberSelect
v-if="scopeByPrincipal"
class="w-72"
- :selectedId="state.selectedPrincipalId"
+ :show-all="true"
+ :selected-id="state.selectedPrincipalId"
@select-principal-id="selectPrincipal"
/>
<BBTableSearch
@@ -40,11 +41,12 @@
</template>
<script lang="ts">
-import { useRouter } from "vue-router";
+import { useRoute, useRouter } from "vue-router";
+import { isEmpty } from "lodash-es";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import { IssueTable } from "../components/Issue";
import MemberSelect from "../components/MemberSelect.vue";
-import { Environment, Issue, PrincipalId, ProjectId } from "../types";
+import { EMPTY_ID, Environment, Issue, PrincipalId, ProjectId } from "../types";
import {
reactive,
ref,
@@ -53,7 +55,7 @@ import {
watchEffect,
defineComponent,
} from "vue";
-import { activeEnvironment, projectSlug } from "../utils";
+import { activeEnvironment, isDBAOrOwner, projectSlug } from "../utils";
import { BBTableSectionDataSource } from "../bbkit/types";
import { useI18n } from "vue-i18n";
import {
@@ -83,12 +85,13 @@ export default defineComponent({
const issueStore = useIssueStore();
const router = useRouter();
+ const route = useRoute();
const currentUser = useCurrentUser();
const projectStore = useProjectStore();
- const statusList: string[] = router.currentRoute.value.query.status
- ? (router.currentRoute.value.query.status as string).split(",")
+ const statusList: string[] = route.query.status
+ ? (route.query.status as string).split(",")
: [];
// Applies principal scope if we explicitly specify user in the query parameter
@@ -97,9 +100,7 @@ export default defineComponent({
// we do NOT apply principal scope, which is the case if we want to list all issues
// for a particular project.
// Note: We do not use computed, otherwise it will cause prepareIssueList to refetch everytime we click environment tab
- const scopeByPrincipal =
- !router.currentRoute.value.query.user ||
- !router.currentRoute.value.query.project;
+ const scopeByPrincipal = !route.query.user || !route.query.project;
const state = reactive<LocalState>({
showOpen: statusList.length == 0 || statusList.includes("open"),
@@ -107,18 +108,27 @@ export default defineComponent({
openList: [],
closedList: [],
searchText: "",
- selectedPrincipalId:
- parseInt(router.currentRoute.value.query.user as string, 10) ||
- currentUser.value.id,
- selectedEnvironment: router.currentRoute.value.query.environment
+ selectedPrincipalId: currentUser.value.id, // initialized below
+ selectedEnvironment: route.query.environment
? useEnvironmentStore().getEnvironmentById(
- parseInt(router.currentRoute.value.query.environment as string, 10)
+ parseInt(route.query.environment as string, 10)
)
: undefined,
- selectedProjectId: router.currentRoute.value.query.project
- ? parseInt(router.currentRoute.value.query.project as string)
+ selectedProjectId: route.query.project
+ ? parseInt(route.query.project as string)
: undefined,
});
+ // initialize the selectedPrincipalId
+ const initializeSelectedPrincipalIdFromQuery = (): PrincipalId => {
+ const id = parseInt(route.query.user as string, 10);
+ if (id >= 0) {
+ return id;
+ }
+ return isDBAOrOwner(currentUser.value.role)
+ ? EMPTY_ID // default to 'All' if current user is owner or DBA
+ : currentUser.value.id; // default to current user otherwise
+ };
+ state.selectedPrincipalId = initializeSelectedPrincipalIdFromQuery();
onMounted(() => {
// Focus on the internal search field when mounted
@@ -135,6 +145,8 @@ export default defineComponent({
const prepareIssueList = () => {
// We call open and close separately because normally the number of open issues is limited
// while the closed issues could be a lot.
+ // When "All" is selected, the userId is eventually ignored by `fetchIssueList` because
+ // it's 0 (EMPTY_ID), so we need not to check the special value here.
if (state.showOpen) {
issueStore
.fetchIssueList({
@@ -205,7 +217,7 @@ export default defineComponent({
router.replace({
name: "workspace.issue",
query: {
- ...router.currentRoute.value.query,
+ ...route.query,
environment: environment.id,
},
});
@@ -213,7 +225,7 @@ export default defineComponent({
router.replace({
name: "workspace.issue",
query: {
- ...router.currentRoute.value.query,
+ ...route.query,
environment: undefined,
},
});
@@ -225,7 +237,7 @@ export default defineComponent({
router.replace({
name: "workspace.issue",
query: {
- ...router.currentRoute.value.query,
+ ...route.query,
user: principalId,
},
});