Skip to content

Commit

Permalink
Merge pull request #1511 from jumpserver/pr@dev@perf_message_tip
Browse files Browse the repository at this point in the history
perf: A message when a node fails
  • Loading branch information
ZhaoJiSen authored Sep 19, 2024
2 parents e8e7f23 + 5d8b9d6 commit b4780f4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ const handleClose = (name: string) => {
panels.value.splice(index, 1);
treeStore.removeK8sIdMap(name);
const panelLength = panels.value.length;
if (panelLength >= 1) {
Expand Down
16 changes: 14 additions & 2 deletions ui/src/hooks/useK8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ref, h } from 'vue';
import { storeToRefs } from 'pinia';
import { useLogger } from './useLogger.ts';
import { useWebSocket } from '@vueuse/core';
import { createDiscreteApi } from 'naive-ui';
import { createDiscreteApi, darkTheme } from 'naive-ui';
import { useTreeStore } from '@/store/modules/tree.ts';
import { useParamsStore } from '@/store/modules/params.ts';
import { generateWsURL, onWebsocketOpen, onWebsocketWrong } from './helper';
Expand All @@ -17,7 +17,11 @@ import type { Ref } from 'vue';
import { customTreeOption, IContainer, IPods } from '@/hooks/interface';

const { debug } = useLogger('K8s');
const { message } = createDiscreteApi(['message']);
const { message, notification } = createDiscreteApi(['message', 'notification'], {
configProviderProps: {
theme: darkTheme
}
});

export const useK8s = () => {
const treeStore = useTreeStore();
Expand Down Expand Up @@ -168,6 +172,14 @@ export const useK8s = () => {
* 二次处理节点
*/
const filterSyncNodes = (msg: any) => {
if (msg.err) {
treeStore.setTreeNodes({} as customTreeOption);
return notification.error({
content: msg.err,
duration: 100000
});
}

const data = JSON.parse(msg.data as string);

if (Object.keys(data).length === 0) {
Expand Down
7 changes: 6 additions & 1 deletion ui/src/hooks/useTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,11 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr

const { currentTab } = storeToRefs(useTerminalStore());

treeStore.setK8sIdMap(currentNode.value.k8s_id!, { terminal, socket, ...currentNode.value });
treeStore.setK8sIdMap(currentNode.value.k8s_id!, {
terminal,
socket,
...currentNode.value
});

messageHandlers = {
[currentTab.value]: (e: MessageEvent) => {
Expand All @@ -558,6 +562,7 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr
option.transSocket?.addEventListener('message', (e: MessageEvent) => {
// @ts-ignore
const handler = messageHandlers[currentTab.value as string];

if (handler) {
handler(e);
}
Expand Down

0 comments on commit b4780f4

Please sign in to comment.