Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves handling of overlays during dry-runs #4204

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
return false;
});

rowVirtualizer.scrollToIndex(index);
if (index >= 0) {
rowVirtualizer.scrollToIndex(index);
}
}, [preview, list, rowVirtualizer]);

if (isLoading) {
Expand Down Expand Up @@ -163,7 +165,7 @@

// Styled Components

const EmptyText = styled.div`

Check warning on line 168 in src/components/organisms/ExplorerPane/DryRunsPane/DryRunsPane.tsx

View workflow job for this annotation

GitHub Actions / lint-mac

'EmptyText' is assigned a value but never used
padding: 16px;
color: ${Colors.grey8};
`;
Expand Down
2 changes: 1 addition & 1 deletion src/redux/selectors/dryRunsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 3 additions & 0 deletions src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -55,6 +57,7 @@ combineListeners([
...appConfigListeners,
...clusterListeners,
imageListParserListener,
shouldStopKustomizeDryRunListener,
]);

const appReducer = combineReducers({
Expand Down
25 changes: 25 additions & 0 deletions src/redux/thunks/listeners/shouldStopKustomizeDryRunListener.ts
Original file line number Diff line number Diff line change
@@ -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());
}
},
});
};
11 changes: 8 additions & 3 deletions src/redux/thunks/updateFileEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -101,7 +107,6 @@ export const updateFileEntry = createAsyncThunk<
},
});
});
mainState.highlights = newHighlights;
}
}

Expand Down
Loading