Skip to content

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

chore: filter issues by label (#11923)

ecmadao47b8e9a1426c
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 540fd550d7..990232d5bb 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -274,6 +274,14 @@ func (s *IssueService) getIssueFind(ctx context.Context, permissionFilter *store
return nil, status.Errorf(codes.InvalidArgument, `database "%q" not found`, spec.value)
}
issueFind.DatabaseUID = &database.UID
+ case "labels":
+ if spec.operator != comparatorTypeEqual {
+ return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "%s" filter`, spec.key)
+ }
+ for _, label := range strings.Split(spec.value, " & ") {
+ issueLabel := label
+ issueFind.LabelList = append(issueFind.LabelList, issueLabel)
+ }
}
}
diff --git a/backend/store/issue.go b/backend/store/issue.go
index 51881fe5f4..5b24a568f1 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -111,6 +111,8 @@ type FindIssueMessage struct {
Query *string
PermissionFilter *FindIssueMessagePermissionFilter
+
+ LabelList []string
}
// GetIssueV2 gets issue by issue UID.
@@ -454,6 +456,10 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
if v := find.Offset; v != nil {
limitOffsetClause += fmt.Sprintf(" OFFSET %d", *v)
}
+ if len(find.LabelList) != 0 {
+ where = append(where, fmt.Sprintf("payload->'labels' ?& $%d::TEXT[]", len(args)+1))
+ args = append(args, find.LabelList)
+ }
var issues []*IssueMessage
tx, err := s.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
index 5ff0c1197c..a1a82be6c2 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useSearchScopeOptions.ts
@@ -23,7 +23,7 @@ import {
} 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 { Workflow, Label } from "@/types/proto/v1/project_service";
import type { SearchParams, SearchScopeId } from "@/utils";
import {
environmentV1Name,
@@ -46,6 +46,25 @@ export type ValueOption = {
render: RenderFunction;
};
+const useProjectLabels = (params: Ref<SearchParams>) => {
+ const { projectList } = useProjectV1List();
+ const projectName = params.value.scopes.find(
+ (scope) => scope.id === "project"
+ )?.value;
+
+ const labels = new Map<string, Label>();
+ for (const project of projectList.value) {
+ if (projectName && project.name !== `projects/${projectName}`) {
+ continue;
+ }
+ for (const label of project.issueLabels) {
+ const key = `${label.value}-${label.color}`;
+ labels.set(key, label);
+ }
+ }
+ return [...labels.values()];
+};
+
export const useSearchScopeOptions = (
params: Ref<SearchParams>,
supportOptionIdList: Ref<SearchScopeId[]>
@@ -295,6 +314,25 @@ export const useSearchScopeOptions = (
},
],
},
+ {
+ id: "label",
+ title: t("issue.advanced-search.scope.label.title"),
+ description: t("issue.advanced-search.scope.label.description"),
+ options: useProjectLabels(params).map((label) => {
+ return {
+ value: label.value,
+ keywords: [label.value],
+ render: () =>
+ h("div", { class: "flex items-center gap-x-2" }, [
+ h("div", {
+ class: "w-4 h-4 rounded",
+ style: `background-color: ${label.color};`,
+ }),
+ label.value,
+ ]),
+ };
+ }),
+ },
];
const supportOptionIdSet = new Set(supportOptionIdList.value);
return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
diff --git a/frontend/src/components/IssueV1/components/IssueTableV1.vue b/frontend/src/components/IssueV1/components/IssueTableV1.vue
index a8bf1772fb..d860ee22c8 100644
--- a/frontend/src/components/IssueV1/components/IssueTableV1.vue
+++ b/frontend/src/components/IssueV1/components/IssueTableV1.vue
@@ -40,7 +40,7 @@
<script lang="ts" setup>
import { useElementSize } from "@vueuse/core";
import type { DataTableColumn } from "naive-ui";
-import { NPerformantEllipsis, NDataTable } from "naive-ui";
+import { NPerformantEllipsis, NDataTable, NDynamicTags, NTag } from "naive-ui";
import { reactive, computed, watch, ref, h } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -54,6 +54,7 @@ import { useCurrentUserV1 } from "@/store";
import { type ComposedIssue } from "@/types";
import { IssueStatus } from "@/types/proto/v1/issue_service";
import { Workflow } from "@/types/proto/v1/project_service";
+import { Label } from "@/types/proto/v1/project_service";
import {
getHighlightHTMLByRegExp,
issueSlug,
@@ -123,6 +124,40 @@ const columnList = computed((): DataTableColumn<ComposedIssue>[] => {
),
]),
},
+ {
+ key: "labels",
+ title: t("common.labels"),
+ resizable: true,
+ render: (issue) => {
+ const labelMap: Map<string, Label> =
+ issue.projectEntity.issueLabels.reduce((map, label) => {
+ map.set(label.value, label);
+ return map;
+ }, new Map<string, Label>());
+
+ return h(NDynamicTags, {
+ size: "small",
+ disabled: true,
+ class: "issue-row-dynamic-tags",
+ value: issue.labels.filter((label) => labelMap.has(label)),
+ renderTag: (value: string) =>
+ h(
+ NTag,
+ { closable: false, size: "small" },
+ {
+ default: () =>
+ h("div", { class: "flex items-center gap-x-2" }, [
+ h("div", {
+ class: "w-4 h-4 rounded cursor-pointer relative",
+ style: `background-color: ${labelMap.get(value)?.color};`,
+ }),
+ value,
+ ]),
+ }
+ ),
+ });
+ },
+ },
{
key: "updateTime",
title: t("issue.table.updated"),
@@ -371,3 +406,9 @@ const isIssueExpanded = (issue: ComposedIssue): boolean => {
return sections.some((item) => item.highlight);
};
</script>
+
+<style scoped lang="postcss">
+:deep(.issue-row-dynamic-tags) > :last-child {
+ @apply !hidden;
+}
+</style>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 6d9d6d510b..e480f93698 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1031,6 +1031,10 @@
"yes": "yes",
"no": "no"
}
+ },
+ "label": {
+ "title": "Label",
+ "description": "Filter by issue label"
}
},
"hide": "Hide advanced search"
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 2dcbfadd72..bcfc0e4818 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1031,6 +1031,10 @@
"yes": "yes",
"no": "no"
}
+ },
+ "label": {
+ "title": "Etiqueta",
+ "description": "Filtrar por etiqueta de problema"
}
},
"hide": "Ocultar búsqueda avanzada"
@@ -3467,4 +3471,4 @@
"drop-partition-with-subpartitions-confirm": "También eliminará todas sus subparticiones."
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 3e6aab677f..6b83675347 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1031,6 +1031,10 @@
"yes": "はい",
"no": "いいえ"
}
+ },
+ "label": {
+ "title": "ラベル",
+ "description": "チケットタグで絞り込む"
}
},
"hide": "詳細検索を非表示にする"
@@ -3467,4 +3471,4 @@
"drop-partition-with-subpartitions-confirm": "すべてのサブパーティションが同時に削除されます。"
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 38db6aa3f9..069d14361e 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1031,6 +1031,10 @@
"yes": "Đúng",
"no": "KHÔNG"
}
+ },
+ "label": {
+ "title": "Nhãn",
+ "description": "Lọc theo nhãn vấn đề"
}
},
"hide": "Ẩn tìm kiếm nâng cao"
@@ -3467,4 +3471,4 @@
"drop-partition-with-subpartitions-confirm": "Cũng sẽ bỏ tất cả các phân vùng của nó."
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 26081396ad..841cac9df6 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1031,6 +1031,10 @@
"yes": "是",
"no": "否"
}
+ },
+ "label": {
+ "title": "标签",
+ "description": "按工单标签过滤"
}
},
"hide": "隐藏高级搜索"
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index 561f8642a2..0782bd5c66 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -67,6 +67,9 @@ export const buildIssueFilter = (find: IssueFilter): string => {
if (find.database) {
filter.push(`database = "${find.database}"`);
}
+ if (find.labels && find.labels.length > 0) {
+ filter.push(`labels = "${find.labels.join(" & ")}"`);
+ }
return filter.join(" && ");
};
diff --git a/frontend/src/types/v1/issue/issue.ts b/frontend/src/types/v1/issue/issue.ts
index f7f903bf95..779da73cac 100644
--- a/frontend/src/types/v1/issue/issue.ts
+++ b/frontend/src/types/v1/issue/issue.ts
@@ -90,4 +90,6 @@ export interface IssueFilter {
createdTsAfter?: number;
createdTsBefore?: number;
type?: string;
+ // filter by labels, for example: labels = "feature & bug"
+ labels?: string[];
}
diff --git a/frontend/src/utils/v1/issue/search/advanced-search.ts b/frontend/src/utils/v1/issue/search/advanced-search.ts
index 1f4502f74d..39f7c0f6e7 100644
--- a/frontend/src/utils/v1/issue/search/advanced-search.ts
+++ b/frontend/src/utils/v1/issue/search/advanced-search.ts
@@ -22,6 +22,7 @@ export const buildIssueFilterBySearchParams = (params: SearchParams) => {
const createdTsRange = getTsRangeFromSearchParams(params, "created");
const status = getSemanticIssueStatusFromSearchParams(params);
+ const label = getValueFromSearchParams(params, "label");
const filter: IssueFilter = {
query,
@@ -40,6 +41,7 @@ export const buildIssueFilterBySearchParams = (params: SearchParams) => {
: status === "CLOSED"
? [IssueStatus.DONE, IssueStatus.CANCELED]
: undefined,
+ labels: label ? [label] : [],
};
return filter;
};
diff --git a/frontend/src/utils/v1/issue/search/common.ts b/frontend/src/utils/v1/issue/search/common.ts
index b33e0b1241..7c66648eac 100644
--- a/frontend/src/utils/v1/issue/search/common.ts
+++ b/frontend/src/utils/v1/issue/search/common.ts
@@ -24,6 +24,7 @@ export const SearchScopeIdList = [
"subscriber",
"status",
"created",
+ "label",
] as const;
export type SearchScopeId =