Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: advanced search (#20005)
ecmadao01e1debf20d2
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex da34fce456..bc0d94aa78 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2516,7 +2516,6 @@},"sql-editor": {"access-grants": "Access Grants",- "access-grants-redirect-hint": "Go to {link} to view and manage your own access grants.","access-type-unmask": "See unmasked sensitive data","activate-access": "Activate","activate-confirm": "Are you sure you want to activate this access grant?",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex cbdbd89e9f..37d0f9739f 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2516,7 +2516,6 @@},"sql-editor": {"access-grants": "Access Grants",- "access-grants-redirect-hint": "Go to {link} to view and manage your own access grants.","access-type-unmask": "See unmasked sensitive data","activate-access": "Activate","activate-confirm": "Are you sure you want to activate this access grant?",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 8cca76c363..0446ffd0e8 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2516,7 +2516,6 @@},"sql-editor": {"access-grants": "Access Grants",- "access-grants-redirect-hint": "Go to {link} to view and manage your own access grants.","access-type-unmask": "See unmasked sensitive data","activate-access": "Activate","activate-confirm": "Are you sure you want to activate this access grant?",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 3221d7d379..c2bc1a3a2c 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2516,7 +2516,6 @@},"sql-editor": {"access-grants": "Access Grants",- "access-grants-redirect-hint": "Go to {link} to view and manage your own access grants.","access-type-unmask": "See unmasked sensitive data","activate-access": "Activate","activate-confirm": "Are you sure you want to activate this access grant?",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 42d2c45996..f98c97645e 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2516,7 +2516,6 @@},"sql-editor": {"access-grants": "访问授权",- "access-grants-redirect-hint": "前往 {link} 查看和管理您自己的访问授权。","access-type-unmask": "查看未脱敏的敏感数据","activate-access": "激活","activate-confirm": "确定要激活此访问授权吗?",diff --git a/frontend/src/react/components/AdvancedSearch.tsx b/frontend/src/react/components/AdvancedSearch.tsxindex 22f0e9e3c0..59d752f4c5 100644--- a/frontend/src/react/components/AdvancedSearch.tsx+++ b/frontend/src/react/components/AdvancedSearch.tsx@@ -1,5 +1,7 @@import { Filter, X } from "lucide-react";import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { useTranslation } from "react-i18next";+import { HighlightLabelText } from "@/react/components/HighlightLabelText";import { cn } from "@/react/lib/utils";// ============================================================@@ -20,7 +22,11 @@ export interface SearchParams {export interface ValueOption {value: string;keywords: string[];- render?: () => React.ReactNode;+ /**+ * Custom renderer for the option's primary cell. Receives the current+ * search keyword so the renderer can highlight matches.+ */+ render?: (keyword: string) => React.ReactNode;custom?: boolean;}@@ -145,6 +151,7 @@ export function AdvancedSearch({placeholder,onParamsChange,}: AdvancedSearchProps) {+ const { t } = useTranslation();const containerRef = useRef<HTMLDivElement>(null);const tagsContainerRef = useRef<HTMLDivElement>(null);const scopeMenuListRef = useRef<HTMLDivElement>(null);@@ -227,30 +234,62 @@ export function AdvancedSearch({return inputText.trim().toLowerCase();}, [currentScope, inputText]);+ // Keyword typed before any "scope:" prefix — used to filter & highlight+ // the scope menu.+ const scopeKeyword = useMemo(+ () => inputText.trim().replace(/:.*$/, ""),+ [inputText]+ );+// Visible scope options (filtered by typing)const visibleScopeOptions = useMemo(() => {if (currentScopeOption) return [currentScopeOption];- const keyword = inputText.trim().replace(/:.*$/, "").toLowerCase();+ const keyword = scopeKeyword.toLowerCase();if (!keyword) return availableScopeOptions;return availableScopeOptions.filter((opt) =>opt.id.toLowerCase().includes(keyword) ||opt.title.toLowerCase().includes(keyword));- }, [currentScopeOption, inputText, availableScopeOptions]);+ }, [currentScopeOption, scopeKeyword, availableScopeOptions]);- // Trigger async search when scope has onSearchconst isAsyncScope = currentScopeOption?.onSearch != null;++ // Keep the latest onSearch in a ref so the timer always fires against the+ // freshest callback — without adding it as an effect dep. Page-level+ // callbacks (e.g. `searchDatabases`) often close over async-loaded state+ // like `project`, and their useCallback identity can churn on every render+ // when that state flows through unstable references (e.g. a fallback+ // `unknownProject()` that allocates a new proto each call). Depending on+ // that identity would refire this effect on every render and loop forever.+ const onSearchRef = useRef(currentScopeOption?.onSearch);+ onSearchRef.current = currentScopeOption?.onSearch;++ // Trigger async search when the current scope or its keyword changes.+ // Reset is folded into the same effect so we never race with it.useEffect(() => {- if (!isAsyncScope || !currentScopeOption?.onSearch) return;clearTimeout(asyncSearchRef.current);- const keyword = currentValueForScope;- const onSearch = currentScopeOption.onSearch;- const requestID = asyncRequestRef.current + 1;- asyncRequestRef.current = requestID;+ asyncRequestRef.current += 1;+ // Clear previous results on every run so stale options from the prior+ // scope/keyword aren't selectable during the debounce + fetch window.+ setAsyncOptions([]);++ if (!currentScope || !onSearchRef.current) {+ setAsyncLoading(false);+ return;+ }++ const requestID = asyncRequestRef.current;setAsyncLoading(true);asyncSearchRef.current = setTimeout(() => {- onSearch(keyword)+ const fn = onSearchRef.current;+ if (!fn) {+ if (asyncRequestRef.current !== requestID) return;+ setAsyncOptions([]);+ setAsyncLoading(false);+ return;+ }+ fn(currentValueForScope).then((results) => {if (asyncRequestRef.current !== requestID) return;setAsyncOptions(results);@@ -267,17 +306,8 @@ export function AdvancedSearch({}, 300);return () => {clearTimeout(asyncSearchRef.current);- if (asyncRequestRef.current === requestID) {- asyncRequestRef.current += 1;- }};- }, [isAsyncScope, currentScopeOption, currentValueForScope]);-- // Reset async state when scope changes- useEffect(() => {- setAsyncOptions([]);- setAsyncLoading(false);- }, [currentScope]);+ }, [currentScope, currentValueForScope]);// Visible value options (filtered, de-duped)const visibleValueOptions = useMemo(() => {@@ -569,7 +599,7 @@ export function AdvancedSearch({const opt = scopeOptions.find((o) => o.id === scope.id)?.options?.find((o) => o.value === scope.value);- if (opt?.render) return opt.render();+ if (opt?.render) return opt.render("");return scope.value;},[scopeOptions]@@ -701,11 +731,17 @@ export function AdvancedSearch({onMouseEnter={() => setMenuIndex(index)}onClick={() => selectScope(option.id)}>- <span className="text-accent">{option.id}</span>+ <HighlightLabelText+ className="text-accent"+ text={option.id}+ keyword={scopeKeyword}+ />{option.description && (- <span className="text-control-light truncate">- {option.description}- </span>+ <HighlightLabelText+ className="text-control-light truncate"+ text={option.description}+ keyword={scopeKeyword}+ />)}</div>))}@@ -735,6 +771,9 @@ export function AdvancedSearch({{currentScopeOption.description && (<div className="text-xs text-control-light">{currentScopeOption.description}+ {currentScopeOption.onSearch && (+ <span>. {t("common.type-to-search")}</span>+ )}</div>)}</div>@@ -756,7 +795,7 @@ export function AdvancedSearch({>{option.render && (<span className="min-w-0 truncate text-control text-sm">- {option.render()}+ {option.render(currentValueForScope)}</span>)}{!option.custom && (@@ -764,7 +803,10 @@ export function AdvancedSearch({className="min-w-0 flex-1 truncate text-control-light text-sm"title={option.value}>- {option.value}+ <HighlightLabelText+ text={option.value}+ keyword={currentValueForScope}+ /></span>)}</div>diff --git a/frontend/src/react/components/AuditLogTable.tsx b/frontend/src/react/components/AuditLogTable.tsxindex d04d1337a9..e7f78c8553 100644--- a/frontend/src/react/components/AuditLogTable.tsx+++ b/frontend/src/react/components/AuditLogTable.tsx@@ -18,6 +18,7 @@ import {AdvancedSearch,type ScopeOption,type SearchParams,+ type ValueOption,} from "@/react/components/AdvancedSearch";import { FeatureAttention } from "@/react/components/FeatureAttention";import { TimeRangePicker } from "@/react/components/TimeRangePicker";@@ -29,7 +30,11 @@ import {} from "@/react/hooks/useSessionPageSize";import { useVueState } from "@/react/hooks/useVueState";import { cn } from "@/react/lib/utils";-import { pushNotification, useSubscriptionV1Store } from "@/store";+import {+ pushNotification,+ useSubscriptionV1Store,+ useUserStore,+} from "@/store";import {extractUserEmail,getProjectIdPlanUidStageUidFromRolloutName,@@ -56,7 +61,11 @@ import { RolloutService } from "@/types/proto-es/v1/rollout_service_pb";import { SettingSchema } from "@/types/proto-es/v1/setting_service_pb";import { SQLService } from "@/types/proto-es/v1/sql_service_pb";import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";-import { formatAbsoluteDateTime, humanizeDurationV1 } from "@/utils";+import {+ formatAbsoluteDateTime,+ getDefaultPagination,+ humanizeDurationV1,+} from "@/utils";dayjs.extend(utc);@@ -709,12 +718,28 @@ export function AuditLogTable({return "";}, [filter, t]);+ const userStore = useUserStore();+ const searchUsers = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ const { users } = await userStore.fetchUserList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return users.map((u) => ({+ value: u.email,+ keywords: [u.email, u.title],+ }));+ },+ [userStore]+ );+const scopeOptions = useMemo((): ScopeOption[] => {return [{id: "actor",title: t("audit-log.advanced-search.scope.actor.title"),description: t("audit-log.advanced-search.scope.actor.description"),+ onSearch: searchUsers,},{id: "method",@@ -737,7 +762,7 @@ export function AuditLogTable({})),},];- }, [t]);+ }, [t, searchUsers]);const renderSortIndicator = (columnKey: string) => {if (sortKey !== columnKey)diff --git a/frontend/src/react/components/HighlightLabelText.tsx b/frontend/src/react/components/HighlightLabelText.tsxnew file mode 100644index 0000000000..37a04e687e--- /dev/null+++ b/frontend/src/react/components/HighlightLabelText.tsx@@ -0,0 +1,28 @@+import { getHighlightHTMLByRegExp } from "@/utils";++interface HighlightLabelTextProps {+ text: string;+ keyword?: string;+ className?: string;+}++export function HighlightLabelText({+ text,+ keyword,+ className,+}: HighlightLabelTextProps) {+ const trimmed = keyword?.trim() ?? "";+ if (!trimmed) {+ return <span className={className}>{text}</span>;+ }+ return (+ <span+ className={className}+ // getHighlightHTMLByRegExp escapes the input and sanitizes with+ // DOMPurify, so the returned string is safe to inject.+ dangerouslySetInnerHTML={{+ __html: getHighlightHTMLByRegExp(text, trimmed),+ }}+ />+ );+}diff --git a/frontend/src/react/locales/en-US.json b/frontend/src/react/locales/en-US.jsonindex 9827c0d49c..42e5ccb3cf 100644--- a/frontend/src/react/locales/en-US.json+++ b/frontend/src/react/locales/en-US.json@@ -1072,6 +1072,13 @@"instance.your-snowflake-account-locator": "Your Snowflake account locator","issue": {"access-grant": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Filter by access grant status"+ }+ }+ },"details": "Access Grant Details","expired-at": "Expired at"},@@ -1098,6 +1105,18 @@"description": "Search by the issue current approver","title": "Current approver"},+ "database": {+ "description": "Filter by database"+ },+ "engine": {+ "description": "Filter by engines"+ },+ "environment": {+ "description": "Filter by environment"+ },+ "instance": {+ "description": "Filter by instance"+ },"issue-label": {"description": "Filter by issue label","title": "Issue label"@@ -1112,11 +1131,20 @@"role-grant": "Role Grant"}},+ "label": {+ "description": "Input the \"key:value\" pair then press Enter"+ },+ "project": {+ "description": "Filter by project"+ },"state": {"description": "Filter by state"},"status": {"description": "Search by the issue status"+ },+ "user": {+ "description": "Filter by user"}}},@@ -1322,6 +1350,13 @@},"filter-projects": "Filter projects","masking-exemption": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Filter by exemption status"+ }+ }+ },"all-levels": "All levels","expires-in-days_one": "Expires in {{days}} day","expires-in-days_other": "Expires in {{days}} days",diff --git a/frontend/src/react/locales/es-ES.json b/frontend/src/react/locales/es-ES.jsonindex 72c8b5a320..c90e61533a 100644--- a/frontend/src/react/locales/es-ES.json+++ b/frontend/src/react/locales/es-ES.json@@ -1072,6 +1072,13 @@"instance.your-snowflake-account-locator": "Su localizador de cuentas Snowflake","issue": {"access-grant": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Filtrar por estado de la concesión de acceso"+ }+ }+ },"details": "Access Grant Details","expired-at": "Expired at"},@@ -1098,6 +1105,18 @@"description": "Buscar por el aprobador actual del problema","title": "aprobador actual"},+ "database": {+ "description": "Filtrar por base de datos"+ },+ "engine": {+ "description": "Filtrar por motores"+ },+ "environment": {+ "description": "Filtrar por entorno"+ },+ "instance": {+ "description": "Filtrar por instancia"+ },"issue-label": {"description": "Filtrar por etiqueta de problema","title": "Etiqueta de emisión"@@ -1112,11 +1131,20 @@"role-grant": "Role Grant"}},+ "label": {+ "description": "Ingrese el par \"clave:valor\" y luego presione Enter"+ },+ "project": {+ "description": "Filtrar por proyecto"+ },"state": {"description": "Filtrar por estado"},"status": {"description": "Buscar por el estado del issue"+ },+ "user": {+ "description": "Filtrar por usuario"}}},@@ -1322,6 +1350,13 @@},"filter-projects": "Filtrar proyectos","masking-exemption": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Filtrar por estado de la exención"+ }+ }+ },"all-levels": "Todos los niveles","expires-in-days_one": "Expira en {{days}} día","expires-in-days_other": "Expira en {{days}} días",diff --git a/frontend/src/react/locales/ja-JP.json b/frontend/src/react/locales/ja-JP.jsonindex 8606eb67c3..f775804441 100644--- a/frontend/src/react/locales/ja-JP.json+++ b/frontend/src/react/locales/ja-JP.json@@ -1072,6 +1072,13 @@"instance.your-snowflake-account-locator": "Snowflake アカウント ロケーター","issue": {"access-grant": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "アクセス権限のステータスでフィルター"+ }+ }+ },"details": "Access Grant Details","expired-at": "Expired at"},@@ -1098,6 +1105,18 @@"description": "イシューの現在の承認者による検索","title": "現在の承認者"},+ "database": {+ "description": "データベースでフィルター"+ },+ "engine": {+ "description": "エンジンでフィルタリング"+ },+ "environment": {+ "description": "環境に基づいてフィルタリングする"+ },+ "instance": {+ "description": "インスタンスによるフィルター"+ },"issue-label": {"description": "イシューラベルでフィルタリング","title": "イシューラベル"@@ -1112,11 +1131,20 @@"role-grant": "Role Grant"}},+ "label": {+ "description": "「キー:値」のペアを入力し、Enterを押します"+ },+ "project": {+ "description": "プロジェクトでフィルターする"+ },"state": {"description": "状態でフィルタ"},"status": {"description": "イシューのステータスで検索"+ },+ "user": {+ "description": "ユーザーでフィルター"}}},@@ -1322,6 +1350,13 @@},"filter-projects": "プロジェクトをフィルタリング","masking-exemption": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "免除ステータスでフィルター"+ }+ }+ },"all-levels": "全レベル","expires-in-days_one": "{{days}} 日後に期限切れ","expires-in-days_other": "{{days}} 日後に期限切れ",diff --git a/frontend/src/react/locales/vi-VN.json b/frontend/src/react/locales/vi-VN.jsonindex 8f87c2824b..418968ce24 100644--- a/frontend/src/react/locales/vi-VN.json+++ b/frontend/src/react/locales/vi-VN.json@@ -1072,6 +1072,13 @@"instance.your-snowflake-account-locator": "Định vị tài khoản Snowflake của bạn","issue": {"access-grant": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Lọc theo trạng thái cấp quyền truy cập"+ }+ }+ },"details": "Access Grant Details","expired-at": "Expired at"},@@ -1098,6 +1105,18 @@"description": "Tìm kiếm theo người phê duyệt hiện tại","title": "Người phê duyệt hiện tại"},+ "database": {+ "description": "Lọc theo cơ sở dữ liệu"+ },+ "engine": {+ "description": "Lọc theo engine"+ },+ "environment": {+ "description": "Lọc theo môi trường"+ },+ "instance": {+ "description": "Lọc theo phiên bản"+ },"issue-label": {"description": "Lọc theo nhãn vấn đề","title": "Nhãn vấn đề"@@ -1112,11 +1131,20 @@"role-grant": "Role Grant"}},+ "label": {+ "description": "Nhập cặp \"key:value\" rồi nhấn Enter"+ },+ "project": {+ "description": "Lọc theo dự án"+ },"state": {"description": "Lọc theo trạng thái"},"status": {"description": "Tìm kiếm theo trạng thái issue"+ },+ "user": {+ "description": "Lọc theo người dùng"}}},@@ -1322,6 +1350,13 @@},"filter-projects": "Lọc dự án","masking-exemption": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "Lọc theo trạng thái miễn trừ"+ }+ }+ },"all-levels": "Tất cả các cấp","expires-in-days_one": "Hết hạn sau {{days}} ngày","expires-in-days_other": "Hết hạn sau {{days}} ngày",diff --git a/frontend/src/react/locales/zh-CN.json b/frontend/src/react/locales/zh-CN.jsonindex ac85ba02cc..5d9889480d 100644--- a/frontend/src/react/locales/zh-CN.json+++ b/frontend/src/react/locales/zh-CN.json@@ -1072,6 +1072,13 @@"instance.your-snowflake-account-locator": "您的 Snowflake 账户定位符","issue": {"access-grant": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "按访问授权状态筛选"+ }+ }+ },"details": "Access Grant Details","expired-at": "Expired at"},@@ -1098,6 +1105,18 @@"description": "按工单的当前审批人搜索","title": "当前审批人"},+ "database": {+ "description": "按数据库筛选"+ },+ "engine": {+ "description": "按引擎过滤"+ },+ "environment": {+ "description": "根据环境过滤"+ },+ "instance": {+ "description": "根据实例过滤"+ },"issue-label": {"description": "按工单标签过滤","title": "工单标签"@@ -1112,11 +1131,20 @@"role-grant": "角色授权"}},+ "label": {+ "description": "输入 \"key:value\" 后按下回车"+ },+ "project": {+ "description": "根据项目过滤"+ },"state": {"description": "按状态过滤"},"status": {"description": "按工单状态搜索"+ },+ "user": {+ "description": "按用户筛选"}}},@@ -1322,6 +1350,13 @@},"filter-projects": "过滤项目","masking-exemption": {+ "advanced-search": {+ "scope": {+ "status": {+ "description": "按豁免状态筛选"+ }+ }+ },"all-levels": "所有等级","expires-in-days_one": "{{days}} 天后到期","expires-in-days_other": "{{days}} 天后到期",diff --git a/frontend/src/react/pages/project/ProjectAccessGrantsPage.tsx b/frontend/src/react/pages/project/ProjectAccessGrantsPage.tsxindex 4aef3111c6..b2b67bde05 100644--- a/frontend/src/react/pages/project/ProjectAccessGrantsPage.tsx+++ b/frontend/src/react/pages/project/ProjectAccessGrantsPage.tsx@@ -157,6 +157,9 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {// Server-side search for database filter optionsconst searchDatabases = useCallback(async (keyword: string): Promise<ValueOption[]> => {+ if (!project || !hasProjectPermissionV2(project, "bb.databases.list")) {+ return [];+ }const result = await databaseStore.fetchDatabases({parent: projectName,pageSize: getDefaultPagination(),@@ -192,7 +195,7 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {};});},- [databaseStore, projectName]+ [databaseStore, projectName, project]);// Server-side search for creator filter options@@ -235,6 +238,9 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {{id: "status",title: t("common.status"),+ description: t(+ "issue.access-grant.advanced-search.scope.status.description"+ ),allowMultiple: true,options: [{@@ -262,11 +268,13 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {{id: "database",title: t("common.database"),+ description: t("issue.advanced-search.scope.database.description"),onSearch: searchDatabases,},{id: "creator",title: t("common.creator"),+ description: t("issue.advanced-search.scope.creator.description"),onSearch: searchUsers,},],diff --git a/frontend/src/react/pages/project/ProjectDataExportPage.tsx b/frontend/src/react/pages/project/ProjectDataExportPage.tsxindex 58b3fa70c4..fcc99e50e8 100644--- a/frontend/src/react/pages/project/ProjectDataExportPage.tsx+++ b/frontend/src/react/pages/project/ProjectDataExportPage.tsx@@ -6,6 +6,7 @@ import {type ScopeOption,type SearchParams,type SearchScope,+ type ValueOption,} from "@/react/components/AdvancedSearch";import { Button } from "@/react/components/ui/button";import { Tooltip } from "@/react/components/ui/tooltip";@@ -13,7 +14,13 @@ import { PagedTableFooter, usePagedData } from "@/react/hooks/usePagedData";import { useVueState } from "@/react/hooks/useVueState";import { router } from "@/router";import { WORKSPACE_ROUTE_USER_PROFILE } from "@/router/dashboard/workspaceRoutes";-import { useIssueV1Store, useProjectV1Store, useUserStore } from "@/store";+import {+ useDatabaseV1Store,+ useInstanceV1Store,+ useIssueV1Store,+ useProjectV1Store,+ useUserStore,+} from "@/store";import { projectNamePrefix } from "@/store/modules/v1/common";import { getTimeForPbTimestampProtoEs, unknownUser } from "@/types";import { RiskLevel } from "@/types/proto-es/v1/common_pb";@@ -26,12 +33,16 @@ import {import {buildIssueFilterBySearchParams,displayRoleTitle,+ extractDatabaseResourceName,+ extractInstanceResourceName,extractIssueUID,extractProjectResourceName,formatAbsoluteDateTime,+ getDefaultPagination,getHighlightHTMLByRegExp,getIssueRoute,hasProjectPermissionV2,+ hasWorkspacePermissionV2,humanizeTs,PERMISSIONS_FOR_DATABASE_EXPORT_ISSUE,type SearchParams as VueSearchParams,@@ -80,12 +91,47 @@ export function ProjectDataExportPage({ projectId }: { projectId: string }) {setSearchParams(defaultSearchParams());}, [projectId]);+ const instanceStore = useInstanceV1Store();+ const databaseStore = useDatabaseV1Store();+ const searchInstances = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ if (!hasWorkspacePermissionV2("bb.instances.list")) return [];+ const { instances } = await instanceStore.fetchInstanceList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return instances.map((i) => {+ const id = extractInstanceResourceName(i.name);+ return { value: id, keywords: [id, i.title] };+ });+ },+ [instanceStore]+ );+ const searchDatabases = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ if (!project || !hasProjectPermissionV2(project, "bb.databases.list")) {+ return [];+ }+ const { databases } = await databaseStore.fetchDatabases({+ parent: projectName,+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return databases.map((db) => {+ const { databaseName } = extractDatabaseResourceName(db.name);+ return { value: db.name, keywords: [databaseName, db.name] };+ });+ },+ [databaseStore, projectName, project]+ );+// Scope options for the search barconst scopeOptions: ScopeOption[] = useMemo(() => [{id: "status",title: t("common.status"),+ description: t("issue.advanced-search.scope.status.description"),options: [{value: IssueStatus[IssueStatus.OPEN],@@ -107,17 +153,22 @@ export function ProjectDataExportPage({ projectId }: { projectId: string }) {{id: "instance",title: t("common.instance"),+ description: t("issue.advanced-search.scope.instance.description"),+ onSearch: searchInstances,},{id: "database",title: t("common.database"),+ description: t("issue.advanced-search.scope.database.description"),+ onSearch: searchDatabases,},{id: "issue-label",title: t("issue.labels"),+ description: t("issue.advanced-search.scope.issue-label.description"),},],- [t]+ [t, searchInstances, searchDatabases]);// Permission check for creating export issuesdiff --git a/frontend/src/react/pages/project/ProjectDatabasesPage.tsx b/frontend/src/react/pages/project/ProjectDatabasesPage.tsxindex cf2d3d82e8..e82c87c73f 100644--- a/frontend/src/react/pages/project/ProjectDatabasesPage.tsx+++ b/frontend/src/react/pages/project/ProjectDatabasesPage.tsx@@ -9,6 +9,7 @@ import {getValueFromScopes,type ScopeOption,type SearchParams,+ type ValueOption,} from "@/react/components/AdvancedSearch";import {CreateDatabaseSheet,@@ -26,6 +27,7 @@ import {useDatabaseV1Store,useDBSchemaV1Store,useEnvironmentV1Store,+ useInstanceV1Store,useProjectV1Store,} from "@/store";import {@@ -49,7 +51,10 @@ import {} from "@/types/proto-es/v1/database_service_pb";import {engineNameV1,+ extractInstanceResourceName,+ getDefaultPagination,hasProjectPermissionV2,+ hasWorkspacePermissionV2,PERMISSIONS_FOR_DATABASE_CREATE_ISSUE,supportedEngineV1List,} from "@/utils";@@ -96,6 +101,22 @@ export function ProjectDatabasesPage({ projectId }: { projectId: string }) {() => environmentStore.environmentList ?? []);+ const instanceStore = useInstanceV1Store();+ const searchInstances = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ if (!hasWorkspacePermissionV2("bb.instances.list")) return [];+ const { instances } = await instanceStore.fetchInstanceList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return instances.map((i) => {+ const id = extractInstanceResourceName(i.name);+ return { value: id, keywords: [id, i.title] };+ });+ },+ [instanceStore]+ );+const scopeOptions: ScopeOption[] = useMemo(() => {return [{@@ -123,7 +144,8 @@ export function ProjectDatabasesPage({ projectId }: { projectId: string }) {{id: "instance",title: t("common.instance"),- description: t("common.instance"),+ description: t("issue.advanced-search.scope.instance.description"),+ onSearch: searchInstances,},{id: "engine",@@ -138,11 +160,11 @@ export function ProjectDatabasesPage({ projectId }: { projectId: string }) {{id: "label",title: t("common.labels"),- description: t("common.labels"),+ description: t("issue.advanced-search.scope.label.description"),allowMultiple: true,},];- }, [t, environments]);+ }, [t, environments, searchInstances]);// Derived filter valuesconst envVal = getValueFromScopes(searchParams, "environment");diff --git a/frontend/src/react/pages/project/ProjectMaskingExemptionPage.tsx b/frontend/src/react/pages/project/ProjectMaskingExemptionPage.tsxindex 0256c051d7..7022d357ee 100644--- a/frontend/src/react/pages/project/ProjectMaskingExemptionPage.tsx+++ b/frontend/src/react/pages/project/ProjectMaskingExemptionPage.tsx@@ -268,6 +268,9 @@ export function ProjectMaskingExemptionPage({// Scope options for advanced searchconst searchDatabases = useCallback(async (keyword: string): Promise<ValueOption[]> => {+ if (!project || !hasProjectPermissionV2(project, "bb.databases.list")) {+ return [];+ }const result = await databaseStore.fetchDatabases({parent: projectName,pageSize: getDefaultPagination(),@@ -287,7 +290,7 @@ export function ProjectMaskingExemptionPage({};});},- [databaseStore, projectName]+ [databaseStore, projectName, project]);const searchUsers = useCallback(@@ -329,16 +332,21 @@ export function ProjectMaskingExemptionPage({{id: "database",title: t("common.database"),+ description: t("issue.advanced-search.scope.database.description"),onSearch: searchDatabases,},{id: "user",title: t("common.users"),+ description: t("issue.advanced-search.scope.user.description"),onSearch: searchUsers,},{id: "status",title: t("common.status"),+ description: t(+ "project.masking-exemption.advanced-search.scope.status.description"+ ),options: [{value: "active",diff --git a/frontend/src/react/pages/settings/DatabasesPage.tsx b/frontend/src/react/pages/settings/DatabasesPage.tsxindex e016c0c8f9..8c5c90f76c 100644--- a/frontend/src/react/pages/settings/DatabasesPage.tsx+++ b/frontend/src/react/pages/settings/DatabasesPage.tsx@@ -9,6 +9,7 @@ import {getValueFromScopes,type ScopeOption,type SearchParams,+ type ValueOption,} from "@/react/components/AdvancedSearch";import {CreateDatabaseSheet,@@ -29,6 +30,8 @@ import {useDatabaseV1Store,useDBSchemaV1Store,useEnvironmentV1Store,+ useInstanceV1Store,+ useProjectV1Store,useUIStateStore,} from "@/store";import {@@ -50,7 +53,9 @@ import {} from "@/types/proto-es/v1/database_service_pb";import {engineNameV1,+ extractInstanceResourceName,extractProjectResourceName,+ getDefaultPagination,hasWorkspacePermissionV2,supportedEngineV1List,} from "@/utils";@@ -113,28 +118,67 @@ export function DatabasesPage() {() => environmentStore.environmentList ?? []);+ const projectStore = useProjectV1Store();+ const defaultProjectId = extractProjectResourceName(+ actuatorStore.serverInfo?.defaultProject ?? ""+ );+ const searchProjects = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ const { projects } = await projectStore.fetchProjectList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ const unassigned: ValueOption = {+ value: defaultProjectId,+ keywords: ["unassigned", "default"],+ render: () => (+ <span className="italic text-control-light">Unassigned</span>+ ),+ };+ const matchesUnassigned =+ !keyword.trim() || "unassigned".includes(keyword.trim().toLowerCase());+ const remote = projects+ .filter((p) => extractProjectResourceName(p.name) !== defaultProjectId)+ .map<ValueOption>((p) => {+ const id = extractProjectResourceName(p.name);+ return { value: id, keywords: [id, p.title] };+ });+ return matchesUnassigned ? [unassigned, ...remote] : remote;+ },+ [projectStore, defaultProjectId]+ );++ const instanceStore = useInstanceV1Store();+ const searchInstances = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ if (!hasWorkspacePermissionV2("bb.instances.list")) return [];+ const { instances } = await instanceStore.fetchInstanceList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return instances.map((i) => {+ const id = extractInstanceResourceName(i.name);+ return {+ value: id,+ keywords: [id, i.title],+ };+ });+ },+ [instanceStore]+ );+const scopeOptions: ScopeOption[] = useMemo(() => {return [{id: "project",title: t("common.project"),- description: t("common.project"),- options: [- {- value: extractProjectResourceName(- actuatorStore.serverInfo?.defaultProject ?? ""- ),- keywords: ["unassigned", "default"],- render: () => (- <span className="italic text-control-light">Unassigned</span>- ),- },- ],+ description: t("issue.advanced-search.scope.project.description"),+ onSearch: searchProjects,},{id: "environment",title: t("common.environment"),- description: t("common.environment"),+ description: t("issue.advanced-search.scope.environment.description"),options: [unknownEnvironment(), ...environments].map((env) => {const isUnknown = env.name === UNKNOWN_ENVIRONMENT_NAME;return {@@ -150,12 +194,13 @@ export function DatabasesPage() {{id: "instance",title: t("common.instance"),- description: t("common.instance"),+ description: t("issue.advanced-search.scope.instance.description"),+ onSearch: searchInstances,},{id: "engine",title: t("database.engine"),- description: t("database.engine"),+ description: t("issue.advanced-search.scope.engine.description"),options: supportedEngineV1List().map((engine) => ({value: Engine[engine],keywords: [Engine[engine].toLowerCase(), engineNameV1(engine)],@@ -176,11 +221,11 @@ export function DatabasesPage() {{id: "label",title: t("common.labels"),- description: t("common.labels"),+ description: t("issue.advanced-search.scope.label.description"),allowMultiple: true,},];- }, [t, environments]);+ }, [t, environments, searchInstances, searchProjects]);// Derived filter valuesconst projectVal = getValueFromScopes(searchParams, "project");diff --git a/frontend/src/react/pages/settings/InstanceDetailPage.tsx b/frontend/src/react/pages/settings/InstanceDetailPage.tsxindex a945721902..30f30015af 100644--- a/frontend/src/react/pages/settings/InstanceDetailPage.tsx+++ b/frontend/src/react/pages/settings/InstanceDetailPage.tsx@@ -5,8 +5,10 @@ import {getValueFromScopes,type ScopeOption,type SearchParams,+ type ValueOption,} from "@/react/components/AdvancedSearch";import { DatabaseTable } from "@/react/components/database";+import { EnvironmentLabel } from "@/react/components/EnvironmentLabel";import {InstanceActionDropdown,InstanceFormBody,@@ -24,15 +26,26 @@ import {TabsTrigger,} from "@/react/components/ui/tabs";import { useVueState } from "@/react/hooks/useVueState";-import { useDatabaseV1Store, useInstanceV1Store } from "@/store";+import {+ useDatabaseV1Store,+ useEnvironmentV1Store,+ useInstanceV1Store,+ useProjectV1Store,+} from "@/store";import {environmentNamePrefix,instanceNamePrefix,projectNamePrefix,} from "@/store/modules/v1/common";import type { DatabaseFilter } from "@/store/modules/v1/database";+import { UNKNOWN_ENVIRONMENT_NAME, unknownEnvironment } from "@/types";import { State } from "@/types/proto-es/v1/common_pb";-import { instanceV1Name, setDocumentTitle } from "@/utils";+import {+ extractProjectResourceName,+ getDefaultPagination,+ instanceV1Name,+ setDocumentTitle,+} from "@/utils";const instanceHashList = ["overview", "databases", "users"] as const;type InstanceHash = (typeof instanceHashList)[number];@@ -106,26 +119,61 @@ export function InstanceDetailPage({ instanceId }: { instanceId: string }) {[selectedEnvironment, selectedProject, searchParams.query, selectedLabels]);+ const environmentStore = useEnvironmentV1Store();+ const environments = useVueState(+ () => environmentStore.environmentList ?? []+ );++ const projectStore = useProjectV1Store();+ const searchProjects = useCallback(+ async (keyword: string): Promise<ValueOption[]> => {+ const { projects } = await projectStore.fetchProjectList({+ pageSize: getDefaultPagination(),+ filter: keyword.trim() ? { query: keyword } : undefined,+ });+ return projects.map((p) => {+ const id = extractProjectResourceName(p.name);+ return {+ value: id,+ keywords: [id, p.title],+ };+ });+ },+ [projectStore]+ );+const scopeOptions: ScopeOption[] = useMemo(() => [{id: "environment",title: t("common.environment"),- description: t("common.environment"),+ description: t("issue.advanced-search.scope.environment.description"),+ options: [unknownEnvironment(), ...environments].map((env) => {+ const isUnknown = env.name === UNKNOWN_ENVIRONMENT_NAME;+ return {+ value: env.id,+ keywords: isUnknown+ ? ["unassigned", "none", env.id]+ : [env.id, env.title],+ custom: true,+ render: () => <EnvironmentLabel environment={env} />,+ };+ }),},{id: "project",title: t("common.project"),- description: t("common.project"),+ description: t("issue.advanced-search.scope.project.description"),+ onSearch: searchProjects,},{id: "label",title: t("common.labels"),- description: t("common.labels"),+ description: t("issue.advanced-search.scope.label.description"),allowMultiple: true,},],- [t]+ [t, environments, searchProjects]);const handleTabChange = useCallback((tab: string | number | null) => {diff --git a/frontend/src/react/pages/settings/InstancesPage.tsx b/frontend/src/react/pages/settings/InstancesPage.tsxindex dd92e2a015..5b2cbaa4f0 100644--- a/frontend/src/react/pages/settings/InstancesPage.tsx+++ b/frontend/src/react/pages/settings/InstancesPage.tsx@@ -740,7 +740,7 @@ export function InstancesPage() {{id: "environment",title: t("common.environment"),- description: t("common.environment"),+ description: t("issue.advanced-search.scope.environment.description"),options: [unknownEnvironment(), ...environments].map((env) => {const isUnknown = env.name === UNKNOWN_ENVIRONMENT_NAME;return {@@ -756,7 +756,7 @@ export function InstancesPage() {{id: "engine",title: t("database.engine"),- description: t("database.engine"),+ description: t("issue.advanced-search.scope.engine.description"),options: supportedEngineV1List().map((engine) => ({value: Engine[engine],keywords: [Engine[engine].toLowerCase(), engineNameV1(engine)],@@ -777,13 +777,13 @@ export function InstancesPage() {{id: "label",title: t("common.labels"),- description: t("common.labels"),+ description: t("issue.advanced-search.scope.label.description"),allowMultiple: true,},{id: "state",title: t("common.state"),- description: t("common.state"),+ description: t("issue.advanced-search.scope.state.description"),options: [{ value: "ACTIVE", keywords: ["active"] },...(canUndeletediff --git a/frontend/src/react/pages/settings/ProjectsPage.tsx b/frontend/src/react/pages/settings/ProjectsPage.tsxindex fd124aebdf..dc0a9578f8 100644--- a/frontend/src/react/pages/settings/ProjectsPage.tsx+++ b/frontend/src/react/pages/settings/ProjectsPage.tsx@@ -746,7 +746,7 @@ export function ProjectsPage() {const stateOption: ScopeOption = {id: "state",title: t("common.state"),- description: t("common.state"),+ description: t("issue.advanced-search.scope.state.description"),options: [{ value: "ACTIVE", keywords: ["active"] },...(canUndelete@@ -760,7 +760,7 @@ export function ProjectsPage() {const labelOption: ScopeOption = {id: "label",title: t("common.labels"),- description: t("common.labels"),+ description: t("issue.advanced-search.scope.label.description"),allowMultiple: true,};return [labelOption, stateOption];diff --git a/frontend/src/views/project/ProjectAccessGrantDashboard.vue b/frontend/src/views/project/ProjectAccessGrantDashboard.vuedeleted file mode 100644index f6cafa499c..0000000000--- a/frontend/src/views/project/ProjectAccessGrantDashboard.vue+++ /dev/null@@ -1,469 +0,0 @@-<template>- <div class="py-4 w-full flex flex-col">- <FeatureAttention class="mx-4 mb-2" :feature="PlanFeature.FEATURE_JIT" />-- <ComponentPermissionGuard- :project="project"- class="mx-4"- :permissions="['bb.accessGrants.list']"- >- <div class="px-4 pb-2 flex items-center gap-x-2">- <AdvancedSearch- class="flex-1"- v-model:params="searchParams"- :scope-options="scopeOptions"- :placeholder="$t('issue.advanced-search.filter')"- :autofocus="false"- :cache-query="true"- />- <TimeRange- v-model:show="showTimeRange"- v-model:params="searchParams"- @update:params="$emit('update:params', $event)"- />- </div>-- <PagedTable- ref="pagedTableRef"- :key="projectName"- :session-key="`project-${projectName}-access-grants`"- :footer-class="'mx-4'"- :fetch-list="fetchList"- :order-keys="ORDER_KEYS"- >- <template #table="{ list, loading, sorters, onSortersUpdate }">- <NDataTable- v-if="hasJITFeature"- :columns="getSortedColumns(sorters)"- :data="list"- :bordered="false"- :striped="true"- :loading="loading"- :row-key="(row: AccessGrant) => row.name"- @update:sorter="onSortersUpdate"- />- <NEmpty v-else class="py-12 border rounded-sm" />- </template>- </PagedTable>- </ComponentPermissionGuard>-- <BBAttention v-if="!canList" type="info" class="mx-4 mt-2">- <i18n-t keypath="sql-editor.access-grants-redirect-hint" tag="span">- <template #link>- <router-link- class="normal-link"- :to="{- name: 'sql-editor.project',- params: { project: projectId },- query: { panel: 'access' },- }"- >- {{ $t("sql-editor.self") }}- </router-link>- </template>- </i18n-t>- </BBAttention>- </div>-</template>--<script setup lang="tsx">-import { useWindowSize } from "@vueuse/core";-import type { DataTableColumn, DataTableSortState } from "naive-ui";-import {- NButton,- NDataTable,- NEmpty,- NTag,- NTooltip,- useDialog,-} from "naive-ui";-import { computed, h, ref, type VNode, type VNodeChild, watch } from "vue";-import type { ComponentExposed } from "vue-component-type-helpers";-import { useI18n } from "vue-i18n";-import { useRouter } from "vue-router";-import { BBAttention } from "@/bbkit";-import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";-import { FeatureAttention } from "@/components/FeatureGuard";-import ComponentPermissionGuard from "@/components/Permission/ComponentPermissionGuard.vue";-import PagedTable from "@/components/v2/Model/PagedTable.vue";-import { mapSorterStatus } from "@/components/v2/Model/utils";-import {- type AccessFilter,- featureToRef,- pushNotification,- useAccessGrantStore,- useProjectByName,-} from "@/store";-import { extractUserEmail, projectNamePrefix } from "@/store/modules/v1/common";-import { getTimeForPbTimestampProtoEs } from "@/types";-import { type AccessGrant } from "@/types/proto-es/v1/access_grant_service_pb";-import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";-import {- type AccessGrantFilterStatus,- formatAbsoluteDateTime,- getAccessGrantDisplayStatus,- getAccessGrantDisplayStatusText,- getAccessGrantExpirationText,- getAccessGrantStatusTagType,- getAccessSearchOptions,- getTsRangeFromSearchParams,- hasProjectPermissionV2,- type SearchParams,-} from "@/utils";-import {- getValueFromSearchParams,- getValuesFromSearchParams,-} from "@/utils/v1/advanced-search/common";--const ORDER_KEYS = ["creator", "create_time", "expire_time"];--const props = defineProps<{- projectId: string;-}>();--const { width: windowWidth } = useWindowSize();-const { t } = useI18n();-const router = useRouter();-const dialog = useDialog();-const accessGrantStore = useAccessGrantStore();-const showTimeRange = ref(false);--const projectName = computed(() => `${projectNamePrefix}${props.projectId}`);-const { project } = useProjectByName(projectName);--const pagedTableRef = ref<ComponentExposed<typeof PagedTable<AccessGrant>>>();--const hasJITFeature = featureToRef(PlanFeature.FEATURE_JIT);-const canList = computed(() =>- hasProjectPermissionV2(project.value, "bb.accessGrants.list")-);-const canActivate = computed(() =>- hasProjectPermissionV2(project.value, "bb.accessGrants.activate")-);-const canRevoke = computed(() =>- hasProjectPermissionV2(project.value, "bb.accessGrants.revoke")-);--const searchParams = ref<SearchParams>({- query: "",- scopes: [],-});--const scopeOptions = computed(() => {- return getAccessSearchOptions({- project: project.value.name,- showCreator: true,- });-});--const filter = computed((): AccessFilter => {- const f: AccessFilter = {};- const statuses = getValuesFromSearchParams(- searchParams.value,- "status"- ) as AccessGrantFilterStatus[];- f.status = statuses;-- const creator = getValueFromSearchParams(- searchParams.value,- "creator",- undefined- );- if (creator) {- f.creator = `users/${creator}`;- }- const database = getValueFromSearchParams(- searchParams.value,- "database",- undefined- );- if (database) {- f.target = database;- }- const queryText = searchParams.value.query.trim();- if (queryText) {- f.statement = queryText;- }-- const createdTsRange = getTsRangeFromSearchParams(- searchParams.value,- "created"- );- if (createdTsRange) {- f.createdTsAfter = createdTsRange[0];- f.createdTsBefore = createdTsRange[1];- }- return f;-});--const fetchList = async ({- pageToken,- pageSize,- orderBy,-}: {- pageToken: string;- pageSize: number;- orderBy?: string;-}) => {- const response = await accessGrantStore.listAccessGrants({- parent: projectName.value,- filter: filter.value,- pageSize,- pageToken: pageToken || undefined,- orderBy: orderBy ?? "",- });- return {- nextPageToken: response.nextPageToken,- list: response.accessGrants,- };-};--watch(- () => JSON.stringify(filter.value),- () => pagedTableRef.value?.refresh()-);--const getDatabaseNames = (targets: string[]) => {- return targets.map((target) => {- const match = target.match(/databases\/(.+)$/);- return match ? match[1] : target;- });-};--const handleActivate = (grant: AccessGrant) => {- dialog.info({- title: t("sql-editor.activate-access"),- content: t("sql-editor.activate-confirm"),- negativeText: t("common.cancel"),- positiveText: t("sql-editor.activate-access"),- onPositiveClick: async () => {- await accessGrantStore.activateAccessGrant(grant.name);- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.activated"),- });- pagedTableRef.value?.refresh();- },- });-};--const handleRevoke = (grant: AccessGrant) => {- dialog.warning({- title: t("sql-editor.revoke-access"),- content: t("sql-editor.revoke-confirm"),- negativeText: t("common.cancel"),- positiveText: t("sql-editor.revoke-access"),- onPositiveClick: async () => {- await accessGrantStore.revokeAccessGrant(grant.name);- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("common.revoked"),- });- pagedTableRef.value?.refresh();- },- });-};--const isWideScreen = computed(() => windowWidth.value >= 1280);--const columns = computed((): DataTableColumn<AccessGrant>[] => [- {- key: "status",- title: t("common.status"),- width: 100,- render: (grant) => {- const status = getAccessGrantDisplayStatus(grant);- return h(- NTag,- {- type: getAccessGrantStatusTagType(status),- size: "small",- bordered: false,- },- { default: () => getAccessGrantDisplayStatusText(grant) }- );- },- },- {- key: "creator",- title: t("common.creator"),- width: 180,- ellipsis: true,- render: (grant) => extractUserEmail(grant.creator),- },- ...(isWideScreen.value- ? ([- {- key: "create_time",- title: t("common.created-at"),- width: 180,- render: (grant: AccessGrant) => {- if (!grant.createTime) return "-";- const ms = getTimeForPbTimestampProtoEs(grant.createTime);- return h("span", { class: "text-sm" }, formatAbsoluteDateTime(ms));- },- },- {- key: "expire_time",- title: t("common.expiration"),- sortOrder: false as const,- width: 180,- render: (grant: AccessGrant) => {- const info = getAccessGrantExpirationText(grant);- if (info.type !== "datetime") return "-";- return h("span", { class: "text-sm" }, info.value);- },- },- ] as DataTableColumn<AccessGrant>[])- : []),- {- key: "query",- title: t("common.statement"),- render: (grant) => {- return (- <NTooltip>- {{- trigger: () => (- <div class="flex items-center gap-x-1 overflow-hidden">- <span class="font-mono text-xs truncate shrink">- {grant.query}- </span>- {grant.unmask && (- <NTag- class="shrink-0"- size="small"- type="warning"- round={true}- bordered={false}- >- {t("sql-editor.grant-type-unmask")}- </NTag>- )}- </div>- ),- default: () => (- <pre class="max-w-lg whitespace-pre-wrap">{grant.query}</pre>- ),- }}- </NTooltip>- );- },- },- {- key: "targets",- title: t("common.databases"),- width: 200,- render: (grant) => {- const targets = grant.targets;- if (targets.length === 0) return "-";- const renderLink = (target: string): VNodeChild => {- const name = getDatabaseNames([target])[0];- return h(- "span",- {- class: "normal-link hover:underline cursor-pointer text-sm",- onClick: () => router.push({ path: `/${target}` }),- },- name- );- };- const visible = targets.slice(0, 2);- const rest = targets.length - visible.length;- const children: VNodeChild[] = [];- visible.forEach((t, i) => {- if (i > 0) children.push(h("span", { class: "text-sm" }, ", "));- children.push(renderLink(t));- });- if (rest > 0) {- children.push(- h("span", { class: "text-sm text-control-placeholder" }, ` +${rest}`)- );- }- const inline = h(- "div",- { class: "flex items-center truncate gap-x-0.5" },- children- );- if (rest <= 0) return inline;- return h(- NTooltip,- { style: "background: white; color: inherit" },- {- trigger: () => inline,- default: () =>- h(- "div",- { class: "flex flex-col gap-y-1" },- targets.map((t) => renderLink(t))- ),- }- );- },- },- {- key: "actions",- title: "",- width: 160,- render: (grant) => {- const buttons: VNode[] = [];- const status = getAccessGrantDisplayStatus(grant);- if (status === "REVOKED" && canActivate.value) {- buttons.push(- h(- NButton,- {- tertiary: true,- size: "tiny",- type: "primary",- onClick: () => handleActivate(grant),- },- () => t("sql-editor.activate-access")- )- );- }- if (status === "ACTIVE" && canRevoke.value) {- buttons.push(- h(- NButton,- {- tertiary: true,- size: "tiny",- type: "error",- onClick: () => handleRevoke(grant),- },- () => t("sql-editor.revoke-access")- )- );- }- if (grant.issue) {- const issuePath = grant.issue.startsWith("/")- ? grant.issue- : `/${grant.issue}`;- buttons.push(- h(- "a",- {- href: issuePath,- target: "_blank",- onClick: (e: Event) => e.stopPropagation(),- },- h(NButton, { tertiary: true, size: "tiny" }, () =>- t("sql-editor.view-issue")- )- )- );- }- return h(- "div",- { class: "flex items-center justify-end gap-x-1" },- buttons- );- },- },-]);--const getSortedColumns = (sorters: DataTableSortState[]) =>- mapSorterStatus(columns.value, sorters);-</script>