Skip to content

Commit

Permalink
feat(console): support paste string to vnc (#1833)
Browse files Browse the repository at this point in the history
* feat(console): support paste string to vnc

* feat(console): hide volume mode

* fix(console): change vmi text to vm
  • Loading branch information
jo-hnny committed Apr 11, 2022
1 parent a7b2e26 commit 71de1c8
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 62 deletions.
83 changes: 48 additions & 35 deletions web/console/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-thunk": "=2.0.1",
"tea-component": "^2.6.22",
"tea-component": "^2.7.3",
"ts-optchain": "^0.1.7",
"use-immer": "^0.4.1",
"uuid": "^8.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const DiskPanel = () => {
id: uuidv4(),
name: '',
type: DiskTypeEnum.Data,
volumeMode: VolumeModeEnum.Block,
volumeMode: VolumeModeEnum.Filesystem,
storageClass: null,
size: 50
}
Expand Down Expand Up @@ -64,22 +64,22 @@ export const DiskPanel = () => {
}
},

{
key: 'volumeMode',
header: '卷模式',
render({ volumeMode, id }) {
return (
<Form.Control>
<Select
size="s"
value={volumeMode}
options={VolumeModeOptions}
onChange={volumeMode => modifyDiskItem({ volumeMode, id })}
/>
</Form.Control>
);
}
},
// {
// key: 'volumeMode',
// header: '卷模式',
// render({ volumeMode, id }) {
// return (
// <Form.Control>
// <Select
// size="s"
// value={volumeMode}
// options={VolumeModeOptions}
// onChange={volumeMode => modifyDiskItem({ volumeMode, id })}
// />
// </Form.Control>
// );
// }
// },

{
key: 'storageClass',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,16 @@ export const VMCreatePanel = () => {
<Form.Item label="镜像" {...getReactHookFormStatusWithMessage(others)}>
<Select
type="simulate"
matchButtonWidth
style={{ width: 200 }}
searchable
appearence="button"
size="auto"
options={mirrorListLoadable?.state === 'hasValue' ? mirrorListLoadable?.contents : []}
{...field}
onChange={value => {
field.onChange(value);
field.onBlur();
}}
/>
</Form.Item>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export const VMListPanel = ({ route }) => {
{
mode: 'continue',
defaultPageSize,
fetchAble: !!(clusterId && namespace)
fetchAble: !!(clusterId && namespace),
polling: true,
pollingDelay: 30 * 1000
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const mirrorListState = selector({
return (
items?.map(({ metadata }) => ({
text: metadata?.annotations?.['tkestack.io/image-display-name'],
value: metadata?.name
value: metadata?.name,
tooltip: metadata?.annotations?.['tkestack.io/image-display-name']
})) ?? []
);
}
Expand All @@ -39,7 +40,7 @@ export const diskListState = atom<DiskInterface[]>({
id: uuidv4(),
name: 'datavolume1',
type: DiskTypeEnum.Data,
volumeMode: VolumeModeEnum.Block,
volumeMode: VolumeModeEnum.Filesystem,
storageClass: null,
size: 50
}
Expand Down
2 changes: 1 addition & 1 deletion web/console/src/modules/cluster/constants/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const ServiceWorkloadList = [
},
{
value: 'vmi',
name: 'VirtualMachineInstance'
name: 'VirtualMachines'
}
];

Expand Down
19 changes: 19 additions & 0 deletions web/console/src/modules/vnc/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ export const ShortcutKeyOptions = [
}
}
];

// paste string to noVNC
export const pasteStringToVnc = (rfb, str) => {
rfb.focus();

str.split('').forEach(char => {
const code = char.charCodeAt();
const needsShift = char.match(/[A-Z!@#$%^&*()_+{}:\"<>?~|]/);
if (needsShift) {
rfb.sendKey(KeyTable.XK_Shift_L, 'ShiftLeft', true);
}

rfb.sendKey(code);

if (needsShift) {
rfb.sendKey(KeyTable.XK_Shift_L, 'ShiftLeft', false);
}
});
};
23 changes: 20 additions & 3 deletions web/console/src/modules/vnc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useEffect, useRef, useState } from 'react';
import RFB from '@novnc/novnc/core/rfb';
import { Text, Dropdown, List } from 'tea-component';
import { encode } from 'js-base64';
import { VNCStatusEnum, vncStatusToText, ShortcutKeyOptions } from './constants';
import { VNCStatusEnum, vncStatusToText, ShortcutKeyOptions, pasteStringToVnc } from './constants';
import { VncClipboard } from './vncClipboard';

let rfb;

Expand All @@ -27,9 +28,13 @@ export const VNCPage = () => {
setVncStatus(VNCStatusEnum.Connected);
});

rfb.addEventListener('disconnect', e => {
rfb.addEventListener('disconnect', () => {
setVncStatus(VNCStatusEnum.Disconnected);
});

rfb.addEventListener('clipboard', e => {
console.log('clipboard', e?.detail?.text);
});
}, []);

return (
Expand All @@ -54,7 +59,19 @@ export const VNCPage = () => {
</List>
</Dropdown>

<Text style={{ color: 'white' }}>状态:{vncStatusToText[vncStatus]}</Text>
<Text style={{ color: 'white' }}>
状态:{vncStatusToText[vncStatus]}
{vncStatus === VNCStatusEnum.Connected && (
<>
。如需粘贴命令,请点击
<VncClipboard
onConfirm={content => {
pasteStringToVnc(rfb, content);
}}
/>
</>
)}
</Text>

<Text style={{ color: 'white' }}>虚拟机名称:{name}</Text>
</div>
Expand Down

0 comments on commit 71de1c8

Please sign in to comment.