Skip to content

Commit

Permalink
fix: disable new-resource in cluster/preview modes, added <none> opti…
Browse files Browse the repository at this point in the history
…on to namespace
  • Loading branch information
olensmar committed Aug 31, 2021
1 parent 55e9aba commit 6d3c344
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/components/organisms/NavigatorPane/NavigatorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
helmChartsSelector,
helmValuesSelector,
kustomizationsSelector,
isInPreviewModeSelector,
} from '@redux/selectors';

import {HelmValuesFile} from '@models/helm';
Expand Down Expand Up @@ -148,6 +149,7 @@ const NavigatorPane = () => {
const helmValues = useSelector(helmValuesSelector);
const kustomizations = useSelector(kustomizationsSelector);
const isInClusterMode = useSelector(isInClusterModeSelector);
const isInPreviewMode = useSelector(isInPreviewModeSelector);

const [isValidationsErrorsModalVisible, setValidationsErrorsVisible] = useState<boolean>(false);
const [currentValidationErrors, setCurrentValidationErrors] = useState<ResourceValidationError[]>([]);
Expand Down Expand Up @@ -205,7 +207,7 @@ const NavigatorPane = () => {
<span>Navigator</span>
<RightButtons>
<StyledPlusButton
disabled={!doesRootFileEntryExist()}
disabled={!doesRootFileEntryExist() || isInClusterMode || isInPreviewMode}
onClick={onClickNewResource}
type="link"
size="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {createUnsavedResource} from '@redux/services/unsavedResource';
import {ResourceKindHandlers, getResourceKindHandler} from '@src/kindhandlers';
import {getNamespaces} from '@redux/services/resource';

const NO_NAMESPACE = '<none>';
const NewResourceWizard = () => {
const dispatch = useAppDispatch();
const isNewResourceWizardOpen = useAppSelector(state => state.ui.isNewResourceWizardOpen);
const resourceMap = useAppSelector(state => state.main.resourceMap);
const [namespaces, setNamespaces] = useState<string[]>([]);

useEffect(() => {
setNamespaces([...new Set(['default', ...getNamespaces(resourceMap)])]);
setNamespaces([...new Set([NO_NAMESPACE, 'default', ...getNamespaces(resourceMap)])]);
}, [resourceMap]);

const [form] = Form.useForm();
Expand Down Expand Up @@ -53,7 +54,7 @@ const NewResourceWizard = () => {
{
name: data.name,
kind: data.kind,
namespace: data.namespace,
namespace: data.namespace === NO_NAMESPACE ? undefined : data.namespace,
apiVersion: data.apiVersion,
},
dispatch
Expand Down Expand Up @@ -94,7 +95,7 @@ const NewResourceWizard = () => {
name="namespace"
label="Namespace"
tooltip={{title: 'Select the namespace', icon: <InfoCircleOutlined />}}
initialValue="default"
initialValue={NO_NAMESPACE}
>
<Select>
{namespaces.map(namespace => (
Expand Down
4 changes: 3 additions & 1 deletion src/redux/services/unsavedResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apiVersion: ${input.apiVersion ? input.apiVersion : 'apps/v1'}
kind: ${input.kind}
metadata:
name: ${input.name}
namespace: ${input.namespace ? input.namespace : 'default'}
${input.namespace ? `namespace: ${input.namespace}` : ''}
`.trim();
}

Expand All @@ -22,6 +22,8 @@ export function createUnsavedResource(
input: {name: string; kind: string; apiVersion: string; namespace?: string},
dispatch: AppDispatch
) {
console.log(input);

// TODO: add logic to use a resource template
const newResourceId = uuidv4();
const newResourceText = createDefaultResourceText(input);
Expand Down

0 comments on commit 6d3c344

Please sign in to comment.