diff --git a/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx b/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx index 550622be8..1685ccaff 100644 --- a/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx +++ b/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx @@ -62,7 +62,9 @@ const DryRunsPane: React.FC = () => { return false; }); - rowVirtualizer.scrollToIndex(index); + if (index >= 0) { + rowVirtualizer.scrollToIndex(index); + } }, [preview, list, rowVirtualizer]); if (isLoading) { diff --git a/src/redux/selectors/dryRunsSelectors.ts b/src/redux/selectors/dryRunsSelectors.ts index 4304e5d67..8b66e8c9c 100644 --- a/src/redux/selectors/dryRunsSelectors.ts +++ b/src/redux/selectors/dryRunsSelectors.ts @@ -189,7 +189,7 @@ export const dryRunLabelSelector = createSelector( if (preview.type === 'kustomize') { const resource = localResourceMetaMap[preview.kustomizationId]; - return basename(resource.name); + return resource ? basename(resource.name) : 'Kustomize Overlay'; } if (preview.type === 'helm') { diff --git a/src/redux/store.ts b/src/redux/store.ts index 602b8c0ed..34d7d66d6 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -2,6 +2,8 @@ import {Middleware, combineReducers, configureStore, createAction} from '@reduxj import {createLogger} from 'redux-logger'; +import {shouldStopKustomizeDryRunListener} from '@redux/thunks/listeners/shouldStopKustomizeDryRunListener'; + import {editorSlice} from '@editor/editor.slice'; import {editorListeners} from '@editor/listeners'; @@ -55,6 +57,7 @@ combineListeners([ ...appConfigListeners, ...clusterListeners, imageListParserListener, + shouldStopKustomizeDryRunListener, ]); const appReducer = combineReducers({ diff --git a/src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts b/src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts new file mode 100644 index 000000000..6ec620942 --- /dev/null +++ b/src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts @@ -0,0 +1,25 @@ +import {isAnyOf} from '@reduxjs/toolkit'; + +import {AppListenerFn} from '@redux/listeners/base'; +import {multiplePathsChanged} from '@redux/thunks/multiplePathsChanged'; +import {stopPreview} from '@redux/thunks/preview'; +import {updateFileEntry} from '@redux/thunks/updateFileEntry'; + +export const shouldStopKustomizeDryRunListener: AppListenerFn = listen => { + listen({ + matcher: isAnyOf(updateFileEntry.fulfilled, multiplePathsChanged.fulfilled), + effect: (action, listenerApi) => { + listenerApi.cancelActiveListeners(); + + const mainState = listenerApi.getState().main; + + // check if the update resulted in the removal of the currently dry-run kustomize overlay + if ( + mainState.preview?.type === 'kustomize' && + !mainState.resourceMetaMapByStorage.local[mainState.preview.kustomizationId] + ) { + listenerApi.dispatch(stopPreview()); + } + }, + }); +}; diff --git a/src/redux/thunks/updateFileEntry.ts b/src/redux/thunks/updateFileEntry.ts index 89997cc2c..12a93766a 100644 --- a/src/redux/thunks/updateFileEntry.ts +++ b/src/redux/thunks/updateFileEntry.ts @@ -88,8 +88,14 @@ export const updateFileEntry = createAsyncThunk< }); const newHighlights: AppSelection[] = []; - Object.values(extractedResources).forEach(r => { - fileSideEffect.affectedResourceIds.push(r.id); + Object.values(extractedResources).forEach((r, ix) => { + // if we're just replacing one resource with another consider this an update + if (extractedResources.length === fileSideEffect.affectedResourceIds.length) { + r.id = fileSideEffect.affectedResourceIds[ix]; + } else { + fileSideEffect.affectedResourceIds.push(r.id); + } + const {meta, content} = splitK8sResource(r); mainState.resourceMetaMapByStorage.local[meta.id] = meta; mainState.resourceContentMapByStorage.local[content.id] = content; @@ -101,7 +107,6 @@ export const updateFileEntry = createAsyncThunk< }, }); }); - mainState.highlights = newHighlights; } }