From cfbf63bfbf561cd150e0a9bd9b964725b371f575 Mon Sep 17 00:00:00 2001 From: olensmar Date: Wed, 16 Feb 2022 21:57:00 +0100 Subject: [PATCH 1/6] fix: disable namespace selection elements if a namespace is being deployed --- .../ModalConfirmWithNamespaceSelect.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx index 91b681b80d..bb01f6ec1d 100644 --- a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx +++ b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx @@ -119,6 +119,8 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { return null; } + const disableNamespaces = !resources.some(r => r.kind !== 'Namespace'); + return ( = props => { Select namespace: { setSelectedOption(e.target.value); setErrorMessage(''); @@ -152,6 +155,7 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { Namespace: Date: Wed, 16 Feb 2022 22:07:37 +0100 Subject: [PATCH 2/6] fix: use state instead of const for disableNamespaces --- .../ModalConfirmWithNamespaceSelect.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx index bb01f6ec1d..e6d8c2fc5b 100644 --- a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx +++ b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx @@ -65,6 +65,7 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { const {defaultNamespace, defaultOption} = getDefaultNamespaceForApply(resources); const [namespaces] = useTargetClusterNamespaces(); + const [disableNamespaces, setDisableNamespaces] = useState(); const [createNamespaceName, setCreateNamespaceName] = useState(); const [errorMessage, setErrorMessage] = useState(''); const [selectedNamespace, setSelectedNamespace] = useState(defaultNamespace); @@ -115,12 +116,14 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { } }, [defaultOption, defaultNamespace, namespaces]); + useEffect(() => { + setDisableNamespaces(!resources.some(r => r.kind !== 'Namespace')); + }, [resources]); + if (!selectedOption) { return null; } - const disableNamespaces = !resources.some(r => r.kind !== 'Namespace'); - return ( Date: Thu, 17 Feb 2022 11:10:59 +0100 Subject: [PATCH 3/6] fix: useMemo fix and improved label in multi-deploy scenario --- .../ModalConfirmWithNamespaceSelect.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx index e6d8c2fc5b..f631838dba 100644 --- a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx +++ b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx @@ -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'; @@ -65,7 +65,6 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { const {defaultNamespace, defaultOption} = getDefaultNamespaceForApply(resources); const [namespaces] = useTargetClusterNamespaces(); - const [disableNamespaces, setDisableNamespaces] = useState(); const [createNamespaceName, setCreateNamespaceName] = useState(); const [errorMessage, setErrorMessage] = useState(''); const [selectedNamespace, setSelectedNamespace] = useState(defaultNamespace); @@ -116,9 +115,8 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { } }, [defaultOption, defaultNamespace, namespaces]); - useEffect(() => { - setDisableNamespaces(!resources.some(r => r.kind !== 'Namespace')); - }, [resources]); + const onlyNamespaces = useMemo(() => !resources.some(r => r.kind !== 'Namespace'), [resources]); + const hasNamespaces = useMemo(() => resources.some(r => r.kind === 'Namespace'), [resources]); if (!selectedOption) { return null; @@ -138,10 +136,12 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { onCancel={onCancel} > <> - Select namespace: + + Select namespace {hasNamespaces && !onlyNamespaces && ' for all non-Namespace resources'}: + { setSelectedOption(e.target.value); setErrorMessage(''); @@ -158,7 +158,7 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { Namespace: Date: Thu, 17 Feb 2022 11:32:54 +0100 Subject: [PATCH 4/6] fix: fixed missing hook dependencies and removed logging --- .../molecules/FormEditor/FormWidgets/NamespaceSelection.tsx | 2 -- .../molecules/FormEditor/FormWidgets/ResourceSelection.tsx | 2 +- .../ModalConfirmWithNamespaceSelect.tsx | 2 +- src/components/molecules/Monaco/Monaco.tsx | 1 + .../organisms/LocalResourceDiffModal/LocalResourceDiffModal.tsx | 1 + 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/molecules/FormEditor/FormWidgets/NamespaceSelection.tsx b/src/components/molecules/FormEditor/FormWidgets/NamespaceSelection.tsx index 6bace7ca13..2ff4a5ed74 100644 --- a/src/components/molecules/FormEditor/FormWidgets/NamespaceSelection.tsx +++ b/src/components/molecules/FormEditor/FormWidgets/NamespaceSelection.tsx @@ -23,8 +23,6 @@ export const NamespaceSelection = (params: any) => { const [selectValue, setSelectValue] = useState(); const [inputValue, setInputValue] = useState(); - console.log('Creating namespace selection with params', params); - const handleChange = (providedValue: string) => { if (providedValue === NEW_ITEM) { setSelectValue(inputValue); diff --git a/src/components/molecules/FormEditor/FormWidgets/ResourceSelection.tsx b/src/components/molecules/FormEditor/FormWidgets/ResourceSelection.tsx index 32c24e6d20..4e2a746418 100644 --- a/src/components/molecules/FormEditor/FormWidgets/ResourceSelection.tsx +++ b/src/components/molecules/FormEditor/FormWidgets/ResourceSelection.tsx @@ -67,7 +67,7 @@ export function ResourceSelection(props: any) { } else { setResourceNames([]); } - }, [resourceMap]); + }, [resourceMap,options.resourceKinds]); return ( { resourceFilter.namespace, targetResource, isDiffModalVisible, - configState + configState, ]); useEffect(() => { From e93a1706599ca71392d6e2074fed1f20c8d512f7 Mon Sep 17 00:00:00 2001 From: olensmar Date: Thu, 17 Feb 2022 12:57:48 +0100 Subject: [PATCH 6/6] fix: replaced some with every --- .../ModalConfirmWithNamespaceSelect.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx index 1016f9acd8..76a263a784 100644 --- a/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx +++ b/src/components/molecules/ModalConfirmWithNamespaceSelect/ModalConfirmWithNamespaceSelect.tsx @@ -115,7 +115,7 @@ const ModalConfirmWithNamespaceSelect: React.FC = props => { } }, [defaultOption, defaultNamespace, namespaces]); - const onlyNamespaces = useMemo(() => !resources.some(r => r.kind !== 'Namespace'), [resources]); + const onlyNamespaces = useMemo(() => resources.every(r => r.kind === 'Namespace'), [resources]); const hasNamespaces = useMemo(() => resources.some(r => r.kind === 'Namespace'), [resources]); if (!selectedOption) {