Skip to content

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

chore: optimize access grant ux (#19413)

ecmadao91b76c05b5ab
diff --git a/frontend/src/utils/accessGrant.ts b/frontend/src/utils/accessGrant.ts
index d7f55106b1..2b096862b8 100644
--- a/frontend/src/utils/accessGrant.ts
+++ b/frontend/src/utils/accessGrant.ts
@@ -1,5 +1,14 @@
import dayjs from "dayjs";
+import { h } from "vue";
+import BBAvatar from "@/bbkit/BBAvatar.vue";
+import type {
+ ScopeOption,
+ ValueOption,
+} from "@/components/AdvancedSearch/types";
+import YouTag from "@/components/misc/YouTag.vue";
+import { RichDatabaseName } from "@/components/v2";
import { t } from "@/plugins/i18n";
+import { useCurrentUserV1, useDatabaseV1Store, useUserStore } from "@/store";
import { getTimeForPbTimestampProtoEs } from "@/types";
import {
type AccessGrant,
@@ -10,6 +19,8 @@ import {
Issue_ApprovalStatus,
IssueStatus,
} from "@/types/proto-es/v1/issue_service_pb";
+import { getDefaultPagination } from "@/utils/pagination";
+import { extractDatabaseResourceName } from "@/utils/v1/database";
export type AccessGrantFilterStatus =
| "ACTIVE"
@@ -132,3 +143,111 @@ export const getAccessGrantStatusTagType = (
return "default";
}
};
+
+export const getAccessSearchOptions = ({
+ project,
+ showCreator,
+}: {
+ project: string;
+ showCreator: boolean;
+}): ScopeOption[] => {
+ const databaseStore = useDatabaseV1Store();
+ const userStore = useUserStore();
+ const me = useCurrentUserV1();
+
+ const options: ScopeOption[] = [
+ {
+ id: "status",
+ title: t("common.status"),
+ allowMultiple: true,
+ options: [
+ {
+ value: AccessGrant_Status[AccessGrant_Status.ACTIVE],
+ keywords: ["active"],
+ render: () => t("common.active"),
+ },
+ {
+ value: AccessGrant_Status[AccessGrant_Status.PENDING],
+ keywords: ["pending"],
+ render: () => t("common.pending"),
+ },
+ {
+ value: "EXPIRED",
+ keywords: ["expired"],
+ render: () => t("sql-editor.expired"),
+ },
+ {
+ value: AccessGrant_Status[AccessGrant_Status.REVOKED],
+ keywords: ["revoked"],
+ render: () => t("common.revoked"),
+ },
+ ],
+ },
+ {
+ id: "database",
+ title: t("common.database"),
+ search: ({ keyword, nextPageToken: pageToken }) =>
+ databaseStore
+ .fetchDatabases({
+ parent: project,
+ pageToken: pageToken,
+ pageSize: getDefaultPagination(),
+ filter: { query: keyword },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.databases.map<ValueOption>((db) => {
+ const { database: dbName } = extractDatabaseResourceName(db.name);
+ return {
+ value: db.name,
+ keywords: [dbName, db.name],
+ custom: true,
+ render: () =>
+ h(RichDatabaseName, {
+ database: db,
+ showInstance: true,
+ showEngineIcon: true,
+ }),
+ };
+ }),
+ })),
+ },
+ ];
+
+ if (showCreator) {
+ options.push({
+ id: "creator",
+ title: t("common.creator"),
+ search: ({ keyword, nextPageToken: pageToken }) =>
+ userStore
+ .fetchUserList({
+ pageToken,
+ pageSize: getDefaultPagination(),
+ filter: { query: keyword },
+ })
+ .then((resp) => ({
+ nextPageToken: resp.nextPageToken,
+ options: resp.users.map<ValueOption>((user) => ({
+ value: user.email,
+ keywords: [user.email, user.title],
+ render: () => {
+ const children = [
+ h(BBAvatar, { size: "TINY", username: user.title }),
+ h("span", user.title),
+ ];
+ if (user.name === me.value.name) {
+ children.push(h(YouTag));
+ }
+ return h(
+ "div",
+ { class: "flex items-center gap-x-1" },
+ children
+ );
+ },
+ })),
+ })),
+ });
+ }
+
+ return options;
+};
diff --git a/frontend/src/views/project/ProjectAccessGrantDashboard.vue b/frontend/src/views/project/ProjectAccessGrantDashboard.vue
index 588f0c3f6d..f3dd0cba02 100644
--- a/frontend/src/views/project/ProjectAccessGrantDashboard.vue
+++ b/frontend/src/views/project/ProjectAccessGrantDashboard.vue
@@ -81,16 +81,9 @@ import type { ComponentExposed } from "vue-component-type-helpers";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBAttention } from "@/bbkit";
-import BBAvatar from "@/bbkit/BBAvatar.vue";
import AdvancedSearch, { TimeRange } from "@/components/AdvancedSearch";
-import type {
- ScopeOption,
- ValueOption,
-} from "@/components/AdvancedSearch/types";
import { FeatureAttention } from "@/components/FeatureGuard";
-import YouTag from "@/components/misc/YouTag.vue";
import ComponentPermissionGuard from "@/components/Permission/ComponentPermissionGuard.vue";
-import { RichDatabaseName } from "@/components/v2";
import PagedTable from "@/components/v2/Model/PagedTable.vue";
import { mapSorterStatus } from "@/components/v2/Model/utils";
import {
@@ -98,26 +91,19 @@ import {
featureToRef,
pushNotification,
useAccessGrantStore,
- useCurrentUserV1,
- useDatabaseV1Store,
useProjectByName,
- useUserStore,
} from "@/store";
import { extractUserEmail, projectNamePrefix } from "@/store/modules/v1/common";
import { getTimeForPbTimestampProtoEs } from "@/types";
-import {
- type AccessGrant,
- AccessGrant_Status,
-} from "@/types/proto-es/v1/access_grant_service_pb";
+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,
- extractDatabaseResourceName,
getAccessGrantDisplayStatus,
getAccessGrantDisplayStatusText,
getAccessGrantExpirationText,
getAccessGrantStatusTagType,
- getDefaultPagination,
+ getAccessSearchOptions,
getTsRangeFromSearchParams,
hasProjectPermissionV2,
type SearchParams,
@@ -127,7 +113,6 @@ import {
getValuesFromSearchParams,
} from "@/utils/v1/advanced-search/common";
-const PAGE_SIZE = getDefaultPagination();
const ORDER_KEYS = ["creator", "create_time", "expire_time"];
const props = defineProps<{
@@ -137,9 +122,6 @@ const props = defineProps<{
const { t } = useI18n();
const router = useRouter();
const dialog = useDialog();
-const me = useCurrentUserV1();
-const userStore = useUserStore();
-const databaseStore = useDatabaseV1Store();
const accessGrantStore = useAccessGrantStore();
const showTimeRange = ref(false);
@@ -164,91 +146,12 @@ const searchParams = ref<SearchParams>({
scopes: [],
});
-const scopeOptions = computed((): ScopeOption[] => [
- {
- id: "status",
- title: t("common.status"),
- allowMultiple: true,
- options: [
- {
- value: AccessGrant_Status[AccessGrant_Status.ACTIVE],
- keywords: ["active"],
- render: () => t("common.active"),
- },
- {
- value: AccessGrant_Status[AccessGrant_Status.PENDING],
- keywords: ["pending"],
- render: () => t("common.pending"),
- },
- {
- value: "EXPIRED",
- keywords: ["expired"],
- render: () => t("sql-editor.expired"),
- },
- {
- value: AccessGrant_Status[AccessGrant_Status.REVOKED],
- keywords: ["revoked"],
- render: () => t("common.revoked"),
- },
- ],
- },
- {
- id: "creator",
- title: t("common.creator"),
- search: ({ keyword, nextPageToken: pageToken }) =>
- userStore
- .fetchUserList({
- pageToken,
- pageSize: PAGE_SIZE,
- filter: { query: keyword },
- })
- .then((resp) => ({
- nextPageToken: resp.nextPageToken,
- options: resp.users.map<ValueOption>((user) => ({
- value: user.email,
- keywords: [user.email, user.title],
- render: () => {
- const children = [
- h(BBAvatar, { size: "TINY", username: user.title }),
- h("span", user.title),
- ];
- if (user.name === me.value.name) {
- children.push(h(YouTag));
- }
- return h("div", { class: "flex items-center gap-x-1" }, children);
- },
- })),
- })),
- },
- {
- id: "database",
- title: t("common.database"),
- search: ({ keyword, nextPageToken: pageToken }) =>
- databaseStore
- .fetchDatabases({
- parent: projectName.value,
- pageToken: pageToken,
- pageSize: PAGE_SIZE,
- filter: { query: keyword },
- })
- .then((resp) => ({
- nextPageToken: resp.nextPageToken,
- options: resp.databases.map<ValueOption>((db) => {
- const { database: dbName } = extractDatabaseResourceName(db.name);
- return {
- value: db.name,
- keywords: [dbName, db.name],
- render: () =>
- h(RichDatabaseName, {
- database: db,
- showInstance: true,
- showEngineIcon: true,
- }),
- };
- }),
- })),
- },
-]);
+const scopeOptions = computed(() => {
+ return getAccessSearchOptions({
+ project: project.value.name,
+ showCreator: true,
+ });
+});
const filter = computed((): AccessFilter => {
const f: AccessFilter = {};
diff --git a/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessGrantRequestDrawer.vue b/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessGrantRequestDrawer.vue
index 3b55e0b2f0..2daa232c7e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessGrantRequestDrawer.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessGrantRequestDrawer.vue
@@ -68,7 +68,8 @@
type="datetime"
:is-date-disabled="isDateDisabled"
clearable
- :actions="['clear', 'confirm']"
+ :actions="null"
+ :update-value-on-close="true"
/>
</div>
diff --git a/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessPane.vue b/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessPane.vue
index 2f73bf9886..a05fc53e4a 100644
--- a/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessPane.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/AccessPane/AccessPane.vue
@@ -2,7 +2,7 @@
<div class="relative w-full h-full flex flex-col justify-start items-start gap-y-1">
<div
ref="containerRef"
- class="w-full px-1 flex flex-wrap items-center gap-x-2 gap-y-1"
+ class="w-full px-1 flex flex-wrap items-center gap-x-2 gap-y-2"
>
<AdvancedSearch
class="flex-1"
@@ -21,6 +21,7 @@
:permissions="[
'bb.accessGrants.create'
]"
+ class="ml-auto"
>
<NButton
ghost
@@ -89,17 +90,11 @@
<script lang="ts" setup>
import { useElementSize } from "@vueuse/core";
import { NButton } from "naive-ui";
-import { computed, h, nextTick, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
+import { computed, nextTick, ref, watch } from "vue";
import AdvancedSearch from "@/components/AdvancedSearch";
-import type {
- ScopeOption,
- ValueOption,
-} from "@/components/AdvancedSearch/types";
import { FeatureBadge } from "@/components/FeatureGuard";
import MaskSpinner from "@/components/misc/MaskSpinner.vue";
import PermissionGuardWrapper from "@/components/Permission/PermissionGuardWrapper.vue";
-import { RichDatabaseName } from "@/components/v2";
import { useExecuteSQL } from "@/composables/useExecuteSQL";
import {
type AccessFilter,
@@ -120,7 +115,7 @@ import type { Issue } from "@/types/proto-es/v1/issue_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
import {
type AccessGrantFilterStatus,
- extractDatabaseResourceName,
+ getAccessSearchOptions,
getDefaultPagination,
type SearchParams,
} from "@/utils";
@@ -134,11 +129,9 @@ import AccessGrantRequestDrawer from "./AccessGrantRequestDrawer.vue";
const PAGE_SIZE = getDefaultPagination();
-const { t } = useI18n();
const projectStore = useProjectV1Store();
const editorStore = useSQLEditorStore();
const tabStore = useSQLEditorTabStore();
-const databaseStore = useDatabaseV1Store();
const accessGrantStore = useAccessGrantStore();
const issueStore = useIssueV1Store();
const { instance: currentInstance } = useConnectionOfCurrentSQLEditorTab();
@@ -187,68 +180,11 @@ const searchParams = ref<SearchParams>({
],
});
-const scopeOptions = computed((): ScopeOption[] => {
- const options: ScopeOption[] = [
- {
- id: "status",
- title: t("common.status"),
- allowMultiple: true,
- options: [
- {
- value: AccessGrant_Status[AccessGrant_Status.ACTIVE],
- keywords: ["active"],
- render: () => t("common.active"),
- },
- {
- value: AccessGrant_Status[AccessGrant_Status.PENDING],
- keywords: ["pending"],
- render: () => t("common.pending"),
- },
- {
- value: "EXPIRED",
- keywords: ["expired"],
- render: () => t("sql-editor.expired"),
- },
- {
- value: AccessGrant_Status[AccessGrant_Status.REVOKED],
- keywords: ["revoked"],
- render: () => t("common.revoked"),
- },
- ],
- },
- ];
- const project = editorStore.project;
- if (project) {
- options.push({
- id: "database",
- title: t("common.database"),
- search: ({ keyword, nextPageToken: pageToken }) =>
- databaseStore
- .fetchDatabases({
- parent: project,
- pageToken: pageToken,
- pageSize: PAGE_SIZE,
- filter: { query: keyword },
- })
- .then((resp) => ({
- nextPageToken: resp.nextPageToken,
- options: resp.databases.map<ValueOption>((db) => {
- const { database: dbName } = extractDatabaseResourceName(db.name);
- return {
- value: db.name,
- keywords: [dbName, db.name],
- render: () =>
- h(RichDatabaseName, {
- database: db,
- showInstance: true,
- showEngineIcon: true,
- }),
- };
- }),
- })),
- });
- }
- return options;
+const scopeOptions = computed(() => {
+ return getAccessSearchOptions({
+ project: editorStore.project,
+ showCreator: false,
+ });
});
const selectedStatuses = computed(
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
index 503fad675d..f3abff3fb3 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/DataTable/common/selection-logic.ts
@@ -13,7 +13,7 @@ import {
import { useI18n } from "vue-i18n";
import { pushNotification } from "@/store";
import type { QueryRow, RowValue } from "@/types/proto-es/v1/sql_service_pb";
-import { extractSQLRowValuePlain, isDescendantOf } from "@/utils";
+import { extractSQLRowValuePlain } from "@/utils";
import { type SQLResultViewContext } from "../../context";
import {
type BinaryFormatContext,
@@ -22,8 +22,6 @@ import {
} from "./binary-format-store";
import type { ResultTableColumn, ResultTableRow } from "./types";
-const PREVENT_DISMISS_SELECTION = "bb-prevent-dismiss-selection";
-
export type SelectionState = {
rows: number[];
columns: number[];
@@ -125,14 +123,6 @@ export const provideSelectionContext = ({
};
};
- useEventListener("click", (e) => {
- if (copying.value) return;
- if (isDescendantOf(e.target as Element, `.${PREVENT_DISMISS_SELECTION}`)) {
- return;
- }
- deselect();
- });
-
const getFormattedValue = ({
value,
colIndex,