Skip to content

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

chore: deprecate some bbkits (#10000)

ecmadaod913041e8361
diff --git a/frontend/src/bbkit/BBContextMenuButton.vue b/frontend/src/bbkit/BBContextMenuButton.vue
deleted file mode 100644
index f266f328ae..0000000000
--- a/frontend/src/bbkit/BBContextMenuButton.vue
+++ /dev/null
@@ -1,230 +0,0 @@
-<template>
- <button
- class="select-none h-[38px] inline-flex items-center border rounded-md disabled:opacity-50 disabled:cursor-not-allowed text-sm leading-5 font-medium overflow-hidden focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-2"
- :data-button-type="state.currentAction.type ?? 'NORMAL'"
- :class="actionButtonClass.wrapper"
- :disabled="disabled"
- >
- <div
- class="flex items-center px-4 py-2"
- :class="[actionButtonClass.btn, disabled && 'pointer-events-none']"
- @click.stop="handleClickButton"
- >
- <slot name="default" :action="state.currentAction">
- {{ state.currentAction.text }}
- </slot>
- </div>
-
- <div
- v-if="actionList.length > 1"
- class="flex h-full w-0 border-l"
- :class="actionButtonClass.divider"
- />
-
- <NPopover
- v-if="actionList.length > 1"
- ref="popover"
- :disabled="disabled"
- placement="bottom-end"
- trigger="click"
- raw
- style="box-shadow: none"
- :show-arrow="false"
- >
- <template #trigger>
- <div
- class="flex items-center px-2 h-full"
- :class="[actionButtonClass.btn, disabled && 'pointer-events-none']"
- >
- <heroicons-outline:chevron-down />
- </div>
- </template>
-
- <div
- class="flex flex-col divide-y divide-gray-200 border border-gray-200 rounded-md shadow-md overflow-hidden"
- >
- <slot
- v-for="(action, index) in actionList"
- :key="action.key"
- name="action-item"
- :action="action"
- :index="index"
- :selected="isCurrentAction(action)"
- :click-handler="() => handleClickActionList(action)"
- >
- <div
- class="flex items-center justify-between gap-x-4 py-2 pl-4 pr-2 bg-white cursor-pointer text-sm font-medium text-control hover:bg-main-hover hover:text-white"
- @click.stop="handleClickActionList(action)"
- >
- <span>{{ action.text }}</span>
- <span :class="!isCurrentAction(action) && 'invisible'">
- <heroicons-outline:check />
- </span>
- </div>
- </slot>
- </div>
- </NPopover>
- </button>
-</template>
-
-<script lang="ts" setup>
-import { useLocalStorage } from "@vueuse/core";
-import { NPopover } from "naive-ui";
-import { computed, PropType, reactive, shallowRef, watch } from "vue";
-import { BBButtonType } from "./types";
-
-export type ButtonAction<T = unknown> = {
- key: string;
- text: string;
- type: BBButtonType;
- params: T;
-};
-
-type LocalState = {
- currentAction: ButtonAction;
-};
-
-const STORE_PREFIX = "bb.button-with-context-menu";
-
-const props = defineProps({
- preferenceKey: {
- type: String,
- default: "",
- },
- actionList: {
- type: Array as PropType<ButtonAction[]>,
- required: true,
- },
- defaultActionKey: {
- type: String,
- default: "",
- },
- disabled: {
- type: Boolean,
- default: false,
- },
-});
-
-const emit = defineEmits<{
- (event: "click", action: ButtonAction): void;
-}>();
-
-const popover = shallowRef<InstanceType<typeof NPopover>>();
-
-const getStorage = () => {
- const { preferenceKey } = props;
- if (!preferenceKey) return undefined;
- // e.g key = "bb.button-with-context-menu.task-status-transition"
- const key = `${STORE_PREFIX}.${preferenceKey}`;
- return useLocalStorage(key, props.defaultActionKey, {
- listenToStorageChanges: false,
- });
-};
-
-// Load user stored default action from localStorage if possible.
-// The stored default action may not be in the actionList this time.
-// Fallback to the first action if not found.
-// But we won't mutate the stored value.
-const getDefaultAction = (): ButtonAction => {
- const storage = getStorage();
- if (storage && storage.value) {
- const storedDefaultAction = props.actionList.find(
- (action) => action.key === storage.value
- );
- if (storedDefaultAction) {
- return storedDefaultAction;
- }
- }
- if (props.defaultActionKey) {
- const defaultAction = props.actionList.find(
- (action) => action.key === props.defaultActionKey
- );
- if (defaultAction) {
- return defaultAction;
- }
- }
-
- return props.actionList[0];
-};
-
-const state = reactive<LocalState>({
- currentAction: getDefaultAction(),
-});
-
-const actionButtonClass = computed(() => {
- const { type } = state.currentAction;
- if (type in BUTTON_CLASS_MAP) {
- return BUTTON_CLASS_MAP[type];
- }
- return BUTTON_CLASS_MAP.NORMAL;
-});
-
-const isCurrentAction = (action: ButtonAction) => {
- return action.key === state.currentAction.key;
-};
-
-const handleClickActionList = (action: ButtonAction) => {
- const reset = () => {
- popover.value?.setShow(false);
- };
-
- if (isCurrentAction(action)) return reset();
-
- const storage = getStorage();
- if (storage) {
- // Save the selected action as the default action
- storage.value = action.key;
- }
-
- state.currentAction = action;
-
- reset();
-};
-
-const handleClickButton = () => {
- if (props.disabled) return;
- emit("click", state.currentAction);
-};
-
-watch(
- () => props.actionList,
- () => {
- state.currentAction = getDefaultAction();
- }
-);
-
-const BUTTON_CLASS_MAP: Record<
- BBButtonType,
- {
- wrapper: string;
- btn: string;
- divider: string;
- }
-> = {
- NORMAL: {
- wrapper: "border-control-border text-control disabled:bg-control-bg",
- btn: "bg-white hover:bg-control-bg-hover",
- divider: "border-control-border",
- },
- PRIMARY: {
- wrapper: "border-transparent text-accent-text disabled:bg-accent",
- btn: "bg-accent hover:bg-accent-hover",
- divider: "border-indigo-500",
- },
- SECONDARY: {
- wrapper: "border-control-border text-main disabled:bg-control-bg",
- btn: "bg-white hover:bg-control-bg-hover hover:text-control-hover",
- divider: "border-control-border",
- },
- SUCCESS: {
- wrapper: "border-transparent text-accent-text disabled:bg-success",
- btn: "bg-success hover:bg-success-hover",
- divider: "border-green-500",
- },
- DANGER: {
- wrapper: "border-transparent text-accent-text disabled:bg-error",
- btn: "bg-error hover:bg-error-hover",
- divider: "border-red-500",
- },
-};
-</script>
diff --git a/frontend/src/bbkit/BBLoader.vue b/frontend/src/bbkit/BBLoader.vue
deleted file mode 100644
index bbf889e8a1..0000000000
--- a/frontend/src/bbkit/BBLoader.vue
+++ /dev/null
@@ -1,26 +0,0 @@
-<template>
- <div class="flex flex-row items-center text-control text-sm">
- <svg
- xmlns="http://www.w3.org/2000/svg"
- width="24"
- height="24"
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- stroke-width="2"
- stroke-linecap="round"
- stroke-linejoin="round"
- class="animate-spin h-5 w-5"
- v-bind="$attrs"
- >
- <line x1="12" x2="12" y1="2" y2="6"></line>
- <line x1="12" x2="12" y1="18" y2="22"></line>
- <line x1="4.93" x2="7.76" y1="4.93" y2="7.76"></line>
- <line x1="16.24" x2="19.07" y1="16.24" y2="19.07"></line>
- <line x1="2" x2="6" y1="12" y2="12"></line>
- <line x1="18" x2="22" y1="12" y2="12"></line>
- <line x1="4.93" x2="7.76" y1="19.07" y2="16.24"></line>
- <line x1="16.24" x2="19.07" y1="7.76" y2="4.93"></line>
- </svg>
- </div>
-</template>
diff --git a/frontend/src/bbkit/BBTooltipButton.vue b/frontend/src/bbkit/BBTooltipButton.vue
deleted file mode 100644
index c74dc58388..0000000000
--- a/frontend/src/bbkit/BBTooltipButton.vue
+++ /dev/null
@@ -1,100 +0,0 @@
-<template>
- <NTooltip trigger="manual" :show="state.tooltipVisible" v-bind="tooltipProps">
- <template #trigger>
- <!--
- Allowing to overwrite the entire button
- with manual tooltip control functions
- -->
- <slot
- name="button"
- :show-tooltip="showTooltip"
- :hide-tooltip="hideTooltip"
- >
- <!--
- <button disabled> will swallow all mouse related events such as mouseover/mouseout...
- so we need to handle it manually with lower level DOM pointer events
- -->
- <button
- type="button"
- v-bind="$attrs"
- :disabled="disabled"
- :class="[`btn-${props.type}`, $attrs.class]"
- @click.prevent="$emit('click')"
- @pointerenter="showTooltip"
- @pointerleave="hideTooltip"
- >
- <slot name="default"></slot>
- </button>
- </slot>
- </template>
- <slot name="tooltip"></slot>
- </NTooltip>
-</template>
-
-<script lang="ts">
-export default {
- name: "BBTooltipButton",
- inheritAttrs: false,
-};
-</script>
-
-<script lang="ts" setup>
-import { withDefaults, computed, reactive, watch, useSlots } from "vue";
-import { NTooltip, type TooltipProps } from "naive-ui";
-
-export type ButtonType =
- | "normal"
- | "primary"
- | "secondary"
- | "cancel"
- | "danger"
- | "success";
-
-export type TooltipMode = "ALWAYS" | "DISABLED-ONLY";
-
-const props = withDefaults(
- defineProps<{
- type?: ButtonType;
- disabled: boolean;
- tooltipMode: TooltipMode;
- tooltipProps?: TooltipProps;
- }>(),
- {
- type: "normal",
- disabled: false,
- tooltipMode: "ALWAYS",
- tooltipProps: undefined,
- }
-);
-
-defineEmits<{
- (event: "click"): void;
-}>();
-
-const slots = useSlots();
-
-const state = reactive({
- tooltipVisible: false,
-});
-
-const tooltipEnabled = computed(() => {
- if (props.tooltipMode === "ALWAYS") return true;
- if (!slots.tooltip) return false;
- return props.disabled;
-});
-
-const showTooltip = () => {
- if (!tooltipEnabled.value) return;
- state.tooltipVisible = true;
-};
-
-const hideTooltip = () => {
- state.tooltipVisible = false;
-};
-
-watch(tooltipEnabled, (enable) => {
- if (!enable) {
- state.tooltipVisible = false;
- }
-});
-</script>
diff --git a/frontend/src/bbkit/index.ts b/frontend/src/bbkit/index.ts
index 4728fb07ed..bdd441add5 100644
--- a/frontend/src/bbkit/index.ts
+++ b/frontend/src/bbkit/index.ts
@@ -5,7 +5,6 @@ import BBBetaBadge from "./BBBetaBadge.vue";
import BBButtonConfirm from "./BBButtonConfirm.vue";
import BBCheckbox from "./BBCheckbox.vue";
import BBContextMenu from "./BBContextMenu.vue";
-import BBContextMenuButton from "./BBContextMenuButton.vue";
import BBDialog from "./BBDialog.vue";
import { BBGrid } from "./BBGrid";
import BBModal from "./BBModal.vue";
@@ -22,7 +21,6 @@ import {
BBTableSearch,
} from "./BBTable";
import BBTextField from "./BBTextField.vue";
-import BBTooltipButton from "./BBTooltipButton.vue";
export * from "./types";
@@ -30,11 +28,9 @@ export {
BBAlert,
BBAttention,
BBAvatar,
- BBTooltipButton,
BBButtonConfirm,
BBCheckbox,
BBContextMenu,
- BBContextMenuButton,
BBModal,
BBDialog,
BBNotification,
diff --git a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
index 1fc6c46927..2468541fc2 100644
--- a/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
+++ b/frontend/src/components/DatabaseDetail/PITRRestoreButton.vue
@@ -1,19 +1,19 @@
<template>
<div class="flex relative mr-6">
- <BBTooltipButton
+ <TooltipButton
type="normal"
tooltip-mode="DISABLED-ONLY"
:disabled="pitrButtonDisabled"
@click="openDialog"
>
- <template #button="{ showTooltip, hideTooltip }">
- <BBContextMenuButton
+ <template #default>
+ <ContextMenuButton
preference-key="pitr"
+ :default-action-key="'CUSTOM'"
:action-list="buttonActionList"
:disabled="pitrButtonDisabled"
- @pointerenter="showTooltip"
- @pointerleave="hideTooltip"
- @click="(action) => onClickPITRButton(action)"
+ :size="'medium'"
+ @click="(action) => onClickPITRButton(action as PITRButtonAction)"
>
<template #default="{ action }">
<span>{{ action.text }}</span>
@@ -23,13 +23,13 @@
:instance="database.instanceEntity"
/>
</template>
- </BBContextMenuButton>
+ </ContextMenuButton>
</template>
<template v-if="allowAdmin && !pitrAvailable.result" #tooltip>
{{ pitrAvailable.message }}
</template>
- </BBTooltipButton>
+ </TooltipButton>
<BBBetaBadge corner />
</div>
@@ -150,10 +150,12 @@ import { v4 as uuidv4 } from "uuid";
import { computed, PropType, reactive, ref, toRef } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import BBContextMenuButton, {
- type ButtonAction,
-} from "@/bbkit/BBContextMenuButton.vue";
import { Drawer, DrawerContent } from "@/components/v2";
+import {
+ TooltipButton,
+ ContextMenuButton,
+ ContextMenuButtonAction,
+} from "@/components/v2";
import { usePITRLogic } from "@/plugins";
import {
experimentalCreateIssueByPlan,
@@ -176,7 +178,7 @@ type PITRTarget = "IN-PLACE" | "NEW";
type Mode = "LAST_MIGRATION" | "CUSTOM";
type Step = "LAST_MIGRATION_INFO" | "PITR_FORM";
-type PITRButtonAction = ButtonAction<{ step: Step; mode: Mode }>;
+type PITRButtonAction = ContextMenuButtonAction<{ step: Step; mode: Mode }>;
interface LocalState {
showDatabasePITRModal: boolean;
@@ -239,23 +241,21 @@ const buttonActionList = computed((): PITRButtonAction[] => {
{
key: "CUSTOM",
text: t("database.pitr.restore-to-point-in-time"),
- type: "NORMAL",
params: { step: "PITR_FORM", mode: "CUSTOM" },
},
{
key: "LAST_MIGRATION",
text: t("database.pitr.restore-before-last-migration"),
- type: "NORMAL",
params: { step: "LAST_MIGRATION_INFO", mode: "LAST_MIGRATION" },
},
];
});
-const onClickPITRButton = (action: ButtonAction) => {
+const onClickPITRButton = (action: PITRButtonAction) => {
if (!hasPITRFeature.value) {
return;
}
- const { step, mode } = (action as PITRButtonAction).params;
+ const { step, mode } = action.params;
openDialog(step, mode);
};
diff --git a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
index b134eb589f..969c3d82c5 100644
--- a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
@@ -1,7 +1,7 @@
<template>
<div v-if="!hideTitle" class="mb-2 flex flex-row items-center">
<span class="text-base mr-2">{{ $t("common.databases") }}</span>
- <BBLoader v-show="loading" class="opacity-60" />
+ <BBSpin v-if="loading" class="opacity-60" />
</div>
<div
class="w-full border rounded min-h-[20rem] max-h-[24rem] overflow-y-auto"
@@ -102,7 +102,6 @@
<script lang="ts" setup>
import { NEllipsis } from "naive-ui";
import { reactive } from "vue";
-import BBLoader from "@/bbkit/BBLoader.vue";
import { ComposedDatabase } from "@/types";
import { InstanceV1EngineIcon } from "../v2";
diff --git a/frontend/src/components/DatabaseGroup/MatchedTableView.vue b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
index 633d1b211d..5f78519d0f 100644
--- a/frontend/src/components/DatabaseGroup/MatchedTableView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedTableView.vue
@@ -1,7 +1,7 @@
<template>
<div class="mb-2 flex flex-row items-center">
<span class="text-lg mr-2">{{ $t("db.tables") }}</span>
- <BBLoader v-show="loading" class="opacity-60" />
+ <BBSpin v-if="loading" class="opacity-60" />
</div>
<div
class="w-full border rounded min-h-[20rem] max-h-[24rem] overflow-y-auto"
@@ -69,7 +69,6 @@
<script lang="ts" setup>
import { reactive } from "vue";
-import BBLoader from "@/bbkit/BBLoader.vue";
import { ComposedSchemaGroupTable } from "@/types";
import { DatabaseView } from "../v2";
diff --git a/frontend/src/components/v2/Button/TooltipButton.vue b/frontend/src/components/v2/Button/TooltipButton.vue
index a6fc8c12f5..e3db1b990a 100644
--- a/frontend/src/components/v2/Button/TooltipButton.vue
+++ b/frontend/src/components/v2/Button/TooltipButton.vue
@@ -21,16 +21,9 @@
</NTooltip>
</template>
-<script lang="ts">
-export default {
- name: "BBTooltipButton",
- inheritAttrs: false,
-};
-</script>
-
<script lang="ts" setup>
-import { withDefaults, computed, useSlots } from "vue";
import { NTooltip, type TooltipProps } from "naive-ui";
+import { withDefaults, computed, useSlots } from "vue";
import { TooltipMode } from "./types";
const props = withDefaults(