Skip to content

Commit 03ef10f

Browse files
committed
frontend: add node shell
Fixes #996 Signed-off-by: farodin91 <github@jan-jansen.net>
1 parent caf13c2 commit 03ef10f

File tree

19 files changed

+435
-139
lines changed

19 files changed

+435
-139
lines changed

frontend/src/components/App/Settings/SettingsCluster.tsx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import React from 'react';
1414
import { useTranslation } from 'react-i18next';
1515
import { useDispatch } from 'react-redux';
1616
import { useHistory, useLocation } from 'react-router-dom';
17-
import helpers, { ClusterSettings } from '../../../helpers';
17+
import helpers, { ClusterSettings, DEFAULT_NODE_SHELL_LINUX_IMAGE } from '../../../helpers';
1818
import { useCluster, useClustersConf } from '../../../lib/k8s';
1919
import { deleteCluster, parseKubeConfig, renameCluster } from '../../../lib/k8s/apiProxy';
2020
import { setConfig, setStatelessConfig } from '../../../redux/configSlice';
@@ -85,6 +85,7 @@ export default function SettingsCluster() {
8585
const { t } = useTranslation(['translation']);
8686
const [defaultNamespace, setDefaultNamespace] = React.useState('default');
8787
const [userDefaultNamespace, setUserDefaultNamespace] = React.useState('');
88+
const [nodeShellLinuxImage, setNodeShellLinuxImage] = React.useState('');
8889
const [newAllowedNamespace, setNewAllowedNamespace] = React.useState('');
8990
const [clusterSettings, setClusterSettings] = React.useState<ClusterSettings | null>(null);
9091
const [cluster, setCluster] = React.useState(useCluster() || '');
@@ -217,10 +218,32 @@ export default function SettingsCluster() {
217218
}
218219
}, [location.search, clusters]);
219220

221+
React.useEffect(() => {
222+
let timeoutHandle: NodeJS.Timeout | null = null;
223+
224+
if (isEditingNodeShellLinuxImage()) {
225+
// We store the node shell image after a timeout.
226+
timeoutHandle = setTimeout(() => {
227+
storeNewNodeShellLinuxImage(nodeShellLinuxImage);
228+
}, 1000);
229+
}
230+
231+
return () => {
232+
if (timeoutHandle) {
233+
clearTimeout(timeoutHandle);
234+
timeoutHandle = null;
235+
}
236+
};
237+
}, [nodeShellLinuxImage]);
238+
220239
function isEditingDefaultNamespace() {
221240
return clusterSettings?.defaultNamespace !== userDefaultNamespace;
222241
}
223242

243+
function isEditingNodeShellLinuxImage() {
244+
return clusterSettings?.nodeShellLinuxImage !== nodeShellLinuxImage;
245+
}
246+
224247
function storeNewAllowedNamespace(namespace: string) {
225248
setNewAllowedNamespace('');
226249
setClusterSettings((settings: ClusterSettings | null) => {
@@ -265,6 +288,14 @@ export default function SettingsCluster() {
265288
});
266289
}
267290

291+
function storeNewNodeShellLinuxImage(image: string) {
292+
setClusterSettings((settings: ClusterSettings | null) => {
293+
const newSettings = { ...(settings || {}) };
294+
newSettings.nodeShellLinuxImage = image;
295+
return newSettings;
296+
});
297+
}
298+
268299
const isValidDefaultNamespace = isValidNamespaceFormat(userDefaultNamespace);
269300
const isValidCurrentName = isValidClusterNameFormat(newClusterName);
270301
const isValidNewAllowedNamespace = isValidNamespaceFormat(newAllowedNamespace);
@@ -504,6 +535,35 @@ export default function SettingsCluster() {
504535
</>
505536
),
506537
},
538+
{
539+
name: t('translation|Node Shell Linux Image'),
540+
value: (
541+
<TextField
542+
onChange={event => {
543+
let value = event.target.value;
544+
value = value.replace(' ', '');
545+
setNodeShellLinuxImage(value);
546+
}}
547+
value={nodeShellLinuxImage}
548+
placeholder={DEFAULT_NODE_SHELL_LINUX_IMAGE}
549+
helperText={t(
550+
'translation|The default image is used for dropping a shell into a node (when not specified directly).'
551+
)}
552+
InputProps={{
553+
endAdornment: isEditingNodeShellLinuxImage() ? (
554+
<Icon
555+
width={24}
556+
color={theme.palette.text.secondary}
557+
icon="mdi:progress-check"
558+
/>
559+
) : (
560+
<Icon width={24} icon="mdi:check-bold" />
561+
),
562+
sx: { maxWidth: 250 },
563+
}}
564+
/>
565+
),
566+
},
507567
]}
508568
/>
509569
</SectionBox>

0 commit comments

Comments
 (0)