Skip to content

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

refactor: combine advanced search components (#11951)

boojack7a16911fb0c2
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vue b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
similarity index 82%
rename from frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vue
rename to frontend/src/components/AdvancedSearch/AdvancedSearch.vue
index cb202ce591..a045a05c23 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vue
+++ b/frontend/src/components/AdvancedSearch/AdvancedSearch.vue
@@ -63,7 +63,7 @@
class="absolute top-[36px] w-full bg-gray-100 shadow-xl origin-top-left rounded-[3px] overflow-clip"
>
<ScopeMenu
- :show="menuView === 'scope'"
+ :show="state.menuView === 'scope'"
:params="params"
:options="visibleScopeOptions"
:menu-index="menuIndex"
@@ -71,7 +71,7 @@
@hover-item="menuIndex = $event"
/>
<ValueMenu
- :show="menuView === 'value'"
+ :show="state.menuView === 'value'"
:params="params"
:scope-option="currentScopeOption"
:value-options="visibleValueOptions"
@@ -94,15 +94,7 @@ import type { InputInst } from "naive-ui";
import { NInput } from "naive-ui";
import scrollIntoView from "scroll-into-view-if-needed";
import { zindexable as vZindexable } from "vdirs";
-import {
- reactive,
- watch,
- onMounted,
- ref,
- toRef,
- computed,
- nextTick,
-} from "vue";
+import { reactive, watch, onMounted, ref, computed, nextTick } from "vue";
import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";
import {
emptySearchParams,
@@ -113,19 +105,19 @@ import {
import ScopeMenu from "./ScopeMenu.vue";
import ScopeTags from "./ScopeTags.vue";
import ValueMenu from "./ValueMenu.vue";
-import { useSearchScopeOptions } from "./useSearchScopeOptions";
+import type { ScopeOption } from "./types";
const props = withDefaults(
defineProps<{
- placeholder?: string | undefined;
params: SearchParams;
+ scopeOptions: ScopeOption[];
+ placeholder?: string | undefined;
readonlyScopes?: SearchScope[];
autofocus?: boolean;
- supportOptionIdList?: SearchScopeId[];
}>(),
{
+ scopeOptions: () => [],
readonlyScopes: () => [],
- supportOptionIdList: () => [],
autofocus: false,
placeholder: undefined,
}
@@ -138,8 +130,8 @@ const emit = defineEmits<{
interface LocalState {
searchText: string;
- showSearchScopes: boolean;
currentScope?: SearchScopeId;
+ menuView?: "value" | "scope";
}
const defaultSearchParams = () => {
@@ -163,7 +155,6 @@ const buildSearchTextByParams = (params: SearchParams | undefined): string => {
const state = reactive<LocalState>({
searchText: buildSearchTextByParams(props.params),
- showSearchScopes: props.autofocus,
});
const containerRef = ref<HTMLElement>();
const tagsContainerRef = ref<HTMLElement>();
@@ -179,13 +170,6 @@ const editableScopes = computed(() => {
return props.params.scopes.filter((s) => !readonlyScopeIds.value.has(s.id));
});
-watch(
- () => state.showSearchScopes,
- (show) => {
- if (show) state.currentScope = undefined;
- }
-);
-
watch(
() => props.params,
(params) => {
@@ -193,17 +177,34 @@ watch(
}
);
-const {
- menuView,
- fullScopeOptions,
- availableScopeOptions,
- currentScope,
- currentScopeOption,
- valueOptions,
-} = useSearchScopeOptions(
- toRef(props, "params"),
- toRef(props, "supportOptionIdList")
-);
+const valueOptions = computed(() => {
+ if (state.menuView === "value" && currentScopeOption.value) {
+ return currentScopeOption.value.options;
+ }
+ return [];
+});
+
+const currentScopeOption = computed(() => {
+ if (state.currentScope) {
+ return props.scopeOptions.find((opt) => opt.id === state.currentScope);
+ }
+ return undefined;
+});
+
+// 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[] => {
+ const existedScopes = new Set<SearchScopeId>(
+ props.params.scopes.map((scope) => scope.id)
+ );
+
+ return props.scopeOptions.filter((scope) => {
+ if (existedScopes.has(scope.id)) {
+ return false;
+ }
+ return true;
+ });
+});
const visibleScopeOptions = computed(() => {
if (currentScopeOption.value) {
@@ -221,8 +222,8 @@ const visibleScopeOptions = computed(() => {
});
const visibleValueOptions = computed(() => {
- if (!currentScope.value) return [];
- const scopePrefix = `${currentScope.value}:`;
+ if (!state.currentScope) return [];
+ const scopePrefix = `${state.currentScope}:`;
const keyword = inputText.value
.trim()
.toLowerCase()
@@ -238,7 +239,7 @@ const visibleValueOptions = computed(() => {
const currentValue = getValueFromSearchParams(
props.params,
- currentScope.value
+ state.currentScope
);
const option = valueOptions.value.find((opt) => opt.value === currentValue);
if (currentValue && option) {
@@ -252,18 +253,18 @@ const visibleValueOptions = computed(() => {
});
const visibleOptions = computed(() => {
- return menuView.value === "scope"
+ return state.menuView === "scope"
? visibleScopeOptions.value
- : menuView.value === "value"
+ : state.menuView === "value"
? visibleValueOptions.value
: ([] as unknown[]);
});
const showMenu = computed(() => {
- if (menuView.value === "scope") {
+ if (state.menuView === "scope") {
return visibleScopeOptions.value.length > 0;
}
- if (menuView.value === "value") {
+ if (state.menuView === "value") {
return true;
}
return false;
@@ -277,8 +278,8 @@ const clearable = computed(() => {
const hideMenu = () => {
nextTick(() => {
- menuView.value = undefined;
- currentScope.value = undefined;
+ state.menuView = undefined;
+ state.currentScope = undefined;
focusedTagId.value = undefined;
});
};
@@ -302,22 +303,22 @@ const selectScope = (
id: SearchScopeId | undefined,
value: string | undefined = undefined
) => {
- currentScope.value = id;
+ state.currentScope = id;
if (id) {
- menuView.value = "value";
+ state.menuView = "value";
// Fill-in the scope prefix if needed
if (!inputText.value.startsWith(`${id}:`)) {
inputText.value = `${id}:${value ?? ""}`;
}
scrollScopeTagIntoViewIfNeeded(id);
} else {
- menuView.value = "scope";
+ state.menuView = "scope";
}
};
const selectValue = (value: string) => {
- const id = currentScope.value;
+ const id = state.currentScope;
if (!id) {
- menuView.value = undefined;
+ state.menuView = undefined;
return;
}
const updated = upsertScope(props.params, {
@@ -333,20 +334,20 @@ const selectValue = (value: string) => {
hideMenu();
};
const selectScopeFromTag = (id: SearchScopeId) => {
- if (fullScopeOptions.value.find((opt) => opt.id === id)) {
- // For AdvancedSearchBox supported scopes
+ if (props.scopeOptions.find((opt) => opt.id === id)) {
+ // For AdvancedSearch supported scopes
selectScope(id);
return;
}
- // Unsupported scope for AdvancedSearchBox
+ // Unsupported scope for AdvancedSearch
// emit an event and wish the parent UI can handle this
emit("select-unsupported-scope", id);
hideMenu();
};
const maybeSelectMatchedScope = () => {
- if (!menuView.value || menuView.value === "scope") {
+ if (!state.menuView || state.menuView === "scope") {
const matchedScope = visibleScopeOptions.value.find((opt) =>
inputText.value.startsWith(`${opt.id}:`)
);
@@ -355,19 +356,19 @@ const maybeSelectMatchedScope = () => {
selectScope(matchedScope.id);
return true;
}
- if (!menuView.value) {
+ if (!state.menuView) {
// Show scope menu if none of the menus are shown
- menuView.value = "scope";
+ state.menuView = "scope";
return true;
}
}
return false;
};
const maybeDeselectMismatchedScope = () => {
- if (menuView.value === "value" && currentScope.value) {
- if (!inputText.value.startsWith(`${currentScope.value}:`)) {
+ if (state.menuView === "value" && state.currentScope) {
+ if (!inputText.value.startsWith(`${state.currentScope}:`)) {
// de-select current scope since the inputText doesn't match its prefix.
- menuView.value = "scope";
+ state.menuView = "scope";
selectScope(undefined);
return true;
}
@@ -433,7 +434,7 @@ const handleKeyUp = (e: KeyboardEvent) => {
const { key } = e;
if (key === "Escape") {
maybeEmitIncompleteValue();
- menuView.value = undefined;
+ state.menuView = undefined;
return;
}
if (key === "Backspace" && inputText.value === "") {
@@ -454,7 +455,7 @@ const handleKeyUp = (e: KeyboardEvent) => {
// Press enter to select scope (dive into the next step)
// or select value
const index = menuIndex.value;
- if (menuView.value === "scope") {
+ if (state.menuView === "scope") {
const option = visibleScopeOptions.value[index];
if (option) {
selectScope(option.id);
@@ -462,7 +463,7 @@ const handleKeyUp = (e: KeyboardEvent) => {
return;
}
}
- if (menuView.value === "value") {
+ if (state.menuView === "value") {
const option = visibleValueOptions.value[index];
if (option) {
selectValue(option.value);
@@ -500,21 +501,24 @@ onMounted(() => {
inputRef.value?.inputElRef?.focus();
}
});
-watch(menuView, () => {
- focusedTagId.value = undefined;
- menuIndex.value = 0;
- if (menuView.value === "value" && currentScope.value) {
- const value = getValueFromSearchParams(props.params, currentScope.value);
- if (value) {
- const index = valueOptions.value.findIndex(
- (option) => option.value === value
- );
- if (index >= 0) menuIndex.value = index;
+watch(
+ () => state.menuView,
+ () => {
+ focusedTagId.value = undefined;
+ menuIndex.value = 0;
+ if (state.menuView === "value" && state.currentScope) {
+ const value = getValueFromSearchParams(props.params, state.currentScope);
+ if (value) {
+ const index = valueOptions.value.findIndex(
+ (option) => option.value === value
+ );
+ if (index >= 0) menuIndex.value = index;
+ }
}
}
-});
+);
watch(visibleScopeOptions, (newOptions, oldOptions) => {
- if (menuView.value !== "scope") return;
+ if (state.menuView !== "scope") return;
const highlightedScope = oldOptions[menuIndex.value]?.id;
if (highlightedScope) {
const index = newOptions.findIndex((opt) => opt.id === highlightedScope);
@@ -526,7 +530,7 @@ watch(visibleScopeOptions, (newOptions, oldOptions) => {
menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);
});
watch(visibleValueOptions, (newOptions, oldOptions) => {
- if (menuView.value !== "value") return;
+ if (state.menuView !== "value") return;
const highlightedValue = oldOptions[menuIndex.value]?.value;
if (highlightedValue) {
const index = newOptions.findIndex((opt) => opt.value === highlightedValue);
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue b/frontend/src/components/AdvancedSearch/ScopeMenu.vue
similarity index 97%
rename from frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue
rename to frontend/src/components/AdvancedSearch/ScopeMenu.vue
index 811294bbff..5ce290614c 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue
+++ b/frontend/src/components/AdvancedSearch/ScopeMenu.vue
@@ -39,7 +39,7 @@ import { useElementBounding, useWindowSize } from "@vueuse/core";
import { computed, nextTick, ref, watch } from "vue";
import { VirtualList } from "vueuc";
import type { SearchParams, SearchScopeId } from "@/utils";
-import type { ScopeOption } from "./useSearchScopeOptions";
+import type { ScopeOption } from "./types";
type ListItem = {
item: ScopeOption;
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ScopeTags.vue b/frontend/src/components/AdvancedSearch/ScopeTags.vue
similarity index 100%
rename from frontend/src/components/AuditLog/AuditLogSearch/ScopeTags.vue
rename to frontend/src/components/AdvancedSearch/ScopeTags.vue
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/TimeRange.vue b/frontend/src/components/AdvancedSearch/TimeRange.vue
similarity index 100%
rename from frontend/src/components/AuditLog/AuditLogSearch/TimeRange.vue
rename to frontend/src/components/AdvancedSearch/TimeRange.vue
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vue b/frontend/src/components/AdvancedSearch/ValueMenu.vue
similarity index 97%
rename from frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vue
rename to frontend/src/components/AdvancedSearch/ValueMenu.vue
index 94b83c32ec..2c77a5fa89 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vue
+++ b/frontend/src/components/AdvancedSearch/ValueMenu.vue
@@ -61,7 +61,7 @@ import { NEmpty } from "naive-ui";
import { computed, nextTick, ref, watch } from "vue";
import { VirtualList } from "vueuc";
import type { SearchParams } from "@/utils";
-import type { ScopeOption, ValueOption } from "./useSearchScopeOptions";
+import type { ScopeOption, ValueOption } from "./types";
type ListItem = {
item: ValueOption;
diff --git a/frontend/src/components/AdvancedSearch/index.ts b/frontend/src/components/AdvancedSearch/index.ts
new file mode 100644
index 0000000000..04780dc6a4
--- /dev/null
+++ b/frontend/src/components/AdvancedSearch/index.ts
@@ -0,0 +1,6 @@
+import AdvancedSearch from "./AdvancedSearch.vue";
+import TimeRange from "./TimeRange.vue";
+
+export default AdvancedSearch;
+
+export { TimeRange };
diff --git a/frontend/src/components/AdvancedSearch/types.ts b/frontend/src/components/AdvancedSearch/types.ts
new file mode 100644
index 0000000000..85ac271e11
--- /dev/null
+++ b/frontend/src/components/AdvancedSearch/types.ts
@@ -0,0 +1,16 @@
+import type { RenderFunction } from "vue";
+import type { SearchScopeId } from "@/utils";
+
+export type ScopeOption = {
+ id: SearchScopeId;
+ title: string;
+ description: string;
+ options: ValueOption[];
+};
+
+export type ValueOption = {
+ value: string;
+ keywords: string[];
+ custom?: boolean;
+ render: RenderFunction;
+};
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
similarity index 58%
rename from frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
rename to frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index a1a82be6c2..ee6edbfcaa 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -1,6 +1,6 @@
import { orderBy } from "lodash-es";
-import type { Ref, RenderFunction, VNode } from "vue";
-import { computed, h, ref } from "vue";
+import type { Ref, VNode } from "vue";
+import { computed, h, unref } from "vue";
import { useI18n } from "vue-i18n";
import BBAvatar from "@/bbkit/BBAvatar.vue";
import GitIcon from "@/components/GitIcon.vue";
@@ -21,9 +21,9 @@ import {
useEnvironmentV1List,
useProjectV1List,
} from "@/store";
-import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";
+import { SYSTEM_BOT_EMAIL, UNKNOWN_ID, type MaybeRef } from "@/types";
import { engineToJSON } from "@/types/proto/v1/common";
-import { Workflow, Label } from "@/types/proto/v1/project_service";
+import { Workflow } from "@/types/proto/v1/project_service";
import type { SearchParams, SearchScopeId } from "@/utils";
import {
environmentV1Name,
@@ -31,43 +31,11 @@ import {
extractInstanceResourceName,
extractProjectResourceName,
} from "@/utils";
+import type { ScopeOption, ValueOption } from "./types";
-export type ScopeOption = {
- id: SearchScopeId;
- title: string;
- description: string;
- options: ValueOption[];
-};
-
-export type ValueOption = {
- value: string;
- keywords: string[];
- custom?: boolean;
- render: RenderFunction;
-};
-
-const useProjectLabels = (params: Ref<SearchParams>) => {
- const { projectList } = useProjectV1List();
- const projectName = params.value.scopes.find(
- (scope) => scope.id === "project"
- )?.value;
-
- const labels = new Map<string, Label>();
- for (const project of projectList.value) {
- if (projectName && project.name !== `projects/${projectName}`) {
- continue;
- }
- for (const label of project.issueLabels) {
- const key = `${label.value}-${label.color}`;
- labels.set(key, label);
- }
- }
- return [...labels.values()];
-};
-
-export const useSearchScopeOptions = (
+export const useCommonSearchScopeOptions = (
params: Ref<SearchParams>,
- supportOptionIdList: Ref<SearchScopeId[]>
+ supportOptionIdList: MaybeRef<SearchScopeId[]>
) => {
const { t } = useI18n();
const me = useCurrentUserV1();
@@ -133,72 +101,12 @@ export const useSearchScopeOptions = (
};
}),
},
- {
- id: "status",
- title: t("common.status"),
- description: t("issue.advanced-search.scope.approval.description"),
- options: [
- {
- value: "OPEN",
- keywords: ["open"],
- render: () => renderSpan(t("issue.table.open")),
- },
- {
- value: "CLOSED",
- keywords: ["closed", "canceled", "done"],
- render: () => renderSpan(t("issue.table.closed")),
- },
- ],
- },
- {
- id: "approval",
- title: t("issue.advanced-search.scope.approval.title"),
- description: t("issue.advanced-search.scope.approval.description"),
- options: [
- {
- value: "pending",
- keywords: ["pending"],
- render: () =>
- renderSpan(
- t("issue.advanced-search.scope.approval.value.pending")
- ),
- },
- {
- value: "approved",
- keywords: ["approved", "done"],
- render: () =>
- renderSpan(
- t("issue.advanced-search.scope.approval.value.approved")
- ),
- },
- ],
- },
{
id: "creator",
title: t("issue.advanced-search.scope.creator.title"),
description: t("issue.advanced-search.scope.creator.description"),
options: principalSearchValueOptions.value,
},
- {
- id: "assignee",
- title: t("issue.advanced-search.scope.assignee.title"),
- description: t("issue.advanced-search.scope.assignee.description"),
- options: principalSearchValueOptions.value,
- },
- {
- id: "approver",
- title: t("issue.advanced-search.scope.approver.title"),
- description: t("issue.advanced-search.scope.approver.description"),
- options: principalSearchValueOptions.value.filter(
- (o) => o.value !== SYSTEM_BOT_EMAIL
- ),
- },
- {
- id: "subscriber",
- title: t("issue.advanced-search.scope.subscriber.title"),
- description: t("issue.advanced-search.scope.subscriber.description"),
- options: principalSearchValueOptions.value,
- },
{
id: "instance",
title: t("issue.advanced-search.scope.instance.title"),
@@ -272,23 +180,6 @@ export const useSearchScopeOptions = (
};
}),
},
- {
- id: "type",
- title: t("issue.advanced-search.scope.type.title"),
- description: t("issue.advanced-search.scope.type.description"),
- options: [
- {
- value: "DDL",
- keywords: ["ddl", "data definition language"],
- render: () => renderSpan("Data Definition Language"),
- },
- {
- value: "DML",
- keywords: ["dml", "data manipulation language"],
- render: () => renderSpan("Data Manipulation Language"),
- },
- ],
- },
{
id: "project-assigned",
title: t("issue.advanced-search.scope.project-assigned.title"),
@@ -314,28 +205,10 @@ export const useSearchScopeOptions = (
},
],
},
- {
- id: "label",
- title: t("issue.advanced-search.scope.label.title"),
- description: t("issue.advanced-search.scope.label.description"),
- options: useProjectLabels(params).map((label) => {
- return {
- value: label.value,
- keywords: [label.value],
- render: () =>
- h("div", { class: "flex items-center gap-x-2" }, [
- h("div", {
- class: "w-4 h-4 rounded",
- style: `background-color: ${label.color};`,
- }),
- label.value,
- ]),
- };
- }),
- },
];
- const supportOptionIdSet = new Set(supportOptionIdList.value);
- return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
+ return scopes.filter((scope) =>
+ unref(supportOptionIdList).includes(scope.id)
+ );
});
// filteredScopeOptions will filter search options by chosen scope.
@@ -383,52 +256,7 @@ export const useSearchScopeOptions = (
return clone;
});
- // 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[] => {
- const existedScopes = new Set<SearchScopeId>(
- params.value.scopes.map((scope) => scope.id)
- );
-
- return filteredScopeOptions.value.filter((scope) => {
- if (existedScopes.has(scope.id)) {
- return false;
- }
- return true;
- });
- });
-
- const menuView = ref<"scope" | "value">();
- const currentScope = ref<SearchScopeId>();
- const currentScopeOption = computed(() => {
- if (currentScope.value) {
- return filteredScopeOptions.value.find(
- (opt) => opt.id === currentScope.value
- );
- }
- return undefined;
- });
- const scopeOptions = computed(() => {
- if (menuView.value === "scope") return availableScopeOptions.value;
- return [];
- });
- const valueOptions = computed(() => {
- if (menuView.value === "value" && currentScopeOption.value) {
- return currentScopeOption.value.options;
- }
- return [];
- });
-
- return {
- fullScopeOptions,
- filteredScopeOptions,
- availableScopeOptions,
- menuView,
- currentScope,
- currentScopeOption,
- scopeOptions,
- valueOptions,
- };
+ return filteredScopeOptions;
};
const renderSpan = (content: string) => {
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 9d249a2001..8af17719c0 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -137,11 +137,11 @@
<NTabPane :tab="$t('common.database')" name="DATABASE">
<div class="space-y-3">
<div class="w-full flex items-center space-x-2">
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
:autofocus="false"
:placeholder="$t('database.filter-database')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<DatabaseLabelFilter
v-model:selected="state.selectedLabels"
@@ -164,11 +164,11 @@
</NTabPane>
<NTabPane :tab="renderDatabaseGroupTabTitle" name="DATABASE_GROUP">
<div class="space-y-3">
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
:autofocus="false"
:placeholder="$t('database.filter-database')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<DatabaseGroupDataTable
:database-group-list="filteredDatabaseGroupList"
@@ -296,7 +296,7 @@ import type {
import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";
import { State } from "@/types/proto/v1/common";
import { TenantMode } from "@/types/proto/v1/project_service";
-import type { SearchScopeId, SearchParams } from "@/utils";
+import type { SearchParams } from "@/utils";
import {
allowUsingSchemaEditorV1,
instanceV1HasAlterSchema,
@@ -307,6 +307,8 @@ import {
extractInstanceResourceName,
extractProjectResourceName,
} from "@/utils";
+import AdvancedSearch from "../AdvancedSearch";
+import { useCommonSearchScopeOptions } from "../AdvancedSearch/useCommonSearchScopeOptions";
import { DatabaseLabelFilter, DrawerContent } from "../v2";
import DatabaseGroupPrevEditorModal from "./DatabaseGroupPrevEditorModal.vue";
import ProjectStandardView from "./ProjectStandardView.vue";
@@ -374,6 +376,15 @@ const state = reactive<LocalState>({
},
});
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => state.params),
+ computed(() =>
+ state.databaseSelectedTab === "DATABASE"
+ ? ["project", "instance", "environment"]
+ : ["project", "environment"]
+ )
+);
+
const hasDatabaseGroupFeature = computed(() => {
return hasFeature("bb.feature.database-grouping");
});
@@ -737,12 +748,4 @@ const generateTenant = async () => {
const cancel = () => {
emit("dismiss");
};
-
-const supportOptionIdList = computed((): SearchScopeId[] => {
- if (state.databaseSelectedTab === "DATABASE") {
- return ["project", "instance", "environment"];
- }
-
- return ["project", "environment"];
-});
</script>
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
index 1d76179151..b8a1725b59 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
+++ b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue
@@ -1,11 +1,10 @@
<template>
<div class="flex flex-row items-center gap-x-2">
- <AdvancedSearchBox
+ <AdvancedSearch
+ class="flex-1"
:params="params"
- :autofocus="autofocus"
:readonly-scopes="readonlyScopes"
- :support-option-id-list="supportOptionIdList"
- class="flex-1"
+ :scope-options="scopeOptions"
@update:params="$emit('update:params', $event)"
/>
<TimeRange
@@ -17,30 +16,132 @@
</div>
</template>
-<script lang="ts" setup>
-import { ref, computed } from "vue";
-import type { SearchParams, SearchScope } from "@/utils";
-import { SearchScopeIdList } from "@/utils";
-import AdvancedSearchBox from "./AdvancedSearchBox.vue";
-import TimeRange from "./TimeRange.vue";
+<script lang="tsx" setup>
+import { orderBy } from "lodash-es";
+import { computed, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import { BBAvatar } from "@/bbkit";
+import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";
+import type {
+ ScopeOption,
+ ValueOption,
+} from "@/components/AdvancedSearch/types";
+import GitIcon from "@/components/GitIcon.vue";
+import SystemBotTag from "@/components/misc/SystemBotTag.vue";
+import YouTag from "@/components/misc/YouTag.vue";
+import { ProjectV1Name } from "@/components/v2";
+import ALL_METHODS from "@/grpcweb/methods";
+import { useCurrentUserV1, useProjectV1List, useUserStore } from "@/store";
+import { SYSTEM_BOT_EMAIL } from "@/types";
+import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";
+import { Workflow } from "@/types/proto/v1/project_service";
+import {
+ extractProjectResourceName,
+ type SearchParams,
+ type SearchScope,
+} from "@/utils";
withDefaults(
defineProps<{
params: SearchParams;
readonlyScopes?: SearchScope[];
- autofocus?: boolean;
}>(),
{
readonlyScopes: () => [],
- components: () => ["searchbox", "time-range"],
- componentProps: undefined,
}
);
defineEmits<{
(event: "update:params", params: SearchParams): void;
}>();
+const { t } = useI18n();
+const me = useCurrentUserV1();
+const userStore = useUserStore();
+const { projectList } = useProjectV1List();
+
const showTimeRange = ref(false);
-const supportOptionIdList = computed(() => [...SearchScopeIdList]);
+const principalSearchValueOptions = computed(() => {
+ // Put "you" to the top
+ const sortedUsers = orderBy(
+ userStore.activeUserList,
+ (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.email === SYSTEM_BOT_EMAIL) {
+ 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[] = [
+ {
+ id: "project",
+ title: t("issue.advanced-search.scope.project.title"),
+ description: t("issue.advanced-search.scope.project.description"),
+ options: projectList.value.map<ValueOption>((proj) => {
+ const name = extractProjectResourceName(proj.name);
+ return {
+ value: name,
+ keywords: [name, proj.title, proj.key],
+ render: () => {
+ const children = [<ProjectV1Name project={proj} link={false} />];
+ if (proj.workflow === Workflow.VCS) {
+ children.push(<GitIcon class="h-4" />);
+ }
+ 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,
+ },
+ {
+ id: "method",
+ title: t("audit-log.advanced-search.scope.method.title"),
+ description: t("audit-log.advanced-search.scope.method.description"),
+ options: ALL_METHODS.map((method) => {
+ return {
+ value: method,
+ keywords: [method],
+ render: () => "",
+ };
+ }),
+ },
+ {
+ id: "level",
+ title: t("audit-log.advanced-search.scope.level.title"),
+ description: t("audit-log.advanced-search.scope.level.description"),
+ options: Object.values(AuditLog_Severity).map((severity) => {
+ return {
+ value: severity,
+ keywords: [severity],
+ render: () => "",
+ };
+ }),
+ },
+ ];
+ return scopes;
+});
</script>
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vue b/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vue
deleted file mode 100644
index 811294bbff..0000000000
--- a/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vue
+++ /dev/null
@@ -1,100 +0,0 @@
-<template>
- <div
- v-if="options.length > 0"
- v-show="show"
- class="overflow-hidden"
- :style="{
- 'max-height': `${maxListHeight}px`,
- }"
- >
- <VirtualList
- ref="virtualListRef"
- :items="options"
- :key-field="`id`"
- :item-resizable="false"
- :item-size="38"
- >
- <template #default="{ item: option, index }: ListItem">
- <div
- class="h-[38px] flex gap-x-1 px-3 items-center cursor-pointer border-t text-sm"
- :class="[
- index === menuIndex && 'bg-gray-200/75',
- index === 0 ? 'border-transparent' : 'border-block-border',
- ]"
- :data-index="index"
- :data-id="option.id"
- @mouseenter.prevent.stop="$emit('hover-item', index)"
- @mousedown.prevent.stop="$emit('select-scope', option.id)"
- >
- <span class="text-accent">{{ option.id }}:</span>
- <span class="text-control-light">{{ option.description }}</span>
- </div>
- </template>
- </VirtualList>
- </div>
-</template>
-
-<script setup lang="ts">
-import { useElementBounding, useWindowSize } from "@vueuse/core";
-import { computed, nextTick, ref, watch } from "vue";
-import { VirtualList } from "vueuc";
-import type { SearchParams, SearchScopeId } from "@/utils";
-import type { ScopeOption } from "./useSearchScopeOptions";
-
-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 { top: containerTop } = useElementBounding(containerRef);
-const { height: windowHeight } = useWindowSize();
-
-const maxListHeight = computed(() => {
- const MAX_HEIGHT = 480;
- const PADDING_BOTTOM = 16;
-
- return Math.min(
- MAX_HEIGHT,
- windowHeight.value - containerTop.value - PADDING_BOTTOM
- );
-});
-
-const highlightedItem = computed((): ListItem | undefined => {
- if (!props.show) return undefined;
- const { options, menuIndex: index } = props;
- const item = options[index];
- if (item) {
- return { item, index };
- }
- return undefined;
-});
-
-watch(
- [highlightedItem, () => props.show],
- ([item, show]) => {
- if (!show) return;
- if (!item) return;
- nextTick(() => {
- const virtualList = virtualListRef.value;
- if (!virtualList) return;
- virtualList.scrollTo({
- index: item.index,
- });
- });
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/index.ts b/frontend/src/components/AuditLog/AuditLogSearch/index.ts
index 7eeca1ff27..5f8980b273 100644
--- a/frontend/src/components/AuditLog/AuditLogSearch/index.ts
+++ b/frontend/src/components/AuditLog/AuditLogSearch/index.ts
@@ -1,5 +1,3 @@
-import AdvancedSearchBox from "./AdvancedSearchBox.vue";
import AuditLogSearch from "./AuditLogSearch.vue";
export default AuditLogSearch;
-export { AuditLogSearch, AdvancedSearchBox };
diff --git a/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.ts b/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.ts
deleted file mode 100644
index c87350a9ea..0000000000
--- a/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.ts
+++ /dev/null
@@ -1,192 +0,0 @@
-import { orderBy } from "lodash-es";
-import type { Ref, RenderFunction, VNode } from "vue";
-import { computed, h, ref } from "vue";
-import { useI18n } from "vue-i18n";
-import BBAvatar from "@/bbkit/BBAvatar.vue";
-import GitIcon from "@/components/GitIcon.vue";
-import SystemBotTag from "@/components/misc/SystemBotTag.vue";
-import YouTag from "@/components/misc/YouTag.vue";
-import { ProjectV1Name } from "@/components/v2";
-import ALL_METHODS from "@/grpcweb/methods";
-import { useCurrentUserV1, useUserStore, useProjectV1List } from "@/store";
-import { SYSTEM_BOT_EMAIL } from "@/types";
-import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";
-import { Workflow } from "@/types/proto/v1/project_service";
-import type { SearchParams, SearchScopeId } from "@/utils";
-import { extractProjectResourceName } from "@/utils";
-
-export type ScopeOption = {
- id: SearchScopeId;
- title: string;
- description: string;
- options: ValueOption[];
-};
-
-export type ValueOption = {
- value: string;
- keywords: string[];
- custom?: boolean;
- render: RenderFunction;
-};
-
-export const useSearchScopeOptions = (
- params: Ref<SearchParams>,
- supportOptionIdList: Ref<SearchScopeId[]>
-) => {
- const { t } = useI18n();
- const me = useCurrentUserV1();
- const userStore = useUserStore();
- const { projectList } = useProjectV1List();
-
- const principalSearchValueOptions = computed(() => {
- // Put "you" to the top
- const sortedUsers = orderBy(
- userStore.activeUserList,
- (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 = [
- h(BBAvatar, { size: "TINY", username: user.title }),
- renderSpan(user.title),
- ];
- if (user.name === me.value.name) {
- children.push(h(YouTag));
- }
- if (user.email === SYSTEM_BOT_EMAIL) {
- 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.
- const fullScopeOptions = computed((): ScopeOption[] => {
- const scopes: ScopeOption[] = [
- {
- id: "project",
- title: t("issue.advanced-search.scope.project.title"),
- description: t("issue.advanced-search.scope.project.description"),
- options: projectList.value.map<ValueOption>((proj) => {
- const name = extractProjectResourceName(proj.name);
- return {
- value: name,
- keywords: [name, proj.title, proj.key],
- render: () => {
- const children: VNode[] = [
- h(ProjectV1Name, { project: proj, link: false }),
- ];
- if (proj.workflow === Workflow.VCS) {
- children.push(h(GitIcon, { class: "h-4" }));
- }
- return h("div", { class: "flex items-center gap-x-2" }, children);
- },
- };
- }),
- },
- {
- id: "actor",
- title: t("audit-log.advanced-search.scope.actor.title"),
- description: t("audit-log.advanced-search.scope.actor.description"),
- options: principalSearchValueOptions.value,
- },
- {
- id: "method",
- title: t("audit-log.advanced-search.scope.method.title"),
- description: t("audit-log.advanced-search.scope.method.description"),
- options: ALL_METHODS.map((method) => {
- return {
- value: method,
- keywords: [method],
- render: () => "",
- };
- }),
- },
- {
- id: "level",
- title: t("audit-log.advanced-search.scope.level.title"),
- description: t("audit-log.advanced-search.scope.level.description"),
- options: Object.values(AuditLog_Severity).map((severity) => {
- return {
- value: severity,
- keywords: [severity],
- render: () => "",
- };
- }),
- },
- ];
- const supportOptionIdSet = new Set(supportOptionIdList.value);
- return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
- });
-
- // filteredScopeOptions will filter search options by chosen scope.
- // For example, if users select a specific project, we should only allow them select instances related with this project.
- const filteredScopeOptions = computed((): ScopeOption[] => {
- const clone = fullScopeOptions.value.map((scope) => ({
- ...scope,
- options: scope.options.map((option) => ({
- ...option,
- })),
- }));
-
- return clone;
- });
-
- // 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[] => {
- const existedScopes = new Set<SearchScopeId>(
- params.value.scopes.map((scope) => scope.id)
- );
-
- return filteredScopeOptions.value.filter((scope) => {
- if (existedScopes.has(scope.id)) {
- return false;
- }
- return true;
- });
- });
-
- const menuView = ref<"scope" | "value">();
- const currentScope = ref<SearchScopeId>();
- const currentScopeOption = computed(() => {
- if (currentScope.value) {
- return filteredScopeOptions.value.find(
- (opt) => opt.id === currentScope.value
- );
- }
- return undefined;
- });
- const scopeOptions = computed(() => {
- if (menuView.value === "scope") return availableScopeOptions.value;
- return [];
- });
- const valueOptions = computed(() => {
- if (menuView.value === "value" && currentScopeOption.value) {
- return currentScopeOption.value.options;
- }
- return [];
- });
-
- return {
- fullScopeOptions,
- filteredScopeOptions,
- availableScopeOptions,
- menuView,
- currentScope,
- currentScopeOption,
- scopeOptions,
- valueOptions,
- };
-};
-
-const renderSpan = (content: string) => {
- return h("span", {}, content);
-};
diff --git a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
index e030bc7172..e5890bab5f 100644
--- a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
+++ b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
@@ -14,11 +14,10 @@
<div v-if="ready">
<div class="space-y-3">
<div class="w-full flex items-center space-x-2">
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
- :autofocus="false"
:placeholder="$t('database.filter-database')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<DatabaseLabelFilter
v-model:selected="state.selectedLabels"
@@ -68,6 +67,7 @@
import { NButton } from "naive-ui";
import { computed, reactive } from "vue";
import { useRouter } from "vue-router";
+import AdvancedSearch from "@/components/AdvancedSearch";
import DatabaseV1Table from "@/components/v2/Model/DatabaseV1Table";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import {
@@ -79,7 +79,7 @@ import {
import type { ComposedDatabase } from "@/types";
import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";
import { State } from "@/types/proto/v1/common";
-import type { SearchScopeId, SearchParams } from "@/utils";
+import type { SearchParams } from "@/utils";
import {
filterDatabaseV1ByKeyword,
sortDatabaseV1List,
@@ -88,6 +88,7 @@ import {
generateIssueName,
extractProjectResourceName,
} from "@/utils";
+import { useCommonSearchScopeOptions } from "../AdvancedSearch/useCommonSearchScopeOptions";
import { DatabaseLabelFilter, DrawerContent } from "../v2";
type LocalState = {
@@ -120,6 +121,11 @@ const state = reactive<LocalState>({
},
});
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => state.params),
+ ["project", "instance", "environment"]
+);
+
const selectedProject = computed(() => {
if (props.projectId) {
return projectV1Store.getProjectByUID(props.projectId);
@@ -238,8 +244,4 @@ const navigateToIssuePage = async () => {
const cancel = () => {
emit("dismiss");
};
-
-const supportOptionIdList = computed((): SearchScopeId[] => {
- return ["project", "instance", "environment"];
-});
</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
deleted file mode 100644
index 96d9701b8a..0000000000
--- a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
+++ /dev/null
@@ -1,551 +0,0 @@
-<template>
- <div ref="containerRef" class="bb-advanced-issue-search-box w-full relative">
- <NInput
- ref="inputRef"
- v-model:value="inputText"
- :placeholder="placeholder ?? $t('issue.advanced-search.self')"
- class="bb-advanced-issue-search-box__input"
- style="--n-padding-left: 8px; --n-padding-right: 4px"
- @click="handleInputClick"
- @blur="hideMenu"
- @keyup="handleKeyUp"
- @keydown="handleKeyDown"
- >
- <template #prefix>
- <div
- class="flex flex-row items-center justify-start gap-x-2"
- :style="{
- 'max-width': `calc(${containerWidth}px - 14rem)`,
- }"
- >
- <div class="flex items-center space-x-2">
- <FilterIcon class="w-4 h-4 text-control-placeholder" />
- <span class="textinfolabel">
- {{ $t("issue.advanced-search.filter") }}
- </span>
- </div>
- <div
- ref="tagsContainerRef"
- class="flex-1 flex flex-row items-center flex-nowrap gap-1 overflow-auto hide-scrollbar"
- >
- <ScopeTags
- :params="params"
- :focused-tag-id="focusedTagId"
- :readonly-scopes="readonlyScopes"
- @select-scope="selectScopeFromTag"
- @remove-scope="removeScope"
- />
- </div>
- </div>
- </template>
- <template #suffix>
- <NButton
- v-show="clearable"
- quaternary
- circle
- size="tiny"
- @click.stop.prevent="handleClear"
- >
- <template #icon>
- <XIcon class="w-3 h-3" />
- </template>
- </NButton>
- </template>
- </NInput>
-
- <Transition name="fade-slide-up" :appear="true">
- <div
- v-show="showMenu"
- v-zindexable="{ enabled: true }"
- class="absolute top-[36px] w-full bg-gray-100 shadow-xl origin-top-left rounded-[3px] overflow-clip"
- >
- <ScopeMenu
- :show="menuView === 'scope'"
- :params="params"
- :options="visibleScopeOptions"
- :menu-index="menuIndex"
- @select-scope="selectScope"
- @hover-item="menuIndex = $event"
- />
- <ValueMenu
- :show="menuView === 'value'"
- :params="params"
- :scope-option="currentScopeOption"
- :value-options="visibleValueOptions"
- :menu-index="menuIndex"
- @select-value="selectValue"
- @hover-item="menuIndex = $event"
- />
- </div>
- </Transition>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { useElementSize } from "@vueuse/core";
-import { cloneDeep, last } from "lodash-es";
-import { FilterIcon } from "lucide-vue-next";
-import { XIcon } from "lucide-vue-next";
-import { matchSorter } from "match-sorter";
-import type { InputInst } from "naive-ui";
-import { NInput } from "naive-ui";
-import scrollIntoView from "scroll-into-view-if-needed";
-import { zindexable as vZindexable } from "vdirs";
-import {
- reactive,
- watch,
- onMounted,
- ref,
- toRef,
- computed,
- nextTick,
-} from "vue";
-import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";
-import {
- emptySearchParams,
- getValueFromSearchParams,
- minmax,
- upsertScope,
-} from "@/utils";
-import ScopeMenu from "./ScopeMenu.vue";
-import ScopeTags from "./ScopeTags.vue";
-import ValueMenu from "./ValueMenu.vue";
-import { useSearchScopeOptions } from "./useSearchScopeOptions";
-
-const props = withDefaults(
- defineProps<{
- placeholder?: string | undefined;
- params: SearchParams;
- readonlyScopes?: SearchScope[];
- autofocus?: boolean;
- supportOptionIdList?: SearchScopeId[];
- }>(),
- {
- readonlyScopes: () => [],
- supportOptionIdList: () => [],
- autofocus: false,
- placeholder: undefined,
- }
-);
-
-const emit = defineEmits<{
- (event: "update:params", params: SearchParams): void;
- (event: "select-unsupported-scope", id: SearchScopeId): void;
-}>();
-
-interface LocalState {
- searchText: string;
- showSearchScopes: boolean;
- currentScope?: SearchScopeId;
-}
-
-const defaultSearchParams = () => {
- const params = emptySearchParams();
- props.readonlyScopes.forEach((s) => {
- params.scopes.push({ ...s });
- });
- return params;
-};
-
-const buildSearchTextByParams = (params: SearchParams | undefined): string => {
- const prefix = (params?.scopes ?? [])
- .map((scope) => `${scope.id}:${scope.value}`)
- .join(" ");
- const query = params?.query ?? "";
- if (!prefix && !query) {
- return "";
- }
- return `${prefix} ${query}`;
-};
-
-const state = reactive<LocalState>({
- searchText: buildSearchTextByParams(props.params),
- showSearchScopes: props.autofocus,
-});
-const containerRef = ref<HTMLElement>();
-const tagsContainerRef = ref<HTMLElement>();
-const inputText = ref(props.params.query);
-const inputRef = ref<InputInst>();
-const menuIndex = ref(0);
-const { width: containerWidth } = useElementSize(containerRef);
-const focusedTagId = ref<SearchScopeId>();
-const readonlyScopeIds = computed(() => {
- return new Set(props.readonlyScopes.map((s) => s.id));
-});
-const editableScopes = computed(() => {
- return props.params.scopes.filter((s) => !readonlyScopeIds.value.has(s.id));
-});
-
-watch(
- () => state.showSearchScopes,
- (show) => {
- if (show) state.currentScope = undefined;
- }
-);
-
-watch(
- () => props.params,
- (params) => {
- state.searchText = buildSearchTextByParams(params);
- }
-);
-
-const {
- menuView,
- fullScopeOptions,
- availableScopeOptions,
- currentScope,
- currentScopeOption,
- valueOptions,
-} = useSearchScopeOptions(
- toRef(props, "params"),
- toRef(props, "supportOptionIdList")
-);
-
-const visibleScopeOptions = computed(() => {
- if (currentScopeOption.value) {
- return [currentScopeOption.value];
- }
-
- const keyword = inputText.value.trim().replace(/:.*$/, "").toLowerCase();
- if (!keyword) return availableScopeOptions.value;
-
- const filtered = matchSorter(availableScopeOptions.value, keyword, {
- keys: ["id", "title", "description"],
- });
-
- return filtered;
-});
-
-const visibleValueOptions = computed(() => {
- if (!currentScope.value) return [];
- const scopePrefix = `${currentScope.value}:`;
- const keyword = inputText.value
- .trim()
- .toLowerCase()
- .substring(scopePrefix.length);
-
- if (!keyword) return valueOptions.value;
-
- // Apply multiple segments of keyword splitted by whitespace
- const terms = keyword.split(/\s+/g);
- const filtered = terms.reduceRight((options, term) => {
- return matchSorter(options, term, { keys: ["value", "keywords"] });
- }, valueOptions.value);
-
- const currentValue = getValueFromSearchParams(
- props.params,
- currentScope.value
- );
- const option = valueOptions.value.find((opt) => opt.value === currentValue);
- if (currentValue && option) {
- // If we have current value, put it to the first if it doesn't match the keyword
- const index = filtered.findIndex((opt) => opt.value === currentValue);
- if (index < 0) {
- filtered.unshift(option);
- }
- }
- return filtered;
-});
-
-const visibleOptions = computed(() => {
- return menuView.value === "scope"
- ? visibleScopeOptions.value
- : menuView.value === "value"
- ? visibleValueOptions.value
- : ([] as unknown[]);
-});
-
-const showMenu = computed(() => {
- if (menuView.value === "scope") {
- return visibleScopeOptions.value.length > 0;
- }
- if (menuView.value === "value") {
- return true;
- }
- return false;
-});
-
-const clearable = computed(() => {
- return (
- props.params.query.trim().length > 0 || editableScopes.value.length > 0
- );
-});
-
-const hideMenu = () => {
- nextTick(() => {
- menuView.value = undefined;
- currentScope.value = undefined;
- focusedTagId.value = undefined;
- });
-};
-
-const moveMenuIndex = (delta: -1 | 1) => {
- const options = visibleOptions.value;
- if (options.length === 0) return;
-
- const target = minmax(menuIndex.value + delta, 0, options.length - 1);
- menuIndex.value = target;
-};
-
-const removeScope = (id: SearchScopeId) => {
- const updated = upsertScope(props.params, {
- id,
- value: "",
- });
- emit("update:params", updated);
-};
-const selectScope = (
- id: SearchScopeId | undefined,
- value: string | undefined = undefined
-) => {
- currentScope.value = id;
- if (id) {
- menuView.value = "value";
- // Fill-in the scope prefix if needed
- if (!inputText.value.startsWith(`${id}:`)) {
- inputText.value = `${id}:${value ?? ""}`;
- }
- scrollScopeTagIntoViewIfNeeded(id);
- } else {
- menuView.value = "scope";
- }
-};
-const selectValue = (value: string) => {
- const id = currentScope.value;
- if (!id) {
- menuView.value = undefined;
- return;
- }
- const updated = upsertScope(props.params, {
- id,
- value,
- });
- updated.query = "";
- inputText.value = "";
- selectScope(undefined);
- emit("update:params", updated);
-
- scrollScopeTagIntoViewIfNeeded(id);
- hideMenu();
-};
-const selectScopeFromTag = (id: SearchScopeId) => {
- if (fullScopeOptions.value.find((opt) => opt.id === id)) {
- // For AdvancedSearchBox supported scopes
- selectScope(id);
- return;
- }
-
- // Unsupported scope for AdvancedSearchBox
- // emit an event and wish the parent UI can handle this
- emit("select-unsupported-scope", id);
- hideMenu();
-};
-
-const maybeSelectMatchedScope = () => {
- if (!menuView.value || menuView.value === "scope") {
- const matchedScope = visibleScopeOptions.value.find((opt) =>
- inputText.value.startsWith(`${opt.id}:`)
- );
- if (matchedScope) {
- // select the scope if the inputText matches its prefix
- selectScope(matchedScope.id);
- return true;
- }
- if (!menuView.value) {
- // Show scope menu if none of the menus are shown
- menuView.value = "scope";
- return true;
- }
- }
- return false;
-};
-const maybeDeselectMismatchedScope = () => {
- if (menuView.value === "value" && currentScope.value) {
- if (!inputText.value.startsWith(`${currentScope.value}:`)) {
- // de-select current scope since the inputText doesn't match its prefix.
- menuView.value = "scope";
- selectScope(undefined);
- return true;
- }
- }
- return false;
-};
-
-const maybeEmitIncompleteValue = () => {
- const updated = cloneDeep(props.params);
- updated.query = inputText.value;
- emit("update:params", updated);
-};
-
-const handleInputClick = () => {
- maybeSelectMatchedScope();
- maybeDeselectMismatchedScope();
- maybeEmitIncompleteValue();
-};
-
-const handleKeyDown = (e: KeyboardEvent) => {
- if (e.isComposing) return;
- if (e.defaultPrevented) return;
- const { key } = e;
- if (key === "Backspace" && inputText.value === "") {
- // Pressing "backspace" when the input box is empty
- if (focusedTagId.value) {
- e.stopPropagation();
- e.preventDefault();
- // Delete the focusedTag if it exists
- const id = focusedTagId.value;
- focusedTagId.value = undefined;
- removeScope(id);
- return;
- } else {
- e.stopPropagation();
- e.preventDefault();
- // Otherwise mark the last tag as 'focusedTag'
- const id = last(props.params.scopes)?.id;
- if (id) {
- focusedTagId.value = id;
- scrollScopeTagIntoViewIfNeeded(id);
- }
- return;
- }
- }
- focusedTagId.value = undefined;
-
- if (key === "ArrowUp") {
- moveMenuIndex(-1);
- e.preventDefault();
- return;
- }
- if (key === "ArrowDown") {
- moveMenuIndex(1);
- e.preventDefault();
- return;
- }
-};
-
-const handleKeyUp = (e: KeyboardEvent) => {
- if (e.isComposing) return;
- if (e.defaultPrevented) return;
- const { key } = e;
- if (key === "Escape") {
- maybeEmitIncompleteValue();
- menuView.value = undefined;
- return;
- }
- if (key === "Backspace" && inputText.value === "") {
- // backspace key might be processed by KeyDown
- if (focusedTagId.value) {
- return;
- }
- }
- if (maybeSelectMatchedScope()) {
- maybeEmitIncompleteValue();
- return;
- }
- if (maybeDeselectMismatchedScope()) {
- maybeEmitIncompleteValue();
- return;
- }
- if (key === "Enter") {
- // Press enter to select scope (dive into the next step)
- // or select value
- const index = menuIndex.value;
- if (menuView.value === "scope") {
- const option = visibleScopeOptions.value[index];
- if (option) {
- selectScope(option.id);
- maybeEmitIncompleteValue();
- return;
- }
- }
- if (menuView.value === "value") {
- const option = visibleValueOptions.value[index];
- if (option) {
- selectValue(option.value);
- return;
- }
- }
- }
-
- maybeEmitIncompleteValue();
-};
-
-const handleClear = () => {
- const params = defaultSearchParams();
- emit("update:params", params);
- hideMenu();
-};
-
-const scrollScopeTagIntoViewIfNeeded = (id: SearchScopeId) => {
- nextTick(() => {
- const tagsContainerEl = tagsContainerRef.value;
- if (!tagsContainerEl) return;
- const tagEl = tagsContainerEl.querySelector(
- `[data-search-scope-id="${id}"]`
- );
- if (tagEl) {
- scrollIntoView(tagEl, {
- scrollMode: "if-needed",
- });
- }
- });
-};
-
-onMounted(() => {
- if (props.autofocus) {
- inputRef.value?.inputElRef?.focus();
- }
-});
-watch(menuView, () => {
- focusedTagId.value = undefined;
- menuIndex.value = 0;
- if (menuView.value === "value" && currentScope.value) {
- const value = getValueFromSearchParams(props.params, currentScope.value);
- if (value) {
- const index = valueOptions.value.findIndex(
- (option) => option.value === value
- );
- if (index >= 0) menuIndex.value = index;
- }
- }
-});
-watch(visibleScopeOptions, (newOptions, oldOptions) => {
- if (menuView.value !== "scope") return;
- const highlightedScope = oldOptions[menuIndex.value]?.id;
- if (highlightedScope) {
- const index = newOptions.findIndex((opt) => opt.id === highlightedScope);
- if (index >= 0) {
- menuIndex.value = index;
- return;
- }
- }
- menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);
-});
-watch(visibleValueOptions, (newOptions, oldOptions) => {
- if (menuView.value !== "value") return;
- const highlightedValue = oldOptions[menuIndex.value]?.value;
- if (highlightedValue) {
- const index = newOptions.findIndex((opt) => opt.value === highlightedValue);
- if (index >= 0) {
- menuIndex.value = index;
- return;
- }
- }
- menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);
-});
-watch(
- () => props.params,
- (params) => {
- inputText.value = params.query;
- }
-);
-</script>
-
-<style lang="postcss" scoped>
-.bb-advanced-issue-search-box
- .bb-advanced-issue-search-box__input
- :deep(.n-input__input) {
- @apply flex flex-row items-center;
-}
-</style>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
index d233723119..0851a85216 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -4,21 +4,25 @@
v-if="components.includes('searchbox')"
class="flex flex-row items-center gap-x-2"
>
- <AdvancedSearchBox
+ <AdvancedSearch
+ class="flex-1"
:params="params"
- :autofocus="autofocus"
:readonly-scopes="readonlyScopes"
- :support-option-id-list="supportOptionIdList"
- class="flex-1"
- v-bind="componentProps?.searchbox"
+ :scope-options="scopeOptions"
+ @update:params="$emit('update:params', $event)"
+ />
+ <TimeRange
+ v-if="components.includes('time-range')"
+ v-model:show="showTimeRange"
+ :params="params"
+ v-bind="componentProps?.['time-range']"
@update:params="$emit('update:params', $event)"
- @select-unsupported-scope="handleSelectScope"
/>
<slot name="searchbox-suffix" />
</div>
<slot name="default" />
- <div class="flex flex-col md:flex-row md:items-center gap-y-1">
+ <div class="mt-2 flex flex-col md:flex-row md:items-center gap-y-1">
<div class="flex-1 flex items-start">
<Status
v-if="components.includes('status')"
@@ -28,29 +32,18 @@
/>
<slot name="primary" />
</div>
- <div class="flex flex-row space-x-4">
- <NInputGroup>
- <TimeRange
- v-if="components.includes('time-range')"
- v-model:show="showTimeRange"
- :params="params"
- v-bind="componentProps?.['time-range']"
- @update:params="$emit('update:params', $event)"
- />
- <slot name="secondary" />
- </NInputGroup>
- </div>
</div>
</div>
</template>
<script lang="ts" setup>
import { ref, computed } from "vue";
-import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";
+import AdvancedSearch from "@/components/AdvancedSearch";
+import TimeRange from "@/components/AdvancedSearch/TimeRange.vue";
+import type { SearchParams, SearchScope } from "@/utils";
import { UIIssueFilterScopeIdList, SearchScopeIdList } from "@/utils";
-import AdvancedSearchBox from "./AdvancedSearchBox.vue";
import Status from "./Status.vue";
-import TimeRange from "./TimeRange.vue";
+import { useIssueSearchScopeOptions } from "./useIssueSearchScopeOptions";
export type SearchComponent =
| "searchbox"
@@ -65,7 +58,7 @@ export type SearchComponent =
| "approver"
| "approval";
-withDefaults(
+const props = withDefaults(
defineProps<{
params: SearchParams;
readonlyScopes?: SearchScope[];
@@ -75,7 +68,7 @@ withDefaults(
}>(),
{
readonlyScopes: () => [],
- components: () => ["searchbox", "status", "time-range"],
+ components: () => ["searchbox", "time-range", "status"],
componentProps: undefined,
}
);
@@ -85,14 +78,8 @@ defineEmits<{
const showTimeRange = ref(false);
-const handleSelectScope = (id: SearchScopeId) => {
- if (id === "created") {
- showTimeRange.value = true;
- }
-};
-
-const supportOptionIdList = computed(() => [
- ...UIIssueFilterScopeIdList,
- ...SearchScopeIdList,
-]);
+const scopeOptions = useIssueSearchScopeOptions(
+ computed(() => props.params),
+ computed(() => [...UIIssueFilterScopeIdList, ...SearchScopeIdList])
+);
</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
deleted file mode 100644
index c48fc3e2a0..0000000000
--- a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
+++ /dev/null
@@ -1,73 +0,0 @@
-<template>
- <NTag
- v-for="(scope, i) in params.scopes"
- :key="scope.id"
- :closable="!isReadonlyScope(scope)"
- :disabled="isReadonlyScope(scope)"
- :data-search-scope-id="scope.id"
- :bordered="false"
- size="small"
- style="--n-icon-size: 12px"
- v-bind="tagProps(scope)"
- @close="$emit('remove-scope', scope.id, scope.value)"
- @click.stop.prevent="$emit('select-scope', scope.id, scope.value)"
- >
- <span>{{ scope.id }}</span>
- <span>:</span>
- <component :is="() => renderValue(scope, i)" />
- </NTag>
-</template>
-<script setup lang="ts">
-import dayjs from "dayjs";
-import type { TagProps } from "naive-ui";
-import { NTag } from "naive-ui";
-import { computed, h } from "vue";
-import { useI18n } from "vue-i18n";
-import { UNKNOWN_ID } from "@/types";
-import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";
-import { callCssVariable } from "@/utils";
-
-const props = defineProps<{
- params: SearchParams;
- focusedTagId?: SearchScopeId;
- readonlyScopes?: SearchScope[];
-}>();
-
-defineEmits<{
- (event: "remove-scope", id: SearchScopeId, value: string): void;
- (event: "select-scope", id: SearchScopeId, value: string): void;
-}>();
-
-const { t } = useI18n();
-
-const readonlyScopeIds = computed(() => {
- return new Set((props.readonlyScopes ?? []).map((s) => s.id));
-});
-
-const isReadonlyScope = (scope: SearchScope) => {
- return readonlyScopeIds.value.has(scope.id);
-};
-
-const tagProps = (scope: SearchScope): TagProps => {
- if (props.focusedTagId !== scope.id) {
- return {};
- }
- return {
- bordered: true,
- color: {
- borderColor: callCssVariable("--color-accent"),
- },
- };
-};
-
-const renderValue = (scope: SearchScope, index: number) => {
- if (scope.id === "created") {
- const [begin, end] = scope.value.split(",").map((ts) => parseInt(ts, 10));
- return [dayjs(begin).format("L"), dayjs(end).format("L")].join("-");
- }
- if (scope.value === `${UNKNOWN_ID}`) {
- return h("span", {}, t("common.all").toLocaleLowerCase());
- }
- return h("span", {}, scope.value);
-};
-</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
deleted file mode 100644
index 9679362670..0000000000
--- a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
+++ /dev/null
@@ -1,56 +0,0 @@
-<template>
- <NDatePicker
- :key="timeRange ? 'filled' : 'empty'"
- :value="timeRange"
- :is-date-disabled="isDateDisabled"
- type="daterange"
- clearable
- style="width: 14rem"
- class="time-range-picker"
- @update:value="handleUpdate"
- >
- </NDatePicker>
-</template>
-
-<script setup lang="ts">
-import dayjs from "dayjs";
-import { NDatePicker } from "naive-ui";
-import { computed } from "vue";
-import type { SearchParams } from "@/utils";
-import { getTsRangeFromSearchParams, upsertScope } from "@/utils";
-
-const props = defineProps<{
- params: SearchParams;
-}>();
-
-const emit = defineEmits<{
- (event: "update:params", params: SearchParams): void;
-}>();
-
-const timeRange = computed(() => {
- return getTsRangeFromSearchParams(props.params, "created");
-});
-
-const isDateDisabled = (ts: number) => {
- const today = dayjs().add(1, "day").endOf("day").valueOf();
- if (ts > today) {
- return true;
- }
- return false;
-};
-
-const handleUpdate = (values: [number, number] | null) => {
- const updated = upsertScope(props.params, {
- id: "created",
- value: values ? values.join(",") : "",
- });
- emit("update:params", updated);
-};
-</script>
-
-<style lang="postcss" scoped>
-.time-range-picker :deep(.n-input) {
- --n-padding-left: 6px !important;
- --n-padding-right: 6px !important;
-}
-</style>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue b/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue
deleted file mode 100644
index 94b83c32ec..0000000000
--- a/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue
+++ /dev/null
@@ -1,128 +0,0 @@
-<template>
- <div
- v-if="scopeOption"
- v-show="show"
- ref="containerRef"
- 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>
- <div
- v-if="valueOptions.length > 0"
- class="flex-1 overflow-hidden"
- :style="{
- 'max-height': `${maxListHeight}px`,
- }"
- >
- <VirtualList
- ref="virtualListRef"
- :items="valueOptions"
- :key-field="`value`"
- :item-resizable="false"
- :item-size="38"
- >
- <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>
- </div>
- </template>
- </VirtualList>
- </div>
- <div v-if="valueOptions.length === 0" class="pb-2">
- <NEmpty />
- </div>
- </div>
-</template>
-
-<script setup lang="ts">
-import {
- useElementBounding,
- useElementSize,
- useWindowSize,
-} from "@vueuse/core";
-import { NEmpty } from "naive-ui";
-import { computed, nextTick, ref, watch } from "vue";
-import { VirtualList } from "vueuc";
-import type { SearchParams } from "@/utils";
-import type { ScopeOption, ValueOption } from "./useSearchScopeOptions";
-
-type ListItem = {
- item: ValueOption;
- index: number;
-};
-
-const props = defineProps<{
- show: boolean;
- params: SearchParams;
- scopeOption?: ScopeOption;
- valueOptions: ValueOption[];
- menuIndex: number;
-}>();
-defineEmits<{
- (event: "select-value", value: string): void;
- (event: "hover-item", index: number): void;
-}>();
-
-const containerRef = ref<HTMLElement>();
-const titleRef = ref<HTMLElement>();
-const virtualListRef = ref<InstanceType<typeof VirtualList>>();
-const { height: titleHeight } = useElementSize(titleRef, undefined, {
- box: "border-box",
-});
-const { top: containerTop } = useElementBounding(containerRef);
-const { height: windowHeight } = useWindowSize();
-
-const maxListHeight = computed(() => {
- const MAX_HEIGHT = 240;
- const PADDING_BOTTOM = 16;
-
- return Math.min(
- MAX_HEIGHT,
- windowHeight.value - titleHeight.value - containerTop.value - PADDING_BOTTOM
- );
-});
-
-const highlightedItem = computed((): ListItem | undefined => {
- if (!props.show) return undefined;
- const options = props.valueOptions;
- const index = props.menuIndex;
- const item = options[index];
- if (item) {
- return { item, index };
- }
- return undefined;
-});
-
-watch(
- [highlightedItem, () => props.show],
- ([item, show]) => {
- if (!show) return;
- if (!item) return;
- nextTick(() => {
- const virtualList = virtualListRef.value;
- if (!virtualList) return;
- virtualList.scrollTo({
- index: item.index,
- });
- });
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/index.ts b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
index 09c11e8e0d..7c083bd0c9 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/index.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
@@ -1,5 +1,3 @@
-import AdvancedSearchBox from "./AdvancedSearchBox.vue";
import IssueSearch from "./IssueSearch.vue";
export default IssueSearch;
-export { IssueSearch, AdvancedSearchBox };
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
new file mode 100644
index 0000000000..cb1b3612cd
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
@@ -0,0 +1,256 @@
+import { orderBy } from "lodash-es";
+import type { Ref, RenderFunction } from "vue";
+import { computed, h } from "vue";
+import { useI18n } from "vue-i18n";
+import BBAvatar from "@/bbkit/BBAvatar.vue";
+import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
+import SystemBotTag from "@/components/misc/SystemBotTag.vue";
+import YouTag from "@/components/misc/YouTag.vue";
+import {
+ useCurrentUserV1,
+ useDatabaseV1Store,
+ useUserStore,
+ useProjectV1List,
+} from "@/store";
+import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";
+import { Label } from "@/types/proto/v1/project_service";
+import type { SearchParams, SearchScopeId } from "@/utils";
+
+export type ScopeOption = {
+ id: SearchScopeId;
+ title: string;
+ description: string;
+ options: ValueOption[];
+};
+
+export type ValueOption = {
+ value: string;
+ keywords: string[];
+ custom?: boolean;
+ render: RenderFunction;
+};
+
+const useProjectLabels = (params: Ref<SearchParams>) => {
+ const { projectList } = useProjectV1List();
+ const projectName = params.value.scopes.find(
+ (scope) => scope.id === "project"
+ )?.value;
+
+ const labels = new Map<string, Label>();
+ for (const project of projectList.value) {
+ if (projectName && project.name !== `projects/${projectName}`) {
+ continue;
+ }
+ for (const label of project.issueLabels) {
+ const key = `${label.value}-${label.color}`;
+ labels.set(key, label);
+ }
+ }
+ return [...labels.values()];
+};
+
+export const useIssueSearchScopeOptions = (
+ params: Ref<SearchParams>,
+ supportOptionIdList: Ref<SearchScopeId[]>
+) => {
+ const { t } = useI18n();
+ const me = useCurrentUserV1();
+ const userStore = useUserStore();
+ const databaseV1Store = useDatabaseV1Store();
+
+ const commonScopeOptions = useCommonSearchScopeOptions(
+ params,
+ supportOptionIdList
+ );
+
+ const principalSearchValueOptions = computed(() => {
+ // Put "you" to the top
+ const sortedUsers = orderBy(
+ userStore.activeUserList,
+ (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 = [
+ h(BBAvatar, { size: "TINY", username: user.title }),
+ renderSpan(user.title),
+ ];
+ if (user.name === me.value.name) {
+ children.push(h(YouTag));
+ }
+ if (user.email === SYSTEM_BOT_EMAIL) {
+ 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.
+ const fullScopeOptions = computed((): ScopeOption[] => {
+ const scopes: ScopeOption[] = [
+ ...commonScopeOptions.value,
+ {
+ id: "status",
+ title: t("common.status"),
+ description: t("issue.advanced-search.scope.approval.description"),
+ options: [
+ {
+ value: "OPEN",
+ keywords: ["open"],
+ render: () => renderSpan(t("issue.table.open")),
+ },
+ {
+ value: "CLOSED",
+ keywords: ["closed", "canceled", "done"],
+ render: () => renderSpan(t("issue.table.closed")),
+ },
+ ],
+ },
+ {
+ id: "approval",
+ title: t("issue.advanced-search.scope.approval.title"),
+ description: t("issue.advanced-search.scope.approval.description"),
+ options: [
+ {
+ value: "pending",
+ keywords: ["pending"],
+ render: () =>
+ renderSpan(
+ t("issue.advanced-search.scope.approval.value.pending")
+ ),
+ },
+ {
+ value: "approved",
+ keywords: ["approved", "done"],
+ render: () =>
+ renderSpan(
+ t("issue.advanced-search.scope.approval.value.approved")
+ ),
+ },
+ ],
+ },
+ {
+ id: "creator",
+ title: t("issue.advanced-search.scope.creator.title"),
+ description: t("issue.advanced-search.scope.creator.description"),
+ options: principalSearchValueOptions.value,
+ },
+ {
+ id: "assignee",
+ title: t("issue.advanced-search.scope.assignee.title"),
+ description: t("issue.advanced-search.scope.assignee.description"),
+ options: principalSearchValueOptions.value,
+ },
+ {
+ id: "approver",
+ title: t("issue.advanced-search.scope.approver.title"),
+ description: t("issue.advanced-search.scope.approver.description"),
+ options: principalSearchValueOptions.value.filter(
+ (o) => o.value !== SYSTEM_BOT_EMAIL
+ ),
+ },
+ {
+ id: "subscriber",
+ title: t("issue.advanced-search.scope.subscriber.title"),
+ description: t("issue.advanced-search.scope.subscriber.description"),
+ options: principalSearchValueOptions.value,
+ },
+ {
+ id: "type",
+ title: t("issue.advanced-search.scope.type.title"),
+ description: t("issue.advanced-search.scope.type.description"),
+ options: [
+ {
+ value: "DDL",
+ keywords: ["ddl", "data definition language"],
+ render: () => renderSpan("Data Definition Language"),
+ },
+ {
+ value: "DML",
+ keywords: ["dml", "data manipulation language"],
+ render: () => renderSpan("Data Manipulation Language"),
+ },
+ ],
+ },
+ {
+ id: "label",
+ title: t("issue.advanced-search.scope.label.title"),
+ description: t("issue.advanced-search.scope.label.description"),
+ options: useProjectLabels(params).map((label) => {
+ return {
+ value: label.value,
+ keywords: [label.value],
+ render: () =>
+ h("div", { class: "flex items-center gap-x-2" }, [
+ h("div", {
+ class: "w-4 h-4 rounded",
+ style: `background-color: ${label.color};`,
+ }),
+ label.value,
+ ]),
+ };
+ }),
+ },
+ ];
+ const supportOptionIdSet = new Set(supportOptionIdList.value);
+ return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
+ });
+
+ // filteredScopeOptions will filter search options by chosen scope.
+ // For example, if users select a specific project, we should only allow them select instances related with this project.
+ const filteredScopeOptions = computed((): ScopeOption[] => {
+ const existedScopes = new Map<SearchScopeId, string>(
+ params.value.scopes.map((scope) => [scope.id, scope.value])
+ );
+
+ const clone = fullScopeOptions.value.map((scope) => ({
+ ...scope,
+ 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) => {
+ if (!existedScopes.has("project") && !existedScopes.has("instance")) {
+ return true;
+ }
+
+ const uid = option.value.split("-").slice(-1)[0];
+ const db = databaseV1Store.getDatabaseByUID(uid);
+ const project = db.project;
+ const instance = db.instance;
+
+ const existedProject = `projects/${
+ existedScopes.get("project") ?? UNKNOWN_ID
+ }`;
+ if (project === existedProject) {
+ return true;
+ }
+ const existedInstance = `instances/${
+ existedScopes.get("instance") ?? UNKNOWN_ID
+ }`;
+ if (instance === existedInstance) {
+ return true;
+ }
+
+ return false;
+ });
+ }
+
+ return clone;
+ });
+
+ return filteredScopeOptions;
+};
+
+const renderSpan = (content: string) => {
+ return h("span", {}, content);
+};
diff --git a/frontend/src/components/Project/ProjectIssuesPanel.vue b/frontend/src/components/Project/ProjectIssuesPanel.vue
index 53a96166a4..01d130e4ae 100644
--- a/frontend/src/components/Project/ProjectIssuesPanel.vue
+++ b/frontend/src/components/Project/ProjectIssuesPanel.vue
@@ -4,7 +4,7 @@
v-model:params="state.params"
:readonly-scopes="readonlyScopes"
:components="
- state.advanced ? ['searchbox', 'status', 'time-range'] : ['status']
+ state.advanced ? ['searchbox', 'time-range', 'status'] : ['status']
"
:component-props="{ status: { disabled: statusTabDisabled } }"
class="gap-y-1"
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index a5931c3297..ae99471869 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -3,12 +3,12 @@
<div
class="w-full text-lg font-medium leading-7 text-main flex flex-col sm:flex-row items-start sm:items-end justify-between gap-2"
>
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
class="flex-1"
:autofocus="false"
:placeholder="$t('database.filter-database')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<DatabaseLabelFilter
v-model:selected="state.selectedLabels"
@@ -50,6 +50,8 @@ import {
extractInstanceResourceName,
databaseV1Url,
} from "@/utils";
+import AdvancedSearch from "./AdvancedSearch";
+import { useCommonSearchScopeOptions } from "./AdvancedSearch/useCommonSearchScopeOptions";
import { DatabaseOperations, DatabaseLabelFilter } from "./v2";
interface LocalState {
@@ -77,6 +79,11 @@ const state = reactive<LocalState>({
},
});
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => state.params),
+ [...CommonFilterScopeIdList]
+);
+
const selectedInstance = computed(() => {
return (
state.params.scopes.find((scope) => scope.id === "instance")?.value ??
@@ -143,8 +150,6 @@ const selectedDatabases = computed((): ComposedDatabase[] => {
);
});
-const supportOptionIdList = computed(() => [...CommonFilterScopeIdList]);
-
const handleDatabasesSelectionChanged = (
selectedDatabaseNameList: Set<string>
): void => {
diff --git a/frontend/src/components/SlowQuery/Panel/LogFilter.vue b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
index d909d5c783..94781996ab 100644
--- a/frontend/src/components/SlowQuery/Panel/LogFilter.vue
+++ b/frontend/src/components/SlowQuery/Panel/LogFilter.vue
@@ -3,13 +3,12 @@
<div
class="flex flex-col md:flex-row items-end md:items-center gap-y-2 gap-x-2"
>
- <AdvancedSearchBox
+ <AdvancedSearch
v-if="supportOptionIdList.length > 0"
+ class="flex-1 hidden md:block"
:params="params"
- :autofocus="false"
:placeholder="''"
- class="flex-1 hidden md:block"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
@update:params="$emit('update:params', $event)"
/>
<NInputGroup style="width: auto">
@@ -46,6 +45,9 @@
<script lang="ts" setup>
import dayjs from "dayjs";
import { NDatePicker, NInputGroup } from "naive-ui";
+import { computed } from "vue";
+import AdvancedSearch from "@/components/AdvancedSearch";
+import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import { useSlowQueryPolicyList } from "@/store";
import type { SearchParams, SearchScopeId } from "@/utils";
@@ -67,6 +69,11 @@ const emit = defineEmits<{
const { ready } = useSlowQueryPolicyList();
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => props.params),
+ computed(() => props.supportOptionIdList)
+);
+
const changeTime = (
fromTime: number | undefined,
toTime: number | undefined
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 6323543bb0..8872fe944c 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -3,11 +3,11 @@
<div
class="w-full px-4 flex flex-col sm:flex-row items-start sm:items-end justify-between gap-2"
>
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
:autofocus="false"
:placeholder="$t('database.filter-database')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<DatabaseLabelFilter
v-model:selected="state.selectedLabels"
@@ -35,6 +35,8 @@
<script lang="ts" setup>
import { computed, onMounted, reactive, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
+import AdvancedSearch from "@/components/AdvancedSearch";
+import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import DatabaseV1Table from "@/components/v2/Model/DatabaseV1Table";
import {
useDatabaseV1Store,
@@ -44,7 +46,7 @@ import {
} from "@/store";
import type { ComposedDatabase } from "@/types";
import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";
-import type { SearchScopeId, SearchParams } from "@/utils";
+import type { SearchParams } from "@/utils";
import {
filterDatabaseV1ByKeyword,
sortDatabaseV1List,
@@ -110,6 +112,11 @@ watch(
const databaseV1Store = useDatabaseV1Store();
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => state.params),
+ [...CommonFilterScopeIdList, "project", "project-assigned"]
+);
+
const isStandaloneMode = computed(() => pageMode.value === "STANDALONE");
const selectedInstance = computed(() => {
@@ -215,12 +222,6 @@ const selectedDatabases = computed((): ComposedDatabase[] => {
);
});
-const supportOptionIdList = computed((): SearchScopeId[] => [
- ...CommonFilterScopeIdList,
- "project",
- "project-assigned",
-]);
-
const handleDatabasesSelectionChanged = (
selectedDatabaseNameList: Set<string>
): void => {
diff --git a/frontend/src/views/ExportCenter/index.vue b/frontend/src/views/ExportCenter/index.vue
index 7ff3e54c20..19d87e623c 100644
--- a/frontend/src/views/ExportCenter/index.vue
+++ b/frontend/src/views/ExportCenter/index.vue
@@ -4,25 +4,28 @@
class="w-full flex flex-col lg:flex-row items-start lg:items-center justify-between gap-2"
>
<div class="flex flex-1 max-w-full items-center gap-x-2">
- <AdvancedSearchBox
+ <IssueSearch
v-model:params="state.params"
- :autofocus="false"
+ class="flex-1"
:placeholder="''"
- :support-option-id-list="supportOptionIdList"
- />
+ :readonly-scopes="readonlyScopes"
+ >
+ <template #searchbox-suffix>
+ <NTooltip :disabled="allowExportData">
+ <template #trigger>
+ <NButton
+ type="primary"
+ :disabled="!allowExportData"
+ @click="state.showRequestExportPanel = true"
+ >
+ {{ $t("quick-action.request-export-data") }}
+ </NButton>
+ </template>
+ {{ $t("export-center.permission-denied") }}
+ </NTooltip>
+ </template>
+ </IssueSearch>
</div>
- <NTooltip :disabled="allowExportData">
- <template #trigger>
- <NButton
- type="primary"
- :disabled="!allowExportData"
- @click="state.showRequestExportPanel = true"
- >
- {{ $t("quick-action.request-export-data") }}
- </NButton>
- </template>
- {{ $t("export-center.permission-denied") }}
- </NTooltip>
</div>
<div class="relative w-full mt-4 min-h-[20rem]">
@@ -62,6 +65,7 @@
import { NButton, NTooltip } from "naive-ui";
import { computed, reactive } from "vue";
import DataExportPrepForm from "@/components/DataExportPrepForm";
+import IssueSearch from "@/components/IssueV1/components/IssueSearch/IssueSearch.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { Drawer } from "@/components/v2";
import { useCurrentUserV1, useProjectV1Store } from "@/store";
@@ -72,7 +76,7 @@ import {
extractProjectResourceName,
hasPermissionToCreateDataExportIssueInProject,
type SearchParams,
- type SearchScopeId,
+ type SearchScope,
} from "@/utils";
import DataExportIssueDataTable from "./DataExportIssueDataTable";
import type { ExportRecord } from "./types";
@@ -89,30 +93,42 @@ interface LocalState {
loadingMore: boolean;
}
+const specificProject = computed(() => {
+ return props.projectId
+ ? projectV1Store.getProjectByName(`${projectNamePrefix}${props.projectId}`)
+ : undefined;
+});
+
+const readonlyScopes = computed((): SearchScope[] => {
+ if (!specificProject.value) {
+ return [];
+ }
+ return [
+ {
+ id: "project",
+ value: extractProjectResourceName(specificProject.value.name),
+ },
+ ];
+});
+
+const defaultSearchParams = () => {
+ const params: SearchParams = {
+ query: "",
+ scopes: [...readonlyScopes.value, { id: "status", value: "OPEN" }],
+ };
+ return params;
+};
+
const currentUser = useCurrentUserV1();
const projectV1Store = useProjectV1Store();
const state = reactive<LocalState>({
exportRecords: [],
showRequestExportPanel: false,
- params: {
- query: "",
- scopes: [
- {
- id: "status",
- value: "OPEN",
- },
- ],
- },
+ params: defaultSearchParams(),
loading: false,
loadingMore: false,
});
-const specificProject = computed(() => {
- return props.projectId
- ? projectV1Store.getProjectByName(`${projectNamePrefix}${props.projectId}`)
- : undefined;
-});
-
const dataExportIssueSearchParams = computed(() => {
// Default scopes with type and creator.
const defaultScopes = [
@@ -146,14 +162,6 @@ const mergedUIIssueFilter = computed(() => {
return buildUIIssueFilterBySearchParams(dataExportIssueSearchParams.value);
});
-const supportOptionIdList = computed((): SearchScopeId[] => {
- const scopes: SearchScopeId[] = ["instance", "database", "status"];
- if (!specificProject.value) {
- scopes.unshift("project");
- }
- return scopes;
-});
-
const allowExportData = computed(() => {
if (specificProject.value) {
return hasPermissionToCreateDataExportIssueInProject(
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 079e20c0ad..f28c7d7a64 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -3,7 +3,7 @@
<IssueSearch
v-model:params="state.params"
:components="
- state.advanced ? ['searchbox', 'status', 'time-range'] : ['status']
+ state.advanced ? ['searchbox', 'time-range', 'status'] : ['status']
"
:component-props="{ status: { disabled: statusTabDisabled } }"
class="px-4 pb-2 gap-y-1"
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 8912e668e3..95de3e4aab 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -5,12 +5,12 @@
feature="bb.feature.instance-count"
:description="instanceCountAttention"
/>
- <AdvancedSearchBox
+ <AdvancedSearch
v-model:params="state.params"
class="px-4"
:autofocus="false"
:placeholder="$t('instance.filter-instance-name')"
- :support-option-id-list="supportOptionIdList"
+ :scope-options="scopeOptions"
/>
<InstanceV1Table
:bordered="false"
@@ -24,6 +24,8 @@
<script lang="ts" setup>
import { computed, onMounted, reactive } from "vue";
import { useI18n } from "vue-i18n";
+import AdvancedSearch from "@/components/AdvancedSearch";
+import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import { InstanceV1Table } from "@/components/v2";
import {
useUIStateStore,
@@ -34,7 +36,7 @@ import {
} from "@/store";
import { UNKNOWN_ID } from "@/types";
import { PlanType } from "@/types/proto/v1/subscription_service";
-import type { SearchParams, SearchScopeId } from "@/utils";
+import type { SearchParams } from "@/utils";
import {
sortInstanceV1ListByEnvironmentV1,
extractEnvironmentResourceName,
@@ -58,6 +60,11 @@ const state = reactive<LocalState>({
},
});
+const scopeOptions = useCommonSearchScopeOptions(
+ computed(() => state.params),
+ ["environment"]
+);
+
const selectedEnvironment = computed(() => {
return (
state.params.scopes.find((scope) => scope.id === "environment")?.value ??
@@ -118,8 +125,4 @@ const instanceCountAttention = computed((): string => {
return `${status} ${upgrade}`;
});
-
-const supportOptionIdList = computed((): SearchScopeId[] => {
- return ["environment"];
-});
</script>