Skip to content

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

feat(frontend): re-consolidated issue pages (#9350)

Liu Ji6daf055149b9
diff --git a/frontend/src/components/AdvancedSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
similarity index 94%
rename from frontend/src/components/AdvancedSearch.vue
rename to frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
index 2d1d6bf1bf..8cdcd92592 100644
--- a/frontend/src/components/AdvancedSearch.vue
+++ b/frontend/src/components/IssueV1/components/IssueSearch/AdvancedSearchBox.vue
@@ -17,7 +17,7 @@
</NInput>
<div
v-if="state.showSearchScopes"
- class="absolute z-50 pt-1 top-full w-full divide-y divide-block-border bg-white shadow-md"
+ 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"
@@ -62,10 +62,20 @@
<script lang="ts" setup>
import { debounce, orderBy } from "lodash-es";
import { NInput } from "naive-ui";
-import { reactive, computed, h, watch, VNode, onMounted, ref } from "vue";
+import {
+ reactive,
+ computed,
+ h,
+ watch,
+ VNode,
+ onMounted,
+ ref,
+ 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,
@@ -92,8 +102,8 @@ import {
extractInstanceResourceName,
SearchParams,
SearchScopeId,
+ isValidSearchScopeId,
} from "@/utils";
-import YouTag from "./misc/YouTag.vue";
const props = withDefaults(
defineProps<{
@@ -109,7 +119,7 @@ const props = withDefaults(
);
const emit = defineEmits<{
- (event: "update", params: SearchParams): void;
+ (event: "update:params", params: SearchParams): void;
}>();
const { t } = useI18n();
@@ -159,6 +169,13 @@ watch(
}
);
+watch(
+ () => props.params,
+ (params) => {
+ state.searchText = buildSearchTextByParams(params);
+ }
+);
+
const { projectList } = useProjectV1ListByCurrentUser();
const { instanceList } = useInstanceV1List(false /* !showDeleted */);
const { databaseList } = useSearchDatabaseV1List({
@@ -404,19 +421,22 @@ const onOptionSelect = (scopeValue: string) => {
state.searchText = buildSearchTextByParams(params);
debouncedUpdate();
onClear();
-
- if (params.scopes.length < fullScopes.value.length) {
- state.showSearchScopes = true;
- }
};
-const onClear = () => {
- state.showSearchScopes = false;
- state.currentScope = undefined;
+const onClear = (immediate = false) => {
+ const clear = () => {
+ state.showSearchScopes = false;
+ state.currentScope = undefined;
+ };
+ if (immediate) {
+ clear();
+ } else {
+ nextTick(clear);
+ }
};
const debouncedUpdate = debounce(() => {
- emit("update", getSearchParamsByText(state.searchText));
+ emit("update:params", getSearchParamsByText(state.searchText));
}, 500);
const onUpdate = (value: string) => {
@@ -430,9 +450,7 @@ const query = computed(() => {
while (i < sections.length) {
const section = sections[i];
const keyword = section.split(":")[0];
- const exist =
- fullScopes.value.findIndex((item) => item.id === keyword) >= 0;
- if (!exist) {
+ if (!isValidSearchScopeId(keyword)) {
break;
}
i++;
@@ -507,7 +525,7 @@ const onKeydown = () => {
}
if (i >= sections.length) {
- onClear();
+ onClear(true /* immediate */);
state.showSearchScopes = true;
return;
}
@@ -516,7 +534,7 @@ const onKeydown = () => {
const existed =
fullScopes.value.findIndex((item) => item.id === currentScope) >= 0;
if (!existed) {
- onClear();
+ onClear(true /* immediate */);
state.showSearchScopes = true;
return;
}
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
new file mode 100644
index 0000000000..a566bbaa65
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/IssueSearch.vue
@@ -0,0 +1,80 @@
+<template>
+ <div class="flex flex-col">
+ <AdvancedSearchBox
+ v-if="components.includes('searchbox')"
+ :params="params"
+ :autofocus="autofocus"
+ v-bind="componentProps?.searchbox"
+ @update:params="$emit('update:params', $event)"
+ />
+ <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
+ v-if="components.includes('status')"
+ :params="params"
+ v-bind="componentProps?.status"
+ @update:params="$emit('update:params', $event)"
+ />
+ <slot name="primary" />
+ </div>
+ <div class="flex flex-row space-x-4">
+ <NInputGroup>
+ <TimeRange
+ v-if="components.includes('time-range')"
+ :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 { SearchParams } from "@/utils";
+import AdvancedSearchBox from "./AdvancedSearchBox.vue";
+import Status from "./Status.vue";
+import TimeRange from "./TimeRange.vue";
+
+export type SearchComponent =
+ | "searchbox"
+ | "status"
+ | "type"
+ | "time-range"
+ | "project"
+ | "instance"
+ | "database"
+ | "assignee"
+ | "creator"
+ | "approver"
+ | "approval";
+
+withDefaults(
+ defineProps<{
+ params: SearchParams;
+ autofocus?: boolean;
+ components?: SearchComponent[];
+ showFeatureAttention?: boolean;
+ componentProps?: Partial<Record<SearchComponent, any>>;
+ }>(),
+ {
+ components: () => ["searchbox", "status", "time-range"],
+ showFeatureAttention: false,
+ componentProps: undefined,
+ }
+);
+
+defineEmits<{
+ (event: "update:params", params: SearchParams): void;
+}>();
+</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/Status.vue b/frontend/src/components/IssueV1/components/IssueSearch/Status.vue
new file mode 100644
index 0000000000..a1a895b6de
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/Status.vue
@@ -0,0 +1,57 @@
+<template>
+ <TabFilter
+ :value="tab"
+ :items="tabItemList"
+ :responsive="false"
+ @update:value="updateStatus"
+ />
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { TabFilter, TabFilterItem } from "@/components/v2";
+import {
+ SearchParams,
+ SemanticIssueStatus,
+ getSemanticIssueStatusFromSearchParams,
+ upsertScope,
+} from "@/utils";
+
+const props = defineProps<{
+ params: SearchParams;
+}>();
+
+const emit = defineEmits<{
+ (event: "update:params", params: SearchParams): void;
+}>();
+
+const { t } = useI18n();
+
+const tabItemList = computed(() => {
+ const OPEN: TabFilterItem<SemanticIssueStatus> = {
+ value: "OPEN",
+ label: t("issue.table.open"),
+ };
+ const CLOSED: TabFilterItem<SemanticIssueStatus> = {
+ value: "CLOSED",
+ label: t("issue.table.closed"),
+ };
+ return [OPEN, CLOSED];
+});
+
+const tab = computed(() => {
+ return getSemanticIssueStatusFromSearchParams(props.params);
+});
+
+const updateStatus = (value: string | number | undefined) => {
+ const status = value as SemanticIssueStatus;
+ if (!["OPEN", "CLOSED"].includes(status)) return;
+
+ const updated = upsertScope(props.params, {
+ id: "status",
+ value: status,
+ });
+ emit("update:params", updated);
+};
+</script>
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
new file mode 100644
index 0000000000..18be9e9744
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/TimeRange.vue
@@ -0,0 +1,64 @@
+<template>
+ <NDatePicker
+ :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 { hasFeature } from "@/store";
+import {
+ SearchParams,
+ TimeRangeLimitForFreePlanInTs,
+ 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;
+ }
+ if (hasFeature("bb.feature.issue-advanced-search")) {
+ return false;
+ }
+
+ return ts < today - TimeRangeLimitForFreePlanInTs;
+};
+
+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/index.ts b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
new file mode 100644
index 0000000000..09c11e8e0d
--- /dev/null
+++ b/frontend/src/components/IssueV1/components/IssueSearch/index.ts
@@ -0,0 +1,5 @@
+import AdvancedSearchBox from "./AdvancedSearchBox.vue";
+import IssueSearch from "./IssueSearch.vue";
+
+export default IssueSearch;
+export { IssueSearch, AdvancedSearchBox };
diff --git a/frontend/src/components/IssueV1/components/IssueTableV1.vue b/frontend/src/components/IssueV1/components/IssueTableV1.vue
index 4f245f377d..33a325982b 100644
--- a/frontend/src/components/IssueV1/components/IssueTableV1.vue
+++ b/frontend/src/components/IssueV1/components/IssueTableV1.vue
@@ -103,15 +103,16 @@
<CurrentApproverV1 :issue="issue" />
</div>
<div v-if="showExtendedColumns" class="bb-grid-cell !py-0.5">
- <div class="flex flex-row items-center overflow-hidden gap-x-2">
- <BBAvatar
- :size="'SMALL'"
- :username="issue.assigneeEntity?.title ?? $t('common.unassigned')"
- />
+ <div
+ v-if="issue.assigneeEntity"
+ class="flex flex-row items-center overflow-hidden gap-x-2"
+ >
+ <BBAvatar :size="'SMALL'" :username="issue.assigneeEntity.title" />
<span class="truncate">
- {{ issue.assigneeEntity?.title ?? $t("common.unassigned") }}
+ {{ issue.assigneeEntity.title }}
</span>
</div>
+ <template v-else>-</template>
</div>
<div v-if="showExtendedColumns" class="bb-grid-cell !py-0.5">
<div class="flex flex-row items-center overflow-hidden gap-x-2">
@@ -226,13 +227,14 @@ interface LocalState {
const props = withDefaults(
defineProps<{
- title: string;
+ title?: string;
issueList: ComposedIssue[];
mode?: Mode;
highlightText?: string;
showPlaceholder?: boolean;
}>(),
{
+ title: "",
mode: "ALL",
highlightText: "",
showPlaceholder: false,
diff --git a/frontend/src/components/IssueV1/components/index.ts b/frontend/src/components/IssueV1/components/index.ts
index ce3aeecb57..bb50cb62db 100644
--- a/frontend/src/components/IssueV1/components/index.ts
+++ b/frontend/src/components/IssueV1/components/index.ts
@@ -2,6 +2,7 @@ import ActivitySection from "./ActivitySection";
import BannerSection from "./BannerSection.vue";
import DescriptionSection from "./DescriptionSection";
import HeaderSection from "./HeaderSection";
+import IssueSearch from "./IssueSearch";
import PlanCheckSection from "./PlanCheckSection";
import StageSection from "./StageSection";
import StatementSection from "./StatementSection";
@@ -20,4 +21,5 @@ export {
StatementSection,
DescriptionSection,
ActivitySection,
+ IssueSearch,
};
diff --git a/frontend/src/components/IssueV1/logic/base.ts b/frontend/src/components/IssueV1/logic/base.ts
index 3ca0dc88db..56167d4fd2 100644
--- a/frontend/src/components/IssueV1/logic/base.ts
+++ b/frontend/src/components/IssueV1/logic/base.ts
@@ -1,4 +1,3 @@
-import { asyncComputed } from "@vueuse/core";
import Emittery from "emittery";
import { first } from "lodash-es";
import { useDialog } from "naive-ui";
@@ -135,9 +134,9 @@ export const useBaseIssueContext = (
});
});
- const releaserCandidates = asyncComputed(async () => {
- return await releaserCandidatesForIssue(issue.value);
- }, []);
+ const releaserCandidates = computed(() => {
+ return releaserCandidatesForIssue(issue.value);
+ });
const reviewContext = extractReviewContext(issue);
const phase = computed((): IssuePhase => {
diff --git a/frontend/src/components/IssueV1/logic/releaser.ts b/frontend/src/components/IssueV1/logic/releaser.ts
index 81ca0f1359..6d2d0e2776 100644
--- a/frontend/src/components/IssueV1/logic/releaser.ts
+++ b/frontend/src/components/IssueV1/logic/releaser.ts
@@ -4,7 +4,7 @@ import { ComposedIssue, IssueReleaserRoleType, PresetRoleType } from "@/types";
import { User, UserRole } from "@/types/proto/v1/auth_service";
import { extractUserResourceName, memberListInProjectV1 } from "@/utils";
-export const releaserCandidatesForIssue = async (issue: ComposedIssue) => {
+export const releaserCandidatesForIssue = (issue: ComposedIssue) => {
const users: User[] = [];
const project = issue.projectEntity;
diff --git a/frontend/src/components/Project/ProjectIssuesPanel.vue b/frontend/src/components/Project/ProjectIssuesPanel.vue
index fd85ffc219..7e24c5274a 100644
--- a/frontend/src/components/Project/ProjectIssuesPanel.vue
+++ b/frontend/src/components/Project/ProjectIssuesPanel.vue
@@ -1,95 +1,83 @@
<template>
- <div class="space-y-2">
- <div class="flex items-center">
- <div class="flex-1 overflow-hidden">
- <TabFilter v-model:value="state.tab" :items="tabItemList" />
- </div>
- <div class="flex flex-row space-x-4 p-0.5">
- <router-link
- :to="`/issue?project=${project.uid}`"
- class="flex space-x-1 items-center normal-link !whitespace-nowrap"
- >
- <heroicons-outline:search class="h-4 w-4" />
- <span class="hidden md:block">{{
- $t("issue.advanced-search.self")
- }}</span>
- </router-link>
- </div>
- </div>
+ <div class="flex flex-col gap-y-2">
+ <IssueSearch
+ v-model:params="state.params"
+ :components="['status', 'time-range']"
+ :component-props="{
+ status: tab === 'RECENTLY_CLOSED' ? { disabled: true } : undefined,
+ }"
+ >
+ <template #default>
+ <div class="flex items-center gap-x-2">
+ <div class="flex-1 overflow-auto">
+ <TabFilter v-model:value="tab" :items="tabItemList" />
+ </div>
+ <div class="flex items-center">
+ <router-link
+ :to="issueLink"
+ class="flex items-center gap-x-1 normal-link whitespace-nowrap text-sm"
+ >
+ <SearchIcon class="w-4 h-4" />
+ <span class="hidden md:block">
+ {{ $t("issue.advanced-search.self") }}
+ </span>
+ </router-link>
+ </div>
+ </div>
+ </template>
+ </IssueSearch>
- <div v-show="state.tab === 'WAITING_APPROVAL'" class="mt-2">
+ <div v-if="hasCustomApprovalFeature" v-show="tab === 'WAITING_APPROVAL'">
<PagedIssueTableV1
- v-if="hasCustomApprovalFeature"
session-key="project-waiting-approval"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- }"
- :ui-issue-filter="{
- approval: 'pending',
- }"
+ :issue-filter="mergeIssueFilterByTab('WAITING_APPROVAL')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('WAITING_APPROVAL')"
>
<template #table="{ issueList, loading }">
<IssueTableV1
- :mode="'PROJECT'"
+ mode="PROJECT"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="state.tab === 'OPEN'" class="mt-2">
- <!-- show OPEN issues with pageSize=10 -->
+ <div v-show="tab === 'WAITING_ROLLOUT'">
<PagedIssueTableV1
- session-key="project-open"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- }"
- :page-size="50"
+ session-key="project-waiting-rollout"
+ :issue-filter="mergeIssueFilterByTab('WAITING_ROLLOUT')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('WAITING_ROLLOUT')"
>
<template #table="{ issueList, loading }">
<IssueTableV1
- class="-mt-px"
- :mode="'PROJECT'"
+ mode="PROJECT"
:issue-list="issueList"
:show-placeholder="!loading"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="state.tab === 'RECENTLY_CLOSED'" class="mt-2">
- <!-- show the first 5 DONE or CANCELED issues -->
- <!-- But won't show "Load more", since we have a "View all closed" link below -->
+ <div v-show="tab === 'RECENTLY_CLOSED'" class="flex flex-col gap-y-2 pb-2">
+ <!-- Won't show "Load more", since we have a "View all closed" link below -->
<PagedIssueTableV1
session-key="project-closed"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.DONE, IssueStatus.CANCELED],
- }"
- :page-size="50"
+ :issue-filter="mergeIssueFilterByTab('WAITING_ROLLOUT')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('WAITING_ROLLOUT')"
:hide-load-more="true"
>
<template #table="{ issueList, loading }">
<IssueTableV1
- class="-mt-px"
- :mode="'PROJECT'"
- :title="$t('project.overview.recently-closed')"
+ mode="PROJECT"
:issue-list="issueList"
:show-placeholder="!loading"
/>
</template>
</PagedIssueTableV1>
- <div class="w-full flex justify-end mt-2 px-4">
- <router-link
- :to="`/issue?status=closed&project=${project.uid}`"
- class="normal-link"
- >
+ <div class="w-full flex justify-end">
+ <router-link :to="issueLink" class="normal-link text-sm">
{{ $t("project.overview.view-all-closed") }}
</router-link>
</div>
@@ -98,24 +86,37 @@
</template>
<script lang="ts" setup>
+import { useLocalStorage } from "@vueuse/core";
+import { cloneDeep } from "lodash-es";
+import { SearchIcon } from "lucide-vue-next";
import { reactive, PropType, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { TabFilterItem } from "@/components/v2";
-import { featureToRef, useCurrentUserV1 } from "@/store";
-import { userNamePrefix } from "@/store/modules/v1/common";
-import { IssueFilter } from "@/types";
-import { IssueStatus } from "@/types/proto/v1/issue_service";
+import { featureToRef } from "@/store";
import { Project } from "@/types/proto/v1/project_service";
-import { hasWorkspacePermissionV1 } from "@/utils";
+import {
+ SearchParams,
+ buildIssueFilterBySearchParams,
+ buildSearchTextBySearchParams,
+ buildUIIssueFilterBySearchParams,
+ extractProjectResourceName,
+ maybeApplyDefaultTsRange,
+ upsertScope,
+} from "@/utils";
+import { IssueSearch } from "../IssueV1/components";
-const TABS = ["WAITING_APPROVAL", "OPEN", "RECENTLY_CLOSED"] as const;
+const TABS = [
+ "WAITING_APPROVAL",
+ "WAITING_ROLLOUT",
+ "RECENTLY_CLOSED",
+] as const;
type TabValue = typeof TABS[number];
interface LocalState {
- tab: TabValue;
+ params: SearchParams;
isFetchingActivityList: boolean;
}
@@ -126,53 +127,124 @@ 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>({
- tab: "WAITING_APPROVAL",
+ params: defaultSearchParams(),
isFetchingActivityList: false,
});
const { t } = useI18n();
-const currentUserV1 = useCurrentUserV1();
const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
-const hasPermission = computed(() => {
- return hasWorkspacePermissionV1(
- "bb.permission.workspace.manage-issue",
- currentUserV1.value.userRole
- );
-});
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
- const WAITING_APPROVAL: TabFilterItem<TabValue> = {
- value: "WAITING_APPROVAL",
- label: t("issue.waiting-approval"),
- };
- const list = hasCustomApprovalFeature.value ? [WAITING_APPROVAL] : [];
- return [
- ...list,
- { value: "OPEN", label: t("project.overview.in-progress") },
- { value: "RECENTLY_CLOSED", label: t("project.overview.recently-closed") },
- ];
+ const items: TabFilterItem<TabValue>[] = [];
+ if (hasCustomApprovalFeature.value) {
+ items.push({
+ value: "WAITING_APPROVAL",
+ label: t("issue.waiting-approval"),
+ });
+ }
+ items.push(
+ { value: "WAITING_ROLLOUT", label: t("issue.waiting-rollout") },
+ { value: "RECENTLY_CLOSED", label: t("project.overview.recently-closed") }
+ );
+ return items;
});
+const tab = useLocalStorage<TabValue>(
+ "bb.project.issue-list",
+ "WAITING_APPROVAL",
+ {
+ serializer: {
+ read(raw: TabValue) {
+ if (!TABS.includes(raw)) return "WAITING_APPROVAL";
+ return raw;
+ },
+ write(value) {
+ return value;
+ },
+ },
+ }
+);
-const commonIssueFilter = computed((): IssueFilter => {
- let principal = "";
- if (!hasPermission.value) {
- principal = `${userNamePrefix}${currentUserV1.value.email}`;
+const mergeSearchParamsByTab = (tab: TabValue) => {
+ const common = cloneDeep(state.params);
+ if (tab === "WAITING_APPROVAL") {
+ return upsertScope(common, {
+ id: "approval",
+ value: "pending",
+ });
}
- return {
- project: props.project.name,
- query: "",
- principal,
- };
+ if (tab === "WAITING_ROLLOUT") {
+ return upsertScope(common, {
+ id: "approval",
+ value: "approved",
+ });
+ }
+ if (tab === "RECENTLY_CLOSED") {
+ return upsertScope(common, {
+ id: "status",
+ value: "CLOSED",
+ });
+ }
+ return common;
+};
+
+const issueLink = computed(() => {
+ return `/issue?qs=${encodeURIComponent(
+ buildSearchTextBySearchParams(mergeSearchParamsByTab(tab.value))
+ )}`;
});
+const mergeIssueFilterByTab = (tab: TabValue) => {
+ return buildIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+};
+
+const mergeUIIssueFilterByTab = (tab: TabValue) => {
+ return buildUIIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+};
+
+watch(
+ tab,
+ (tab) => {
+ if (tab === "RECENTLY_CLOSED") {
+ upsertScope(
+ state.params,
+ {
+ id: "status",
+ value: "CLOSED",
+ },
+ true /* mutate */
+ );
+ }
+ },
+ { immediate: true }
+);
+
watch(
- [hasCustomApprovalFeature, () => state.tab],
+ [hasCustomApprovalFeature, tab],
() => {
- if (!hasCustomApprovalFeature.value && state.tab === "WAITING_APPROVAL") {
- state.tab = "OPEN";
+ if (!hasCustomApprovalFeature.value && tab.value === "WAITING_APPROVAL") {
+ tab.value = "WAITING_ROLLOUT";
}
},
{ immediate: true }
);
+
+watch(
+ () => props.project.name,
+ () => {
+ state.params = defaultSearchParams();
+ }
+);
</script>
diff --git a/frontend/src/components/v2/TabFilter/TabFilter.vue b/frontend/src/components/v2/TabFilter/TabFilter.vue
index cdf5b0a063..32d8725331 100644
--- a/frontend/src/components/v2/TabFilter/TabFilter.vue
+++ b/frontend/src/components/v2/TabFilter/TabFilter.vue
@@ -7,7 +7,7 @@
:options="items"
:value="value"
:consistent-menu-width="false"
- @update:value="$emit('update:value', $event)"
+ @update:value="(value: ValueType, option: TabFilterItem<ValueType>) => $emit('update:value', value, option)"
/>
</div>
<div
@@ -19,11 +19,11 @@
v-for="item in items"
:key="item.value"
:disabled="disabled"
- class="rounded-md text-sm px-3 py-1 flex items-center disabled:cursor-not-allowed disabled:pointer-events-none transition-colors duration-150"
+ class="rounded-md text-sm px-3 py-1 flex items-center disabled:cursor-not-allowed transition-colors duration-150"
:class="[
value === item.value
? 'bg-gray-200 text-gray-800 disabled:bg-gray-100'
- : 'text-gray-500 hover:text-gray-700 hover:bg-gray-100',
+ : 'text-gray-500 hover:text-gray-700 hover:bg-gray-100 disabled:text-gray-300 disabled:bg-transparent',
]"
@click.prevent="update(item.value)"
>
@@ -43,12 +43,13 @@ type ValueType = string | number; // Use generic typed component in the future
const props = withDefaults(
defineProps<{
- value: ValueType;
+ value?: ValueType;
items: TabFilterItem<ValueType>[];
disabled?: boolean;
responsive?: boolean;
}>(),
{
+ value: undefined,
disabled: false,
responsive: true,
}
diff --git a/frontend/src/components/v2/TabFilter/types.ts b/frontend/src/components/v2/TabFilter/types.ts
index 58c3cde307..2ca5bd01ed 100644
--- a/frontend/src/components/v2/TabFilter/types.ts
+++ b/frontend/src/components/v2/TabFilter/types.ts
@@ -1,4 +1,4 @@
-export type TabFilterItem<T extends string | number> = {
+export type TabFilterItem<T extends string | number = any> = {
label: string;
value: T;
};
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index ae091e5b03..73e038429a 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -124,6 +124,7 @@ export const useIssueV1Store = defineStore("issue_v1", () => {
const resp = await issueServiceClient.listIssues({
parent: find.project,
filter: buildIssueFilter(find),
+ query: find.query,
pageSize,
pageToken,
});
diff --git a/frontend/src/utils/v1/issue/advanced-search.ts b/frontend/src/utils/v1/issue/advanced-search.ts
deleted file mode 100644
index 2265f21b6a..0000000000
--- a/frontend/src/utils/v1/issue/advanced-search.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { UIIssueFilterScopeId } from "./ui-filter";
-
-export type SearchScopeId =
- | "project"
- | "instance"
- | "database"
- | "type"
- | "creator"
- | "assignee"
- | "subscriber"
- | UIIssueFilterScopeId;
-
-export interface SearchParams {
- query: string;
- scopes: {
- id: SearchScopeId;
- value: string;
- }[];
-}
diff --git a/frontend/src/utils/v1/issue/index.ts b/frontend/src/utils/v1/issue/index.ts
index 5a81c495a2..e0969469b5 100644
--- a/frontend/src/utils/v1/issue/index.ts
+++ b/frontend/src/utils/v1/issue/index.ts
@@ -1,4 +1,3 @@
export * from "./issue";
export * from "./rollout";
-export * from "./ui-filter";
-export * from "./advanced-search";
+export * from "./search";
diff --git a/frontend/src/utils/v1/issue/search/advanced-search.ts b/frontend/src/utils/v1/issue/search/advanced-search.ts
new file mode 100644
index 0000000000..6324622150
--- /dev/null
+++ b/frontend/src/utils/v1/issue/search/advanced-search.ts
@@ -0,0 +1,61 @@
+import { useDatabaseV1Store } from "@/store";
+import { IssueFilter, UNKNOWN_ID } from "@/types";
+import { IssueStatus } from "@/types/proto/v1/issue_service";
+import {
+ SearchParams,
+ SemanticIssueStatus,
+ getTsRangeFromSearchParams,
+ getValueFromSearchParams,
+} from "./common";
+
+export const buildIssueFilterBySearchParams = (params: SearchParams) => {
+ const { query, scopes } = params;
+ const projectScope = scopes.find((s) => s.id === "project");
+ const typeScope = scopes.find((s) => s.id === "type");
+ const databaseScope = scopes.find((s) => s.id === "database");
+
+ let database = "";
+ if (databaseScope) {
+ const uid = databaseScope.value.split("-").slice(-1)[0];
+ const db = useDatabaseV1Store().getDatabaseByUID(uid);
+ if (db.uid !== `${UNKNOWN_ID}`) {
+ database = db.name;
+ }
+ }
+
+ const createdTsRange = getTsRangeFromSearchParams(params, "created");
+ const status = getSemanticIssueStatusFromSearchParams(params);
+
+ const filter: IssueFilter = {
+ query,
+ instance: getValueFromSearchParams(params, "instance", "instances/"),
+ database,
+ project: `projects/${projectScope?.value ?? "-"}`,
+ createdTsAfter: createdTsRange?.[0],
+ createdTsBefore: createdTsRange?.[1],
+ type: typeScope?.value,
+ creator: getValueFromSearchParams(params, "creator", "users/"),
+ assignee: getValueFromSearchParams(params, "assignee", "users/"),
+ subscriber: getValueFromSearchParams(params, "subscriber", "users/"),
+ statusList:
+ status === "OPEN"
+ ? [IssueStatus.OPEN]
+ : status === "CLOSED"
+ ? [IssueStatus.DONE, IssueStatus.CANCELED]
+ : undefined,
+ };
+ return filter;
+};
+
+export const getSemanticIssueStatusFromSearchParams = (
+ params: SearchParams
+) => {
+ const status = getValueFromSearchParams(
+ params,
+ "status",
+ "" /* prefix='' */,
+ ["OPEN", "CLOSED"]
+ ) as SemanticIssueStatus | "";
+ if (!status) return undefined;
+ return status;
+};
diff --git a/frontend/src/utils/v1/issue/search/common.ts b/frontend/src/utils/v1/issue/search/common.ts
new file mode 100644
index 0000000000..185115d7a7
--- /dev/null
+++ b/frontend/src/utils/v1/issue/search/common.ts
@@ -0,0 +1,176 @@
+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";
+
+export const UIIssueFilterScopeIdList = [
+ "approver",
+ "approval",
+ "releaser",
+] as const;
+export type UIIssueFilterScopeId = typeof UIIssueFilterScopeIdList[number];
+
+export const SearchScopeIdList = [
+ "project",
+ "instance",
+ "database",
+ "type",
+ "creator",
+ "assignee",
+ "subscriber",
+ "status",
+ "created",
+] as const;
+
+export type SearchScopeId =
+ | typeof SearchScopeIdList[number]
+ | UIIssueFilterScopeId;
+
+export type SearchScope = {
+ id: SearchScopeId;
+ value: string;
+};
+
+export interface SearchParams {
+ query: string;
+ scopes: SearchScope[];
+}
+
+export const isValidSearchScopeId = (id: string): id is SearchScopeId => {
+ return (
+ SearchScopeIdList.includes(id as any) ||
+ UIIssueFilterScopeIdList.includes(id as any)
+ );
+};
+
+export const buildSearchTextBySearchParams = (
+ params: SearchParams | undefined
+): string => {
+ const parts: string[] = [];
+ params?.scopes.forEach((scope) => {
+ parts.push(`${scope.id}:${scope.value.trim()}`);
+ });
+ const query = (params?.query ?? "").trim();
+ if (params?.query) {
+ parts.push(query);
+ }
+ return parts.join(" ");
+};
+
+export const buildSearchParamsBySearchText = (text: string): SearchParams => {
+ const params = defaultSearchParams();
+ const segments = text.split(/\s+/g);
+ const querySegments: string[] = [];
+
+ for (let i = 0; i < segments.length; i++) {
+ const seg = segments[i];
+ const parts = seg.split(":");
+ if (parts.length === 2 && isValidSearchScopeId(parts[0])) {
+ params.scopes.push({
+ id: parts[0],
+ value: parts[1],
+ });
+ } else {
+ querySegments.push(seg);
+ }
+ }
+ params.query = querySegments.join(" ");
+ params.scopes = params.scopes.filter((scope) => scope.id && scope.value);
+
+ return params;
+};
+
+export const getValueFromSearchParams = (
+ params: SearchParams,
+ scopeId: SearchScopeId,
+ prefix: string = "",
+ validValues: readonly string[] = []
+): string => {
+ const scope = params.scopes.find((s) => s.id === scopeId);
+ if (!scope) {
+ return "";
+ }
+ const value = scope.value;
+ if (validValues.length !== 0) {
+ if (!validValues.includes(value)) {
+ return "";
+ }
+ }
+ return `${prefix}${scope.value}`;
+};
+
+export const getTsRangeFromSearchParams = (
+ params: SearchParams,
+ scopeId: SearchScopeId
+) => {
+ const scope = params.scopes.find((s) => s.id === scopeId);
+ if (!scope) return undefined;
+ const parts = scope.value.split(",");
+ if (parts.length !== 2) return undefined;
+ const range = [parseInt(parts[0], 10), parseInt(parts[1], 10)];
+ return range;
+};
+
+/**
+ * @param scope will remove `scope` from `params.scopes` if `scope.value` is empty.
+ * @param mutate true to mutate `params`. false to create a deep cloned copy. Default to false.
+ * @returns `params` itself or a deep-cloned copy.
+ */
+export const upsertScope = (
+ params: SearchParams,
+ scopes: SearchScope | SearchScope[],
+ mutate = false
+) => {
+ const target = mutate ? params : cloneDeep(params);
+ if (!Array.isArray(scopes)) {
+ scopes = [scopes];
+ }
+ scopes.forEach((scope) => {
+ const index = target.scopes.findIndex((s) => s.id === scope.id);
+ if (index >= 0) {
+ if (!scope.value) {
+ pullAt(target.scopes, index);
+ } else {
+ target.scopes[index].value = scope.value;
+ }
+ } else {
+ if (scope.value) {
+ target.scopes.push(scope);
+ }
+ }
+ });
+ return target;
+};
+
+export const defaultSearchParams = (): 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/utils/v1/issue/search/index.ts b/frontend/src/utils/v1/issue/search/index.ts
new file mode 100644
index 0000000000..e19045175f
--- /dev/null
+++ b/frontend/src/utils/v1/issue/search/index.ts
@@ -0,0 +1,3 @@
+export * from "./common";
+export * from "./advanced-search";
+export * from "./ui-filter";
diff --git a/frontend/src/utils/v1/issue/ui-filter.ts b/frontend/src/utils/v1/issue/search/ui-filter.ts
similarity index 52%
rename from frontend/src/utils/v1/issue/ui-filter.ts
rename to frontend/src/utils/v1/issue/search/ui-filter.ts
index 44bdb31090..061f938ab8 100644
--- a/frontend/src/utils/v1/issue/ui-filter.ts
+++ b/frontend/src/utils/v1/issue/search/ui-filter.ts
@@ -1,12 +1,14 @@
import {
extractReviewContext,
+ releaserCandidatesForIssue,
useWrappedReviewStepsV1,
} from "@/components/IssueV1/logic";
+import { useUserStore } from "@/store";
import { ComposedIssue } from "@/types";
import { Issue_Approver_Status } from "@/types/proto/v1/issue_service";
-
-export const UIIssueFilterScopeIdList = ["approver", "approval"] as const;
-export type UIIssueFilterScopeId = typeof UIIssueFilterScopeIdList[number];
+import { hasWorkspacePermissionV1 } from "@/utils";
+import { extractUserResourceName } from "../../user";
+import { SearchParams, getValueFromSearchParams } from "./common";
export const IssueApprovalStatusList = ["pending", "approved"] as const;
export type IssueApprovalStatus = typeof IssueApprovalStatusList[number];
@@ -19,7 +21,8 @@ export const isValidIssueApprovalStatus = (
// Use snake_case to keep consistent with the advanced search query string
export interface UIIssueFilter {
approver?: string;
- approval?: IssueApprovalStatus;
+ approval?: IssueApprovalStatus | "";
+ releaser?: string;
}
export const filterIssueByApprover = (
@@ -51,9 +54,50 @@ export const filterIssueByApprover = (
return false;
};
+export const filterIssueByReleaser = (
+ issue: ComposedIssue,
+ releaser: string | undefined
+) => {
+ if (!releaser) return true;
+
+ // We support "release:{email}" by now
+ // Planning to support "release:[{email_1}, {email_2}, ...]" and
+ // "release:roles/{role}" in the future
+ if (releaser.startsWith("users/")) {
+ const user = useUserStore().getUserByEmail(
+ extractUserResourceName(releaser)
+ );
+ if (!user) return false;
+
+ if (
+ hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-issue",
+ user.userRole
+ )
+ ) {
+ // Super users are always allowed to rollout issues.
+ return true;
+ }
+
+ const candidates = releaserCandidatesForIssue(issue);
+ // Otherwise any releasers can rollout the issue.
+ if (candidates.findIndex((c) => c.name === user.name) >= 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ console.error(
+ "[filterIssueByReleaser] should never reach this line",
+ releaser
+ );
+ return false;
+};
+
export const filterIssueByApprovalStatus = (
issue: ComposedIssue,
- status: IssueApprovalStatus | undefined
+ status: IssueApprovalStatus | "" | undefined
) => {
if (!status) return true;
@@ -79,5 +123,27 @@ export const applyUIIssueFilter = (
if (!filter) return list;
return list
.filter((issue) => filterIssueByApprover(issue, filter.approver))
- .filter((issue) => filterIssueByApprovalStatus(issue, filter.approval));
+ .filter((issue) => filterIssueByApprovalStatus(issue, filter.approval))
+ .filter((issue) => filterIssueByReleaser(issue, filter.releaser));
+};
+
+export const getIssueApprovalStatusFromSearchParams = (
+ params: SearchParams
+) => {
+ return getValueFromSearchParams(
+ params,
+ "approval",
+ "" /* prefix='' */,
+ IssueApprovalStatusList
+ ) as IssueApprovalStatus | "";
+};
+
+export const buildUIIssueFilterBySearchParams = (params: SearchParams) => {
+ const uiIssueFilter: UIIssueFilter = {
+ approval: getIssueApprovalStatusFromSearchParams(params),
+ approver: getValueFromSearchParams(params, "approver", "users/"),
+ releaser: getValueFromSearchParams(params, "releaser", "users/"),
+ };
+
+ return uiIssueFilter;
};
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 86db35cb14..a5d010de3f 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -1,57 +1,55 @@
<template>
<div class="flex flex-col">
- <div class="px-2 flex items-center">
- <div class="flex-1 overflow-hidden">
- <TabFilter v-model:value="tab" :items="tabItemList" />
- </div>
- <div class="flex items-center space-x-2 p-0.5">
- <router-link
- :to="issueLink"
- class="flex space-x-1 items-center normal-link !whitespace-nowrap"
- >
- <heroicons-outline:search class="h-4 w-4" />
- <span class="hidden md:block">{{
- $t("issue.advanced-search.self")
- }}</span>
- </router-link>
- </div>
- </div>
- <div v-show="tab === 'APPROVAL_REQUESTED'" class="mt-2">
+ <IssueSearch
+ v-model:params="state.params"
+ :components="['status', 'time-range']"
+ :component-props="{
+ status: tab === 'RECENTLY_CLOSED' ? { disabled: true } : undefined,
+ }"
+ class="px-4 py-2"
+ >
+ <template #default>
+ <div class="flex items-center gap-x-2">
+ <div class="flex-1 overflow-auto">
+ <TabFilter v-model:value="tab" :items="tabItemList" />
+ </div>
+ <div class="flex items-center">
+ <router-link
+ :to="issueLink"
+ class="flex items-center gap-x-1 normal-link whitespace-nowrap text-sm"
+ >
+ <SearchIcon class="w-4 h-4" />
+ <span class="hidden md:block">
+ {{ $t("issue.advanced-search.self") }}
+ </span>
+ </router-link>
+ </div>
+ </div>
+ </template>
+ </IssueSearch>
+
+ <div v-show="tab === 'CREATED'">
<PagedIssueTableV1
- v-if="hasCustomApprovalFeature"
- session-key="home-waiting-approval"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- }"
- :ui-issue-filter="{
- approver: `users/${currentUserV1.email}`,
- approval: 'pending',
- }"
+ session-key="home-created"
+ :issue-filter="mergeIssueFilterByTab('CREATED')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('CREATED')"
+ :page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
<template #table="{ issueList, loading }">
<IssueTableV1
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="tab === 'WAITING_ROLLOUT'" class="mt-2">
- <!-- show OPEN Assigned issues with pageSize=10 -->
+ <div v-show="tab === 'ASSIGNED'">
<PagedIssueTableV1
session-key="home-assigned"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- assignee: `${userNamePrefix}${currentUserV1.email}`,
- }"
- :ui-issue-filter="{
- approval: 'approved',
- }"
+ :issue-filter="mergeIssueFilterByTab('ASSIGNED')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('ASSIGNED')"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
<template #table="{ issueList, loading }">
@@ -59,21 +57,32 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="tab === 'CREATED'" class="mt-2">
- <!-- show OPEN Created issues with pageSize=10 -->
+ <div v-show="tab === 'APPROVAL_REQUESTED' && hasCustomApprovalFeature">
<PagedIssueTableV1
- session-key="home-created"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- creator: `${userNamePrefix}${currentUserV1.email}`,
- }"
+ session-key="home-waiting-approval"
+ :issue-filter="mergeIssueFilterByTab('APPROVAL_REQUESTED')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('APPROVAL_REQUESTED')"
+ >
+ <template #table="{ issueList, loading }">
+ <IssueTableV1
+ class="border-x-0"
+ :show-placeholder="!loading"
+ :issue-list="issueList"
+ />
+ </template>
+ </PagedIssueTableV1>
+ </div>
+
+ <div v-show="tab === 'WAITING_ROLLOUT'">
+ <PagedIssueTableV1
+ session-key="home-awaiting-rollout"
+ :issue-filter="mergeIssueFilterByTab('WAITING_ROLLOUT')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('WAITING_ROLLOUT')"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
<template #table="{ issueList, loading }">
@@ -81,21 +90,16 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="tab === 'SUBSCRIBED'" class="mt-2">
- <!-- show OPEN Subscribed issues with pageSize=10 -->
+ <div v-show="tab === 'SUBSCRIBED'">
<PagedIssueTableV1
session-key="home-subscribed"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.OPEN],
- subscriber: `${userNamePrefix}${currentUserV1.email}`,
- }"
+ :issue-filter="mergeIssueFilterByTab('SUBSCRIBED')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('SUBSCRIBED')"
:page-size="OPEN_ISSUE_LIST_PAGE_SIZE"
>
<template #table="{ issueList, loading }">
@@ -103,22 +107,18 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
</div>
- <div v-show="tab === 'RECENTLY_CLOSED'" class="mt-2">
+ <div v-show="tab === 'RECENTLY_CLOSED'" class="flex flex-col gap-y-2 pb-2">
<!-- show the first 5 DONE or CANCELED issues -->
<!-- But won't show "Load more", since we have a "View all closed" link below -->
<PagedIssueTableV1
session-key="home-closed"
- :issue-filter="{
- ...commonIssueFilter,
- statusList: [IssueStatus.DONE, IssueStatus.CANCELED],
- principal: `${userNamePrefix}${currentUserV1.email}`,
- }"
+ :issue-filter="mergeIssueFilterByTab('RECENTLY_CLOSED')"
+ :ui-issue-filter="mergeUIIssueFilterByTab('RECENTLY_CLOSED')"
:page-size="MAX_CLOSED_ISSUE"
:hide-load-more="true"
>
@@ -127,15 +127,11 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- title=""
/>
</template>
</PagedIssueTableV1>
- <div class="w-full flex justify-end mt-2 px-4">
- <router-link
- :to="`/issue?status=closed&user=${currentUserUID}`"
- class="normal-link"
- >
+ <div class="w-full flex justify-end px-4">
+ <router-link :to="issueLink" class="normal-link text-sm">
{{ $t("project.overview.view-all-closed") }}
</router-link>
</div>
@@ -207,8 +203,11 @@
<script lang="ts" setup>
import { useLocalStorage } from "@vueuse/core";
+import { cloneDeep } from "lodash-es";
+import { SearchIcon } from "lucide-vue-next";
import { reactive, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
+import { IssueSearch } from "@/components/IssueV1/components";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
import { TabFilter, TabFilterItem } from "@/components/v2";
@@ -218,13 +217,19 @@ import {
featureToRef,
useCurrentUserV1,
} from "@/store";
-import { userNamePrefix } from "@/store/modules/v1/common";
-import { IssueStatus } from "@/types/proto/v1/issue_service";
-import { IssueFilter, planTypeToString } from "../types";
-import { extractUserUID } from "../utils";
+import { planTypeToString } from "@/types";
+import {
+ SearchParams,
+ buildIssueFilterBySearchParams,
+ buildSearchTextBySearchParams,
+ buildUIIssueFilterBySearchParams,
+ maybeApplyDefaultTsRange,
+ upsertScope,
+} from "@/utils";
const TABS = [
"CREATED",
+ "ASSIGNED",
"APPROVAL_REQUESTED",
"WAITING_ROLLOUT",
"SUBSCRIBED",
@@ -234,6 +239,7 @@ const TABS = [
type TabValue = typeof TABS[number];
interface LocalState {
+ params: SearchParams;
showTrialStartModal: boolean;
}
@@ -259,29 +265,102 @@ const tab = useLocalStorage<TabValue>(
}
);
+const defaultSearchParams = () => {
+ const params: SearchParams = {
+ query: "",
+ scopes: [
+ {
+ id: "status",
+ value: "OPEN",
+ },
+ ],
+ };
+ maybeApplyDefaultTsRange(params, "created", true /* mutate */);
+ return params;
+};
+
const state = reactive<LocalState>({
+ params: defaultSearchParams(),
showTrialStartModal: false,
});
-const currentUserV1 = useCurrentUserV1();
-const currentUserUID = computed(() => extractUserUID(currentUserV1.value.name));
+const me = useCurrentUserV1();
const hasCustomApprovalFeature = featureToRef("bb.feature.custom-approval");
const tabItemList = computed((): TabFilterItem<TabValue>[] => {
- const APPROVAL_REQUESTED: TabFilterItem<TabValue> = {
- value: "APPROVAL_REQUESTED",
- label: t("issue.approval-requested"),
- };
- const list = hasCustomApprovalFeature.value ? [APPROVAL_REQUESTED] : [];
- return [
+ const items: TabFilterItem<TabValue>[] = [];
+ items.push(
{ value: "CREATED", label: t("common.created") },
- ...list,
+ { value: "ASSIGNED", label: t("common.assigned") }
+ );
+ if (hasCustomApprovalFeature.value) {
+ items.push({
+ value: "APPROVAL_REQUESTED",
+ label: t("issue.approval-requested"),
+ });
+ }
+ items.push(
{ value: "WAITING_ROLLOUT", label: t("issue.waiting-rollout") },
{ value: "SUBSCRIBED", label: t("common.subscribed") },
- { value: "RECENTLY_CLOSED", label: t("project.overview.recently-closed") },
- ];
+ { value: "RECENTLY_CLOSED", label: t("project.overview.recently-closed") }
+ );
+ return items;
});
+const mergeSearchParamsByTab = (tab: TabValue) => {
+ const common = cloneDeep(state.params);
+ const myEmail = me.value.email;
+ if (tab === "CREATED") {
+ return upsertScope(common, {
+ id: "creator",
+ value: myEmail,
+ });
+ }
+ if (tab === "ASSIGNED") {
+ return upsertScope(common, {
+ id: "assignee",
+ value: myEmail,
+ });
+ }
+ if (tab === "SUBSCRIBED") {
+ return upsertScope(common, {
+ id: "subscriber",
+ value: myEmail,
+ });
+ }
+ if (tab === "RECENTLY_CLOSED") {
+ return upsertScope(common, {
+ id: "status",
+ value: "CLOSED",
+ });
+ }
+ if (tab === "APPROVAL_REQUESTED") {
+ return upsertScope(common, [
+ {
+ id: "approval",
+ value: "pending",
+ },
+ {
+ id: "approver",
+ value: myEmail,
+ },
+ ]);
+ }
+ if (tab === "WAITING_ROLLOUT") {
+ return upsertScope(common, [
+ {
+ id: "approval",
+ value: "approved",
+ },
+ {
+ id: "releaser",
+ value: myEmail,
+ },
+ ]);
+ }
+ return common;
+};
+
const onTrialingModalClose = () => {
state.showTrialStartModal = false;
onboardingStateStore.consume("show-trialing-modal");
@@ -297,26 +376,35 @@ const planImage = computed(() => {
});
const issueLink = computed(() => {
- if (tab.value === "CREATED") {
- return "/issue?creator=" + currentUserUID.value;
- }
- if (tab.value === "APPROVAL_REQUESTED") {
- return "/issue?approver=" + currentUserUID.value;
- }
- if (tab.value === "SUBSCRIBED") {
- return "/issue?subscriber=" + currentUserUID.value;
- }
-
- // TODO(d): use closed filter for WAITING_ROLLOUT and RECENTLY_CLOSED.
- return "/issue";
+ return `/issue?qs=${encodeURIComponent(
+ buildSearchTextBySearchParams(mergeSearchParamsByTab(tab.value))
+ )}`;
});
-const commonIssueFilter = computed((): IssueFilter => {
- return {
- project: "projects/-",
- query: "",
- };
-});
+const mergeIssueFilterByTab = (tab: TabValue) => {
+ return buildIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+};
+
+const mergeUIIssueFilterByTab = (tab: TabValue) => {
+ return buildUIIssueFilterBySearchParams(mergeSearchParamsByTab(tab));
+};
+
+watch(
+ tab,
+ (tab) => {
+ if (tab === "RECENTLY_CLOSED") {
+ upsertScope(
+ state.params,
+ {
+ id: "status",
+ value: "CLOSED",
+ },
+ true /* mutate */
+ );
+ }
+ },
+ { immediate: true }
+);
watch(
[hasCustomApprovalFeature, tab],
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index a207cf852e..879f6731fa 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -1,70 +1,19 @@
<template>
- <div class="flex flex-col">
- <AdvancedSearch
- custom-class="w-full px-4 py-2"
- :params="state.searchParams"
- :autofocus="autofocus"
- @update="onSearchParamsUpdate($event)"
+ <div class="flex flex-col gap-y-2">
+ <IssueSearch
+ v-model:params="state.params"
+ :show-feature-attention="true"
+ :component-props="{
+ searchbox: { autofocus },
+ }"
+ class="px-4 py-2 gap-y-2"
/>
- <FeatureAttention
- v-if="!!state.searchParams.query || state.searchParams.scopes.length > 0"
- custom-class="w-full px-4 py-2"
- feature="bb.feature.issue-advanced-search"
- />
-
- <div class="px-4 flex items-center">
- <div class="flex-1 overflow-hidden">
- <TabFilter v-model:value="state.tab" :items="tabItemList" />
- </div>
- <div class="flex flex-row space-x-4 p-0.5">
- <NInputGroup style="width: auto">
- <NDatePicker
- v-model:value="selectedTimeRange"
- type="daterange"
- size="medium"
- :on-confirm="confirmDatePicker"
- :on-clear="clearDatePicker"
- :is-date-disabled="isDateDisabled"
- clearable
- >
- </NDatePicker>
- </NInputGroup>
- </div>
- </div>
-
- <div v-show="state.tab === 'OPEN'" class="mt-2">
- <!-- show all OPEN issues with pageSize=10 -->
- <PagedIssueTableV1
- session-key="dashboard-open"
- :issue-filter="{
- ...issueFilter,
- statusList: [IssueStatus.OPEN],
- }"
- :ui-issue-filter="uiIssueFilter"
- :page-size="50"
- >
- <template #table="{ issueList, loading }">
- <IssueTableV1
- class="border-x-0"
- :show-placeholder="!loading"
- :issue-list="issueList"
- :highlight-text="state.searchParams.query"
- title=""
- />
- </template>
- </PagedIssueTableV1>
- </div>
-
- <div v-show="state.tab === 'CLOSED'" class="mt-2">
- <!-- show all DONE and CANCELED issues with pageSize=10 -->
+ <div>
<PagedIssueTableV1
- session-key="dashboard-closed"
- :issue-filter="{
- ...issueFilter,
- statusList: [IssueStatus.DONE, IssueStatus.CANCELED],
- }"
- :ui-issue-filter="uiIssueFilter"
+ session-key="issue-dashboard"
+ :issue-filter="buildIssueFilterBySearchParams(state.params)"
+ :ui-issue-filter="buildUIIssueFilterBySearchParams(state.params)"
:page-size="50"
>
<template #table="{ issueList, loading }">
@@ -72,8 +21,7 @@
class="border-x-0"
:show-placeholder="!loading"
:issue-list="issueList"
- :highlight-text="state.searchParams.query"
- title=""
+ :highlight-text="state.params.query"
/>
</template>
</PagedIssueTableV1>
@@ -82,288 +30,73 @@
</template>
<script lang="ts" setup>
-import dayjs from "dayjs";
-import { NInputGroup, NDatePicker } from "naive-ui";
-import { reactive, computed, watchEffect, onMounted } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRoute, useRouter } from "vue-router";
-import AdvancedSearch from "@/components/AdvancedSearch.vue";
+import { reactive, computed, watchEffect, watch } from "vue";
+import { useRoute } from "vue-router";
+import { useRouter } from "vue-router";
+import IssueSearch from "@/components/IssueV1/components/IssueSearch";
import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";
import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";
-import { TabFilterItem } from "@/components/v2";
-import {
- useCurrentUserV1,
- useProjectV1Store,
- useUserStore,
- useDatabaseV1Store,
- hasFeature,
-} from "@/store";
+import { useProjectV1Store } from "@/store";
import {
- projectNamePrefix,
- userNamePrefix,
- instanceNamePrefix,
-} from "@/store/modules/v1/common";
-import { UNKNOWN_ID, IssueFilter } from "@/types";
-import { IssueStatus } from "@/types/proto/v1/issue_service";
-import {
- extractProjectResourceName,
- hasWorkspacePermissionV1,
SearchParams,
- SearchScopeId,
- UIIssueFilter,
- isValidIssueApprovalStatus,
+ buildSearchParamsBySearchText,
+ buildIssueFilterBySearchParams,
+ buildUIIssueFilterBySearchParams,
+ getValueFromSearchParams,
+ buildSearchTextBySearchParams,
+ maybeApplyDefaultTsRange,
} from "@/utils";
-const TABS = ["OPEN", "CLOSED"] as const;
-
-type TabValue = typeof TABS[number];
-
interface LocalState {
- tab: TabValue;
- searchParams: SearchParams;
+ params: SearchParams;
}
-const router = useRouter();
const route = useRoute();
-
-const { t } = useI18n();
-const projectV1Store = useProjectV1Store();
-const databaseV1Store = useDatabaseV1Store();
-const userStore = useUserStore();
-const currentUserV1 = useCurrentUserV1();
-
-const hasPermission = computed(() => {
- return hasWorkspacePermissionV1(
- "bb.permission.workspace.manage-issue",
- currentUserV1.value.userRole
- );
-});
+const router = useRouter();
const autofocus = computed((): boolean => {
return !!route.query.autofocus;
});
const initializeSearchParamsFromQuery = (): SearchParams => {
- const projectName = project.value?.name ?? "";
- const { creator, assignee, approver, subscriber } = route.query;
- const query = (route.query.query as string) ?? "";
-
- const params: SearchParams = {
- query,
- scopes: [],
- };
-
- if (projectName) {
- params.scopes.push({
- id: "project",
- value: extractProjectResourceName(projectName),
- });
- }
- if (creator && hasPermission.value) {
- const creatorEmail = userStore.getUserById(creator as string)?.email ?? "";
- if (creatorEmail) {
- params.scopes.push({
- id: "creator",
- value: creatorEmail,
- });
- }
- }
- if (assignee && hasPermission.value) {
- const assigneeEmail =
- userStore.getUserById(assignee as string)?.email ?? "";
- if (assigneeEmail) {
- params.scopes.push({
- id: "creator",
- value: assigneeEmail,
- });
- }
- }
- if (approver && hasPermission.value) {
- const approverEmail =
- userStore.getUserById(approver as string)?.email ?? "";
- if (approverEmail) {
- params.scopes.push({
- id: "approver",
- value: approverEmail,
- });
- }
- }
- if (subscriber && hasPermission.value) {
- const subscriberEmail =
- userStore.getUserById(subscriber as string)?.email ?? "";
- if (subscriberEmail) {
- params.scopes.push({
- id: "subscriber",
- value: subscriberEmail,
- });
- }
- }
+ 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 */);
return params;
};
-const hasAdvancedSearchFeature = computed(() => {
- return hasFeature("bb.feature.issue-advanced-search");
-});
-
-const project = computed(() => {
- if (selectedProjectId.value) {
- return projectV1Store.getProjectByUID(selectedProjectId.value);
- }
- return undefined;
-});
-
-const tabItemList = computed((): TabFilterItem<TabValue>[] => {
- const OPEN: TabFilterItem<TabValue> = {
- value: "OPEN",
- label: t("issue.table.open"),
- };
- const CLOSED: TabFilterItem<TabValue> = {
- value: "CLOSED",
- label: t("issue.table.closed"),
- };
- return [OPEN, CLOSED];
-});
-
-// timeRangeLimitForFreePlanInTs is the search time limit in ts format.
-// should be 60 days.
-const timeRangeLimitForFreePlanInTs = 60 * 24 * 60 * 60 * 1000;
-
-const selectedTimeRange = computed((): [number, number] => {
- const today = dayjs().add(1, "day").endOf("day").valueOf();
- const defaultTimeRange = [today - timeRangeLimitForFreePlanInTs, today] as [
- number,
- number
- ];
- const createdTsAfter = route.query.createdTsAfter as string;
- if (createdTsAfter) {
- defaultTimeRange[0] = parseInt(createdTsAfter, 10);
- }
- const createdTsBefore = route.query.createdTsBefore as string;
- if (createdTsBefore) {
- defaultTimeRange[1] = parseInt(createdTsBefore, 10);
- }
- return defaultTimeRange;
-});
-
-const isDateDisabled = (ts: number) => {
- const today = dayjs().add(1, "day").endOf("day").valueOf();
- if (ts > today) {
- return true;
- }
- if (hasAdvancedSearchFeature.value) {
- return false;
- }
-
- return ts < today - timeRangeLimitForFreePlanInTs;
-};
-
-const selectedProjectId = computed((): string | undefined => {
- const { project } = route.query;
- return project ? (project as string) : undefined;
-});
-
+const paramsFromQuery = initializeSearchParamsFromQuery();
const state = reactive<LocalState>({
- tab: "OPEN",
- searchParams: initializeSearchParamsFromQuery(),
+ params: paramsFromQuery,
});
-const confirmDatePicker = (value: [number, number]) => {
- router.replace({
- name: "workspace.issue",
- query: {
- ...route.query,
- createdTsAfter: value[0],
- createdTsBefore: value[1],
- },
- });
-};
-
-const clearDatePicker = () => {
- router.replace({
- name: "workspace.issue",
- query: {
- ...route.query,
- createdTsAfter: 0,
- createdTsBefore: Date.now(),
- },
- });
-};
-
watchEffect(() => {
- if (selectedProjectId.value) {
- projectV1Store.getOrFetchProjectByUID(selectedProjectId.value);
- }
-});
-
-onMounted(() => {
- const status = ((route.query.status ?? "") as string).toUpperCase() ?? "OPEN";
- if (status === "CLOSED") {
- state.tab = "CLOSED";
- }
-});
-
-const onSearchParamsUpdate = (params: SearchParams) => {
- state.searchParams = params;
-};
-
-const getValueFromIssueFilter = (
- prefix: string,
- scopeId: SearchScopeId
-): string => {
- const { scopes } = state.searchParams;
- const scope = scopes.find((s) => s.id === scopeId);
- if (!scope) {
- return "";
- }
- return `${prefix}${scope.value}`;
-};
-
-const issueFilter = computed((): IssueFilter => {
- const { query, scopes } = state.searchParams;
- const projectScope = scopes.find((s) => s.id === "project");
- const typeScope = scopes.find((s) => s.id === "type");
- const databaseScope = scopes.find((s) => s.id === "database");
-
- let database = "";
- if (databaseScope) {
- const uid = databaseScope.value.split("-").slice(-1)[0];
- const db = databaseV1Store.getDatabaseByUID(uid);
- if (db.uid !== `${UNKNOWN_ID}`) {
- database = db.name;
- }
+ const project = getValueFromSearchParams(
+ state.params,
+ "project",
+ "projects/"
+ );
+ if (project) {
+ useProjectV1Store().getOrFetchProjectByName(project);
}
-
- return {
- query,
- instance: getValueFromIssueFilter(instanceNamePrefix, "instance"),
- database,
- project: `${projectNamePrefix}${projectScope?.value ?? "-"}`,
- createdTsAfter: selectedTimeRange.value
- ? selectedTimeRange.value[0]
- : undefined,
- createdTsBefore: selectedTimeRange.value
- ? selectedTimeRange.value[1]
- : undefined,
- type: typeScope?.value,
- creator: getValueFromIssueFilter(userNamePrefix, "creator"),
- assignee: getValueFromIssueFilter(userNamePrefix, "assignee"),
- subscriber: getValueFromIssueFilter(userNamePrefix, "subscriber"),
- };
});
-const uiIssueFilter = computed((): UIIssueFilter => {
- const { scopes } = state.searchParams;
- const approverScope = scopes.find((s) => s.id === "approver");
- const approvalScope = scopes.find((s) => s.id === "approval");
- const uiIssueFilter: UIIssueFilter = {};
- if (approverScope && approverScope.value) {
- uiIssueFilter.approver = `users/${approverScope.value}`;
- }
- if (approvalScope && isValidIssueApprovalStatus(approvalScope.value)) {
- uiIssueFilter.approval = approvalScope.value;
- }
-
- return uiIssueFilter;
-});
+watch(
+ () => state.params,
+ () => {
+ router.replace({
+ query: {
+ qs: buildSearchTextBySearchParams(state.params),
+ },
+ });
+ },
+ { deep: true }
+);
</script>