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: some frontend optimize (#18446)
ecmadaoc5ac677e75eb
diff --git a/frontend/src/components/IdentityProvider/IdentityProviderCreateWizard.vue b/frontend/src/components/IdentityProvider/IdentityProviderCreateWizard.vueindex e6f32dda7d..ec364282b5 100644--- a/frontend/src/components/IdentityProvider/IdentityProviderCreateWizard.vue+++ b/frontend/src/components/IdentityProvider/IdentityProviderCreateWizard.vue@@ -216,6 +216,7 @@</label><BBTextFieldv-model:value="identityProvider.domain"+ :disabled="selectedTemplate?.domainDisabled"size="large"class="w-full text-base":placeholder="$t('settings.sso.form.domain-description')"@@ -455,6 +456,7 @@ import { Drawer, DrawerContent } from "@/components/v2";import ResourceIdField from "@/components/v2/Form/ResourceIdField.vue";import { SETTING_ROUTE_WORKSPACE_GENERAL } from "@/router/dashboard/workspaceSetting";import {+ hasFeature,pushNotification,useActuatorV1Store,useSubscriptionV1Store,@@ -487,6 +489,7 @@ import TestConnection from "./TestConnection.vue";interface IdentityProviderTemplate extends OAuth2IdentityProviderTemplate {feature: PlanFeature;+ domainDisabled?: boolean;}const props = defineProps<{@@ -612,6 +615,7 @@ const templateList = computed((): IdentityProviderTemplate[] => {title: "Google",name: "",domain: "google.com",+ domainDisabled: !hasFeature(PlanFeature.FEATURE_ENTERPRISE_SSO),type: IdentityProviderType.OAUTH2,feature: PlanFeature.FEATURE_GOOGLE_AND_GITHUB_SSO,config: createProto(OAuth2IdentityProviderConfigSchema, {@@ -638,6 +642,7 @@ const templateList = computed((): IdentityProviderTemplate[] => {title: "GitHub",name: "",domain: "github.com",+ domainDisabled: !hasFeature(PlanFeature.FEATURE_ENTERPRISE_SSO),type: IdentityProviderType.OAUTH2,feature: PlanFeature.FEATURE_GOOGLE_AND_GITHUB_SSO,config: createProto(OAuth2IdentityProviderConfigSchema, {diff --git a/frontend/src/components/Role/Setting/components/ImportPermissionFromRoleModal.vue b/frontend/src/components/Role/Setting/components/ImportPermissionFromRoleModal.vueindex 90faf7d96d..8a1df4bd70 100644--- a/frontend/src/components/Role/Setting/components/ImportPermissionFromRoleModal.vue+++ b/frontend/src/components/Role/Setting/components/ImportPermissionFromRoleModal.vue@@ -25,7 +25,7 @@:key="permission"class="text-sm leading-5">- {{ displayPermissionTitle(permission) }}+ {{ permission }}</p></div></div>@@ -52,7 +52,6 @@ import { computed, reactive } from "vue";import { BBModal } from "@/bbkit";import { useRoleStore } from "@/store";import { displayRoleDescription, displayRoleTitle } from "@/utils";-import { displayPermissionTitle } from "@/utils/permission";interface LocalState {selectedRole?: string;diff --git a/frontend/src/components/Role/Setting/components/RolePanel.vue b/frontend/src/components/Role/Setting/components/RolePanel.vueindex 36e8d4dbf3..7ce1723828 100644--- a/frontend/src/components/Role/Setting/components/RolePanel.vue+++ b/frontend/src/components/Role/Setting/components/RolePanel.vue@@ -122,7 +122,6 @@ import type { Role } from "@/types/proto-es/v1/role_service_pb";import { RoleSchema } from "@/types/proto-es/v1/role_service_pb";import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";import { extractRoleResourceName } from "@/utils";-import { displayPermissionTitle } from "@/utils/permission";import { useCustomRoleSettingContext } from "../context";import ImportPermissionFromRoleModal from "./ImportPermissionFromRoleModal.vue";@@ -165,7 +164,7 @@ const resourceId = computed({const permissionOptions = computed(() => {return PERMISSIONS.sort().map((p) => ({- label: displayPermissionTitle(p),+ label: p,value: p,}));});diff --git a/frontend/src/utils/collections.ts b/frontend/src/utils/collections.tsindex fd7d4b19d8..754c28ccff 100644--- a/frontend/src/utils/collections.ts+++ b/frontend/src/utils/collections.ts@@ -19,16 +19,6 @@ export const keyBy = <T, K>(array: T[], keyOf: (item: T) => K): Map<K, T> => {}, new Map<K, T>());};-export const wrapArray = <T>(arrayOrPrimitive: T | T[]): T[] => {- if (Array.isArray(arrayOrPrimitive)) return arrayOrPrimitive;- return [arrayOrPrimitive];-};--export const unwrapArray = <T>(arrayOrPrimitive: T | T[]): T => {- if (Array.isArray(arrayOrPrimitive)) return arrayOrPrimitive[0];- return arrayOrPrimitive;-};-export const upsertArray = <T>(array: T[], item: T) => {const index = array.indexOf(item);if (index < 0) {diff --git a/frontend/src/utils/databaseGroup/cel.ts b/frontend/src/utils/databaseGroup/cel.tsdeleted file mode 100644index c72c7bf7d9..0000000000--- a/frontend/src/utils/databaseGroup/cel.ts+++ /dev/null@@ -1,15 +0,0 @@-import { emptySimpleExpr, resolveCELExpr, wrapAsGroup } from "@/plugins/cel";-import type { Expr } from "@/types/proto-es/google/api/expr/v1alpha1/syntax_pb";-import { batchConvertCELStringToParsedExpr } from "@/utils";--export const convertCELStringToExpr = async (cel: string) => {- let expr: Expr | undefined;- if (cel) {- const celExpr = await batchConvertCELStringToParsedExpr([cel]);- expr = celExpr[0];- }- if (!expr) {- return emptySimpleExpr();- }- return wrapAsGroup(resolveCELExpr(expr));-};diff --git a/frontend/src/utils/databaseGroup/issue.ts b/frontend/src/utils/databaseGroup/issue.tsdeleted file mode 100644index f3fe231a34..0000000000--- a/frontend/src/utils/databaseGroup/issue.ts+++ /dev/null@@ -1,36 +0,0 @@-import dayjs from "dayjs";-import type { LocationQueryRaw } from "vue-router";-import { t } from "@/plugins/i18n";-import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";-import type { DatabaseGroup } from "@/types/proto-es/v1/database_group_service_pb";-import { extractProjectResourceName } from "../v1";--export const generateDatabaseGroupIssueRoute = (- type: "bb.issue.database.update",- databaseGroup: DatabaseGroup,- sql = ""-) => {- const issueNameParts: string[] = [];- issueNameParts.push(`[${databaseGroup.title}]`);- issueNameParts.push(t("issue.title.change-database"));- const datetime = dayjs().format("@MM-DD HH:mm");- const tz = "UTC" + dayjs().format("ZZ");- issueNameParts.push(`${datetime} ${tz}`);-- const query: LocationQueryRaw = {- template: type,- name: issueNameParts.join(" "),- databaseGroupName: databaseGroup.name,- sql,- };-- return {- name: PROJECT_V1_ROUTE_ISSUE_DETAIL,- params: {- projectId: extractProjectResourceName(databaseGroup.name),- issueSlug: "create",- planId: "create",- },- query,- };-};diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex 388d31af6a..ce6c432f9e 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -1,6 +1,5 @@export * from "./css";export * from "./collections";-export * from "./link";export * from "./role";export * from "./slug";export * from "./types";@@ -16,7 +15,6 @@ export * from "./sso";export * from "./math";export * from "./idp";export * from "./workspaceApprovalSetting";-export * from "./resource-composer";export * from "./TinyTimer";export * from "./sheet";export * from "./naive-ui";diff --git a/frontend/src/utils/link.ts b/frontend/src/utils/link.tsdeleted file mode 100644index 3e70bed16b..0000000000--- a/frontend/src/utils/link.ts+++ /dev/null@@ -1,13 +0,0 @@-import type { ResourceType } from "../types";--const resourceToPrefix = new Map([["DATABASE", "/db"]]);--export function linkfy(type: ResourceType, id: string): string {- return [resourceToPrefix.get(type), id].join("/");-}--export function absolutifyLink(rel: string): string {- const anchor = document.createElement("a");- anchor.setAttribute("href", rel);- return anchor.href;-}diff --git a/frontend/src/utils/localStorage.ts b/frontend/src/utils/localStorage.tsdeleted file mode 100644index 7a89eb9f84..0000000000--- a/frontend/src/utils/localStorage.ts+++ /dev/null@@ -1,3 +0,0 @@-export const getComponentIdLocalStorageKey = (component: string): string => {- return `bb.components.${component}.id`;-};diff --git a/frontend/src/utils/naive-ui.ts b/frontend/src/utils/naive-ui.tsindex a3161f2e1b..535cc8a4b7 100644--- a/frontend/src/utils/naive-ui.ts+++ b/frontend/src/utils/naive-ui.ts@@ -3,7 +3,7 @@ import type { DataTableInst, VirtualListInst } from "naive-ui";import { computed, type MaybeRef, ref, unref } from "vue";import { nextAnimationFrame } from "./dom";-export type AutoHeightDataTableOptions = {+type AutoHeightDataTableOptions = {maxHeight: number | null;};const defaultAutoHeightDataTableOptions = (): AutoHeightDataTableOptions => ({diff --git a/frontend/src/utils/permission.ts b/frontend/src/utils/permission.tsdeleted file mode 100644index 5e7f4d32f3..0000000000--- a/frontend/src/utils/permission.ts+++ /dev/null@@ -1,6 +0,0 @@-// displayPermissionTitle return the formatted permission title.-// Some API users may need to check permissions from the UI.-// We will show the raw permission for now till we support more readable UX and have docs for these permissions.-export const displayPermissionTitle = (permission: string): string => {- return permission;-};diff --git a/frontend/src/utils/resource-composer.ts b/frontend/src/utils/resource-composer.tsdeleted file mode 100644index 82da432182..0000000000--- a/frontend/src/utils/resource-composer.ts+++ /dev/null@@ -1,17 +0,0 @@-type RequestFn = () => Promise<any>;--export class ResourceComposer {- requests: Record<string, RequestFn> = {};- collect(resource: string, request: RequestFn) {- this.requests[resource] = request;- }- compose(method: "all" | "allSettled" = "all") {- const distinctRequests: Promise<void>[] = [];- for (const resource of Object.keys(this.requests)) {- distinctRequests.push(this.requests[resource]());- }- return method === "all"- ? Promise.all(distinctRequests)- : Promise.allSettled(distinctRequests);- }-}diff --git a/frontend/src/utils/schemaEditor/index.ts b/frontend/src/utils/schemaEditor/index.tsindex 9738f5b477..9e09ad699b 100644--- a/frontend/src/utils/schemaEditor/index.ts+++ b/frontend/src/utils/schemaEditor/index.ts@@ -1,4 +1,3 @@-import type { ComposedDatabase } from "@/types";import { Engine } from "@/types/proto-es/v1/common_pb";export * from "./filter";@@ -7,14 +6,6 @@ export const engineSupportsSchemaEditor = (engine: Engine) => {return [Engine.MYSQL, Engine.TIDB, Engine.POSTGRES].includes(engine);};-export const allowUsingSchemaEditor = (- databaseList: ComposedDatabase[]-): boolean => {- return databaseList.every((db) => {- return engineSupportsSchemaEditor(db.instanceResource.engine);- });-};-export const getDataTypeSuggestionList = (engine: Engine = Engine.MYSQL) => {if (engine === Engine.MYSQL || engine === Engine.TIDB) {return [diff --git a/frontend/src/utils/sqlEditor.ts b/frontend/src/utils/sqlEditor.tsindex 298cc914a6..477c4d09b1 100644--- a/frontend/src/utils/sqlEditor.ts+++ b/frontend/src/utils/sqlEditor.ts@@ -26,6 +26,8 @@ import {} from "@/types/proto-es/v1/org_policy_service_pb";import { instanceV1AllowsCrossDatabaseQuery } from "./v1/instance";+export const NEW_WORKSHEET_TITLE = "new worksheet";+export const defaultSQLEditorTab = (): SQLEditorTab => {return {id: uuidv1(),@@ -90,6 +92,14 @@ export const isSameSQLEditorConnection = (return a.instance === b.instance && a.database === b.database;};+export const isSimilarDefaultSQLEditorTabTitle = (title: string) => {+ if (!title || title === NEW_WORKSHEET_TITLE) {+ return true;+ }+ const regex = /(^|\s)(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})$/;+ return regex.test(title);+};+export const suggestedTabTitleForSQLEditorConnection = (conn: SQLEditorConnection) => {diff --git a/frontend/src/utils/string.ts b/frontend/src/utils/string.tsindex 4310432acf..ad18a3030d 100644--- a/frontend/src/utils/string.ts+++ b/frontend/src/utils/string.ts@@ -1,7 +1,3 @@export const escapeMarkdown = (md: string): string => {return md.replaceAll(/[*_~\-#`[\]()\\]/g, (ch) => `\\${ch}`);};--export const escapeFilename = (str: string): string => {- return str.replace(/[/\\?%*:|"<>]/g, "-");-};diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vueindex 54258f25eb..0a19b71291 100644--- a/frontend/src/views/DashboardHeader.vue+++ b/frontend/src/views/DashboardHeader.vue@@ -94,7 +94,6 @@ import {extractDatabaseResourceName,extractProjectResourceName,} from "@/utils";-import { getComponentIdLocalStorageKey } from "@/utils/localStorage";import BytebaseLogo from "../components/BytebaseLogo.vue";import ProfileBrandingLogo from "../components/ProfileBrandingLogo.vue";import ProfileDropdown from "../components/ProfileDropdown.vue";@@ -191,7 +190,7 @@ const goToMyIssues = () => {record(myIssueLink.value.fullPath);// Trigger page reload manually.useLocalStorage<string>(- getComponentIdLocalStorageKey(WORKSPACE_ROUTE_MY_ISSUES),+ `bb.components.${WORKSPACE_ROUTE_MY_ISSUES}.id`,"").value = uuidv4();};diff --git a/frontend/src/views/MyIssues.vue b/frontend/src/views/MyIssues.vueindex 956e42d59d..6ef91a7c22 100644--- a/frontend/src/views/MyIssues.vue+++ b/frontend/src/views/MyIssues.vue@@ -52,7 +52,6 @@ import {buildSearchParamsBySearchText,buildSearchTextBySearchParams,} from "@/utils";-import { getComponentIdLocalStorageKey } from "@/utils/localStorage";interface LocalState {params: SearchParams;@@ -66,7 +65,7 @@ const issuePagedTable =ref<ComponentExposed<typeof PagedTable<ComposedIssue>>>();const viewId = useLocalStorage<string>(- getComponentIdLocalStorageKey(WORKSPACE_ROUTE_MY_ISSUES),+ `bb.components.${WORKSPACE_ROUTE_MY_ISSUES}.id`,"");diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsxindex 555885e557..ee2aba29a5 100644--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/actions.tsx@@ -28,7 +28,6 @@ import {instanceV1HasAlterSchema,instanceV1HasReadonlyMode,setDefaultDataSourceForConn,- suggestedTabTitleForSQLEditorConnection,} from "@/utils";import { type SQLEditorContext, useSQLEditorContext } from "../../context";@@ -202,33 +201,27 @@ export const setConnection = (options: {options.batchQueryContext);- if (!newTab && tabStore.currentTab) {- tabStore.updateCurrentTab({- mode,- connection,- status: "DIRTY",- batchQueryContext,- });- if (tabStore.currentTab.worksheet) {- context.updateWorksheet({- ...tabStore.currentTab,+ const createOrUpdate = () => {+ if (!newTab && tabStore.currentTab) {+ return context.maybeUpdateWorksheet({tabId: tabStore.currentTab.id,+ worksheet: tabStore.currentTab.worksheet,+ title: tabStore.currentTab.title,database: connection.database,+ statement: tabStore.currentTab.statement,});}- context.asidePanelTab.value = "SCHEMA";- } else {+// create new worksheet and set connection- context- .createWorksheet({- title: suggestedTabTitleForSQLEditorConnection(connection),- database: connection.database,- })- .then((tab) => {- if (tab) {- tabStore.updateTab(tab.id, { mode, batchQueryContext });- context.asidePanelTab.value = "SCHEMA";- }- });- }+ return context.createWorksheet({+ database: connection.database,+ });+ };++ createOrUpdate().then((tab) => {+ if (tab) {+ tabStore.updateTab(tab.id, { mode, batchQueryContext });+ context.asidePanelTab.value = "SCHEMA";+ }+ });};diff --git a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vueindex f28e4c8fc5..36db771ffc 100644--- a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue+++ b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue@@ -77,7 +77,7 @@ const doSaveSheet = async () => {const sheetId = Number(extractWorksheetUID(worksheet ?? ""));if (sheetId !== UNKNOWN_ID) {- await editorContext.updateWorksheet({+ await editorContext.maybeUpdateWorksheet({tabId,worksheet,title: pendingEdit.value.title,diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.tsindex 8d838eb047..a743467c3c 100644--- a/frontend/src/views/sql-editor/context.ts+++ b/frontend/src/views/sql-editor/context.ts@@ -12,14 +12,18 @@ import {useWorkSheetStore,} from "@/store";import type { SQLEditorTab } from "@/types";-import { isValidProjectName } from "@/types";+import { isValidDatabaseName, isValidProjectName } from "@/types";import type { GetSchemaStringRequest_ObjectType } from "@/types/proto-es/v1/database_service_pb";import {- type Worksheet,Worksheet_Visibility,WorksheetSchema,} from "@/types/proto-es/v1/worksheet_service_pb";-import { extractWorksheetConnection } from "@/utils";+import {+ extractWorksheetConnection,+ isSimilarDefaultSQLEditorTabTitle,+ NEW_WORKSHEET_TITLE,+ suggestedTabTitleForSQLEditorConnection,+} from "@/utils";import { openWorksheetByName } from "@/views/sql-editor/Sheet";export type AsidePanelTab = "SCHEMA" | "WORKSHEET" | "HISTORY";@@ -80,14 +84,14 @@ export type SQLEditorContext = {statement?: string;database?: string;}) => Promise<SQLEditorTab | undefined>;- updateWorksheet: (options: {+ maybeUpdateWorksheet: (options: {tabId: string;worksheet: string;- title: string;+ title?: string;database: string;statement: string;folders?: string[];- }) => Promise<Worksheet | undefined>;+ }) => Promise<SQLEditorTab | undefined>;};export const KEY = Symbol(@@ -125,7 +129,7 @@ export const provideSQLEditorContext = () => {};});- const updateWorksheet = async ({+ const maybeUpdateWorksheet = async ({tabId,worksheet,title,@@ -134,51 +138,58 @@ export const provideSQLEditorContext = () => {folders,}: {tabId: string;- worksheet: string;- title: string;+ worksheet?: string;+ title?: string;database: string;statement: string;folders?: string[];}) => {- if (!worksheet) {- return;- }- const currentSheet = worksheetStore.getWorksheetByName(worksheet);- if (!currentSheet) {- return;+ const connection = await extractWorksheetConnection({ database });+ let worksheetTitle = title ?? "";+ if (isSimilarDefaultSQLEditorTabTitle(worksheetTitle)) {+ worksheetTitle = suggestedTabTitleForSQLEditorConnection(connection);}- const updated = await worksheetStore.patchWorksheet(- {- ...currentSheet,- title,- database,- content: new TextEncoder().encode(statement),- },- ["title", "database", "content"]- );- if (updated && !isUndefined(folders)) {- await worksheetStore.upsertWorksheetOrganizer(+ if (worksheet) {+ const currentSheet = worksheetStore.getWorksheetByName(worksheet);+ if (!currentSheet) {+ return;+ }+ if (!isSimilarDefaultSQLEditorTabTitle(currentSheet.title)) {+ worksheetTitle = currentSheet.title;+ }++ const updated = await worksheetStore.patchWorksheet({- worksheet: updated.name,- folders: folders,+ ...currentSheet,+ title: worksheetTitle,+ database,+ content: new TextEncoder().encode(statement),},- ["folders"]+ ["title", "database", "content"]);+ if (updated && !isUndefined(folders)) {+ await worksheetStore.upsertWorksheetOrganizer(+ {+ worksheet: updated.name,+ folders: folders,+ },+ ["folders"]+ );+ }}- tabStore.updateTab(tabId, {+ return tabStore.updateTab(tabId, {status: "CLEAN",- title: updated?.title,- worksheet: updated?.name,+ connection,+ title: worksheetTitle,+ worksheet,});-- return updated;};const createWorksheet = async ({tabId,- title = "new worksheet",+ title,statement = "",folders = [],database = "",@@ -189,9 +200,15 @@ export const provideSQLEditorContext = () => {folders?: string[];database?: string;}) => {+ let worksheetTitle = title || NEW_WORKSHEET_TITLE;+ const connection = await extractWorksheetConnection({ database });+ if (!title && isValidDatabaseName(database)) {+ worksheetTitle = suggestedTabTitleForSQLEditorConnection(connection);+ }+const newWorksheet = await worksheetStore.createWorksheet(create(WorksheetSchema, {- title,+ title: worksheetTitle,database,content: new TextEncoder().encode(statement),project: editorStore.project,@@ -210,10 +227,9 @@ export const provideSQLEditorContext = () => {}if (tabId) {- const connection = await extractWorksheetConnection(newWorksheet);return tabStore.updateTab(tabId, {status: "CLEAN",- title,+ title: worksheetTitle,statement,connection,worksheet: newWorksheet.name,@@ -264,7 +280,7 @@ export const provideSQLEditorContext = () => {aiPanelSize.value = 1 - size;},createWorksheet,- updateWorksheet,+ maybeUpdateWorksheet,};provide(KEY, context);