Skip to content

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

feat(frontend): integrate advance search to "My Issues" and "Project / Issues" (#9499)

Liu Ji1a5a77292266
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
index 98dbdf560e..c2f0940ca0 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
@@ -26,6 +26,7 @@
<ScopeTags
:params="params"
:focused-tag-id="focusedTagId"
+ :readonly-scopes="readonlyScopes"
@select-scope="selectScopeFromTag"
@remove-scope="removeScope"
/>
@@ -96,10 +97,10 @@ import {
} from "vue";
import {
SearchParams,
+ SearchScope,
SearchScopeId,
- defaultSearchParams,
+ emptySearchParams,
getValueFromSearchParams,
- maybeApplyDefaultTsRange,
minmax,
upsertScope,
} from "@/utils";
@@ -111,11 +112,11 @@ import { useSearchScopeOptions } from "./useSearchScopeOptions";
const props = withDefaults(
defineProps<{
params: SearchParams;
- customClass?: string;
+ readonlyScopes?: SearchScope[];
autofocus?: boolean;
}>(),
{
- customClass: "",
+ readonlyScopes: () => [],
autofocus: false,
}
);
@@ -131,6 +132,14 @@ interface LocalState {
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}`)
@@ -153,6 +162,12 @@ 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,
@@ -242,7 +257,9 @@ const showMenu = computed(() => {
});
const clearable = computed(() => {
- return inputText.value.length > 0 || props.params.scopes.length > 0;
+ return (
+ props.params.query.trim().length > 0 || editableScopes.value.length > 0
+ );
});
const hideMenu = () => {
@@ -446,7 +463,6 @@ const handleKeyUp = (e: KeyboardEvent) => {
const handleClear = () => {
const params = defaultSearchParams();
- maybeApplyDefaultTsRange(params, "created", true /* mutate */);
emit("update:params", params);
hideMenu();
};
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
index 27dbba1b4a..68744944bf 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -1,21 +1,22 @@
<template>
<div class="flex flex-col">
- <AdvancedSearchBox
+ <div
v-if="components.includes('searchbox')"
- :params="params"
- :autofocus="autofocus"
- v-bind="componentProps?.searchbox"
- @update:params="$emit('update:params', $event)"
- @select-unsupported-scope="handleSelectScope"
- />
+ class="flex flex-row items-center gap-x-2"
+ >
+ <AdvancedSearchBox
+ :params="params"
+ :autofocus="autofocus"
+ :readonly-scopes="readonlyScopes"
+ class="flex-1"
+ v-bind="componentProps?.searchbox"
+ @update:params="$emit('update:params', $event)"
+ @select-unsupported-scope="handleSelectScope"
+ />
+ <slot name="searchbox-suffix" />
+ </div>
<slot name="default" />
- <template v-if="showFeatureAttention">
- <FeatureAttention
- v-if="!!params.query || params.scopes.length > 0"
- feature="bb.feature.issue-advanced-search"
- />
- </template>
<div class="flex flex-col md:flex-row md:items-center gap-y-1">
<div class="flex-1 flex items-start">
<Status
@@ -44,7 +45,7 @@
<script lang="ts" setup>
import { ref } from "vue";
-import { SearchParams, SearchScopeId } from "@/utils";
+import { SearchParams, SearchScope, SearchScopeId } from "@/utils";
import AdvancedSearchBox from "./AdvancedSearchBox.vue";
import Status from "./Status.vue";
import TimeRange from "./TimeRange.vue";
@@ -65,14 +66,14 @@ export type SearchComponent =
withDefaults(
defineProps<{
params: SearchParams;
+ readonlyScopes?: SearchScope[];
autofocus?: boolean;
components?: SearchComponent[];
- showFeatureAttention?: boolean;
componentProps?: Partial<Record<SearchComponent, any>>;
}>(),
{
+ readonlyScopes: () => [],
components: () => ["searchbox", "status", "time-range"],
- showFeatureAttention: false,
componentProps: undefined,
}
);
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
index 05327cdd38..37a2f7b864 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/ScopeTags.vue
@@ -2,7 +2,8 @@
<NTag
v-for="(scope, i) in params.scopes"
:key="scope.id"
- :closable="true"
+ :closable="!isReadonlyScope(scope)"
+ :disabled="isReadonlyScope(scope)"
:data-search-scope-id="scope.id"
:bordered="false"
size="small"
@@ -19,7 +20,7 @@
<script setup lang="ts">
import dayjs from "dayjs";
import { NTag, TagProps } from "naive-ui";
-import { h } from "vue";
+import { computed, h } from "vue";
import {
SearchParams,
SearchScope,
@@ -30,11 +31,19 @@ import {
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 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) {
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
index a8257f1124..c0cb60b2c8 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
@@ -16,13 +16,7 @@
import dayjs from "dayjs";
import { NDatePicker } from "naive-ui";
import { computed } from "vue";
-import { hasFeature } from "@/store";
-import {
- SearchParams,
- TimeRangeLimitForFreePlanInTs,
- getTsRangeFromSearchParams,
- upsertScope,
-} from "@/utils";
+import { SearchParams, getTsRangeFromSearchParams, upsertScope } from "@/utils";
const props = defineProps<{
params: SearchParams;
@@ -41,11 +35,7 @@ const isDateDisabled = (ts: number) => {
if (ts > today) {
return true;
}
- if (hasFeature("bb.feature.issue-advanced-search")) {
- return false;
- }
-
- return ts < today - TimeRangeLimitForFreePlanInTs;
+ return false;
};
const handleUpdate = (values: [number, number] | null) => {
diff --git a/frontend/src/components/Project/ProjectIssuesPanel.vue b/frontend/src/components/Project/ProjectIssuesPanel.vue
index 800410431a..ecd0fac83d 100644
--- a/frontend/src/components/Project/ProjectIssuesPanel.vue
+++ b/frontend/src/components/Project/ProjectIssuesPanel.vue
@@ -2,27 +2,54 @@
<div class="flex flex-col gap-y-2 -mt-4">
<IssueSearch
v-model:params="state.params"
- :components="['status']"
+ :readonly-scopes="readonlyScopes"
+ :components="
+ state.advanced ? ['searchbox', 'status', 'time-range'] : ['status']
+ "
:component-props="{ status: { disabled: statusTabDisabled } }"
+ class="gap-y-1"
>
- <template #default>
- <div class="flex items-center gap-x-2">
+ <template v-if="!state.advanced" #default>
+ <div class="h-[34px] flex items-center gap-x-2">
<div class="flex-1 overflow-auto">
- <TabFilter v-model:value="tab" :items="tabItemList" />
+ <TabFilter
+ :value="tab"
+ :items="tabItemList"
+ @update:value="selectTab($event as TabValue)"
+ />
</div>
<div class="flex items-center">
- <router-link
- :to="issueLink"
+ <div
class="flex items-center gap-x-1 normal-link whitespace-nowrap text-sm"
+ @click="toggleAdvancedSearch(true)"
>
<SearchIcon class="w-4 h-4" />
<span class="hidden md:block">
{{ $t("issue.advanced-search.self") }}
</span>
- </router-link>
+ </div>
</div>
</div>
</template>
+ <template v-if="state.advanced" #searchbox-suffix>
+ <NTooltip>
+ <template #trigger>
+ <NButton
+ style="--n-padding: 0 6px; --n-icon-size: 24px"
+ @click="toggleAdvancedSearch(false)"
+ >
+ <template #icon>
+ <ChevronDownIcon class="w-5 h-5" />
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ <div class="whitespace-nowrap">
+ {{ $t("issue.advanced-search.hide") }}
+ </div>
+ </template>
+ </NTooltip>
+ </template>
</IssueSearch>
<div class="relative min-h-[20rem]">
@@ -38,8 +65,8 @@
v-model:loading="state.loading"
v-model:loading-more="state.loadingMore"
:session-key="keyForTab(tab)"
- :issue-filter="mergeIssueFilterByTab(tab)"
- :ui-issue-filter="mergeUIIssueFilterByTab(tab)"
+ :issue-filter="mergedIssueFilter"
+ :ui-issue-filter="mergedUIIssueFilter"
:page-size="50"
>
<template #table="{ issueList, loading }">
@@ -47,6 +74,7 @@
mode="PROJECT"
:show-placeholder="!loading"
:issue-list="issueList"
+ :highlight-text="state.params.query"
/>
</template>
</PagedIssueTableV1>
@@ -57,33 +85,37 @@
<script lang="ts" setup>
import { useLocalStorage } from "@vueuse/core";
import { cloneDeep } from "lodash-es";
-import { SearchIcon } from "lucide-vue-next";
+import { ChevronDownIcon, SearchIcon } from "lucide-vue-next";
+import { NButton, NTooltip } from "naive-ui";
import { reactive, PropType, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
+import { useRoute, useRouter } from "vue-router";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { TabFilterItem } from "@/components/v2";
-import { featureToRef } from "@/store";
import { Project } from "@/types/proto/v1/project_service";
import {
SearchParams,
+ SearchScope,
+ SearchScopeId,
buildIssueFilterBySearchParams,
+ buildSearchParamsBySearchText,
buildSearchTextBySearchParams,
buildUIIssueFilterBySearchParams,
extractProjectResourceName,
getValueFromSearchParams,
- maybeApplyDefaultTsRange,
upsertScope,
} from "@/utils";
import { IssueSearch } from "../IssueV1/components";
-const TABS = ["WAITING_APPROVAL", "WAITING_ROLLOUT", "ALL"] as const;
+const TABS = ["WAITING_APPROVAL", "WAITING_ROLLOUT", "ALL", ""] as const;
type TabValue = typeof TABS[number];
interface LocalState {
params: SearchParams;
isFetchingActivityList: boolean;
+ advanced: boolean;
loading: boolean;
loadingMore: boolean;
}
@@ -95,50 +127,26 @@ const props = defineProps({
},
});
-const defaultSearchParams = () => {
- const params: SearchParams = {
- query: "",
- scopes: [
- { id: "status", value: "OPEN" },
- { id: "project", value: extractProjectResourceName(props.project.name) },
- ],
- };
- maybeApplyDefaultTsRange(params, "created", true /* mutate */);
- return params;
-};
-
-const state = reactive<LocalState>({
- params: defaultSearchParams(),
- isFetchingActivityList: false,
- loading: false,
- loadingMore: false,
-});
const { t } = useI18n();
-
-const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
-const keyForTab = (tab: TabValue) => {
- if (tab === "WAITING_APPROVAL") return "project-issues-waiting-approval";
- if (tab === "WAITING_ROLLOUT") return "project-issues-waiting-rollout";
- if (tab === "ALL") return "project-issues-all";
-
- return "project-issues-unknown";
-};
-
+const route = useRoute();
+const router = useRouter();
+const readonlyScopes = computed((): SearchScope[] => {
+ return [
+ { id: "project", value: extractProjectResourceName(props.project.name) },
+ ];
+});
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
- const items: TabFilterItem<TabValue>[] = [];
- if (hasCustomApprovalFeature.value) {
- items.push({
+ const items: TabFilterItem<TabValue>[] = [
+ {
value: "WAITING_APPROVAL",
label: t("issue.waiting-approval"),
- });
- }
- items.push(
+ },
{ value: "WAITING_ROLLOUT", label: t("issue.waiting-rollout") },
- { value: "ALL", label: t("common.all") }
- );
+ { value: "ALL", label: t("common.all") },
+ ];
return items;
});
-const tab = useLocalStorage<TabValue>(
+const storedTab = useLocalStorage<TabValue>(
"bb.project.issue-list-tab",
tabItemList.value[0].value,
{
@@ -153,51 +161,150 @@ const tab = useLocalStorage<TabValue>(
},
}
);
-const statusTabDisabled = computed(() => {
- return ["WAITING_APPROVAL", "WAITING_ROLLOUT"].includes(tab.value);
-});
-const mergeSearchParamsByTab = (tab: TabValue) => {
- const common = cloneDeep(state.params);
+const keyForTab = (tab: TabValue) => {
+ if (tab === "WAITING_APPROVAL") return "project-issues-waiting-approval";
+ if (tab === "WAITING_ROLLOUT") return "project-issues-waiting-rollout";
+ if (tab === "ALL") return "project-issues-all";
+
+ return "project-issues-unknown";
+};
+
+const defaultSearchParams = () => {
+ const params: SearchParams = {
+ query: "",
+ scopes: [...readonlyScopes.value, { id: "status", value: "OPEN" }],
+ };
+ return params;
+};
+const defaultScopeIds = computed(() => {
+ return new Set(defaultSearchParams().scopes.map((s) => s.id));
+});
+const mergeSearchParamsByTab = (params: SearchParams, tab: TabValue) => {
+ const common = cloneDeep(params);
+ if (tab === "" || tab === "ALL") {
+ return common;
+ }
if (tab === "WAITING_APPROVAL") {
- return upsertScope(common, {
- id: "approval",
- value: "pending",
- });
+ return upsertScope(common, [
+ {
+ id: "status",
+ value: "OPEN",
+ },
+ {
+ id: "approval",
+ value: "pending",
+ },
+ ]);
}
if (tab === "WAITING_ROLLOUT") {
- return upsertScope(common, {
- id: "approval",
- value: "approved",
- });
- }
- if (tab === "ALL") {
- return common;
+ return upsertScope(common, [
+ {
+ id: "status",
+ value: "OPEN",
+ },
+ {
+ id: "approval",
+ value: "approved",
+ },
+ ]);
}
console.error("[mergeSearchParamsByTab] should never reach this line", tab);
return common;
};
+const guessTabValueFromSearchParams = (params: SearchParams): TabValue => {
+ const verifyScopes = (scopes: SearchScopeId[]) => {
+ const allowed = new Set(scopes);
+ return params.scopes.every(
+ (s) => allowed.has(s.id) || defaultScopeIds.value.has(s.id)
+ );
+ };
+
+ if (
+ verifyScopes(["approval"]) &&
+ getValueFromSearchParams(params, "status") === "OPEN" &&
+ getValueFromSearchParams(params, "approval") === "pending"
+ ) {
+ return "WAITING_APPROVAL";
+ }
+ if (
+ verifyScopes(["approval"]) &&
+ getValueFromSearchParams(params, "status") === "OPEN" &&
+ getValueFromSearchParams(params, "approval") === "approved"
+ ) {
+ return "WAITING_ROLLOUT";
+ }
+
+ if (params.scopes.every((s) => defaultScopeIds.value.has(s.id))) {
+ return "ALL";
+ }
+ return "";
+};
+const initializeSearchParamsFromQueryOrLocalStorage = () => {
+ const { qs } = route.query;
+ if (typeof qs === "string" && qs.length > 0) {
+ return {
+ params: buildSearchParamsBySearchText(qs),
+ advanced: true,
+ };
+ }
+ return {
+ params: mergeSearchParamsByTab(defaultSearchParams(), storedTab.value),
+ advanced: false,
+ };
+};
+
+const state = reactive<LocalState>({
+ isFetchingActivityList: false,
+ ...initializeSearchParamsFromQueryOrLocalStorage(),
+ loading: false,
+ loadingMore: false,
+});
+const tab = computed<TabValue>({
+ set(tab) {
+ if (tab === "") return;
+ const base = cloneDeep(state.params);
+ base.scopes = base.scopes.filter((s) => defaultScopeIds.value.has(s.id));
+ state.params = mergeSearchParamsByTab(base, tab);
+ },
+ get() {
+ return guessTabValueFromSearchParams(state.params);
+ },
+});
-const issueLink = computed(() => {
- return `/issue?qs=${encodeURIComponent(
- buildSearchTextBySearchParams(mergeSearchParamsByTab(tab.value))
- )}`;
+const statusTabDisabled = computed(() => {
+ if (state.advanced) return false;
+ return ["WAITING_APPROVAL", "WAITING_ROLLOUT"].includes(tab.value);
});
-const mergeIssueFilterByTab = (tab: TabValue) => {
- return buildIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+const mergedIssueFilter = computed(() => {
+ return buildIssueFilterBySearchParams(state.params);
+});
+const mergedUIIssueFilter = computed(() => {
+ return buildUIIssueFilterBySearchParams(state.params);
+});
+
+const selectTab = (target: TabValue) => {
+ if (target === "") return;
+ storedTab.value = target;
+ tab.value = target;
};
-const mergeUIIssueFilterByTab = (tab: TabValue) => {
- return buildUIIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+const toggleAdvancedSearch = (on: boolean) => {
+ state.advanced = on;
+ if (!on) {
+ if (storedTab.value !== "") {
+ selectTab(storedTab.value);
+ } else {
+ selectTab(tabItemList.value[0].value);
+ }
+ state.params.query = "";
+ }
};
watch(
- [hasCustomApprovalFeature, tab],
+ tab,
() => {
- if (!hasCustomApprovalFeature.value && tab.value === "WAITING_APPROVAL") {
- tab.value = "WAITING_ROLLOUT";
- }
if (tab.value === "WAITING_APPROVAL" || tab.value === "WAITING_ROLLOUT") {
if (getValueFromSearchParams(state.params, "status") === "CLOSED") {
upsertScope(
@@ -220,4 +327,30 @@ watch(
state.params = defaultSearchParams();
}
);
+
+watch(
+ [() => state.params, tab],
+ () => {
+ const hash = route.hash;
+ if (state.params.query || tab.value === "") {
+ // using custom advanced search query, sync the search query string
+ // to URL
+ router.replace({
+ query: {
+ ...route.query,
+ qs: buildSearchTextBySearchParams(state.params),
+ },
+ hash,
+ });
+ } else {
+ const query = cloneDeep(route.query);
+ delete query["qs"];
+ router.replace({
+ query,
+ hash,
+ });
+ }
+ },
+ { deep: true }
+);
</script>
diff --git a/frontend/src/components/Project/ProjectSidebar.vue b/frontend/src/components/Project/ProjectSidebar.vue
index b0677156c9..a587fc318d 100644
--- a/frontend/src/components/Project/ProjectSidebar.vue
+++ b/frontend/src/components/Project/ProjectSidebar.vue
@@ -303,6 +303,7 @@ const onSelect = (hash: ProjectHash | undefined) => {
router.replace({
name: "workspace.project.detail",
hash: `#${hash}`,
+ query: route.query,
params: {
projectSlug: props.projectSlug || projectSlugV1(project.value),
},
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 7ba03a2c73..4b87f429ca 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -995,7 +995,8 @@
"description": "Search by the issue approval status",
"title": "Approval Status"
}
- }
+ },
+ "hide": "Hide advanced search"
},
"table": {
"open": "Open",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 76949c6905..5a6e2aaae6 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -994,7 +994,8 @@
"description": "Buscar por estado de revisión del problema",
"title": "Estado de aprobación"
}
- }
+ },
+ "hide": "Ocultar búsqueda avanzada"
},
"table": {
"open": "Abierto",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 764a580ab0..e87ed8c1ba 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -992,7 +992,8 @@
"description": "按工单的审批状态搜索",
"title": "审批状态"
}
- }
+ },
+ "hide": "隐藏高级搜索"
},
"table": {
"open": "开启中",
diff --git a/frontend/src/utils/v1/issue/search/common.ts b/frontend/src/utils/v1/issue/search/common.ts
index 8cd3891224..aaf821278f 100644
--- a/frontend/src/utils/v1/issue/search/common.ts
+++ b/frontend/src/utils/v1/issue/search/common.ts
@@ -1,10 +1,4 @@
-import dayjs from "dayjs";
import { cloneDeep, pullAt } from "lodash-es";
-import { hasFeature } from "@/store";
-
-// TimeRangeLimitForFreePlanInTs is the search time limit in ts format.
-// should be 60 days.
-export const TimeRangeLimitForFreePlanInTs = 60 * 24 * 60 * 60 * 1000;
export type SemanticIssueStatus = "OPEN" | "CLOSED";
@@ -63,7 +57,7 @@ export const buildSearchTextBySearchParams = (
};
export const buildSearchParamsBySearchText = (text: string): SearchParams => {
- const params = defaultSearchParams();
+ const params = emptySearchParams();
const segments = text.split(/\s+/g);
const querySegments: string[] = [];
@@ -147,30 +141,9 @@ export const upsertScope = (
return target;
};
-export const defaultSearchParams = (): SearchParams => {
+export const emptySearchParams = (): SearchParams => {
return {
query: "",
scopes: [],
};
};
-
-export const maybeApplyDefaultTsRange = (
- params: SearchParams,
- key: SearchScopeId,
- mutate = false
-) => {
- if (hasFeature("bb.feature.issue-advanced-search")) {
- return mutate ? params : cloneDeep(params);
- }
-
- const endOfToday = dayjs().add(1, "day").endOf("day").valueOf();
- const begin = endOfToday - TimeRangeLimitForFreePlanInTs;
- return upsertScope(
- params,
- {
- id: key,
- value: `${begin},${endOfToday}`,
- },
- mutate
- );
-};
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 1b9e60e3c2..b6b2061c82 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -2,28 +2,53 @@
<div class="flex flex-col">
<IssueSearch
v-model:params="state.params"
- :components="['status']"
+ :components="
+ state.advanced ? ['searchbox', 'status', 'time-range'] : ['status']
+ "
:component-props="{ status: { disabled: statusTabDisabled } }"
- class="px-4 py-2"
+ class="px-4 py-2 gap-y-1"
>
- <template #default>
- <div class="flex items-center gap-x-2">
+ <template v-if="!state.advanced" #default>
+ <div class="h-[34px] flex items-center gap-x-2">
<div class="flex-1 overflow-auto">
- <TabFilter v-model:value="tab" :items="tabItemList" />
+ <TabFilter
+ :value="tab"
+ :items="tabItemList"
+ @update:value="selectTab($event as TabValue)"
+ />
</div>
<div class="flex items-center">
- <router-link
- :to="issueLink"
+ <div
class="flex items-center gap-x-1 normal-link whitespace-nowrap text-sm"
+ @click="toggleAdvancedSearch(true)"
>
<SearchIcon class="w-4 h-4" />
<span class="hidden md:block">
{{ $t("issue.advanced-search.self") }}
</span>
- </router-link>
+ </div>
</div>
</div>
</template>
+ <template v-if="state.advanced" #searchbox-suffix>
+ <NTooltip>
+ <template #trigger>
+ <NButton
+ style="--n-padding: 0 6px; --n-icon-size: 24px"
+ @click="toggleAdvancedSearch(false)"
+ >
+ <template #icon>
+ <ChevronDownIcon class="w-5 h-5" />
+ </template>
+ </NButton>
+ </template>
+ <template #default>
+ <div class="whitespace-nowrap">
+ {{ $t("issue.advanced-search.hide") }}
+ </div>
+ </template>
+ </NTooltip>
+ </template>
</IssueSearch>
<div class="relative min-h-[20rem]">
@@ -39,8 +64,8 @@
v-model:loading="state.loading"
v-model:loading-more="state.loadingMore"
:session-key="keyForTab(tab)"
- :issue-filter="mergeIssueFilterByTab(tab)"
- :ui-issue-filter="mergeUIIssueFilterByTab(tab)"
+ :issue-filter="mergedIssueFilter"
+ :ui-issue-filter="mergedUIIssueFilter"
:page-size="50"
>
<template #table="{ issueList, loading }">
@@ -48,6 +73,7 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
+ :highlight-text="state.params.query"
/>
</template>
</PagedIssueTableV1>
@@ -120,9 +146,11 @@
<script lang="ts" setup>
import { useLocalStorage } from "@vueuse/core";
import { cloneDeep } from "lodash-es";
-import { SearchIcon } from "lucide-vue-next";
+import { ChevronDownIcon, SearchIcon } from "lucide-vue-next";
+import { NButton, NTooltip } from "naive-ui";
import { reactive, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
+import { useRoute, useRouter } from "vue-router";
import { IssueSearch } from "@/components/IssueV1/components";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
@@ -135,11 +163,12 @@ import {
import { planTypeToString } from "@/types";
import {
SearchParams,
+ SearchScopeId,
buildIssueFilterBySearchParams,
+ buildSearchParamsBySearchText,
buildSearchTextBySearchParams,
buildUIIssueFilterBySearchParams,
getValueFromSearchParams,
- maybeApplyDefaultTsRange,
upsertScope,
} from "@/utils";
@@ -150,6 +179,7 @@ const TABS = [
"WAITING_ROLLOUT",
"SUBSCRIBED",
"ALL",
+ "",
] as const;
type TabValue = typeof TABS[number];
@@ -158,12 +188,16 @@ interface LocalState {
loading: boolean;
loadingMore: boolean;
params: SearchParams;
+ advanced: boolean;
showTrialStartModal: boolean;
}
const { t } = useI18n();
const subscriptionStore = useSubscriptionV1Store();
const onboardingStateStore = useOnboardingStateStore();
+const me = useCurrentUserV1();
+const route = useRoute();
+const router = useRouter();
const defaultSearchParams = () => {
const params: SearchParams = {
@@ -175,19 +209,11 @@ const defaultSearchParams = () => {
},
],
};
- maybeApplyDefaultTsRange(params, "created", true /* mutate */);
return params;
};
-
-const state = reactive<LocalState>({
- loading: false,
- loadingMore: false,
- params: defaultSearchParams(),
- showTrialStartModal: false,
+const defaultScopeIds = computed(() => {
+ return new Set(defaultSearchParams().scopes.map((s) => s.id));
});
-
-const me = useCurrentUserV1();
-
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
return [
{ value: "CREATED", label: t("common.created") },
@@ -201,7 +227,7 @@ const tabItemList = computed((): TabFilterItem<TabValue>[] => {
{ value: "ALL", label: t("common.all") },
];
});
-const tab = useLocalStorage<TabValue>(
+const storedTab = useLocalStorage<TabValue>(
"bb.home.issue-list-tab",
tabItemList.value[0].value,
{
@@ -216,7 +242,6 @@ const tab = useLocalStorage<TabValue>(
},
}
);
-
const keyForTab = (tab: TabValue) => {
if (tab === "CREATED") return "my-issues-created";
if (tab === "ASSIGNED") return "my-issues-assigned";
@@ -227,8 +252,12 @@ const keyForTab = (tab: TabValue) => {
return "my-issues-unknown";
};
-const mergeSearchParamsByTab = (tab: TabValue) => {
- const common = cloneDeep(state.params);
+const mergeSearchParamsByTab = (params: SearchParams, tab: TabValue) => {
+ const common = cloneDeep(params);
+ if (tab === "" || tab === "ALL") {
+ return common;
+ }
+
const myEmail = me.value.email;
if (tab === "CREATED") {
return upsertScope(common, {
@@ -248,11 +277,12 @@ const mergeSearchParamsByTab = (tab: TabValue) => {
value: myEmail,
});
}
- if (tab === "ALL") {
- return common;
- }
if (tab === "APPROVAL_REQUESTED") {
return upsertScope(common, [
+ {
+ id: "status",
+ value: "OPEN",
+ },
{
id: "approval",
value: "pending",
@@ -265,6 +295,10 @@ const mergeSearchParamsByTab = (tab: TabValue) => {
}
if (tab === "WAITING_ROLLOUT") {
return upsertScope(common, [
+ {
+ id: "status",
+ value: "OPEN",
+ },
{
id: "approval",
value: "approved",
@@ -278,6 +312,88 @@ const mergeSearchParamsByTab = (tab: TabValue) => {
console.error("[mergeSearchParamsByTab] should never reach this line", tab);
return common;
};
+const guessTabValueFromSearchParams = (params: SearchParams): TabValue => {
+ const myEmail = me.value.email;
+
+ const verifyScopes = (scopes: SearchScopeId[]) => {
+ const allowed = new Set([...scopes]);
+ return params.scopes.every(
+ (s) => allowed.has(s.id) || defaultScopeIds.value.has(s.id)
+ );
+ };
+
+ if (
+ verifyScopes(["creator"]) &&
+ getValueFromSearchParams(params, "creator") === myEmail
+ ) {
+ return "CREATED";
+ }
+ if (
+ verifyScopes(["assignee"]) &&
+ getValueFromSearchParams(params, "assignee") === myEmail
+ ) {
+ return "ASSIGNED";
+ }
+ if (
+ verifyScopes(["subscriber"]) &&
+ getValueFromSearchParams(params, "subscriber") === myEmail
+ ) {
+ return "SUBSCRIBED";
+ }
+ if (
+ verifyScopes(["approval", "approver"]) &&
+ getValueFromSearchParams(params, "status") === "OPEN" &&
+ getValueFromSearchParams(params, "approval") === "pending" &&
+ getValueFromSearchParams(params, "approver") === myEmail
+ ) {
+ return "APPROVAL_REQUESTED";
+ }
+ if (
+ verifyScopes(["approval", "releaser"]) &&
+ getValueFromSearchParams(params, "status") === "OPEN" &&
+ getValueFromSearchParams(params, "approval") === "approved" &&
+ getValueFromSearchParams(params, "releaser") === myEmail
+ ) {
+ return "WAITING_ROLLOUT";
+ }
+
+ if (params.scopes.every((s) => defaultScopeIds.value.has(s.id))) {
+ return "ALL";
+ }
+ return "";
+};
+const initializeSearchParamsFromQueryOrLocalStorage = () => {
+ const { qs } = route.query;
+ if (typeof qs === "string" && qs.length > 0) {
+ return {
+ params: buildSearchParamsBySearchText(qs),
+ advanced: true,
+ };
+ }
+ return {
+ params: mergeSearchParamsByTab(defaultSearchParams(), storedTab.value),
+ advanced: false,
+ };
+};
+
+const state = reactive<LocalState>({
+ loading: false,
+ loadingMore: false,
+ ...initializeSearchParamsFromQueryOrLocalStorage(),
+ showTrialStartModal: false,
+});
+
+const tab = computed<TabValue>({
+ set(tab) {
+ if (tab === "") return;
+ const base = cloneDeep(state.params);
+ base.scopes = base.scopes.filter((s) => defaultScopeIds.value.has(s.id));
+ state.params = mergeSearchParamsByTab(base, tab);
+ },
+ get() {
+ return guessTabValueFromSearchParams(state.params);
+ },
+});
const onTrialingModalClose = () => {
state.showTrialStartModal = false;
@@ -286,29 +402,41 @@ const onTrialingModalClose = () => {
const planImage = computed(() => {
return new URL(
- `../assets/plan-${planTypeToString(
+ `@/assets/plan-${planTypeToString(
subscriptionStore.currentPlan
).toLowerCase()}.png`,
import.meta.url
).href;
});
-const issueLink = computed(() => {
- return `/issue?qs=${encodeURIComponent(
- buildSearchTextBySearchParams(mergeSearchParamsByTab(tab.value))
- )}`;
-});
-
const statusTabDisabled = computed(() => {
+ if (state.advanced) return false;
return ["APPROVAL_REQUESTED", "WAITING_ROLLOUT"].includes(tab.value);
});
-const mergeIssueFilterByTab = (tab: TabValue) => {
- return buildIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+const mergedIssueFilter = computed(() => {
+ return buildIssueFilterBySearchParams(state.params);
+});
+const mergedUIIssueFilter = computed(() => {
+ return buildUIIssueFilterBySearchParams(state.params);
+});
+
+const selectTab = (target: TabValue) => {
+ if (target === "") return;
+ storedTab.value = target;
+ tab.value = target;
};
-const mergeUIIssueFilterByTab = (tab: TabValue) => {
- return buildUIIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+const toggleAdvancedSearch = (on: boolean) => {
+ state.advanced = on;
+ if (!on) {
+ if (storedTab.value !== "") {
+ selectTab(storedTab.value);
+ } else {
+ selectTab(tabItemList.value[0].value);
+ }
+ state.params.query = "";
+ }
};
watch(
@@ -329,4 +457,27 @@ watch(
},
{ immediate: true }
);
+
+watch(
+ [() => state.params, tab],
+ () => {
+ if (state.params.query || tab.value === "") {
+ // using custom advanced search query, sync the search query string
+ // to URL
+ router.replace({
+ query: {
+ ...route.query,
+ qs: buildSearchTextBySearchParams(state.params),
+ },
+ });
+ } else {
+ const query = cloneDeep(route.query);
+ delete query["qs"];
+ router.replace({
+ query,
+ });
+ }
+ },
+ { deep: true }
+);
</script>
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index 879f6731fa..40607028f8 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -44,7 +44,6 @@ import {
buildUIIssueFilterBySearchParams,
getValueFromSearchParams,
buildSearchTextBySearchParams,
- maybeApplyDefaultTsRange,
} from "@/utils";
interface LocalState {
@@ -58,16 +57,25 @@ const autofocus = computed((): boolean => {
return !!route.query.autofocus;
});
+const defaultSearchParams = () => {
+ const params: SearchParams = {
+ query: "",
+ scopes: [
+ {
+ id: "status",
+ value: "OPEN",
+ },
+ ],
+ };
+ return params;
+};
+
const initializeSearchParamsFromQuery = (): SearchParams => {
const { qs } = route.query;
const params: SearchParams =
typeof qs === "string" && qs.length > 0
? buildSearchParamsBySearchText(qs)
- : {
- query: "",
- scopes: [{ id: "status", value: "OPEN" }],
- };
- maybeApplyDefaultTsRange(params, "created", true /* mutate */);
+ : defaultSearchParams();
return params;
};