From 8c216e9c990484f72473f395910e682d9553447b Mon Sep 17 00:00:00 2001 From: Ole Lensmar Date: Tue, 5 Dec 2023 08:41:45 +0100 Subject: [PATCH 1/2] fix: initial attempt --- src/redux/thunks/updateFileEntry.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/redux/thunks/updateFileEntry.ts b/src/redux/thunks/updateFileEntry.ts index 89997cc2ce..ac23ee1efc 100644 --- a/src/redux/thunks/updateFileEntry.ts +++ b/src/redux/thunks/updateFileEntry.ts @@ -10,6 +10,7 @@ import {HELM_CHART_ENTRY_FILE} from '@constants/constants'; import {UpdateFileEntryPayload} from '@redux/reducers/main'; import {getLocalResourceMetasForPath} from '@redux/services/fileEntry'; import {reprocessHelm} from '@redux/services/helm'; +import {isKustomizationFile} from '@redux/services/kustomize'; import {deleteResource, extractK8sResources, splitK8sResource} from '@redux/services/resource'; import {getFileStats, getFileTimestamp} from '@utils/files'; @@ -101,6 +102,18 @@ export const updateFileEntry = createAsyncThunk< }, }); }); + + // did we just replace a kustomization being dry-run? -> update the kustomizationId to the new one + // and restart the dry-run + if ( + isKustomizationFile(fileEntry, mainState.resourceMetaMapByStorage.local) && + mainState.preview?.type === 'kustomize' && + mainState.preview.kustomizationId === fileSideEffect.affectedResourceIds[0] + ) { + // mainState.preview.kustomizationId = fileSideEffect.affectedResourceIds[1]; + // thunkAPI.dispatch(stopPreview()); + } + mainState.highlights = newHighlights; } } From e04ff9c3736a3e4a0a562a6c6832bdb4ec889ef2 Mon Sep 17 00:00:00 2001 From: Ole Lensmar Date: Thu, 7 Dec 2023 16:01:10 +0100 Subject: [PATCH 2/2] fix: improved handling of file updates and automatic termination of kustomize dry-runs --- .../ExplorerPane/DryRunsPane/DryRunsPane.tsx | 4 ++- src/redux/selectors/dryRunsSelectors.ts | 2 +- src/redux/store.ts | 3 +++ .../shouldStopKustomizeDryRunListener.ts | 25 +++++++++++++++++++ src/redux/thunks/updateFileEntry.ts | 24 ++++++------------ 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts diff --git a/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx b/src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx index 550622be83..1685ccaffa 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 4304e5d67a..8b66e8c9c9 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 602b8c0ed6..34d7d66d67 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 0000000000..6ec6209429 --- /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 ac23ee1efc..12a93766ab 100644 --- a/src/redux/thunks/updateFileEntry.ts +++ b/src/redux/thunks/updateFileEntry.ts @@ -10,7 +10,6 @@ import {HELM_CHART_ENTRY_FILE} from '@constants/constants'; import {UpdateFileEntryPayload} from '@redux/reducers/main'; import {getLocalResourceMetasForPath} from '@redux/services/fileEntry'; import {reprocessHelm} from '@redux/services/helm'; -import {isKustomizationFile} from '@redux/services/kustomize'; import {deleteResource, extractK8sResources, splitK8sResource} from '@redux/services/resource'; import {getFileStats, getFileTimestamp} from '@utils/files'; @@ -89,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; @@ -102,19 +107,6 @@ export const updateFileEntry = createAsyncThunk< }, }); }); - - // did we just replace a kustomization being dry-run? -> update the kustomizationId to the new one - // and restart the dry-run - if ( - isKustomizationFile(fileEntry, mainState.resourceMetaMapByStorage.local) && - mainState.preview?.type === 'kustomize' && - mainState.preview.kustomizationId === fileSideEffect.affectedResourceIds[0] - ) { - // mainState.preview.kustomizationId = fileSideEffect.affectedResourceIds[1]; - // thunkAPI.dispatch(stopPreview()); - } - - mainState.highlights = newHighlights; } }