Skip to content

Commit

Permalink
fix: select and highlight first created resource from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
topliceanurazvan committed Aug 10, 2022
1 parent c22cbaf commit 0946e14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/redux/reducers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,16 @@ export const addMultipleResources = createAsyncThunk<AppState, K8sResource[], Th
const userDataDir = String(state.config.userDataDir);

const nextMainState = createNextState(state.main, mainState => {
resources.forEach(resource => {
clearResourceSelections(mainState.resourceMap);

resources.forEach((resource, index) => {
// select first resource
if (!index) {
resource.isSelected = true;
resource.isHighlighted = true;
mainState.selectedResourceId = resource.id;
}

mainState.resourceMap[resource.id] = resource;
const resourceKinds = getResourceKindsWithTargetingRefs(resource);

Expand Down
4 changes: 1 addition & 3 deletions src/redux/services/unsavedResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {UNSAVED_PREFIX} from '@constants/constants';
import {AppDispatch} from '@models/appdispatch';
import {K8sResource} from '@models/k8sresource';

import {addMultipleResources, addResource, selectK8sResource} from '@redux/reducers/main';
import {addMultipleResources, addResource} from '@redux/reducers/main';

import {parseYamlDocument} from '@utils/yaml';

Expand Down Expand Up @@ -65,7 +65,6 @@ export function createUnsavedResource(
isClusterScoped: getResourceKindHandler(input.kind)?.isNamespaced || false,
};
dispatch(addResource(newResource));
dispatch(selectK8sResource({resourceId: newResource.id}));

return newResource;
}
Expand Down Expand Up @@ -114,7 +113,6 @@ export function createMultipleUnsavedResources(
}));

dispatch(addMultipleResources(newResources));
dispatch(selectK8sResource({resourceId: newResources[newResources.length - 1].id}));

return newResources;
}

0 comments on commit 0946e14

Please sign in to comment.