Skip to content

Commit

Permalink
fix: values and dry run config selections
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Oct 19, 2023
1 parent be84f71 commit c903c38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {isEqual} from 'lodash';
import {TOOLTIP_DELAY} from '@constants/constants';

import {addAppListener, useAppDispatch, useAppSelector} from '@redux/hooks';
import {selectFile} from '@redux/reducers/main';
import {selectFile, selectPreviewConfiguration} from '@redux/reducers/main';
import {restartPreview, startPreview, stopPreview} from '@redux/thunks/preview';

import {AnyPreview} from '@shared/models/preview';
import {AppSelection} from '@shared/models/selection';

import * as S from './styled';

Expand All @@ -21,12 +22,21 @@ export const usePreviewTrigger = (preview: AnyPreview) => {
const [isOptimisticLoading, setIsOptimisticLoading] = useState(false);
const isPreviewLoading = useAppSelector(state => state.main.previewOptions.isLoading);
const isPreviewed = useAppSelector(state => isEqual(state.main.preview, preview));
const previewFilePath = useAppSelector(state => {
const nextSelection = useAppSelector<AppSelection | undefined>(state => {
if (preview?.type === 'kustomize') {
return state.main.resourceMetaMapByStorage.local[preview.kustomizationId]?.origin.filePath;
return {
type: 'file',
filePath: state.main.resourceMetaMapByStorage.local[preview.kustomizationId]?.origin.filePath,
};
}
if (preview?.type === 'helm') {
return state.main.helmValuesMap[preview.valuesFileId]?.filePath;
return {type: 'file', filePath: state.main.helmValuesMap[preview.valuesFileId]?.filePath};
}
if (preview?.type === 'command') {
return {type: 'command', commandId: preview.commandId};
}
if (preview?.type === 'helm-config') {
return {type: 'preview.configuration', previewConfigurationId: preview.configId};
}
return undefined;
});
Expand Down Expand Up @@ -59,16 +69,25 @@ export const usePreviewTrigger = (preview: AnyPreview) => {
}, [isPreviewLoading]);

const triggerPreview = useCallback(() => {
if (previewFilePath) {
dispatch(selectFile({filePath: previewFilePath}));
if (nextSelection) {
switch (nextSelection.type) {
case 'file':
dispatch(selectFile(nextSelection));
break;
case 'preview.configuration':
dispatch(selectPreviewConfiguration(nextSelection));
break;
default:
break;
}
}

if (isPreviewed || isPreviewLoading) {
return;
}
setIsOptimisticLoading(true);
dispatch(startPreview(preview));
}, [preview, dispatch, isPreviewed, isPreviewLoading, previewFilePath]);
}, [preview, dispatch, isPreviewed, isPreviewLoading, nextSelection]);

const renderPreviewControls = useCallback(() => {
if (!isPreviewed) {
Expand Down
2 changes: 2 additions & 0 deletions src/redux/reducers/main/selectionReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export const selectionReducers = createSliceReducers('main', {
}
updateSelectionHistory(state.selection, Boolean(action.payload.isVirtualSelection), state);
},
// TODO: implement logic for selecting commands, we have to update the editor to show a new panel displaying the command
// selectCommand: (state: Draft<AppState>, action: PayloadAction<{commandId: string}>) => {
clearSelection: (state: Draft<AppState>) => {
clearSelectionReducer(state);
},
Expand Down

0 comments on commit c903c38

Please sign in to comment.