Skip to content

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

chore: deprecate legacy bbkit (#9992)

ecmadao161a5be17ea2
diff --git a/frontend/src/bbkit/BBAlertDialog.vue b/frontend/src/bbkit/BBAlertDialog.vue
deleted file mode 100644
index aac8038f9d..0000000000
--- a/frontend/src/bbkit/BBAlertDialog.vue
+++ /dev/null
@@ -1,210 +0,0 @@
-<template>
- <div
- v-if="state.visible"
- v-zindexable="{ enabled: true }"
- class="fixed inset-0 overflow-y-auto"
- >
- <div
- class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"
- >
- <!--
- Background overlay, show/hide based on modal state.
-
- Entering: "ease-out duration-300"
- From: "opacity-0"
- To: "opacity-100"
- Leaving: "ease-in duration-200"
- From: "opacity-100"
- To: "opacity-0"
- -->
- <div class="fixed inset-0 transition-opacity" aria-hidden="true">
- <div class="absolute inset-0 bg-gray-500 opacity-75"></div>
- </div>
-
- <!-- This element is to trick the browser into centering the modal contents. -->
- <span
- class="hidden sm:inline-block sm:align-middle sm:h-screen"
- aria-hidden="true"
- >&#8203;</span
- >
- <!--
- Modal panel, show/hide based on modal state.
-
- Entering: "ease-out duration-300"
- From: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
- To: "opacity-100 translate-y-0 sm:scale-100"
- Leaving: "ease-in duration-200"
- From: "opacity-100 translate-y-0 sm:scale-100"
- To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
- -->
- <div
- class="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6"
- role="dialog"
- aria-modal="true"
- aria-labelledby="modal-headline"
- >
- <div class="sm:flex sm:flex-col sm:items-start">
- <div class="flex items-start">
- <div
- v-if="style == 'SUCCESS'"
- class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10"
- >
- <!-- Heroicons name: outline/exclamation -->
- <heroicons-outline:exclamation class="h-6 w-6 text-success" />
- </div>
- <div
- v-else-if="style == 'WARN'"
- class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-yellow-100 sm:mx-0 sm:h-10 sm:w-10"
- >
- <!-- Heroicons name: outline/exclamation -->
- <heroicons-outline:exclamation class="h-6 w-6 text-yellow-600" />
- </div>
- <div
- v-else-if="style == 'CRITICAL'"
- class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10"
- >
- <!-- Heroicons name: outline/exclamation -->
- <heroicons-outline:exclamation class="h-6 w-6 text-red-600" />
- </div>
- <div
- v-else
- class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-blue-100 sm:mx-0 sm:h-10 sm:w-10"
- >
- <!-- Heroicons name: outline/exclamation -->
- <heroicons-outline:exclamation class="h-6 w-6 text-blue-600" />
- </div>
- <h3
- id="modal-headline"
- class="ml-4 flex self-center text-lg leading-6 font-medium text-gray-900"
- >
- {{ $t(title) }}
- </h3>
- </div>
- <div
- v-if="description"
- class="mt-3 text-center sm:mt-0 sm:ml-14 sm:text-left"
- >
- <div class="mt-2">
- <p class="text-gray-500 whitespace-pre-wrap">
- {{ $t(description) }}
- </p>
- </div>
- </div>
- </div>
- <div class="mt-4 flex flex-col space-y-4">
- <div class="flex justify-end">
- <button
- type="button"
- class="btn-normal mt-3 px-4 py-2 sm:mt-0 sm:w-auto"
- data-label="bb-alert-cancel-button"
- :disabled="inProgress"
- @click.prevent="onNegativeClick"
- >
- {{ $t(cancelText) }}
- </button>
- <button
- type="button"
- class="sm:ml-3 inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-error text-base font-medium text-white focus:outline-none focus-visible:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:w-auto sm:text-sm"
- data-label="bb-alert-ok-button"
- :class="okButtonStyle"
- :disabled="inProgress"
- @click.prevent="onPositiveClick()"
- >
- {{ $t(okText) }}
- </button>
- </div>
- <div v-if="inProgress" class="flex flex-row justify-end items-center">
- <BBSpin />{{ progressText }}
- </div>
- </div>
- </div>
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { useEventListener } from "@vueuse/core";
-import { zindexable as vZindexable } from "vdirs";
-import { withDefaults, computed, reactive } from "vue";
-import { Defer, defer } from "@/utils";
-import { BBAlertStyle } from "./types";
-
-const props = withDefaults(
- defineProps<{
- style?: BBAlertStyle;
- title: string;
- description?: string;
- okText?: string;
- cancelText?: string;
- inProgress?: boolean;
- progressText?: string;
- onBeforePositiveClick?: () => boolean;
- onBeforeNegativeClick?: () => boolean;
- }>(),
- {
- style: "INFO",
- description: "",
- okText: "bbkit.common.ok",
- cancelText: "bbkit.common.cancel",
- inProgress: false,
- progressText: "",
- onBeforeNegativeClick: undefined,
- onBeforePositiveClick: undefined,
- }
-);
-
-const state = reactive({
- visible: false,
- defer: undefined as Defer<boolean> | undefined,
-});
-
-const open = () => {
- if (state.defer) {
- state.defer.reject(new Error("duplicated call"));
- }
-
- state.defer = defer<boolean>();
- state.visible = true;
-
- return state.defer.promise;
-};
-
-const onPositiveClick = () => {
- if (props.onBeforePositiveClick) {
- if (!props.onBeforePositiveClick()) {
- return;
- }
- }
-
- state.visible = false;
- state.defer?.resolve(true);
-};
-
-const onNegativeClick = () => {
- if (props.onBeforeNegativeClick) {
- if (!props.onBeforeNegativeClick()) {
- return;
- }
- }
-
- state.visible = false;
- state.defer?.resolve(false);
-};
-
-defineExpose({ open });
-
-useEventListener(document, "keydown", (e) => {
- if (!props.inProgress && e.code == "Escape") {
- onNegativeClick();
- }
-});
-
-const buttonStyleMap: Record<string, string> = {
- INFO: "btn-primary",
- SUCCESS: "btn-success",
- WARN: "btn-primary",
- CRITICAL: "btn-danger",
-};
-
-const okButtonStyle = computed(() => buttonStyleMap[props.style]);
-</script>
diff --git a/frontend/src/bbkit/BBButtonAdd.vue b/frontend/src/bbkit/BBButtonAdd.vue
deleted file mode 100644
index 48eec13a7b..0000000000
--- a/frontend/src/bbkit/BBButtonAdd.vue
+++ /dev/null
@@ -1,14 +0,0 @@
-<template>
- <button
- class="items-center flex justify-center btn-icon-primary"
- @click.prevent="$emit('add')"
- >
- <heroicons-solid:plus class="w-6 h-6" />
- </button>
-</template>
-
-<script lang="ts" setup>
-defineEmits<{
- (event: "add"): void;
-}>();
-</script>
diff --git a/frontend/src/bbkit/BBComboBox.vue b/frontend/src/bbkit/BBComboBox.vue
deleted file mode 100644
index 6c2d987bf6..0000000000
--- a/frontend/src/bbkit/BBComboBox.vue
+++ /dev/null
@@ -1,285 +0,0 @@
-<template>
- <VBinder>
- <VTarget>
- <div
- ref="button"
- class="btn-select relative pl-3 pr-10"
- :class="[
- disabled && '!bg-control-bg opacity-50 !cursor-not-allowed',
- state.open && 'ring-1 ring-control border-control',
- ]"
- v-bind="$attrs"
- @click="toggle"
- >
- <div class="relative h-9 py-1.5">
- <template v-if="state.value && !state.open">
- <slot name="menuItem" :item="state.value" />
- </template>
- <template v-if="!state.value && !state.query">
- <slot name="placeholder" :placeholder="placeholder">
- {{ placeholder }}
- </slot>
- </template>
- <input
- v-if="!disabled"
- v-model="state.query"
- type="text"
- class="absolute w-full h-full inset-0 p-0 border-none focus:border-transparent focus:ring-0"
- :class="{
- 'opacity-0': !state.open,
- }"
- @compositionstart="state.compositing = true"
- @compositionend="state.compositing = false"
- @keydown="handleKeyEvent"
- />
- </div>
- <span
- class="ml-3 absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none"
- >
- <heroicons-solid:selector class="h-5 w-5 text-control-light" />
- </span>
- </div>
- </VTarget>
- <VFollower :show="state.open" placement="bottom-start">
- <transition :appear="true" name="fade-fast">
- <div
- v-if="state.open"
- ref="popup"
- class="z-50 rounded-md bg-white shadow-lg mt-0.5"
- v-bind="dataLabelAttrs"
- :style="{ width: `${width}px` }"
- >
- <ul
- tabindex="-1"
- role="listbox"
- aria-labelledby="listbox-label"
- aria-activedescendant="listbox-item-3"
- class="max-h-56 rounded-md py-1 ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm"
- >
- <!--
- Select option, manage highlight styles based on mouseenter/mouseleave and keyboard navigation.
- Highlighted: "text-white bg-indigo-600", Not Highlighted: "text-gray-900"
- -->
- <li
- v-for="(item, index) in state.filteredOptions"
- :key="index"
- :ref="(el: any) => (itemRefs[index] = el)"
- role="option"
- class="text-main cursor-default select-none relative py-2 pl-3 pr-9"
- :class="index === state.activeIndex && 'bg-gray-200'"
- @click="doSelect(item)"
- @mouseover="state.activeIndex = index"
- >
- <slot name="menuItem" :item="item" />
- <span
- v-if="item === state.value"
- class="absolute inset-y-0 right-0 flex items-center pr-4"
- >
- <heroicons-solid:check class="h-5 w-5" />
- </span>
- </li>
- </ul>
- </div>
- </transition>
- </VFollower>
- </VBinder>
-</template>
-
-<script lang="ts" setup>
-import { reactive, watch, ref, withDefaults } from "vue";
-import { VBinder, VTarget, VFollower } from "vueuc";
-import { onClickOutside, useElementBounding } from "@vueuse/core";
-import useDataLabelAttrs from "@/composables/useDataLabelAttrs";
-import { isAncestorOf, scrollIntoViewIfNeeded } from "./BBUtil";
-
-export type ItemType = number | string | object | any;
-
-type LocalState = {
- open: boolean;
- value: ItemType | undefined;
- query: string;
- compositing: boolean;
- filteredOptions: ItemType[];
- activeIndex: number;
- activeItem: ItemType | undefined;
-};
-
-const props = withDefaults(
- defineProps<{
- value?: ItemType | undefined;
- options: ItemType[];
- placeholder?: string;
- disabled?: boolean;
- filter?: (
- options: ItemType[],
- query: string
- ) => ItemType[] | Promise<ItemType[]>;
- }>(),
- {
- value: undefined,
- placeholder: "",
- disabled: false,
- filter: async (options: ItemType[]) => options,
- }
-);
-
-const emit = defineEmits<{
- (event: "update:value", value: ItemType): void;
-}>();
-
-const state = reactive<LocalState>({
- open: false,
- value: props.value,
- query: "",
- compositing: false,
- filteredOptions: props.options,
- activeIndex: props.options.indexOf(props.value),
- activeItem: props.value,
-});
-
-const dataLabelAttrs = useDataLabelAttrs("", "-item");
-
-const button = ref<HTMLButtonElement>();
-const popup = ref<HTMLElement>();
-const itemRefs = ref<HTMLElement[]>([]);
-
-// Sync the popup's width to the button's
-const { width } = useElementBounding(button);
-
-watch(
- () => props.value,
- (cur) => {
- state.value = cur;
- state.activeIndex = props.options.indexOf(cur);
- state.activeItem = cur;
- }
-);
-
-const close = () => {
- state.open = false;
- state.compositing = false;
-};
-
-const open = () => {
- state.open = true;
- state.query = "";
- state.compositing = false;
-};
-
-const toggle = () => {
- if (props.disabled) {
- return;
- }
-
- if (!state.open) open();
- else close();
-};
-
-onClickOutside(popup, (e) => {
- if (button.value) {
- if (isAncestorOf(button.value, e.target as HTMLElement)) {
- // Do not close the popup when clicking on the button
- return;
- }
- }
- // Otherwise close the popup
- close();
-});
-
-watch(
- () => [state.query, props.options, state.compositing],
- (args) => {
- const [query, options, compositing] = args as [string, ItemType[], boolean];
- if (compositing) {
- // Will do nothing if the IME is compositing
- return;
- }
- if (!query) {
- // Won't call filter function if query is empty
- state.filteredOptions = options;
- } else {
- const result = props.filter(options, query);
- if (Array.isArray(result)) {
- // If filter function returns an Array, set value directly
- state.filteredOptions = result;
- } else {
- // Otherwise it's a Promise<Array>, wait.
- result.then((filteredOptions) => {
- if (query === state.query) {
- // Only to set value when query matches
- // In case that the async filter function does not response as quickly as query changes.
- state.filteredOptions = filteredOptions;
- }
- });
- }
- }
- }
-);
-
-watch(
- () => state.filteredOptions,
- (newList) => {
- // Try to keep activeIndex correct when filteredOptions changed
- // Find the new index of the selected item
- if (state.activeItem) {
- const newIndex = newList.indexOf(state.activeItem);
- state.activeIndex = newIndex; // -1 or some index
- state.activeItem = newList[newIndex]; // undefined or some item
- }
- }
-);
-
-const doSelect = (item: ItemType) => {
- if (item !== state.value) {
- emit("update:value", item);
- }
- close();
-};
-
-const moveIndex = (diff: number) => {
- const max = state.filteredOptions.length;
- const index = state.activeIndex + diff;
- if (index < 0 || index >= max) return;
-
- // Change activeIndex if it doesn't exceed the boundary
- state.activeIndex = index;
- state.activeItem = state.filteredOptions[index];
-
- const elem = itemRefs.value[index];
- if (elem) {
- scrollIntoViewIfNeeded(elem);
- }
-};
-
-const handleKeyEvent = (e: KeyboardEvent) => {
- if (e.key === "ArrowUp") {
- e.preventDefault();
- moveIndex(-1);
- }
- if (e.key === "ArrowDown") {
- e.preventDefault();
- moveIndex(1);
- }
- if (e.key === "Enter") {
- e.preventDefault();
- const index = state.activeIndex;
- const list = state.filteredOptions;
- if (index >= 0 && index < list.length) {
- doSelect(list[index]);
- }
- }
-};
-
-watch(
- () => props.disabled,
- (disabled) => {
- if (!disabled) close();
- }
-);
-</script>
-
-<script lang="ts">
-export default {
- inheritAttrs: false,
-};
-</script>
diff --git a/frontend/src/bbkit/BBDialog.vue b/frontend/src/bbkit/BBDialog.vue
index 8e521c98b3..2d6908c201 100644
--- a/frontend/src/bbkit/BBDialog.vue
+++ b/frontend/src/bbkit/BBDialog.vue
@@ -10,22 +10,16 @@
<slot name="default"></slot>
<div class="pt-4 border-t border-block-border flex justify-end space-x-3">
- <button
- v-if="showNegativeBtn"
- type="button"
- class="btn-normal py-2 px-4"
- @click.prevent="onNegativeClick"
- >
+ <NButton v-if="showNegativeBtn" @click.prevent="onNegativeClick">
{{ negativeText || $t("common.cancel") }}
- </button>
- <button
- type="button"
- class="btn-primary py-2 px-4"
+ </NButton>
+ <NButton
+ type="primary"
data-label="bb-modal-confirm-button"
@click.prevent="onPositiveClick"
>
{{ positiveText || $t("common.confirm") }}
- </button>
+ </NButton>
</div>
</BBModal>
</template>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 40b27adcd4..593d6283ce 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -1,12 +1,9 @@
import BBAlert from "./BBAlert.vue";
-import BBAlertDialog from "./BBAlertDialog.vue";
import BBAttention from "./BBAttention.vue";
import BBAvatar from "./BBAvatar.vue";
import BBBetaBadge from "./BBBetaBadge.vue";
-import BBButtonAdd from "./BBButtonAdd.vue";
import BBButtonConfirm from "./BBButtonConfirm.vue";
import BBCheckbox from "./BBCheckbox.vue";
-import BBComboBox from "./BBComboBox.vue";
import BBContextMenu from "./BBContextMenu.vue";
import BBContextMenuButton from "./BBContextMenuButton.vue";
import BBDialog from "./BBDialog.vue";
@@ -36,11 +33,9 @@ export * from "./types";
export {
BBAlert,
- BBAlertDialog,
BBAttention,
BBAvatar,
BBTooltipButton,
- BBButtonAdd,
BBButtonConfirm,
BBCheckbox,
BBContextMenu,
@@ -50,7 +45,6 @@ export {
BBNotification,
BBOutline,
BBSelect,
- BBComboBox,
BBProgressPie,
BBSpin,
BBStepBar,
diff --git a/frontend/src/components/AuditLog/AuditLogTable.vue b/frontend/src/components/AuditLog/AuditLogTable.vue
index fb05ac01aa..b651b436c0 100644
--- a/frontend/src/components/AuditLog/AuditLogTable.vue
+++ b/frontend/src/components/AuditLog/AuditLogTable.vue
@@ -21,7 +21,7 @@
>
</BBTableCell>
<BBTableCell class="table-cell w-28 whitespace-nowrap">
- {{ t(AuditActivityTypeI18nNameMap[auditLog.action]) }}
+ {{ t(AuditActivityTypeI18nNameMap.get(auditLog.action) ?? "") }}
</BBTableCell>
<BBTableCell class="table-cell w-20">
<UserByEmail :email="auditLog.creator" :plain="true" />
diff --git a/frontend/src/components/AuditLog/TypeSelect.vue b/frontend/src/components/AuditLog/TypeSelect.vue
index 374b0d9ae1..c5a101ed79 100644
--- a/frontend/src/components/AuditLog/TypeSelect.vue
+++ b/frontend/src/components/AuditLog/TypeSelect.vue
@@ -1,36 +1,41 @@
<template>
- <BBSelect
- :multiple="true"
- :selected-item-list="selectedTypeList"
- :item-list="typeList"
+ <NSelect
+ v-bind="$attrs"
+ multiple
+ :value="selected"
+ :options="options"
+ :disabled="disabled"
+ max-tag-count="responsive"
:placeholder="$t('audit-log.table.select-type')"
- @update-item-list="(list: LogEntity_Action[]) => $emit('update-selected-type-list', list)"
- >
- <template #menuItem="{ item }">
- {{ $t(getLabel(item)) }}
- </template>
- <template #menuItemGroup="{ itemList }">
- <ResponsiveTags
- :tags="itemList.map((item: LogEntity_Action) => $t(getLabel(item)))"
- />
- </template>
- </BBSelect>
+ @update:value="$emit('update:selected', $event)"
+ />
</template>
<script lang="ts" setup>
-import { PropType } from "vue";
+import { NSelect, SelectOption } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
import { AuditActivityTypeI18nNameMap } from "@/types";
import { LogEntity_Action } from "@/types/proto/v1/logging_service";
-defineProps({
- selectedTypeList: {
- type: Array as PropType<LogEntity_Action[]>,
- required: true,
- },
-});
-defineEmits(["update-selected-type-list"]);
+defineProps<{
+ selected: LogEntity_Action[];
+ disabled: boolean;
+}>();
+defineEmits<{
+ (event: "update:selected", selected: LogEntity_Action[]): void;
+}>();
+
+const { t } = useI18n();
-const typeList = Object.keys(AuditActivityTypeI18nNameMap);
-const getLabel = (type: LogEntity_Action): string =>
- AuditActivityTypeI18nNameMap[type];
+const options = computed(() => {
+ const resp: SelectOption[] = [];
+ for (const [key, val] of AuditActivityTypeI18nNameMap.entries()) {
+ resp.push({
+ value: key,
+ label: t(val),
+ });
+ }
+ return resp;
+});
</script>
diff --git a/frontend/src/components/MemberSelect.vue b/frontend/src/components/MemberSelect.vue
deleted file mode 100644
index 2efbda3fc4..0000000000
--- a/frontend/src/components/MemberSelect.vue
+++ /dev/null
@@ -1,174 +0,0 @@
-<template>
- <BBComboBox
- :value="selectedPrincipal"
- :options="userList"
- :filter="filter"
- :placeholder="placeholder"
- :disabled="disabled"
- v-bind="$attrs"
- @update:value="
- (user: User) => {
- state.selectedId = extractUserUID(user.name);
- $emit('select-user-id', state.selectedId);
- }
- "
- >
- <template #menuItem="{ item }: { item: User }">
- <!--TODO(tianzhou): Have to set a fixed width, otherwise the width would change based on the selected text.
- Likely, there is a better solution, while the author doesn't want to fight with CSS for now.
- The specific value and breakpoint is to make it align with other select in the issue sidebar.
- -->
- <span class="flex lg:40 xl:w-44 items-center space-x-2">
- <!-- Show a special avatar for "All" -->
- <div
- v-if="showAll && extractUserUID(item.name) === String(UNKNOWN_ID)"
- class="w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white"
- >
- <heroicons-outline:user class="w-4 h-4 text-main" />
- </div>
- <!-- Show the initial letters by default -->
- <UserAvatar v-else :user="item" size="SMALL" />
- <span class="truncate">{{ item.title }}</span>
- </span>
- </template>
- <template #placeholder>
- <span class="leading-6 truncate" :class="required ? 'text-error' : ''">{{
- $t(placeholder)
- }}</span>
- </template>
- </BBComboBox>
-</template>
-
-<script lang="ts" setup>
-import { reactive, computed, watch, PropType } from "vue";
-import { useI18n } from "vue-i18n";
-import { hasFeature, useUserStore } from "@/store";
-import { User, UserRole, UserType } from "@/types/proto/v1/auth_service";
-import { State } from "@/types/proto/v1/common";
-import { BBComboBox } from "../bbkit";
-import {
- SYSTEM_BOT_ID,
- UNKNOWN_ID,
- SYSTEM_BOT_USER_NAME,
- unknownUser,
- filterUserListByKeyword,
-} from "../types";
-import { extractUserUID } from "../utils";
-import UserAvatar from "./User/UserAvatar.vue";
-
-interface LocalState {
- selectedId: string | undefined;
- showMenu: boolean;
-}
-
-const props = defineProps({
- selectedId: {
- type: String,
- default: undefined,
- },
- disabled: {
- default: false,
- type: Boolean,
- },
- showAll: {
- type: Boolean,
- default: false,
- },
- showSystemBot: {
- type: Boolean,
- default: false,
- },
- allowedRoleList: {
- default: () => [UserRole.OWNER, UserRole.DBA, UserRole.DEVELOPER],
- type: Array as PropType<UserRole[]>,
- },
- placeholder: {
- default: "settings.members.not-assigned",
- type: String,
- },
- required: {
- default: true,
- type: Boolean,
- },
- customFilter: {
- type: Function as PropType<(user: User) => boolean>,
- default: undefined,
- },
-});
-
-defineEmits<{
- (event: "select-user-id", uid: string): void;
-}>();
-
-const state = reactive<LocalState>({
- selectedId: props.selectedId,
- showMenu: false,
-});
-const { t } = useI18n();
-const userStore = useUserStore();
-
-const userList = computed((): User[] => {
- const list = userStore.userList.filter((user) => {
- return user.state === State.ACTIVE && user.userType === UserType.USER;
- });
- // If system bot is the selected ID (e.g. when issue is created by the bot on observing new sql file),
- // Then we add system bot to the list so it can display properly.
- if (props.selectedId === String(SYSTEM_BOT_ID) || props.showSystemBot) {
- const systemBotIndex = list.findIndex(
- (user) => user.name === SYSTEM_BOT_USER_NAME
- );
- if (systemBotIndex >= 0) {
- const systemBotUser = list[systemBotIndex];
- list.splice(systemBotIndex, 1);
- list.unshift(systemBotUser);
- } else {
- list.unshift(userStore.getUserByName(SYSTEM_BOT_USER_NAME)!);
- }
- }
- // If `showAll` is true, we insert a virtual user before the list.
- if (props.showAll) {
- const dummyAll = {
- ...unknownUser(),
- title: t("common.all"),
- };
- list.unshift(dummyAll);
- }
- const hasRBACFeature = hasFeature("bb.feature.rbac");
- return list.filter((user) => {
- // The previously selected item might no longer be applicable.
- // e.g. The select limits to DBA only and the selected principal is no longer a DBA
- // in such case, we still show the item.
- if (extractUserUID(user.name) === props.selectedId) {
- return true;
- }
-
- if (typeof props.customFilter === "function") {
- return props.customFilter(user);
- }
-
- if (!hasRBACFeature) return true;
-
- if (props.allowedRoleList.length === 0) {
- // Need not to filter by workspace role.
- return true;
- }
-
- return props.allowedRoleList.includes(user.userRole);
- });
-});
-
-watch(
- () => props.selectedId,
- (cur) => {
- state.selectedId = cur;
- }
-);
-
-const selectedPrincipal = computed(() =>
- userList.value.find((user) => extractUserUID(user.name) === state.selectedId)
-);
-
-const filter = (options: User[], query: string): User[] => {
- return filterUserListByKeyword(options, query);
-};
-</script>
diff --git a/frontend/src/components/SQLReview/SQLReviewCreation.vue b/frontend/src/components/SQLReview/SQLReviewCreation.vue
index ea7017f815..029343ce3e 100644
--- a/frontend/src/components/SQLReview/SQLReviewCreation.vue
+++ b/frontend/src/components/SQLReview/SQLReviewCreation.vue
@@ -31,24 +31,15 @@
/>
</template>
</BBStepTab>
- <BBAlertDialog
- ref="alertDialog"
- :style="'CRITICAL'"
- :ok-text="$t('common.confirm')"
- :title="$t('sql-review.create.configure-rule.confirm-override-title')"
- :description="
- $t('sql-review.create.configure-rule.confirm-override-description')
- "
- >
- </BBAlertDialog>
</div>
</template>
<script lang="ts" setup>
-import { reactive, computed, withDefaults, ref } from "vue";
+import { useDialog } from "naive-ui";
+import { reactive, computed, withDefaults } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { BBAlertDialog, BBStepTab } from "@/bbkit";
+import { BBStepTab } from "@/bbkit";
import { BBStepTabItem } from "@/bbkit/types";
import {
useCurrentUserV1,
@@ -98,7 +89,7 @@ const props = withDefaults(
const emit = defineEmits(["cancel"]);
-const alertDialog = ref<InstanceType<typeof BBAlertDialog>>();
+const dialog = useDialog();
const { t } = useI18n();
const router = useRouter();
const store = useSQLReviewStore();
@@ -196,11 +187,16 @@ const tryChangeStep = (
) => {
if (oldStep === 0 && newStep === 1) {
if (state.pendingApplyTemplate) {
- alertDialog.value!.open().then((result) => {
- if (result) {
+ dialog.warning({
+ title: t("sql-review.create.configure-rule.confirm-override-title"),
+ content: t(
+ "sql-review.create.configure-rule.confirm-override-description"
+ ),
+ positiveText: t("common.confirm"),
+ onPositiveClick: (_: MouseEvent) => {
onTemplateApply(state.pendingApplyTemplate);
allowChangeCallback();
- }
+ },
});
return;
}
diff --git a/frontend/src/components/User/Settings/UserTable.vue b/frontend/src/components/User/Settings/UserTable.vue
index 235de24349..e0924aa9b5 100644
--- a/frontend/src/components/User/Settings/UserTable.vue
+++ b/frontend/src/components/User/Settings/UserTable.vue
@@ -160,20 +160,13 @@
@ok="resetServiceKey"
@cancel="state.showResetKeyAlert = false"
/>
- <BBAlertDialog
- ref="removeSelfOwnerDialog"
- :style="'CRITICAL'"
- :ok-text="$t('common.confirm')"
- :title="$t('settings.members.remove-self-admin.title')"
- :description="$t('settings.members.remove-self-admin.description')"
- />
</template>
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
-import { computed, reactive, ref } from "vue";
+import { useDialog } from "naive-ui";
+import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
-import { BBAlertDialog } from "@/bbkit";
import { BBTableSectionDataSource } from "@/bbkit/types";
import { WorkspaceRoleSelect } from "@/components/v2";
import {
@@ -213,10 +206,10 @@ const props = defineProps<{
userList: User[];
}>();
+const dialog = useDialog();
const { t } = useI18n();
const currentUserV1 = useCurrentUserV1();
const userStore = useUserStore();
-const removeSelfOwnerDialog = ref<InstanceType<typeof BBAlertDialog>>();
const hasRBACFeature = featureToRef("bb.feature.rbac");
@@ -359,20 +352,25 @@ const changeRole = async (user: User, role: UserRole) => {
const me = currentUserV1.value;
if (user.name === me.name) {
if (user.userRole === UserRole.OWNER && role !== UserRole.OWNER) {
- const dialog = removeSelfOwnerDialog.value;
- if (!dialog) {
- throw new Error("dialog is not loaded");
- }
- const result = await dialog.open();
- if (!result) {
- return;
- }
+ dialog.warning({
+ title: t("settings.members.remove-self-admin.title"),
+ content: t("settings.members.remove-self-admin.description"),
+ positiveText: t("common.confirm"),
+ onPositiveClick: (_: MouseEvent) => {
+ updateUserRole(user, role);
+ },
+ });
+ return;
}
}
+ await updateUserRole(user, role);
+};
+
+const updateUserRole = async (user: User, role: UserRole) => {
const userPatch = cloneDeep(user);
userPatch.userRole = role;
- userStore.updateUser({
+ await userStore.updateUser({
user: userPatch,
updateMask: ["role"],
regenerateTempMfaSecret: false,
diff --git a/frontend/src/types/auditLog.ts b/frontend/src/types/auditLog.ts
index c17625b3f9..e6adb31eae 100644
--- a/frontend/src/types/auditLog.ts
+++ b/frontend/src/types/auditLog.ts
@@ -17,18 +17,31 @@ export const AuditActivityTypeList = [
LogEntity_Action.ACTION_DATABASE_SQL_EXPORT,
];
-export const AuditActivityTypeI18nNameMap: { [key: number]: string } = {
- [LogEntity_Action.ACTION_MEMBER_CREATE]:
- "audit-log.type.workspace.member-create",
- [LogEntity_Action.ACTION_MEMBER_ROLE_UPDATE]:
- "audit-log.type.workspace.member-role-update",
- [LogEntity_Action.ACTION_MEMBER_ACTIVATE]:
- "audit-log.type.workspace.member-activate",
- [LogEntity_Action.ACTION_MEMBER_DEACTIVE]:
- "audit-log.type.workspace.member-deactivate",
- [LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER]:
- "audit-log.type.project.database-transfer",
- [LogEntity_Action.ACTION_DATABASE_SQL_EDITOR_QUERY]:
- "audit-log.type.sql-editor-query",
- [LogEntity_Action.ACTION_DATABASE_SQL_EXPORT]: "audit-log.type.sql-export",
-};
+export const AuditActivityTypeI18nNameMap: Map<LogEntity_Action, string> =
+ new Map([
+ [
+ LogEntity_Action.ACTION_MEMBER_CREATE,
+ "audit-log.type.workspace.member-create",
+ ],
+ [
+ LogEntity_Action.ACTION_MEMBER_ROLE_UPDATE,
+ "audit-log.type.workspace.member-role-update",
+ ],
+ [
+ LogEntity_Action.ACTION_MEMBER_ACTIVATE,
+ "audit-log.type.workspace.member-activate",
+ ],
+ [
+ LogEntity_Action.ACTION_MEMBER_DEACTIVE,
+ "audit-log.type.workspace.member-deactivate",
+ ],
+ [
+ LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER,
+ "audit-log.type.project.database-transfer",
+ ],
+ [
+ LogEntity_Action.ACTION_DATABASE_SQL_EDITOR_QUERY,
+ "audit-log.type.sql-editor-query",
+ ],
+ [LogEntity_Action.ACTION_DATABASE_SQL_EXPORT, "audit-log.type.sql-export"],
+ ]);
diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vue
index 25d7d6ec3d..0eba7e1ef7 100644
--- a/frontend/src/views/SettingWorkspaceAuditLog.vue
+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue
@@ -2,27 +2,21 @@
<div class="w-full space-y-4">
<FeatureAttention feature="bb.feature.audit-log" />
<div class="flex justify-end items-center space-x-2">
- <MemberSelect
- class="w-52"
- :disabled="!hasAuditLogFeature"
- :show-all="true"
- :show-system-bot="true"
- :selected-id="selectedUserUID"
- @select-user-id="selectUser"
+ <UserSelect
+ v-model:user="state.userUid"
+ :multiple="false"
+ :include-all="true"
/>
<div class="w-52">
<TypeSelect
+ v-model:selected="state.selectedAuditTypeList"
:disabled="!hasAuditLogFeature"
- :selected-type-list="selectedAuditTypeList"
- :item-list="AuditActivityTypeList"
- @update-selected-type-list="selectAuditType"
/>
</div>
<div class="hidden sm:block w-112">
<NDatePicker
v-model:value="selectedTimeRange"
type="datetimerange"
- size="large"
:on-confirm="confirmDatePicker"
:on-clear="clearDatePicker"
clearable
@@ -30,7 +24,7 @@
</NDatePicker>
</div>
<DataExportButton
- size="large"
+ size="medium"
:support-formats="[
ExportFormat.CSV,
ExportFormat.JSON,
@@ -95,7 +89,7 @@
import dayjs from "dayjs";
import { NGrid, NGi, NDatePicker } from "naive-ui";
import { BinaryLike } from "node:crypto";
-import { reactive, ref, computed } from "vue";
+import { reactive, ref, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
import { BBDialog } from "@/bbkit";
@@ -115,8 +109,9 @@ import {
const dialog = ref<InstanceType<typeof BBDialog> | null>(null);
const state = reactive({
- showModal: false,
modalContent: {},
+ userUid: String(UNKNOWN_ID),
+ selectedAuditTypeList: [] as LogEntity_Action[],
});
const { t } = useI18n();
@@ -136,13 +131,31 @@ const logKeyMap = {
payload: t("audit-log.table.payload"),
};
-const selectedUserUID = computed((): string => {
- const id = route.query.user as string;
- if (id) {
- return id;
+watch(
+ () => state.userUid,
+ (uid) => {
+ router.replace({
+ name: "setting.workspace.audit-log",
+ query: {
+ ...route.query,
+ user: parseInt(uid, 10) > 0 ? uid : undefined,
+ },
+ });
}
- return String(UNKNOWN_ID);
-});
+);
+
+watch(
+ () => state.selectedAuditTypeList,
+ (list) => {
+ router.replace({
+ name: "setting.workspace.audit-log",
+ query: {
+ ...route.query,
+ type: list.join(","),
+ },
+ });
+ }
+);
const selectedUserEmail = computed((): string => {
const id = route.query.user as string;
@@ -150,18 +163,6 @@ const selectedUserEmail = computed((): string => {
return selected?.email ?? "";
});
-const selectedAuditTypeList = computed((): LogEntity_Action[] => {
- const typeList = route.query.type as string;
- if (typeList) {
- if (typeList.includes(",")) {
- return typeList.split(",").map((n) => Number(n) as LogEntity_Action);
- } else {
- return [Number(typeList) as LogEntity_Action];
- }
- }
- return [];
-});
-
const selectedTimeRange = computed((): [number, number] => {
const defaultTimeRange = [0, Date.now()] as [number, number];
const createdTsAfter = route.query.createdTsAfter as string;
@@ -189,7 +190,10 @@ const handleViewDetail = (log: LogEntity) => {
case "level":
return [logKey, logEntity_LevelToJSON(log.level)];
case "action":
- return [logKey, t(AuditActivityTypeI18nNameMap[log.action])];
+ return [
+ logKey,
+ t(AuditActivityTypeI18nNameMap.get(log.action) ?? ""),
+ ];
case "creator":
return [logKey, log.creator];
case "comment":
@@ -201,41 +205,9 @@ const handleViewDetail = (log: LogEntity) => {
})
.filter((arr) => arr.length === 2)
);
- state.showModal = true;
dialog.value!.open();
};
-const selectUser = (user: string) => {
- router.replace({
- name: "setting.workspace.audit-log",
- query: {
- ...route.query,
- user: parseInt(user, 10) > 0 ? user : undefined,
- },
- });
-};
-
-const selectAuditType = (typeList: LogEntity_Action[]) => {
- if (typeList.length === 0) {
- // Clear `type=` query string if no type selected.
- const query = Object.assign({}, route.query);
- delete query.type;
-
- router.replace({
- name: "setting.workspace.audit-log",
- query,
- });
- } else {
- router.replace({
- name: "setting.workspace.audit-log",
- query: {
- ...route.query,
- type: typeList.join(","),
- },
- });
- }
-};
-
const confirmDatePicker = (value: [number, number]) => {
router.replace({
name: "setting.workspace.audit-log",
@@ -261,8 +233,8 @@ const clearDatePicker = () => {
const activityFind = computed((): FindActivityMessage => {
return {
action:
- selectedAuditTypeList.value.length > 0
- ? selectedAuditTypeList.value
+ state.selectedAuditTypeList.length > 0
+ ? state.selectedAuditTypeList
: AuditActivityTypeList,
creatorEmail: selectedUserEmail.value,
order: "desc",