Skip to content

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

feat(frontend): advanced search renew (#9382)

Liu Jid2572aa80386
diff --git a/frontend/package.json b/frontend/package.json
index 0c548fc01b..593057d9c3 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -47,6 +47,7 @@
"lodash-es": "4.17.21",
"lucide-vue-next": "^0.292.0",
"markdown-it": "^13.0.2",
+ "match-sorter": "6.3.1",
"maz-ui": "^3.17.0",
"monaco-editor": "0.34.1",
"monaco-languageclient": "4.0.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 307b8e8bf6..faaf2b2f54 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -1,4 +1,4 @@
-lockfileVersion: '6.0'
+lockfileVersion: '6.1'
settings:
autoInstallPeers: true
@@ -101,6 +101,9 @@ dependencies:
markdown-it:
specifier: ^13.0.2
version: 13.0.2
+ match-sorter:
+ specifier: 6.3.1
+ version: 6.3.1
maz-ui:
specifier: ^3.17.0
@@ -4930,7 +4933,7 @@ packages:
dev: false
- resolution: {integrity: sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==}
+ resolution: {integrity: sha1-CkPTqq4egNuRngeuJUsoXZ4ce7U=}
dev: false
diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.css
index 3dd4512277..71f453b701 100644
--- a/frontend/src/assets/css/tailwind.css
+++ b/frontend/src/assets/css/tailwind.css
@@ -360,6 +360,24 @@
}
}
+.fade-slide-up-leave-active {
+ @apply transition-[opacity,_transform] duration-100 ease-in-out;
+}
+
+.fade-slide-up-enter-active {
+ @apply transition-[opacity,_transform] duration-100 ease-in-out;
+}
+
+.fade-slide-up-enter-from,
+.fade-slide-up-leave-to {
+ @apply opacity-0 scale-90;
+}
+
+.fade-slide-up-leave-from,
+.fade-slide-up-enter-to {
+ @apply opacity-100 scale-100;
+}
+
/* compatibility fixes for tailwindcss and naive-ui */
.n-base-selection-input:focus,
.n-base-selection-input-tag__input:focus,
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
index 23cfffeb92..98dbdf560e 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
@@ -1,147 +1,136 @@
<template>
- <div class="relative" :class="customClass">
+ <div ref="containerRef" class="bb-advanced-issue-search-box relative">
<NInput
ref="inputRef"
- :value="state.searchText"
- :clearable="!!state.searchText"
+ v-model:value="inputText"
:placeholder="$t('issue.advanced-search.self')"
- style="width: 100%"
- @update:value="onUpdate($event)"
- @blur="onClear"
- @keyup="onKeydown"
- @click="onKeydown"
+ 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>
- <heroicons-outline:search class="h-4 w-4 text-control-placeholder" />
- </template>
- </NInput>
- <div
- v-if="state.showSearchScopes"
- class="absolute z-50 pt-2 mt-0.5 top-full w-full divide-y divide-block-border bg-white shadow-md"
- >
- <div
- v-for="item in searchScopes"
- :key="item.id"
- class="flex gap-x-1 px-3 py-1 items-center cursor-pointer hover:bg-gray-100"
- @mousedown.prevent.stop="onScopeSelect(item.id)"
- >
- <div class="space-x-1 text-sm">
- <span class="text-accent">{{ item.id }}:</span>
- <span class="text-control-light">{{ item.description }}</span>
- </div>
- </div>
- </div>
- <div
- v-if="state.currentScope"
- class="absolute z-50 top-full w-full bg-white shadow-md"
- >
- <div class="px-3 pt-2 pb-1 text-sm text-control font-semibold">
- {{ searchKeyword }}
- </div>
- <div class="max-h-60 overflow-y-auto divide-block-border">
<div
- v-for="option in searchOptions"
- :key="option.id"
- class="flex gap-x-2 px-3 py-1 items-center cursor-pointer hover:bg-gray-100"
- @mousedown.prevent.stop="onOptionSelect(option.id)"
+ class="flex flex-row items-center justify-start gap-x-2"
+ :style="{
+ 'max-width': `calc(${containerWidth}px - 14rem)`,
+ }"
>
- <component :is="option.label" class="text-control text-sm" />
- <span class="text-control-light text-sm">{{ option.id }}</span>
+ <SearchIcon class="w-4 h-4 text-control-placeholder" />
+ <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"
+ @select-scope="selectScopeFromTag"
+ @remove-scope="removeScope"
+ />
+ </div>
</div>
- <div
- v-if="searchOptions.length === 0"
- class="px-3 py-1 text-control text-sm"
+ </template>
+ <template #suffix>
+ <NButton
+ v-show="clearable"
+ quaternary
+ circle
+ size="tiny"
+ @click.stop.prevent="handleClear"
>
- N/A
- </div>
+ <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-white shadow-md origin-top-left rounded-[3px] overflow-clip"
+ @wheel="console.log('wheel', $event)"
+ >
+ <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>
- </div>
+ </Transition>
</div>
</template>
<script lang="ts" setup>
-import { debounce, orderBy } from "lodash-es";
-import { NInput } from "naive-ui";
+import { useElementSize } from "@vueuse/core";
+import { cloneDeep, last } from "lodash-es";
+import { SearchIcon } from "lucide-vue-next";
+import { XIcon } from "lucide-vue-next";
+import { matchSorter } from "match-sorter";
+import { InputInst, NInput } from "naive-ui";
+import scrollIntoView from "scroll-into-view-if-needed";
+import { zindexable as vZindexable } from "vdirs";
import {
reactive,
- computed,
- h,
watch,
- VNode,
onMounted,
ref,
+ toRef,
+ computed,
nextTick,
} from "vue";
-import { useI18n } from "vue-i18n";
-import BBAvatar from "@/bbkit/BBAvatar.vue";
-import GitIcon from "@/components/GitIcon.vue";
-import YouTag from "@/components/misc/YouTag.vue";
import {
- InstanceV1Name,
- InstanceV1EngineIcon,
- DatabaseV1Name,
-} from "@/components/v2";
-import {
- useProjectV1ListByCurrentUser,
- useInstanceV1List,
- useSearchDatabaseV1List,
- useUserStore,
- useDatabaseV1Store,
- useCurrentUserV1,
-} from "@/store";
-import {
- projectNamePrefix,
- instanceNamePrefix,
-} from "@/store/modules/v1/common";
-import { SYSTEM_BOT_EMAIL } from "@/types";
-import { Workflow } from "@/types/proto/v1/project_service";
-import {
- projectV1Name,
- environmentV1Name,
- extractProjectResourceName,
- extractInstanceResourceName,
SearchParams,
SearchScopeId,
- buildSearchParamsBySearchText,
+ defaultSearchParams,
+ getValueFromSearchParams,
+ maybeApplyDefaultTsRange,
+ 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<{
+ params: SearchParams;
customClass?: string;
- params?: SearchParams;
autofocus?: boolean;
}>(),
{
customClass: "",
- params: undefined,
autofocus: false,
}
);
const emit = defineEmits<{
(event: "update:params", params: SearchParams): void;
+ (event: "select-unsupported-scope", id: SearchScopeId): void;
}>();
-const { t } = useI18n();
-
interface LocalState {
searchText: string;
showSearchScopes: boolean;
currentScope?: SearchScopeId;
}
-interface SearchOption {
- id: string;
- label: VNode;
-}
-
-interface SearchScope {
- id: SearchScopeId;
- title: string;
- description: string;
- options: SearchOption[];
-}
-
const buildSearchTextByParams = (params: SearchParams | undefined): string => {
const prefix = (params?.scopes ?? [])
.map((scope) => `${scope.id}:${scope.value}`)
@@ -157,10 +146,13 @@ const state = reactive<LocalState>({
searchText: buildSearchTextByParams(props.params),
showSearchScopes: props.autofocus,
});
-const me = useCurrentUserV1();
-const inputRef = ref<InstanceType<typeof NInput>>();
-const userStore = useUserStore();
-const databaseV1Store = useDatabaseV1Store();
+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>();
watch(
() => state.showSearchScopes,
@@ -176,339 +168,358 @@ watch(
}
);
-const { projectList } = useProjectV1ListByCurrentUser();
-const { instanceList } = useInstanceV1List(false /* !showDeleted */);
-const { databaseList } = useSearchDatabaseV1List({
- parent: "instances/-",
-});
+const {
+ menuView,
+ fullScopeOptions,
+ availableScopeOptions,
+ currentScope,
+ currentScopeOption,
+ valueOptions,
+} = useSearchScopeOptions(toRef(props, "params"));
+
+const visibleScopeOptions = computed(() => {
+ if (currentScopeOption.value) {
+ return [currentScopeOption.value];
+ }
-const principalSearchOptions = computed(() => {
- const sortedUsers = orderBy(
- userStore.activeUserList,
- (user) => (user.name === me.value.name ? -1 : 1),
- "asc"
- );
- return sortedUsers.map((user) => {
- const children = [
- h(BBAvatar, { size: "TINY", username: user.title }),
- h("span", {}, user.title),
- ];
- if (user.name === me.value.name) {
- children.push(h(YouTag));
- }
- return {
- id: user.email,
- label: h("div", { class: "flex items-center gap-x-1" }, children),
- };
+ const keyword = inputText.value.trim().replace(/:.*$/, "").toLowerCase();
+ if (!keyword) return availableScopeOptions.value;
+
+ const filtered = matchSorter(availableScopeOptions.value, keyword, {
+ keys: ["id", "title", "description"],
});
-});
-// fullScopes provides full search scopes and options.
-// we need this as the source of truth.
-const fullScopes = computed((): SearchScope[] => {
- const scopes: SearchScope[] = [
- {
- id: "project",
- title: t("issue.advanced-search.scope.project.title"),
- description: t("issue.advanced-search.scope.project.description"),
- options: projectList.value.map((proj) => {
- const children: VNode[] = [
- h("span", { innerHTML: projectV1Name(proj) }),
- ];
- if (proj.workflow === Workflow.VCS) {
- children.push(h(GitIcon, { class: "w-5" }));
- }
- return {
- id: extractProjectResourceName(proj.name),
- label: h("div", { class: "flex items-center gap-x-2" }, children),
- };
- }),
- },
- {
- id: "approval",
- title: t("issue.advanced-search.scope.approval.title"),
- description: t("issue.advanced-search.scope.approval.description"),
- options: [
- {
- id: "pending",
- label: h(
- "span",
- {},
- t("issue.advanced-search.scope.approval.value.pending")
- ),
- },
- {
- id: "approved",
- label: h(
- "span",
- {},
- 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: principalSearchOptions.value,
- },
- {
- id: "assignee",
- title: t("issue.advanced-search.scope.assignee.title"),
- description: t("issue.advanced-search.scope.assignee.description"),
- options: principalSearchOptions.value,
- },
- {
- id: "approver",
- title: t("issue.advanced-search.scope.approver.title"),
- description: t("issue.advanced-search.scope.approver.description"),
- options: principalSearchOptions.value.filter(
- (o) => o.id !== SYSTEM_BOT_EMAIL
- ),
- },
- {
- id: "subscriber",
- title: t("issue.advanced-search.scope.subscriber.title"),
- description: t("issue.advanced-search.scope.subscriber.description"),
- options: principalSearchOptions.value,
- },
- {
- id: "type",
- title: t("issue.advanced-search.scope.type.title"),
- description: t("issue.advanced-search.scope.type.description"),
- options: [
- {
- id: "DDL",
- label: h("span", { innerHTML: "Data Definition Language" }),
- },
- {
- id: "DML",
- label: h("span", { innerHTML: "Data Manipulation Language" }),
- },
- ],
- },
- {
- id: "instance",
- title: t("issue.advanced-search.scope.instance.title"),
- description: t("issue.advanced-search.scope.instance.description"),
- options: instanceList.value.map((ins) => {
- return {
- id: extractInstanceResourceName(ins.name),
- label: h("div", { class: "flex items-center gap-x-1" }, [
- h(InstanceV1Name, { instance: ins, link: false, tooltip: false }),
- h("span", {
- innerHTML: `(${environmentV1Name(ins.environmentEntity)})`,
- }),
- ]),
- };
- }),
- },
- {
- id: "database",
- title: t("issue.advanced-search.scope.database.title"),
- description: t("issue.advanced-search.scope.database.description"),
- options: databaseList.value.map((db) => {
- return {
- id: `${db.databaseName}-${db.uid}`,
- label: h("div", { class: "flex items-center gap-x-1" }, [
- h(InstanceV1EngineIcon, { instance: db.instanceEntity }),
- h(DatabaseV1Name, { database: db, link: false }),
- h("span", {
- innerHTML: `(${environmentV1Name(
- db.effectiveEnvironmentEntity
- )})`,
- }),
- ]),
- };
- }),
- },
- ];
- return scopes;
+ return filtered;
});
-// filteredScopes 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 filteredScopes = computed((): SearchScope[] => {
- const params = buildSearchParamsBySearchText(state.searchText);
- const existedScope = new Map<SearchScopeId, string>(
- params.scopes.map((scope) => [scope.id, scope.value])
+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 clone = fullScopes.value.map((scope) => ({
- ...scope,
- options: scope.options.map((option) => ({
- ...option,
- })),
- }));
- const index = clone.findIndex((scope) => scope.id === "database");
- clone[index].options = clone[index].options.filter((option) => {
- if (!existedScope.has("project") && !existedScope.has("instance")) {
- return true;
+ 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);
}
-
- const uid = option.id.split("-").slice(-1)[0];
- const db = databaseV1Store.getDatabaseByUID(uid);
- const project = db.project;
- const instance = db.instance;
-
- if (project === `${projectNamePrefix}${existedScope.get("project")}`) {
- return true;
- }
- if (instance === `${instanceNamePrefix}${existedScope.get("instance")}`) {
- return true;
- }
-
- return false;
- });
-
- return clone;
+ }
+ return filtered;
});
-// searchScopes will hide chosen search scope.
-// For example, if uses already select the instance, we should NOT show the instance scope in the dropdown.
-const searchScopes = computed((): SearchScope[] => {
- const params = buildSearchParamsBySearchText(state.searchText);
- const existedScope = new Set<SearchScopeId>(
- params.scopes.map((scope) => scope.id)
- );
+const visibleOptions = computed(() => {
+ return menuView.value === "scope"
+ ? visibleScopeOptions.value
+ : menuView.value === "value"
+ ? visibleValueOptions.value
+ : ([] as unknown[]);
+});
- return filteredScopes.value.filter((scope) => {
- if (existedScope.has(scope.id)) {
- return false;
- }
+const showMenu = computed(() => {
+ if (menuView.value === "scope") {
+ return visibleScopeOptions.value.length > 0;
+ }
+ if (menuView.value === "value") {
return true;
- });
+ }
+ return false;
});
-const searchOptions = computed((): SearchOption[] => {
- const item = filteredScopes.value.find(
- (item) => item.id === state.currentScope
- );
- return item?.options ?? [];
+const clearable = computed(() => {
+ return inputText.value.length > 0 || props.params.scopes.length > 0;
});
-const searchKeyword = computed(() => {
- const scope = filteredScopes.value.find(
- (item) => item.id === state.currentScope
- );
- return scope?.title ?? "";
-});
+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 onScopeSelect = (scopeId: SearchScopeId) => {
- state.showSearchScopes = false;
- state.currentScope = scopeId;
+ const target = minmax(menuIndex.value + delta, 0, options.length - 1);
+ menuIndex.value = target;
};
-const onOptionSelect = (scopeValue: string) => {
- const scopeId = state.currentScope;
- if (!scopeId) {
+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 params = buildSearchParamsBySearchText(state.searchText);
- const index = params.scopes.findIndex((s) => s.id === scopeId);
- if (index < 0) {
- params.scopes.push({
- id: scopeId,
- value: scopeValue,
- });
- } else {
- params.scopes[index] = {
- id: scopeId,
- value: scopeValue,
- };
+ 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;
}
- state.searchText = buildSearchTextByParams(params);
- debouncedUpdate();
- onClear();
+
+ // Unsupported scope for AdvancedSearchBox
+ // emit an event and wish the parent UI can handle this
+ emit("select-unsupported-scope", id);
+ hideMenu();
};
-const onClear = (immediate = false) => {
- const clear = () => {
- state.showSearchScopes = false;
- state.currentScope = undefined;
- };
- if (immediate) {
- clear();
- } else {
- nextTick(clear);
+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 debouncedUpdate = debounce(() => {
- emit("update:params", buildSearchParamsBySearchText(state.searchText));
-}, 500);
+const maybeEmitIncompleteValue = () => {
+ const updated = cloneDeep(props.params);
+ updated.query = inputText.value;
+ emit("update:params", updated);
+};
-const onUpdate = (value: string) => {
- state.searchText = value;
- debouncedUpdate();
+const handleInputClick = () => {
+ maybeSelectMatchedScope();
+ maybeDeselectMismatchedScope();
+ maybeEmitIncompleteValue();
};
-onMounted(() => {
- if (props.autofocus) {
- inputRef.value?.inputElRef?.focus();
+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;
-const onKeydown = () => {
- if (!inputRef.value || !inputRef.value.inputElRef) {
+ if (key === "ArrowUp") {
+ moveMenuIndex(-1);
+ e.preventDefault();
return;
}
- if (!state.searchText) {
- state.showSearchScopes = true;
+ if (key === "ArrowDown") {
+ moveMenuIndex(1);
+ e.preventDefault();
return;
}
+};
- const start = inputRef.value.inputElRef.selectionStart ?? -1;
- const end = inputRef.value.inputElRef.selectionEnd ?? -1;
- if (start !== end) {
- onClear();
+const handleKeyUp = (e: KeyboardEvent) => {
+ if (e.isComposing) return;
+ if (e.defaultPrevented) return;
+ const { key } = e;
+ if (key === "Escape") {
+ maybeEmitIncompleteValue();
+ menuView.value = undefined;
return;
}
-
- // Try to find the active section the cursor in.
- // For example, the searchText is (the | is the current cursor):
- // example 1:
- // project:xxx insta|nce:yyy custom-search-text
- // then the active section is instance:yyy, we should show the instances selector
- //
- // example 2:
- // project:xxx| instance:yyy custom-search-text
- // then the active section is project:xxx, we should show the projects selector
- //
- // example 3:
- // project:xxx instance:yyy |
- // we should NOT show any selector.
- const sections = state.searchText.split(" ");
- let i = 0;
- let len = 0;
- while (i < sections.length) {
- len += sections[i].length;
- if (i < sections.length - 1) {
- len += 1; // this is the length for empty space " " between sections.
- }
- if (len > start) {
- break;
+ if (key === "Backspace" && inputText.value === "") {
+ // backspace key might be processed by KeyDown
+ if (focusedTagId.value) {
+ return;
}
- i++;
}
-
- if (i >= sections.length) {
- onClear(true /* immediate */);
- state.showSearchScopes = true;
+ if (maybeSelectMatchedScope()) {
+ maybeEmitIncompleteValue();
return;
}
-
- const currentScope = sections[i].split(":")[0] as SearchScopeId;
- const existed =
- fullScopes.value.findIndex((item) => item.id === currentScope) >= 0;
- if (!existed) {
- onClear(true /* immediate */);
- state.showSearchScopes = true;
+ 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();
+};
- state.showSearchScopes = false;
- state.currentScope = currentScope;
+const handleClear = () => {
+ const params = defaultSearchParams();
+ maybeApplyDefaultTsRange(params, "created", true /* mutate */);
+ 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 a566bbaa65..27dbba1b4a 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -6,6 +6,7 @@
:autofocus="autofocus"
v-bind="componentProps?.searchbox"
@update:params="$emit('update:params', $event)"
+ @select-unsupported-scope="handleSelectScope"
/>
<slot name="default" />
@@ -29,6 +30,7 @@
<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)"
@@ -41,7 +43,8 @@
</template>
<script lang="ts" setup>
-import { SearchParams } from "@/utils";
+import { ref } from "vue";
+import { SearchParams, SearchScopeId } from "@/utils";
import AdvancedSearchBox from "./AdvancedSearchBox.vue";
import Status from "./Status.vue";
import TimeRange from "./TimeRange.vue";
@@ -73,8 +76,15 @@ withDefaults(
componentProps: undefined,
}
);
-
defineEmits<{
(event: "update:params", params: SearchParams): void;
}>();
+
+const showTimeRange = ref(false);
+
+const handleSelectScope = (id: SearchScopeId) => {
+ if (id === "created") {
+ showTimeRange.value = true;
+ }
+};
</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue b/frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue
new file mode 100644
index 0000000000..b227a720cc
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/ScopeMenu.vue
@@ -0,0 +1,100 @@
+<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="32"
+ >
+ <template #default="{ item: option, index }: ListItem">
+ <div
+ class="h-[32px] 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 { SearchParams, SearchScopeId } from "@/utils";
+import { 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/IssueV1/components/IssueSearch/ScopeTags.vue b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
new file mode 100644
index 0000000000..55c3b913dd
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
@@ -0,0 +1,61 @@
+<template>
+ <NTag
+ v-for="(scope, i) in params.scopes"
+ :key="scope.id"
+ :closable="true"
+ :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 { NTag, TagProps } from "naive-ui";
+import { h } from "vue";
+import {
+ SearchParams,
+ SearchScope,
+ SearchScopeId,
+ callCssVariable,
+} from "@/utils";
+
+const props = defineProps<{
+ params: SearchParams;
+ focusedTagId?: SearchScopeId;
+}>();
+defineEmits<{
+ (event: "remove-scope", id: SearchScopeId, value: string): void;
+ (event: "select-scope", id: SearchScopeId, value: string): void;
+}>();
+
+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));
+ const format = "YYYY-MM-DD";
+ return [dayjs(begin).format(format), dayjs(end).format(format)].join(
+ " -> "
+ );
+ }
+ 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
index 18be9e9744..a8257f1124 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
@@ -1,5 +1,6 @@
<template>
<NDatePicker
+ :key="timeRange ? 'filled' : 'empty'"
:value="timeRange"
:is-date-disabled="isDateDisabled"
type="daterange"
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue b/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue
new file mode 100644
index 0000000000..22735aa2e1
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/ValueMenu.vue
@@ -0,0 +1,128 @@
+<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="32"
+ >
+ <template #default="{ item: option, index }: ListItem">
+ <div
+ class="h-[32px] 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 { SearchParams } from "@/utils";
+import { 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/useSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
new file mode 100644
index 0000000000..340a457f9f
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
@@ -0,0 +1,348 @@
+import { orderBy } from "lodash-es";
+import { Ref, RenderFunction, VNode, 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 {
+ InstanceV1Name,
+ ProjectV1Name,
+ RichDatabaseName,
+} from "@/components/v2";
+import {
+ useCurrentUserV1,
+ useDatabaseV1Store,
+ useInstanceV1List,
+ useProjectV1ListByCurrentUser,
+ useSearchDatabaseV1List,
+ useUserStore,
+} from "@/store";
+import { SYSTEM_BOT_EMAIL, UNKNOWN_ID } from "@/types";
+import { engineToJSON } from "@/types/proto/v1/common";
+import { Workflow } from "@/types/proto/v1/project_service";
+import {
+ SearchParams,
+ SearchScopeId,
+ environmentV1Name,
+ extractEnvironmentResourceName,
+ extractInstanceResourceName,
+ 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>) => {
+ const { t } = useI18n();
+ const me = useCurrentUserV1();
+ const userStore = useUserStore();
+ const databaseV1Store = useDatabaseV1Store();
+ const { projectList } = useProjectV1ListByCurrentUser();
+ const { instanceList } = useInstanceV1List(false /* !showDeleted */);
+ const { databaseList } = useSearchDatabaseV1List({
+ parent: "instances/-",
+ });
+
+ 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: "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"),
+ 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),
+ ins.environmentEntity.title,
+ extractEnvironmentResourceName(ins.environment),
+ ],
+ render: () => {
+ return h("div", { class: "flex items-center gap-x-1" }, [
+ h(InstanceV1Name, {
+ instance: ins,
+ link: false,
+ tooltip: false,
+ }),
+ renderSpan(`(${environmentV1Name(ins.environmentEntity)})`),
+ ]);
+ },
+ };
+ }),
+ },
+ {
+ 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.databaseName}-${db.uid}`,
+ keywords: [
+ db.databaseName,
+ extractInstanceResourceName(db.instance),
+ db.instanceEntity.title,
+ extractEnvironmentResourceName(db.effectiveEnvironment),
+ db.effectiveEnvironmentEntity.title,
+ extractProjectResourceName(db.project),
+ db.projectEntity.title,
+ db.projectEntity.key,
+ ],
+ custom: true,
+ render: () => {
+ return h("div", { class: "text-sm" }, [
+ h(RichDatabaseName, {
+ database: db,
+ showProject: true,
+ }),
+ ]);
+ },
+ };
+ }),
+ },
+ {
+ 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"),
+ },
+ ],
+ },
+ ];
+ return scopes;
+ });
+
+ // 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");
+ 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;
+ });
+
+ // 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/misc/SystemBotTag.vue b/frontend/src/components/misc/SystemBotTag.vue
new file mode 100644
index 0000000000..f14615b0a9
--- /dev/null
+++ b/frontend/src/components/misc/SystemBotTag.vue
@@ -0,0 +1,7 @@
+<template>
+ <span
+ class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-semibold bg-green-100 text-green-800"
+ >
+ {{ $t("settings.members.system-bot") }}
+ </span>
+</template>
diff --git a/frontend/src/components/v2/Model/RichDatabaseName.vue b/frontend/src/components/v2/Model/RichDatabaseName.vue
index f3ddf759d8..fbc42b6ecd 100644
--- a/frontend/src/components/v2/Model/RichDatabaseName.vue
+++ b/frontend/src/components/v2/Model/RichDatabaseName.vue
@@ -2,6 +2,15 @@
<NPopover :disabled="!tooltip">
<template #trigger>
<div class="flex flex-row justify-start items-center gap-x-1">
+ <div v-if="showProject">
+ <ProjectV1Name :project="database.projectEntity" :link="false" />
+ </div>
+
+ <heroicons:chevron-right
+ v-if="showProject && showArrow"
+ class="text-control-light"
+ />
+
<div
v-if="showInstance || showEngineIcon"
class="flex flex-row items-center gap-x-1"
@@ -55,10 +64,12 @@ import { ComposedDatabase } from "@/types";
import DatabaseV1Name from "./DatabaseV1Name.vue";
import EnvironmentV1Name from "./EnvironmentV1Name.vue";
import { InstanceV1EngineIcon, InstanceV1Name } from "./Instance";
+import ProjectV1Name from "./ProjectV1Name.vue";
withDefaults(
defineProps<{
database: ComposedDatabase;
+ showProject?: boolean;
showEngineIcon?: boolean;
showInstance?: boolean;
showArrow?: boolean;
@@ -67,6 +78,7 @@ withDefaults(
tooltip?: "instance" | undefined;
}>(),
{
+ showProject: false,
showEngineIcon: true,
showInstance: true,
showArrow: true,
diff --git a/frontend/src/utils/v1/issue/search/common.ts b/frontend/src/utils/v1/issue/search/common.ts
index 185115d7a7..8cd3891224 100644
--- a/frontend/src/utils/v1/issue/search/common.ts
+++ b/frontend/src/utils/v1/issue/search/common.ts
@@ -53,11 +53,11 @@ export const buildSearchTextBySearchParams = (
): string => {
const parts: string[] = [];
params?.scopes.forEach((scope) => {
- parts.push(`${scope.id}:${scope.value.trim()}`);
+ parts.push(`${scope.id}:${encodeURIComponent(scope.value.trim())}`);
});
const query = (params?.query ?? "").trim();
if (params?.query) {
- parts.push(query);
+ parts.push(encodeURIComponent(query));
}
return parts.join(" ");
};
@@ -70,13 +70,13 @@ export const buildSearchParamsBySearchText = (text: string): SearchParams => {
for (let i = 0; i < segments.length; i++) {
const seg = segments[i];
const parts = seg.split(":");
- if (parts.length === 2 && isValidSearchScopeId(parts[0])) {
+ if (parts.length === 2 && isValidSearchScopeId(parts[0]) && parts[1]) {
params.scopes.push({
id: parts[0],
- value: parts[1],
+ value: decodeURIComponent(parts[1]),
});
} else {
- querySegments.push(seg);
+ querySegments.push(decodeURIComponent(seg));
}
}
params.query = querySegments.join(" ");