Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: support more scopes for issue advanced search in frontend (#8202)
ecmadaodbd3bd742832
diff --git a/frontend/src/components/AdvancedSearch.vue b/frontend/src/components/AdvancedSearch.vueindex 8d97c1bfe9..ec682df5ec 100644--- a/frontend/src/components/AdvancedSearch.vue+++ b/frontend/src/components/AdvancedSearch.vue@@ -48,7 +48,7 @@<divv-for="option in searchOptions":key="option.id"- class="flex gap-x-2 px-3 py-1 items-baseline cursor-pointer hover:bg-gray-100"+ class="flex gap-x-2 px-3 py-1 items-center cursor-pointer hover:bg-gray-100"@mousedown.prevent.stop="onOptionSelect(state.currentScope, option.id)"@@ -67,11 +67,17 @@ import { NInput } from "naive-ui";import { reactive, computed, h, VNode, onMounted, ref } from "vue";import { useI18n } from "vue-i18n";import GitIcon from "@/components/GitIcon.vue";-import { useProjectV1ListByCurrentUser } from "@/store";+import { InstanceV1Name } from "@/components/v2";+import { useProjectV1ListByCurrentUser, useInstanceV1List } from "@/store";import { Workflow } from "@/types/proto/v1/project_service";-import { projectV1Name } from "@/utils";+import {+ isDev,+ projectV1Name,+ extractProjectResourceName,+ extractInstanceResourceName,+} from "@/utils";-type SearchScopeId = "project";+type SearchScopeId = "project" | "instance" | "type";export interface SearchParams {query: string;@@ -136,9 +142,12 @@ const state = reactive<LocalState>({const inputRef = ref<InstanceType<typeof NInput>>();const { projectList } = useProjectV1ListByCurrentUser();+const { instanceList } = useInstanceV1List(false /* !showDeleted */);const searchScopes = computed((): SearchScope[] => {- return [+ // TODO(ed): The scope options should have relevance.+ // For example, if users select a specific project, we should only allow them select instances related with this project.+ const scopes: SearchScope[] = [{id: "project",title: t("issue.advanced-search.scope.project.title"),@@ -151,12 +160,43 @@ const searchScopes = computed((): SearchScope[] => {children.push(h(GitIcon, { class: "w-5" }));}return {- id: proj.name,+ id: extractProjectResourceName(proj.name),label: h("div", { class: "flex gap-x-2" }, children),};}),},];+ if (isDev()) {+ scopes.push(+ {+ id: "instance",+ title: t("issue.advanced-search.scope.instance.title"),+ description: t("issue.advanced-search.scope.instance.description"),+ options: instanceList.value.map((ins) => {+ return {+ id: extractInstanceResourceName(ins.name),+ label: h(InstanceV1Name, { instance: ins }),+ };+ }),+ },+ {+ id: "type",+ title: t("issue.advanced-search.scope.type.title"),+ description: t("issue.advanced-search.scope.type.description"),+ options: [+ {+ id: "DDL",+ label: h("span", { innerHTML: "Data Definition Language" }),+ },+ {+ id: "DML",+ label: h("span", { innerHTML: "Data Manipulation Language" }),+ },+ ],+ }+ );+ }+ return scopes;});const searchOptions = computed((): SearchOption[] => {@@ -173,11 +213,27 @@ const searchKeyword = computed(() => {return scope?.title ?? "";});-const onOptionSelect = (keyword: SearchScopeId, id: string) => {- const search = `${keyword}:${id} ${query.value}`;- state.searchText = search;+const onOptionSelect = (scopeId: SearchScopeId, scopeValue: string) => {+ const params = getSearchParamsByText(state.searchText);+ const index = params.scopes.findIndex((s) => s.id === scopeId);+ if (index < 0) {+ params.scopes.push({+ id: scopeId,+ value: scopeValue,+ });+ } else {+ params.scopes[index] = {+ id: scopeId,+ value: scopeValue,+ };+ }+ state.searchText = buildSearchTextByParams(params);debouncedUpdate();onClear();++ if (params.scopes.length < searchScopes.value.length) {+ state.showSearchScopes = true;+ }};const onClear = () => {@@ -211,7 +267,7 @@ const query = computed(() => {});const getSearchParamsByText = (text: string): SearchParams => {- const plainQuery = query.value;+ const plainQuery = query.value.trim();const scopeText = plainQuery ? text.split(plainQuery)[0] || "" : text;return {query: plainQuery,@@ -241,11 +297,6 @@ const onKeydown = (e: KeyboardEvent) => {state.showSearchScopes = true;return;}- const params = getSearchParamsByText(state.searchText);- if (params.scopes.length === 0) {- state.showSearchScopes = true;- return;- }const start = inputRef.value.inputElRef.selectionStart ?? -1;const end = inputRef.value.inputElRef.selectionEnd ?? -1;@@ -254,6 +305,10 @@ const onKeydown = (e: KeyboardEvent) => {return;}+ // Try to find the active section the cursor in.+ // For example, the searchText is (the | is the current cursor):+ // project:xxx insta|nce:yyy custom search text+ // Then the active section is instance:yyy, we should should the instances selectorconst sections = state.searchText.split(" ");let i = 0;let len = 0;@@ -269,6 +324,7 @@ const onKeydown = (e: KeyboardEvent) => {}if (i >= sections.length) {onClear();+ state.showSearchScopes = true;return;}@@ -277,9 +333,11 @@ const onKeydown = (e: KeyboardEvent) => {searchScopes.value.findIndex((item) => item.id === currentScope) >= 0;if (!existed) {onClear();+ state.showSearchScopes = true;return;}+ state.showSearchScopes = false;state.currentScope = currentScope;};</script>diff --git a/frontend/src/components/DataExportButton.vue b/frontend/src/components/DataExportButton.vueindex 57b048ef64..4e73ddf12f 100644--- a/frontend/src/components/DataExportButton.vue+++ b/frontend/src/components/DataExportButton.vue@@ -49,7 +49,7 @@ const emit = defineEmits<{(event: "export",format: ExportFormat,- download: (content: string, format: ExportFormat) => void+ download: (content: BinaryLike | Blob, format: ExportFormat) => void): Promise<void>;}>();diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 4b37f1c590..371c9b9fec 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -815,6 +815,14 @@"project": {"title": "Project","description": "Include only issues from this project"+ },+ "instance": {+ "title": "Instance",+ "description": "Include only issues related with the instance"+ },+ "type": {+ "title": "Change Type",+ "description": "The database change type for issues"}}},diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 484ad5afcc..42e23999bd 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -814,6 +814,14 @@"project": {"title": "Proyecto","description": "Incluir solo ediciones de este proyecto"+ },+ "instance": {+ "title": "Instancia",+ "description": "Incluir solo problemas relacionados con la instancia"+ },+ "type": {+ "title": "Tipo de cambio",+ "description": "El tipo de cambio de base de datos para problemas"}}},diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 701031ecd2..3d3edc78a1 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -812,6 +812,14 @@"project": {"title": "项目","description": "仅搜索某个项目下的工单"+ },+ "instance": {+ "title": "实例",+ "description": "仅搜索与某个实例关联的工单"+ },+ "type": {+ "title": "变更类型",+ "description": "根据数据库变更类型搜索"}}},diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.tsindex 5faaad5710..e51d9af1a7 100644--- a/frontend/src/store/modules/v1/issue.ts+++ b/frontend/src/store/modules/v1/issue.ts@@ -1,3 +1,4 @@+import dayjs from "dayjs";import { uniq, uniqBy } from "lodash-es";import { defineStore } from "pinia";import { ref } from "vue";@@ -63,6 +64,19 @@ export const buildIssueFilter = (find: IssueFilter): string => {.join(" | ")}"`);}+ if (find.createdTsAfter) {+ filter.push(+ `create_time >= "${dayjs(find.createdTsAfter).utc().format()}"`+ );+ }+ if (find.createdTsBefore) {+ filter.push(+ `create_time <= "${dayjs(find.createdTsBefore).utc().format()}"`+ );+ }+ if (find.type) {+ filter.push(`type = "${find.type}"`);+ }return filter.join(" && ");};diff --git a/frontend/src/types/proto/v1/issue_service.ts b/frontend/src/types/proto/v1/issue_service.tsindex aa4f9fd1b0..f189b83db1 100644--- a/frontend/src/types/proto/v1/issue_service.ts+++ b/frontend/src/types/proto/v1/issue_service.ts@@ -164,6 +164,10 @@ export interface SearchIssuesRequest {* - create_time, example:* - create_time <= "2022-01-01T12:00:00.000Z"* - create_time >= "2022-01-01T12:00:00.000Z"+ * - instance, example:+ * - instance = "instancs/{resource id}"+ * - type, only support "DDL" or "DML", example:+ * - type = "DDL"*/filter: string;}diff --git a/frontend/src/types/v1/issue/issue.ts b/frontend/src/types/v1/issue/issue.tsindex 95ca84aa62..f100f3325f 100644--- a/frontend/src/types/v1/issue/issue.ts+++ b/frontend/src/types/v1/issue/issue.ts@@ -78,10 +78,14 @@ export const unknownIssue = (): ComposedIssue => {export interface IssueFilter {project: string;+ instance?: string;query: string;principal?: string;creator?: string;assignee?: string;subscriber?: string;statusList?: IssueStatus[];+ createdTsAfter?: number;+ createdTsBefore?: number;+ type?: string;}diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vueindex 8a495b9f22..0018db549b 100644--- a/frontend/src/views/IssueDashboard.vue+++ b/frontend/src/views/IssueDashboard.vue@@ -28,6 +28,15 @@:include-all="allowSelectAllUsers"@update:user="changeUserUID"/>+ <NDatePicker+ v-model:value="selectedTimeRange"+ type="datetimerange"+ size="medium"+ :on-confirm="confirmDatePicker"+ :on-clear="clearDatePicker"+ clearable+ >+ </NDatePicker><SearchBox:value="state.filterText":placeholder="$t('issue.filter-issue-by-name')"@@ -85,7 +94,8 @@</template><script lang="ts" setup>-import { NInputGroup, NButton } from "naive-ui";+import dayjs from "dayjs";+import { NInputGroup, NButton, NDatePicker } from "naive-ui";import { reactive, computed, watchEffect, onMounted } from "vue";import { useRoute, useRouter } from "vue-router";import AdvancedSearch, { SearchParams } from "@/components/AdvancedSearch.vue";@@ -93,7 +103,11 @@ import IssueTableV1 from "@/components/IssueV1/components/IssueTableV1.vue";import PagedIssueTableV1 from "@/components/IssueV1/components/PagedIssueTableV1.vue";import { UserSelect, SearchBox } from "@/components/v2";import { useCurrentUserV1, useProjectV1Store, useUserStore } from "@/store";-import { projectNamePrefix, userNamePrefix } from "@/store/modules/v1/common";+import {+ projectNamePrefix,+ userNamePrefix,+ instanceNamePrefix,+} from "@/store/modules/v1/common";import { UNKNOWN_ID, IssueFilter, ComposedIssue } from "@/types";import { IssueStatus } from "@/types/proto/v1/issue_service";import {@@ -198,6 +212,22 @@ const selectedUserUID = computed((): string => {: extractUserUID(currentUserV1.value.name); // default to current user otherwise});+const selectedTimeRange = computed((): [number, number] => {+ const defaultTimeRange = [+ dayjs().add(-60, "days").toDate().getTime(),+ Date.now(),+ ] 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 selectedUser = computed(() => {const uid = selectedUserUID.value;if (uid === String(UNKNOWN_ID)) {@@ -234,6 +264,28 @@ const changeUserUID = (user: string | undefined) => {});};+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(),+ },+ });+};+const goProject = () => {if (!project.value) return;router.push({@@ -261,15 +313,29 @@ const onSearchParamsUpdate = (params: SearchParams) => {const issueFilter = computed((): IssueFilter => {const { query, scopes } = state.searchParams;const projectScope = scopes.find((s) => s.id === "project");- const project = projectScope?.value ?? `${projectNamePrefix}-`;+ const instanceScope = scopes.find((s) => s.id === "instance");+ const typeScope = scopes.find((s) => s.id === "type");++ let instance = "";+ if (instanceScope) {+ instance = `${instanceNamePrefix}${instanceScope.value}`;+ }let principal = "";if (selectedUser.value) {principal = `${userNamePrefix}${selectedUser.value.email}`;}return {- project,query,principal,+ instance,+ project: `${projectNamePrefix}${projectScope?.value ?? "-"}`,+ createdTsAfter: selectedTimeRange.value+ ? selectedTimeRange.value[0]+ : undefined,+ createdTsBefore: selectedTimeRange.value+ ? selectedTimeRange.value[1]+ : undefined,+ type: typeScope?.value,};});</script>diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.mdindex 018df67b8f..5ec4b39d0a 100644--- a/proto/gen/grpc-doc/v1/README.md+++ b/proto/gen/grpc-doc/v1/README.md@@ -5668,7 +5668,7 @@ When paginating, all other parameters provided to `ListIssues` must match the caWhen paginating, all other parameters provided to `SearchIssues` must match the call that provided the page token. || query | [string](#string) | | Query is the query statement. |-| filter | [string](#string) | | Filter is used to filter issues returned in the list, follow the [ebnf](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) syntax. Supported field in filter: - principal, example: - principal = "users/{email}" - creator, example: - creator = "users/{email}" - assignee, example: - assignee = "users/{email}" - subscriber, example: - subscriber = "users/{email}" - status, example: - status = "OPEN" - status = "DONE" | "CANCELED" - create_time, example: - create_time <= "2022-01-01T12:00:00.000Z" - create_time >= "2022-01-01T12:00:00.000Z" |+| filter | [string](#string) | | Filter is used to filter issues returned in the list, follow the [ebnf](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form) syntax. Supported field in filter: - principal, example: - principal = "users/{email}" - creator, example: - creator = "users/{email}" - assignee, example: - assignee = "users/{email}" - subscriber, example: - subscriber = "users/{email}" - status, example: - status = "OPEN" - status = "DONE" | "CANCELED" - create_time, example: - create_time <= "2022-01-01T12:00:00.000Z" - create_time >= "2022-01-01T12:00:00.000Z" - instance, example: - instance = "instancs/{resource id}" - type, only support "DDL" or "DML", example: - type = "DDL" |diff --git a/proto/generated-go/v1/issue_service.pb.go b/proto/generated-go/v1/issue_service.pb.goindex 4c954f1034..b1ca65e87d 100644--- a/proto/generated-go/v1/issue_service.pb.go+++ b/proto/generated-go/v1/issue_service.pb.go@@ -701,6 +701,12 @@ type SearchIssuesRequest struct {// - create_time, example:// - create_time <= "2022-01-01T12:00:00.000Z"// - create_time >= "2022-01-01T12:00:00.000Z"+ //+ // - instance, example:+ // - instance = "instancs/{resource id}"+ //+ // - type, only support "DDL" or "DML", example:+ // - type = "DDL"Filter string `protobuf:"bytes,5,opt,name=filter,proto3" json:"filter,omitempty"`}diff --git a/proto/v1/issue_service.proto b/proto/v1/issue_service.protoindex 08f7d9f975..f061aecd16 100644--- a/proto/v1/issue_service.proto+++ b/proto/v1/issue_service.proto@@ -188,6 +188,10 @@ message SearchIssuesRequest {// - create_time, example:// - create_time <= "2022-01-01T12:00:00.000Z"// - create_time >= "2022-01-01T12:00:00.000Z"+ // - instance, example:+ // - instance = "instancs/{resource id}"+ // - type, only support "DDL" or "DML", example:+ // - type = "DDL"string filter = 5;}