Skip to content

Commit

Permalink
perf(frontend): mongodb工具箱重构 TencentBlueKing#8498
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Jan 22, 2025
1 parent a81952a commit 5ed7002
Show file tree
Hide file tree
Showing 18 changed files with 1,859 additions and 5 deletions.
6 changes: 4 additions & 2 deletions dbm-ui/frontend/src/components/cluster-selector/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
getResourceList: getMongoList,
tableContent: MongoTable,
resultContent: ResultPreview,
showPreviewResultTitle: true,
},
[ClusterTypes.MONGO_SHARED_CLUSTER]: {
id: ClusterTypes.MONGO_SHARED_CLUSTER,
Expand All @@ -347,6 +348,7 @@
getResourceList: getMongoList,
tableContent: MongoTable,
resultContent: ResultPreview,
showPreviewResultTitle: true,
},
[ClusterTypes.SQLSERVER_SINGLE]: {
id: ClusterTypes.SQLSERVER_SINGLE,
Expand Down Expand Up @@ -483,14 +485,14 @@
return result;
}
const tabSelectMap = {
map: props.selected[tabKey].reduce(
map: _.cloneDeep(props.selected[tabKey]).reduce(
(selectResult, selectItem) => ({
...selectResult,
[selectItem.id]: selectItem,
}),
{} as Record<string, T>,
),
list: props.selected[tabKey],
list: _.cloneDeep(props.selected[tabKey]),
};
return {
...result,
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/frontend/src/components/editable-table/edit/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@blur="handleBlur"
@change="handleChange"
@focus="handleFocus">
<slot />
<template
v-if="slots.option"
#optionRender="{ item, index }">
Expand Down Expand Up @@ -48,6 +49,7 @@
}>();
const slots = defineSlots<{
default?: () => VNode;
trigger?: (value: { selected: any[] }) => VNode;
option?: (value: { item: Record<string, any>; index: number }) => VNode;
}>();
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from './useTagsOverflow';
export * from './useTaskCount';
export * from './useTicketCloneInfo';
export * from './useTicketCount';
export * from './useTicketDetail';
export * from './useTicketMessage';
export * from './useTimeZoneFormat';
export * from './useUrlSearach';
68 changes: 68 additions & 0 deletions dbm-ui/frontend/src/hooks/useTicketDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
*/
import { useRequest } from 'vue-request';
import { useRoute } from 'vue-router';

import type { DetailBase } from '@services/model/ticket/details/common';
import TicketModel from '@services/model/ticket/ticket';
import { getTicketDetails } from '@services/source/ticket';

import { TicketTypes } from '@common/const';

export function useTicketDetail<T extends DetailBase>(
ticketType: TicketTypes,
options: {
onSuccess: (data: TicketModel<T>) => void;
},
) {
const route = useRoute();
const { ticketId } = route.query;

if (!ticketId) {
return;
}

useRequest(getTicketDetails, {
defaultParams: [{ id: Number(ticketId) }, { permission: 'catch' }],
onSuccess(ticketData) {
if (ticketType !== ticketData.ticket_type) {
return;
}
options.onSuccess(ticketData as TicketModel<T>);
},
});
}

// export function useTicketDetail(
// ticketType: TicketTypes | TicketTypes[],
// options: {
// onSuccess: (data: TicketModel<unknown>, matchingType: TicketTypes) => void;
// },
// ) {
// const route = useRoute();
// const { ticketId } = route.query;
// const { onSuccess } = options;
// if (!ticketId) {
// return;
// }
// useRequest(getTicketDetails, {
// defaultParams: [{ id: Number(ticketId) }, { permission: 'catch' }],
// onSuccess(ticketData) {
// const ticketTypeList = Array.isArray(ticketType) ? ticketType : [ticketType];
// if (!ticketTypeList.includes(ticketData.ticket_type)) {
// return;
// }
// onSuccess(ticketData, ticketData.ticket_type);
// },
// });
// }
6 changes: 6 additions & 0 deletions dbm-ui/frontend/src/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -4075,5 +4075,11 @@
"请先选择版本": "请先选择版本",
"请输入n个主机IP": "请输入 {n} 个主机 IP",
"最多输入n个主机IP": "最多输入 {n} 个主机 IP",
"目标集群n输入格式有误": "目标集群 {n} 输入格式有误",
"目标集群n不存在": "目标集群 {n} 不存在",
"目标集群n重复": "目标集群 {n} 重复",
"待替换的主机重复": "待替换的主机重复",
"请输入或选择主机": "请输入或选择主机",
"目标主机输入格式有误": "目标主机输入格式有误",
"这行勿动!新增翻译请在上一行添加!": ""
}
6 changes: 5 additions & 1 deletion dbm-ui/frontend/src/services/source/dbbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ export function checkClusterDatabase(params: { bk_biz_id: number; cluster_id: nu
}

// 根据用户手动输入的ip[:port]查询真实的实例
export function checkInstance<T extends InstanceInfos>(params: { instance_addresses: string[]; bk_biz_id: number }) {
export function checkInstance<T extends InstanceInfos>(params: {
instance_addresses: string[];
bk_biz_id: number;
cluster_ids?: number[];
}) {
return http.post<T[]>(`${path}/check_instances/`, params);
}

Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/frontend/src/services/types/instanceInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface InstanceInfos {
cluster_id: number;
cluster_name: string;
cluster_type: string;
cluster_domain: string;
// cluster_domain: string;
create_at: string;
db_module_id: number;
db_module_name: string;
Expand Down Expand Up @@ -73,5 +73,5 @@ export interface InstanceInfos {
type: string;
}[];
};
status: 'running' | 'unavailable';
status: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<template>
<EditableColumn
:field="field"
:label="label"
:min-width="200"
:required="required"
:rules="rules">
<template #headAppend>
<BatchEditColumn
v-model="isShowBatchEdit"
:title="label"
type="taginput"
@change="handleBatchEditChange">
<span
v-bk-tooltips="t('统一设置:将该列统一设置为相同的值')"
class="batch-select-button"
@click="handleBatchEditShow">
<DbIcon type="bulk-edit" />
</span>
</BatchEditColumn>
</template>
<div
ref="root"
class="edit-table-name-content"
@click="handleShowTips">
<EditableTagInput
v-model="modelValue"
allow-auto-match
allow-create
clearable
:disabled="disabled"
has-delete-icon
:placeholder="placeholder" />
<div style="display: none">
<div
ref="pop"
style="font-size: 12px; line-height: 24px; color: #63656e">
<slot name="tip" />
</div>
</div>
</div>
</EditableColumn>
</template>

<script setup lang="ts">
import tippy, { type Instance, type SingleTarget } from 'tippy.js';
import { type VNode } from 'vue';
import type { ComponentProps } from 'vue-component-type-helpers';
import { useI18n } from 'vue-i18n';
import { Column as EditableColumn } from '@components/editable-table/Index.vue';
import BatchEditColumn from '@views/db-manage/common/batch-edit-column/Index.vue';
interface Props {
label: string;
field: string;
placeholder: string;
rules: NonNullable<ComponentProps<typeof EditableColumn>['rules']>;
required?: boolean;
disabled?: boolean;
}
interface Emits {
(e: 'batch-edit', value: string[]): void;
}
interface Slots {
tip: VNode;
}
withDefaults(defineProps<Props>(), {
required: true,
disabled: false,
});
const emits = defineEmits<Emits>();
const modelValue = defineModel<string[]>({
required: true,
});
const slots = defineSlots<Slots>();
const { t } = useI18n();
let tippyIns: Instance | undefined;
const isShowBatchEdit = ref(false);
const rootRef = useTemplateRef('root');
const popRef = useTemplateRef('pop');
const handleBatchEditShow = () => {
isShowBatchEdit.value = true;
};
const handleBatchEditChange = (value: string | string[]) => {
emits('batch-edit', value as string[]);
};
const handleShowTips = () => {
tippyIns?.show();
};
onMounted(() => {
nextTick(() => {
if (slots.tip && rootRef.value !== null) {
tippyIns = tippy(rootRef.value as SingleTarget, {
content: popRef.value,
placement: 'top',
appendTo: () => document.body,
theme: 'light',
maxWidth: 'none',
trigger: 'manual',
interactive: true,
arrow: true,
offset: [0, 18],
zIndex: 9998,
hideOnClick: true,
});
}
});
});
onBeforeUnmount(() => {
if (slots.tip && tippyIns) {
tippyIns.hide();
tippyIns.unmount();
tippyIns.destroy();
tippyIns = undefined;
}
});
</script>

<style lang="less" scoped>
.batch-select-button {
font-size: 14px;
color: #3a84ff;
cursor: pointer;
}
.edit-table-name-content {
width: 100%;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
*
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License athttps://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for
* the specific language governing permissions and limitations under the License.
-->

<template>
<EditableColumn
:label="t('当前规格')"
:width="200">
<EditableBlock :placeholder="placeholder">
{{ data?.name ? `${data.name} ${showCounts ? t('((n))台', { n: data?.count }) : ''}` : '' }}
<SpecPanel
v-if="data"
:data="data"
:show-qps="showQps">
<DbIcon
class="visible-icon ml-4"
type="visible1" />
</SpecPanel>
</EditableBlock>
</EditableColumn>
</template>
<script setup lang="ts">
import type { ComponentProps } from 'vue-component-type-helpers';
import { useI18n } from 'vue-i18n';

import SpecPanel from './components/Panel.vue';

interface Props {
data?: ComponentProps<typeof SpecPanel>['data'];
placeholder?: string;
showCounts?: boolean;
showQps?: boolean;
}

withDefaults(defineProps<Props>(), {
data: undefined,
placeholder: undefined,
showCounts: true,
showQps: false,
});

const { t } = useI18n();
</script>

<style lang="less" scoped>
.visible-icon {
font-size: 16px;
color: #3a84ff;
cursor: pointer;
}
</style>
Loading

0 comments on commit 5ed7002

Please sign in to comment.