Skip to content

Commit

Permalink
feat: get default resource name when renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Sep 10, 2021
1 parent 7ae5b21 commit 13aee53
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {useAppSelector, useAppDispatch} from '@redux/hooks';
import {closeRenameResourceModal} from '@redux/reducers/ui';
import {renameResource} from '@redux/services/renameResource';
import styled from 'styled-components';
import {K8sResource} from '@models/k8sresource';

const CheckboxContainer = styled.div`
margin-top: 10px;
Expand All @@ -13,24 +14,32 @@ const RenameResourceModel = () => {
const dispatch = useAppDispatch();
const uiState = useAppSelector(state => state.ui.renameResourceModal);
const resourceMap = useAppSelector(state => state.main.resourceMap);
const selectedResourceId = useAppSelector(state => state.main.selectedResourceId);
const [newResourceName, setNewResourceName] = useState<string>();
const [shouldUpdateRefs, setShouldUpdateRefs] = useState<boolean>(false);
const inputNameRef = useRef<any>();
const [resource, setResource] = useState<K8sResource>();

useEffect(() => {
if (uiState?.isOpen) {
if (uiState) {
const newResource = resourceMap[uiState.resourceId];
if (newResource) {
setResource(newResource);
setNewResourceName(newResource.name);
}
}
if (!uiState || uiState?.isOpen === false) {
setResource(undefined);
setNewResourceName(undefined);
setShouldUpdateRefs(false);
inputNameRef?.current?.focus();
}
}, [uiState?.isOpen]);
setShouldUpdateRefs(false);
inputNameRef?.current?.focus();
}, [uiState, resourceMap]);

if (!uiState) {
return null;
}

const resource = resourceMap[uiState.resourceId];

if (!resource) {
return null;
}
Expand All @@ -39,7 +48,7 @@ const RenameResourceModel = () => {
if (!newResourceName || resource.name === newResourceName) {
return;
}
renameResource(resource.id, newResourceName, shouldUpdateRefs, resourceMap, dispatch);
renameResource(resource.id, newResourceName, shouldUpdateRefs, resourceMap, dispatch, selectedResourceId);
dispatch(closeRenameResourceModal());
};

Expand Down

0 comments on commit 13aee53

Please sign in to comment.