Skip to content

Commit

Permalink
Merge pull request #1375 from kubeshop/olelensmar/fix/disable-ns-sett…
Browse files Browse the repository at this point in the history
…ings-when-deploying-ns

fix: disable namespace selection elements if a namespace is being dep…
  • Loading branch information
olensmar authored Feb 17, 2022
2 parents d1f3d27 + a4a6bbe commit acb0708
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function ResourceSelection(props: any) {
} else {
setResourceNames([]);
}
}, [resourceMap]);
}, [resourceMap, options.resourceKinds]);

return (
<Select
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as k8s from '@kubernetes/client-node';

import React, {useCallback, useEffect, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';

import {Input, Modal, Radio, Select} from 'antd';

Expand Down Expand Up @@ -97,7 +97,7 @@ const ModalConfirmWithNamespaceSelect: React.FC<IProps> = props => {
} else if (selectedOption === 'none') {
onOk();
}
}, [kubeConfigContext, createNamespaceName, kubeConfigPath, selectedNamespace, selectedOption, onOk]);
}, [kubeConfigContext, createNamespaceName, kubeConfigPath, selectedNamespace, selectedOption, onOk, configState]);

useEffect(() => {
if (defaultOption && defaultOption === 'none') {
Expand All @@ -115,6 +115,9 @@ const ModalConfirmWithNamespaceSelect: React.FC<IProps> = props => {
}
}, [defaultOption, defaultNamespace, namespaces]);

const onlyNamespaces = useMemo(() => resources.every(r => r.kind === 'Namespace'), [resources]);
const hasNamespaces = useMemo(() => resources.some(r => r.kind === 'Namespace'), [resources]);

if (!selectedOption) {
return null;
}
Expand All @@ -133,9 +136,12 @@ const ModalConfirmWithNamespaceSelect: React.FC<IProps> = props => {
onCancel={onCancel}
>
<>
<HeadlineLabel>Select namespace:</HeadlineLabel>
<HeadlineLabel>
Select namespace {hasNamespaces && !onlyNamespaces && ' for all non-Namespace resources'}:
</HeadlineLabel>
<Radio.Group
key={selectedOption}
disabled={onlyNamespaces}
onChange={e => {
setSelectedOption(e.target.value);
setErrorMessage('');
Expand All @@ -152,6 +158,7 @@ const ModalConfirmWithNamespaceSelect: React.FC<IProps> = props => {
<NamespaceContainer>
<span>Namespace:</span>
<Select
disabled={onlyNamespaces}
value={selectedNamespace}
showSearch
defaultValue={defaultNamespace}
Expand All @@ -171,6 +178,7 @@ const ModalConfirmWithNamespaceSelect: React.FC<IProps> = props => {
<NamespaceContainer>
<span>Namespace name:</span>
<Input
disabled={onlyNamespaces}
autoFocus
defaultValue={createNamespaceName}
placeholder="Enter namespace name"
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Monaco/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ const Monaco = (props: {diffSelectedResource: () => void; applySelection: () =>
}, [
isInPreviewMode,
selectedResourceId,
selectedResource,
previewResourceId,
selectedValuesFileId,
previewValuesFileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ const DiffModal = () => {
resourceFilter.namespace,
targetResource,
isDiffModalVisible,
configState,
]);

useEffect(() => {
Expand Down

0 comments on commit acb0708

Please sign in to comment.