Skip to content

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

chore: optimize the advanced search for remote fetch (#15759)

ecmadao60becf7ab29b
diff --git a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
index 17c50d4b9c..6b144e69c3 100644
--- a/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
+++ b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
@@ -6,7 +6,6 @@
:placeholder="placeholder ?? $t('issue.advanced-search.self')"
style="--n-padding-left: 8px; --n-padding-right: 4px"
@click="handleInputClick"
- @blur="hideMenu"
@keyup="handleKeyUp"
@keydown="handleKeyDown"
>
@@ -59,21 +58,21 @@
>
<ScopeMenu
:show="state.menuView === 'scope'"
- :params="params"
:options="visibleScopeOptions"
:menu-index="menuIndex"
@select-scope="selectScope"
@hover-item="menuIndex = $event"
/>
<ValueMenu
- v-if="visibleValueOptions.length > 0"
+ v-if="visibleValueOptions.length > 0 || currentScopeOption?.search"
:show="state.menuView === 'value'"
- :params="params"
:scope-option="currentScopeOption"
:value-options="visibleValueOptions"
:menu-index="menuIndex"
+ :fetch-state="currentFetchState"
@select-value="selectValue"
@hover-item="menuIndex = $event"
+ @fetch-next-page="() => handleSearch(currentValueForScope)"
/>
</div>
</Transition>
@@ -81,6 +80,7 @@
</template>
<script lang="ts" setup>
+import { useDebounceFn, onClickOutside } from "@vueuse/core";
import { useElementSize } from "@vueuse/core";
import { cloneDeep, last } from "lodash-es";
import { FilterIcon } from "lucide-vue-next";
@@ -128,6 +128,14 @@ interface LocalState {
searchText: string;
currentScope?: SearchScopeId;
menuView?: "value" | "scope";
+ scopeOptions: ScopeOption[];
+ fetchDataStateMap: Map<
+ SearchScopeId,
+ {
+ loading: boolean;
+ nextPageToken?: string;
+ }
+ >;
}
const route = useRoute();
@@ -156,7 +164,18 @@ const buildSearchTextByParams = (params: SearchParams | undefined): string => {
const state = reactive<LocalState>({
searchText: buildSearchTextByParams(props.params),
+ scopeOptions: [],
+ fetchDataStateMap: new Map(),
});
+
+watch(
+ () => props.scopeOptions,
+ () => {
+ state.scopeOptions = cloneDeep(props.scopeOptions);
+ },
+ { deep: true, immediate: true }
+);
+
const containerRef = ref<HTMLElement>();
const tagsContainerRef = ref<HTMLElement>();
const inputText = ref(props.params.query);
@@ -178,18 +197,79 @@ watch(
const valueOptions = computed(() => {
if (state.menuView === "value" && currentScopeOption.value) {
- return currentScopeOption.value.options;
+ return currentScopeOption.value.options ?? [];
}
return [];
});
const currentScopeOption = computed(() => {
if (state.currentScope) {
- return props.scopeOptions.find((opt) => opt.id === state.currentScope);
+ return state.scopeOptions.find((opt) => opt.id === state.currentScope);
}
return undefined;
});
+const currentValueForScope = computed(() => {
+ if (!state.currentScope) return "";
+ const scopePrefix = `${state.currentScope}:`;
+ return inputText.value.trim().toLowerCase().substring(scopePrefix.length);
+});
+
+const currentFetchState = computed(() => {
+ return state.currentScope
+ ? (state.fetchDataStateMap.get(state.currentScope) ?? {
+ loading: false,
+ })
+ : { loading: false };
+});
+
+const handleSearch = useDebounceFn(async (search: string) => {
+ if (!currentScopeOption.value?.search) {
+ return;
+ }
+
+ const fetchState = { ...currentFetchState.value };
+ if (fetchState.loading) {
+ return;
+ }
+ fetchState.loading = true;
+
+ try {
+ const { options, nextPageToken } = await currentScopeOption.value.search({
+ keyword: search,
+ nextPageToken: fetchState.nextPageToken,
+ });
+ if (!currentScopeOption.value.options) {
+ currentScopeOption.value.options = [];
+ }
+ if (!fetchState.nextPageToken) {
+ currentScopeOption.value.options = [...options];
+ } else {
+ currentScopeOption.value.options.push(...options);
+ }
+ fetchState.nextPageToken = nextPageToken;
+ } finally {
+ fetchState.loading = false;
+ state.fetchDataStateMap.set(currentScopeOption.value.id, fetchState);
+ }
+});
+
+watch(
+ [() => currentScopeOption.value, () => currentValueForScope.value],
+ async ([scopeOption, valueForScope]) => {
+ if (!scopeOption || !scopeOption.search) {
+ return;
+ }
+
+ state.fetchDataStateMap.set(scopeOption.id, {
+ loading: false,
+ nextPageToken: "",
+ });
+ await handleSearch(valueForScope);
+ },
+ { immediate: true }
+);
+
// availableScopeOptions will hide chosen search scope.
// For example, if uses already select the instance, we should NOT show the instance scope in the dropdown.
const availableScopeOptions = computed((): ScopeOption[] => {
@@ -197,7 +277,7 @@ const availableScopeOptions = computed((): ScopeOption[] => {
props.params.scopes.map((scope) => scope.id)
);
- return props.scopeOptions.filter((scope) => {
+ return state.scopeOptions.filter((scope) => {
if (existedScopes.has(scope.id) && !scope.allowMultiple) {
return false;
}
@@ -222,13 +302,11 @@ const visibleScopeOptions = computed(() => {
const visibleValueOptions = computed(() => {
if (!state.currentScope) return [];
- const scopePrefix = `${state.currentScope}:`;
- const keyword = inputText.value
- .trim()
- .toLowerCase()
- .substring(scopePrefix.length);
- if (!keyword) return valueOptions.value;
+ const keyword = currentValueForScope.value;
+ if (!keyword || currentScopeOption.value?.search) {
+ return valueOptions.value;
+ }
// Apply multiple segments of keyword splitted by whitespace
const terms = keyword.split(/\s+/g);
@@ -278,11 +356,12 @@ const clearable = computed(() => {
const hideMenu = () => {
nextTick(() => {
state.menuView = undefined;
- state.currentScope = undefined;
focusedTagId.value = undefined;
});
};
+onClickOutside(containerRef, hideMenu);
+
const moveMenuIndex = (delta: -1 | 1) => {
const options = visibleOptions.value;
if (options.length === 0) return;
@@ -301,6 +380,7 @@ const removeScope = (id: SearchScopeId) => {
});
emit("update:params", updated);
};
+
const selectScope = (
id: SearchScopeId | undefined,
value: string | undefined = undefined
@@ -353,8 +433,9 @@ const selectValue = (value: string) => {
scrollScopeTagIntoViewIfNeeded(id);
hideMenu();
};
+
const selectScopeFromTag = (id: SearchScopeId) => {
- if (props.scopeOptions.find((opt) => opt.id === id)) {
+ if (state.scopeOptions.find((opt) => opt.id === id)) {
// For AdvancedSearch supported scopes
selectScope(id);
return;
@@ -384,6 +465,7 @@ const maybeSelectMatchedScope = () => {
}
return false;
};
+
const maybeDeselectMismatchedScope = () => {
if (state.menuView === "value" && state.currentScope) {
if (!inputText.value.startsWith(`${state.currentScope}:`)) {
@@ -397,9 +479,11 @@ const maybeDeselectMismatchedScope = () => {
};
const maybeEmitIncompleteValue = () => {
- const updated = cloneDeep(props.params);
- updated.query = inputText.value;
- emit("update:params", updated);
+ if (inputText.value !== `${state.currentScope}:`) {
+ const updated = cloneDeep(props.params);
+ updated.query = inputText.value;
+ emit("update:params", updated);
+ }
};
const handleInputClick = () => {
@@ -548,6 +632,7 @@ watch(
}
}
);
+
watch(visibleScopeOptions, (newOptions, oldOptions) => {
if (state.menuView !== "scope") return;
const highlightedScope = oldOptions[menuIndex.value]?.id;
@@ -560,6 +645,7 @@ watch(visibleScopeOptions, (newOptions, oldOptions) => {
}
menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);
});
+
watch(visibleValueOptions, (newOptions, oldOptions) => {
if (state.menuView !== "value") return;
const highlightedValue = oldOptions[menuIndex.value]?.value;
@@ -572,10 +658,11 @@ watch(visibleValueOptions, (newOptions, oldOptions) => {
}
menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);
});
+
watch(
() => props.params,
(params) => {
- inputText.value = params.query;
+ inputText.value = params.query || inputText.value;
router.replace({
query: {
...route.query,
diff --git a/frontend/src/components/AdvancedSearch/ScopeMenu.vue b/frontend/src/components/AdvancedSearch/ScopeMenu.vue
index 2cdb72a19d..184ded6068 100644
--- a/frontend/src/components/AdvancedSearch/ScopeMenu.vue
+++ b/frontend/src/components/AdvancedSearch/ScopeMenu.vue
@@ -1,20 +1,18 @@
<template>
- <div
- v-if="options.length > 0"
- v-show="show"
- class="overflow-hidden"
- :style="{
- 'max-height': `${maxListHeight}px`,
- }"
- >
- <VirtualList
+ <div v-if="options.length > 0" v-show="show">
+ <NVirtualList
ref="virtualListRef"
:items="options"
:key-field="`id`"
:item-resizable="false"
:item-size="38"
+ :style="{
+ 'max-height': `${maxListHeight}px`,
+ }"
>
- <template #default="{ item: option, index }: ListItem">
+ <template
+ #default="{ item: option, index }: { item: ScopeOption; index: number }"
+ >
<div
class="h-[38px] flex gap-x-1 px-3 items-center cursor-pointer border-t text-sm"
:class="[
@@ -32,35 +30,30 @@
<span class="text-control-light">{{ option.description }}</span>
</div>
</template>
- </VirtualList>
+ </NVirtualList>
</div>
</template>
<script setup lang="ts">
import { useElementBounding, useWindowSize } from "@vueuse/core";
+import { NVirtualList } from "naive-ui";
import { computed, nextTick, ref, watch } from "vue";
-import { VirtualList } from "vueuc";
-import type { SearchParams, SearchScopeId } from "@/utils";
+import type { SearchScopeId } from "@/utils";
import type { ScopeOption } from "./types";
-type ListItem = {
- item: ScopeOption;
- index: number;
-};
-
const props = defineProps<{
show: boolean;
- params: SearchParams;
options: ScopeOption[];
menuIndex: number;
}>();
+
defineEmits<{
(event: "select-scope", id: SearchScopeId): void;
(event: "hover-item", index: number): void;
}>();
const containerRef = ref<HTMLElement>();
-const virtualListRef = ref<InstanceType<typeof VirtualList>>();
+const virtualListRef = ref<InstanceType<typeof NVirtualList>>();
const { top: containerTop } = useElementBounding(containerRef);
const { height: windowHeight } = useWindowSize();
@@ -74,7 +67,7 @@ const maxListHeight = computed(() => {
);
});
-const highlightedItem = computed((): ListItem | undefined => {
+const highlightedItem = computed(() => {
if (!props.show) return undefined;
const { options, menuIndex: index } = props;
const item = options[index];
diff --git a/frontend/src/components/AdvancedSearch/ValueMenu.vue b/frontend/src/components/AdvancedSearch/ValueMenu.vue
index 2c77a5fa89..f1b9ee5bd7 100644
--- a/frontend/src/components/AdvancedSearch/ValueMenu.vue
+++ b/frontend/src/components/AdvancedSearch/ValueMenu.vue
@@ -6,44 +6,73 @@
class="flex flex-col overflow-hidden"
:data-top="containerTop"
>
- <div
- v-if="scopeOption.title"
- ref="titleRef"
- class="px-3 py-2 text-sm text-control font-semibold"
- :data-height="titleHeight"
- >
- {{ scopeOption.title }}
+ <div class="px-3 py-2">
+ <div
+ ref="titleRef"
+ class="text-sm text-control font-semibold"
+ :data-height="titleHeight"
+ >
+ {{ scopeOption.title }}
+ </div>
+ <div v-if="scopeOption.search" class="textinfolabel">
+ {{ $t("issue.advanced-search.search") }}
+ </div>
</div>
- <div
- v-if="valueOptions.length > 0"
- class="flex-1 overflow-hidden"
- :style="{
- 'max-height': `${maxListHeight}px`,
- }"
- >
- <VirtualList
+ <div v-if="valueOptions.length > 0">
+ <NVirtualList
ref="virtualListRef"
:items="valueOptions"
:key-field="`value`"
:item-resizable="false"
:item-size="38"
+ :style="{
+ 'max-height': `${maxListHeight}px`,
+ }"
>
- <template #default="{ item: option, index }: ListItem">
- <div
- class="h-[38px] flex gap-x-2 px-3 items-center cursor-pointer border-t border-block-border overflow-hidden"
- :class="[index === menuIndex && 'bg-gray-200/75']"
- :data-index="index"
- :data-value="option.value"
- @mouseenter.prevent.stop="$emit('hover-item', index)"
- @mousedown.prevent.stop="$emit('select-value', option.value)"
- >
- <component :is="option.render" class="text-control text-sm" />
- <span v-if="!option.custom" class="text-control-light text-sm">
- {{ option.value }}
- </span>
+ <template
+ #default="{
+ item: option,
+ index,
+ }: {
+ item: ValueOption;
+ index: number;
+ }"
+ >
+ <div class="border-t border-block-border">
+ <div
+ class="h-[38px] flex gap-x-2 px-3 items-center cursor-pointer overflow-hidden"
+ :class="[index === menuIndex && 'bg-gray-200/75']"
+ :data-index="index"
+ :data-value="option.value"
+ @mouseenter.prevent.stop="$emit('hover-item', index)"
+ @mousedown.prevent.stop="$emit('select-value', option.value)"
+ >
+ <component :is="option.render" class="text-control text-sm" />
+ <span v-if="!option.custom" class="text-control-light text-sm">
+ {{ option.value }}
+ </span>
+ </div>
+
+ <div
+ v-if="
+ !!fetchState?.nextPageToken && index === valueOptions.length - 1
+ "
+ class="py-2 px-1 border-t border-block-border"
+ >
+ <NButton
+ quaternary
+ :size="'small'"
+ :loading="fetchState?.loading"
+ @click="() => $emit('fetch-next-page')"
+ >
+ <span class="textinfolabel">
+ {{ $t("common.load-more") }}
+ </span>
+ </NButton>
+ </div>
</div>
</template>
- </VirtualList>
+ </NVirtualList>
</div>
<div v-if="valueOptions.length === 0" class="pb-2">
<NEmpty />
@@ -57,32 +86,30 @@ import {
useElementSize,
useWindowSize,
} from "@vueuse/core";
-import { NEmpty } from "naive-ui";
+import { NEmpty, NButton, NVirtualList } from "naive-ui";
import { computed, nextTick, ref, watch } from "vue";
-import { VirtualList } from "vueuc";
-import type { SearchParams } from "@/utils";
import type { ScopeOption, ValueOption } from "./types";
-type ListItem = {
- item: ValueOption;
- index: number;
-};
-
const props = defineProps<{
show: boolean;
- params: SearchParams;
scopeOption?: ScopeOption;
valueOptions: ValueOption[];
menuIndex: number;
+ fetchState?: {
+ loading: boolean;
+ nextPageToken?: string;
+ };
}>();
+
defineEmits<{
(event: "select-value", value: string): void;
(event: "hover-item", index: number): void;
+ (event: "fetch-next-page"): void;
}>();
const containerRef = ref<HTMLElement>();
const titleRef = ref<HTMLElement>();
-const virtualListRef = ref<InstanceType<typeof VirtualList>>();
+const virtualListRef = ref<InstanceType<typeof NVirtualList>>();
const { height: titleHeight } = useElementSize(titleRef, undefined, {
box: "border-box",
});
@@ -99,7 +126,7 @@ const maxListHeight = computed(() => {
);
});
-const highlightedItem = computed((): ListItem | undefined => {
+const highlightedItem = computed(() => {
if (!props.show) return undefined;
const options = props.valueOptions;
const index = props.menuIndex;
diff --git a/frontend/src/components/AdvancedSearch/types.ts b/frontend/src/components/AdvancedSearch/types.ts
index c994311c91..518cfd90d5 100644
--- a/frontend/src/components/AdvancedSearch/types.ts
+++ b/frontend/src/components/AdvancedSearch/types.ts
@@ -4,9 +4,13 @@ import type { SearchScopeId } from "@/utils";
export type ScopeOption = {
id: SearchScopeId;
title: string;
- options: ValueOption[];
+ options?: ValueOption[];
description?: string;
allowMultiple?: boolean;
+ search?: (op: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => Promise<{ nextPageToken?: string; options: ValueOption[] }>;
};
export type ValueOption = {
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index be938cd023..091fc3da99 100644
--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -1,5 +1,5 @@
import type { VNode } from "vue";
-import { computed, h, unref, ref, watchEffect } from "vue";
+import { computed, h, unref } from "vue";
import {
InstanceV1Name,
ProjectV1Name,
@@ -13,7 +13,7 @@ import {
useInstanceV1Store,
useProjectV1Store,
} from "@/store";
-import type { MaybeRef, ComposedProject, ComposedInstance } from "@/types";
+import type { MaybeRef } from "@/types";
import { engineToJSON } from "@/types/proto/v1/common";
import type { SearchScopeId } from "@/utils";
import {
@@ -33,30 +33,6 @@ export const useCommonSearchScopeOptions = (
const instanceStore = useInstanceV1Store();
const environmentStore = useEnvironmentV1Store();
const environmentList = useEnvironmentV1List();
- const projectList = ref<ComposedProject[]>([]);
- const instanceList = ref<ComposedInstance[]>([]);
-
- watchEffect(async () => {
- try {
- const { projects } = await projectStore.fetchProjectList({
- pageSize: getDefaultPagination(),
- });
- projectList.value = projects;
- } catch {
- // do nothing
- }
- });
-
- watchEffect(async () => {
- try {
- const { instances } = await instanceStore.fetchInstanceList({
- pageSize: getDefaultPagination(),
- });
- instanceList.value = instances;
- } catch {
- // do nothing
- }
- });
// fullScopeOptions provides full search scopes and options.
// we need this as the source of truth.
@@ -66,54 +42,96 @@ export const useCommonSearchScopeOptions = (
id: "project",
title: t("issue.advanced-search.scope.project.title"),
description: t("issue.advanced-search.scope.project.description"),
- options: projectList.value.map<ValueOption>((project) => {
- const name = extractProjectResourceName(project.name);
- return {
- value: name,
- keywords: [
- name,
- project.title,
- extractProjectResourceName(project.name),
- ],
- render: () => {
- const children: VNode[] = [
- h(ProjectV1Name, { project: project, link: false }),
- ];
- return h("div", { class: "flex items-center gap-x-2" }, children);
- },
- };
- }),
+ search: ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => {
+ return projectStore
+ .fetchProjectList({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ filter: {
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.projects.map<ValueOption>((project) => {
+ const name = extractProjectResourceName(project.name);
+ return {
+ value: name,
+ keywords: [
+ name,
+ project.title,
+ extractProjectResourceName(project.name),
+ ],
+ render: () => {
+ const children: VNode[] = [
+ h(ProjectV1Name, { project: project, link: false }),
+ ];
+ return h(
+ "div",
+ { class: "flex items-center gap-x-2" },
+ children
+ );
+ },
+ };
+ }),
+ }));
+ },
}),
instance: () => ({
id: "instance",
title: t("issue.advanced-search.scope.instance.title"),
description: t("issue.advanced-search.scope.instance.description"),
- options: instanceList.value.map((ins) => {
- const name = extractInstanceResourceName(ins.name);
- return {
- value: name,
- keywords: [
- name,
- ins.title,
- engineToJSON(ins.engine),
- extractEnvironmentResourceName(ins.environment),
- ],
- render: () => {
- return h("div", { class: "flex items-center gap-x-1" }, [
- h(InstanceV1Name, {
- instance: ins,
- link: false,
- tooltip: false,
- }),
- h(
- "span",
- {},
- `(${environmentV1Name(environmentStore.getEnvironmentByName(ins.environment))})`
- ),
- ]);
- },
- };
- }),
+ search: ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => {
+ return instanceStore
+ .fetchInstanceList({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ filter: {
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.instances.map((ins) => {
+ const name = extractInstanceResourceName(ins.name);
+ return {
+ value: name,
+ keywords: [
+ name,
+ ins.title,
+ engineToJSON(ins.engine),
+ extractEnvironmentResourceName(ins.environment),
+ ],
+ render: () => {
+ return h("div", { class: "flex items-center gap-x-1" }, [
+ h(InstanceV1Name, {
+ instance: ins,
+ link: false,
+ tooltip: false,
+ }),
+ h(
+ "span",
+ {},
+ `(${environmentV1Name(environmentStore.getEnvironmentByName(ins.environment))})`
+ ),
+ ]);
+ },
+ };
+ }),
+ }));
+ },
}),
environment: () => ({
id: "environment",
@@ -137,7 +155,6 @@ export const useCommonSearchScopeOptions = (
description: t(
"issue.advanced-search.scope.database-label.description"
),
- options: [] as ValueOption[],
allowMultiple: true,
}),
engine: () => ({
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
index 926988e794..d7ea17331c 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
+++ b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
@@ -16,8 +16,7 @@
</template>
<script lang="tsx" setup>
-import { orderBy } from "lodash-es";
-import { computed, onMounted, ref } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { BBAvatar } from "@/bbkit";
import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";
@@ -30,9 +29,9 @@ import YouTag from "@/components/misc/YouTag.vue";
import { ProjectV1Name } from "@/components/v2";
import { ALL_METHODS_WITH_AUDIT } from "@/grpcweb/methods";
import { useCurrentUserV1, useProjectV1Store, useUserStore } from "@/store";
-import { SYSTEM_BOT_USER_NAME, type ComposedProject } from "@/types";
+import { SYSTEM_BOT_USER_NAME } from "@/types";
import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";
-import { type User, UserType } from "@/types/proto/v1/user_service";
+import { UserType } from "@/types/proto/v1/user_service";
import {
getDefaultPagination,
extractProjectResourceName,
@@ -50,55 +49,8 @@ const { t } = useI18n();
const me = useCurrentUserV1();
const userStore = useUserStore();
const projectStore = useProjectV1Store();
-
-const activeUserList = ref<User[]>([]);
-const projectList = ref<ComposedProject[]>([]);
const showTimeRange = ref(false);
-onMounted(async () => {
- const [listUsersResponse, listProjectsResponse] = await Promise.all([
- userStore.fetchUserList({
- pageSize: getDefaultPagination(),
- filter: {
- types: [UserType.USER],
- },
- }),
- projectStore.fetchProjectList({
- pageSize: getDefaultPagination(),
- }),
- ]);
- activeUserList.value = listUsersResponse.users;
- projectList.value = listProjectsResponse.projects;
-});
-
-const principalSearchValueOptions = computed(() => {
- // Put "you" to the top
- const sortedUsers = orderBy(
- activeUserList.value,
- (user) => (user.name === me.value.name ? -1 : 1),
- "asc"
- );
- return sortedUsers.map<ValueOption>((user) => {
- return {
- value: user.email,
- keywords: [user.email, user.title],
- render: () => {
- const children = [
- <BBAvatar size="TINY" username={user.title} />,
- <span>{user.title}</span>,
- ];
- if (user.name === me.value.name) {
- children.push(<YouTag />);
- }
- if (user.name === SYSTEM_BOT_USER_NAME) {
- children.push(<SystemBotTag />);
- }
- return <div class="flex items-center gap-x-1">{children}</div>;
- },
- };
- });
-});
-
// fullScopeOptions provides full search scopes and options.
const scopeOptions = computed((): ScopeOption[] => {
const scopes: ScopeOption[] = [
@@ -106,27 +58,90 @@ const scopeOptions = computed((): ScopeOption[] => {
id: "project",
title: t("issue.advanced-search.scope.project.title"),
description: t("issue.advanced-search.scope.project.description"),
- options: projectList.value.map<ValueOption>((project) => {
- const name = extractProjectResourceName(project.name);
- return {
- value: name,
- keywords: [
- name,
- project.title,
- extractProjectResourceName(project.name),
- ],
- render: () => {
- const children = [<ProjectV1Name project={project} link={false} />];
- return <div class="flex items-center gap-x-2">{children}</div>;
- },
- };
- }),
+ search: ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => {
+ return projectStore
+ .fetchProjectList({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ filter: {
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.projects.map<ValueOption>((project) => {
+ const name = extractProjectResourceName(project.name);
+ return {
+ value: name,
+ keywords: [
+ name,
+ project.title,
+ extractProjectResourceName(project.name),
+ ],
+ render: () => {
+ const children = [
+ <ProjectV1Name project={project} link={false} />,
+ ];
+ return (
+ <div class="flex items-center gap-x-2">{children}</div>
+ );
+ },
+ };
+ }),
+ }));
+ },
},
{
id: "actor",
title: t("audit-log.advanced-search.scope.actor.title"),
description: t("audit-log.advanced-search.scope.actor.description"),
- options: principalSearchValueOptions.value,
+ search: ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => {
+ return userStore
+ .fetchUserList({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ filter: {
+ types: [UserType.USER],
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.users.map<ValueOption>((user) => {
+ return {
+ value: user.email,
+ keywords: [user.email, user.title],
+ render: () => {
+ const children = [
+ <BBAvatar size="TINY" username={user.title} />,
+ <span>{user.title}</span>,
+ ];
+ if (user.name === me.value.name) {
+ children.push(<YouTag />);
+ }
+ if (user.name === SYSTEM_BOT_USER_NAME) {
+ children.push(<SystemBotTag />);
+ }
+ return (
+ <div class="flex items-center gap-x-1">{children}</div>
+ );
+ },
+ };
+ }),
+ }));
+ },
},
{
id: "method",
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
index 31ae56a819..a58b816cfa 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -39,17 +39,11 @@
</template>
<script lang="ts" setup>
-import { ref, computed, onMounted } from "vue";
+import { ref, computed } from "vue";
import AdvancedSearch from "@/components/AdvancedSearch";
import TimeRange from "@/components/AdvancedSearch/TimeRange.vue";
-import { useUserStore } from "@/store";
-import { User, UserType } from "@/types/proto/v1/user_service";
import type { SearchParams, SearchScopeId } from "@/utils";
-import {
- getDefaultPagination,
- UIIssueFilterScopeIdList,
- useSearchScopeIdList,
-} from "@/utils";
+import { UIIssueFilterScopeIdList, useSearchScopeIdList } from "@/utils";
import Status from "./Status.vue";
import { useIssueSearchScopeOptions } from "./useIssueSearchScopeOptions";
@@ -75,7 +69,6 @@ defineEmits<{
const SearchScopeIdList = useSearchScopeIdList();
const showTimeRange = ref(false);
-const userStore = useUserStore();
const allowedScopes = computed(() => {
if (props.overrideScopeIdList && props.overrideScopeIdList.length > 0) {
@@ -84,21 +77,8 @@ const allowedScopes = computed(() => {
return [...UIIssueFilterScopeIdList, ...SearchScopeIdList.value];
});
-const activeUserList = ref<User[]>([]);
-
-onMounted(async () => {
- const { users } = await userStore.fetchUserList({
- pageSize: getDefaultPagination(),
- filter: {
- types: [UserType.USER],
- },
- });
- activeUserList.value = users;
-});
-
const scopeOptions = useIssueSearchScopeOptions(
computed(() => props.params),
- allowedScopes,
- activeUserList
+ allowedScopes
);
</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
index 5d477ebb06..46fa48d6ae 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
@@ -1,9 +1,12 @@
-import { orderBy } from "lodash-es";
-import type { Ref, RenderFunction } from "vue";
+import type { Ref } from "vue";
import { computed, h, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
import BBAvatar from "@/bbkit/BBAvatar.vue";
+import type {
+ ScopeOption,
+ ValueOption,
+} from "@/components/AdvancedSearch/types";
import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import SystemBotTag from "@/components/misc/SystemBotTag.vue";
import YouTag from "@/components/misc/YouTag.vue";
@@ -12,15 +15,11 @@ import {
useCurrentUserV1,
useDatabaseV1Store,
useProjectV1Store,
+ useUserStore,
} from "@/store";
-import {
- SYSTEM_BOT_USER_NAME,
- UNKNOWN_ID,
- isValidProjectName,
- type ComposedDatabase,
-} from "@/types";
+import { SYSTEM_BOT_USER_NAME, UNKNOWN_ID, isValidProjectName } from "@/types";
import { type Label } from "@/types/proto/v1/project_service";
-import { User } from "@/types/proto/v1/user_service";
+import { UserType } from "@/types/proto/v1/user_service";
import type { SearchParams, SearchScopeId } from "@/utils";
import {
getDefaultPagination,
@@ -29,31 +28,16 @@ import {
extractProjectResourceName,
} from "@/utils";
-export type ScopeOption = {
- id: SearchScopeId;
- title: string;
- options: ValueOption[];
- description?: string;
-};
-
-export type ValueOption = {
- value: string;
- keywords: string[];
- bot?: boolean;
- custom?: boolean;
- render: RenderFunction;
-};
-
export const useIssueSearchScopeOptions = (
params: Ref<SearchParams>,
- supportOptionIdList: Ref<SearchScopeId[]>,
- activeUserList: Ref<User[]>
+ supportOptionIdList: Ref<SearchScopeId[]>
) => {
const { t } = useI18n();
const route = useRoute();
const me = useCurrentUserV1();
const databaseV1Store = useDatabaseV1Store();
const projectStore = useProjectV1Store();
+ const userStore = useUserStore();
const projectName = computed(() => {
const { projectId } = route?.params ?? {};
@@ -69,7 +53,6 @@ export const useIssueSearchScopeOptions = (
return undefined;
});
- const databaseList = ref<ComposedDatabase[]>([]);
const projectLabels = ref<Label[]>([]);
watchEffect(async () => {
@@ -87,47 +70,53 @@ export const useIssueSearchScopeOptions = (
projectLabels.value = [...labels.values()];
});
- watchEffect(async () => {
- if (!isValidProjectName(projectName.value)) {
- return;
- }
- const { databases } = await databaseV1Store.fetchDatabases({
- pageSize: getDefaultPagination(),
- parent: projectName.value!,
- });
- databaseList.value = databases;
- });
-
const commonScopeOptions = useCommonSearchScopeOptions(supportOptionIdList);
- const principalSearchValueOptions = computed(() => {
- // Put "you" to the top
- const sortedUsers = orderBy(
- activeUserList.value,
- (user) => (user.name === me.value.name ? -1 : 1),
- "asc"
- );
- return sortedUsers.map<ValueOption>((user) => {
- return {
- value: user.email,
- keywords: [user.email, user.title],
- bot: user.name === SYSTEM_BOT_USER_NAME,
- render: () => {
- const children = [
- h(BBAvatar, { size: "TINY", username: user.title }),
- renderSpan(user.title),
- ];
- if (user.name === me.value.name) {
- children.push(h(YouTag));
- }
- if (user.name === SYSTEM_BOT_USER_NAME) {
- children.push(h(SystemBotTag));
- }
- return h("div", { class: "flex items-center gap-x-1" }, children);
- },
- };
- });
- });
+ const searchPrincipalSearchValueOptions = (userTypes: UserType[]) => {
+ return ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) =>
+ userStore
+ .fetchUserList({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ filter: {
+ types: userTypes,
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.users.map<ValueOption>((user) => {
+ return {
+ value: user.email,
+ keywords: [user.email, user.title],
+ bot: user.name === SYSTEM_BOT_USER_NAME,
+ render: () => {
+ const children = [
+ h(BBAvatar, { size: "TINY", username: user.title }),
+ renderSpan(user.title),
+ ];
+ if (user.name === me.value.name) {
+ children.push(h(YouTag));
+ }
+ if (user.name === SYSTEM_BOT_USER_NAME) {
+ children.push(h(SystemBotTag));
+ }
+ return h(
+ "div",
+ { class: "flex items-center gap-x-1" },
+ children
+ );
+ },
+ };
+ }),
+ }));
+ };
// fullScopeOptions provides full search scopes and options.
// we need this as the source of truth.
@@ -138,29 +127,49 @@ export const useIssueSearchScopeOptions = (
id: "database",
title: t("issue.advanced-search.scope.database.title"),
description: t("issue.advanced-search.scope.database.description"),
- options: databaseList.value.map((db) => {
- return {
- value: db.name,
- keywords: [
- db.databaseName,
- extractInstanceResourceName(db.instance),
- db.instanceResource.title,
- extractEnvironmentResourceName(db.effectiveEnvironment),
- db.effectiveEnvironmentEntity.title,
- extractProjectResourceName(db.project),
- db.projectEntity.title,
- ],
- custom: true,
- render: () => {
- return h("div", { class: "text-sm" }, [
- h(RichDatabaseName, {
- database: db,
- showProject: true,
- }),
- ]);
- },
- };
- }),
+ search: ({
+ keyword,
+ nextPageToken,
+ }: {
+ keyword: string;
+ nextPageToken?: string;
+ }) => {
+ return databaseV1Store
+ .fetchDatabases({
+ pageToken: nextPageToken,
+ pageSize: getDefaultPagination(),
+ parent: projectName.value!,
+ filter: {
+ query: keyword,
+ },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.databases.map((db) => {
+ return {
+ value: db.name,
+ keywords: [
+ db.databaseName,
+ extractInstanceResourceName(db.instance),
+ db.instanceResource.title,
+ extractEnvironmentResourceName(db.effectiveEnvironment),
+ db.effectiveEnvironmentEntity.title,
+ extractProjectResourceName(db.project),
+ db.projectEntity.title,
+ ],
+ custom: true,
+ render: () => {
+ return h("div", { class: "text-sm" }, [
+ h(RichDatabaseName, {
+ database: db,
+ showProject: true,
+ }),
+ ]);
+ },
+ };
+ }),
+ }));
+ },
},
{
id: "status",
@@ -206,19 +215,30 @@ export const useIssueSearchScopeOptions = (
id: "creator",
title: t("issue.advanced-search.scope.creator.title"),
description: t("issue.advanced-search.scope.creator.description"),
- options: principalSearchValueOptions.value,
+ search: searchPrincipalSearchValueOptions([
+ UserType.USER,
+ UserType.SERVICE_ACCOUNT,
+ UserType.SYSTEM_BOT,
+ ]),
},
{
id: "approver",
title: t("issue.advanced-search.scope.approver.title"),
description: t("issue.advanced-search.scope.approver.description"),
- options: principalSearchValueOptions.value.filter((o) => !o.bot),
+ search: searchPrincipalSearchValueOptions([
+ UserType.USER,
+ UserType.SERVICE_ACCOUNT,
+ ]),
},
{
id: "subscriber",
title: t("issue.advanced-search.scope.subscriber.title"),
description: t("issue.advanced-search.scope.subscriber.description"),
- options: principalSearchValueOptions.value,
+ search: searchPrincipalSearchValueOptions([
+ UserType.USER,
+ UserType.SERVICE_ACCOUNT,
+ UserType.SYSTEM_BOT,
+ ]),
},
{
id: "taskType",
@@ -258,9 +278,7 @@ export const useIssueSearchScopeOptions = (
},
];
const supportOptionIdSet = new Set(supportOptionIdList.value);
- return scopes.filter(
- (scope) => supportOptionIdSet.has(scope.id) && scope.options.length > 0
- );
+ return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
});
// filteredScopeOptions will filter search options by chosen scope.
@@ -272,13 +290,13 @@ export const useIssueSearchScopeOptions = (
const clone = fullScopeOptions.value.map((scope) => ({
...scope,
- options: scope.options.map((option) => ({
+ options: scope.options?.map((option) => ({
...option,
})),
}));
const index = clone.findIndex((scope) => scope.id === "database");
if (index >= 0) {
- clone[index].options = clone[index].options.filter((option) => {
+ clone[index].options = clone[index].options?.filter((option) => {
if (!existedScopes.has("project") && !existedScopes.has("instance")) {
return true;
}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index dec44961a4..d1c22fc194 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -777,6 +777,7 @@
"advanced-search": {
"self": "Advanced search",
"filter": "Filter",
+ "search": "Input title or id to search",
"scope": {
"project": {
"title": "Project",
@@ -824,7 +825,7 @@
},
"database-label": {
"title": "Label",
- "description": "Input the \"label key\":\"label value\" then press Enter"
+ "description": "Input the \"key:value\" pair then press Enter"
},
"engine": {
"title": "Engine",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 96fa18896d..3ab5b8ae78 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -777,6 +777,7 @@
"advanced-search": {
"self": "Búsqueda Avanzada",
"filter": "Filtrar",
+ "search": "Ingrese título o id para buscar",
"scope": {
"project": {
"title": "Proyecto",
@@ -824,7 +825,7 @@
},
"database-label": {
"title": "Etiqueta",
- "description": "Ingrese la \"key\":\"value\" y luego presione Enter"
+ "description": "Ingrese la \"key:value\" y luego presione Enter"
},
"engine": {
"title": "Motor",
@@ -2599,4 +2600,4 @@
"last-visit": "Última visita",
"changelog-for-version": "Registro de cambios para {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index b5261b29f0..c8096860f6 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -777,6 +777,7 @@
"advanced-search": {
"self": "高度な検索",
"filter": "フィルター",
+ "search": "検索するにはタイトルまたはIDを入力してください",
"scope": {
"project": {
"title": "プロジェクト",
@@ -824,7 +825,7 @@
},
"database-label": {
"title": "ラベル",
- "description": "\"key\":\"value\"を入力し、Enterを押します。"
+ "description": "\"key:value\"を入力し、Enterを押します。"
},
"engine": {
"title": "エンジン",
@@ -2599,4 +2600,4 @@
"last-visit": "最終訪問",
"changelog-for-version": "{version} の変更履歴"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index ad50f11544..b5574c9536 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -777,6 +777,7 @@
"advanced-search": {
"self": "Tìm kiếm nâng cao",
"filter": "Bộ lọc",
+ "search": "Nhập tiêu đề hoặc id để tìm kiếm",
"scope": {
"project": {
"title": "Dự án",
@@ -824,7 +825,7 @@
},
"database-label": {
"title": "Nhãn",
- "description": "Nhập \"key\":\"value\" rồi nhấn Enter"
+ "description": "Nhập \"key:value\" rồi nhấn Enter"
},
"engine": {
"title": "Động cơ",
@@ -2599,4 +2600,4 @@
"last-visit": "Lần truy cập cuối",
"changelog-for-version": "Nhật ký thay đổi cho phiên bản {version}"
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 79e35d76af..6965d750ea 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -777,6 +777,7 @@
"advanced-search": {
"self": "高级搜索",
"filter": "过滤",
+ "search": "输入名称或 ID 来搜索",
"scope": {
"project": {
"title": "项目",
@@ -824,7 +825,7 @@
},
"database-label": {
"title": "标签",
- "description": "输入\"key\":\"value\"后按下回车"
+ "description": "输入 \"key:value\" 后按下回车"
},
"engine": {
"title": "引擎",
@@ -2599,4 +2600,4 @@
"last-visit": "上次访问",
"changelog-for-version": "{version} 的更新日志"
}
-}
+}
\ No newline at end of file