Skip to content

Commit

Permalink
fix: Change window title in helm and kustomization modes & disable up…
Browse files Browse the repository at this point in the history
…date modal on refresh
  • Loading branch information
erdkse committed Sep 30, 2021
1 parent 87b6e06 commit 927770b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
4 changes: 0 additions & 4 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ export const createWindow = (givenPath?: string) => {
mainStore.dispatch(updateNewVersion({code: NewVersionCode.Downloaded, data: null}));
});

autoUpdater.on('error', error => {
mainStore.dispatch(updateNewVersion({code: NewVersionCode.Errored, data: {errorCode: -10}}));
});

const missingDependecies = checkMissingDependencies(APP_DEPENDENCIES);

if (missingDependecies.length > 0) {
Expand Down
58 changes: 49 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import React, {useEffect, useState} from 'react';
import 'antd/dist/antd.less';
import {Layout} from '@atoms';
import {
Expand All @@ -16,20 +16,33 @@ import {
import {Size} from '@models/window';
import {useWindowSize} from '@utils/hooks';
import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {AppState} from '@models/appstate';
import {useSelector} from 'react-redux';
import {ROOT_FILE_ENTRY} from '@constants/constants';
import {initKubeconfig} from '@redux/reducers/appConfig';
import {ipcRenderer, remote} from 'electron';
import {setAlert} from '@redux/reducers/alert';
import {AlertEnum, AlertType} from '@models/alert';
import ValidationErrorsModal from '@components/molecules/ValidationErrorsModal';
import UpdateModal from '@components/organisms/UpdateModal';
import {isInPreviewModeSelector} from '@redux/selectors';
import {K8sResource} from '@models/k8sresource';
import {HelmChart, HelmValuesFile} from '@models/helm';
import AppContext from './AppContext';

const App = () => {
const dispatch = useAppDispatch();
const size: Size = useWindowSize();
const mainState: AppState = useAppSelector(state => state.main);
const isInPreviewMode = useSelector(isInPreviewModeSelector);
const previewType = useAppSelector(state => state.main.previewResourceId);
const previewResourceId = useAppSelector(state => state.main.previewResourceId);
const fileMap = useAppSelector(state => state.main.fileMap);
const resourceMap = useAppSelector(state => state.main.resourceMap);
const [previewResource, setPreviewResource] = useState<K8sResource>();
const [previewValuesFile, setPreviewValuesFile] = useState<HelmValuesFile>();
const [helmChart, setHelmChart] = useState<HelmChart>();
const previewValuesFileId = useAppSelector(state => state.main.previewValuesFileId);
const helmValuesMap = useAppSelector(state => state.main.helmValuesMap);
const helmChartMap = useAppSelector(state => state.main.helmChartMap);

const mainHeight = `${size.height}px`;

Expand All @@ -39,14 +52,41 @@ const App = () => {
}, []);

useEffect(() => {
if (mainState.previewType && mainState.previewResourceId) {
remote.getCurrentWindow().setTitle(mainState.previewResourceId);
} else if (mainState.fileMap && mainState.fileMap[ROOT_FILE_ENTRY] && mainState.fileMap[ROOT_FILE_ENTRY].filePath) {
remote.getCurrentWindow().setTitle(mainState.fileMap[ROOT_FILE_ENTRY].filePath);
if (previewResourceId) {
setPreviewResource(resourceMap[previewResourceId]);
} else {
remote.getCurrentWindow().setTitle('Monokle');
setPreviewResource(undefined);
}
}, [mainState]);

if (previewValuesFileId && helmValuesMap[previewValuesFileId]) {
const valuesFile = helmValuesMap[previewValuesFileId];
setPreviewValuesFile(valuesFile);
setHelmChart(helmChartMap[valuesFile.helmChartId]);
} else {
setPreviewValuesFile(undefined);
setHelmChart(undefined);
}
}, [previewResourceId, previewValuesFileId, helmValuesMap, resourceMap, helmChartMap]);

useEffect(() => {
if (isInPreviewMode && previewType === 'kustomization') {
remote.getCurrentWindow().setTitle(previewResource ? `[${previewResource.name}] kustomization` : `Monokle`);
return;
}
if (isInPreviewMode && previewType === 'cluster') {
remote.getCurrentWindow().setTitle(String(previewResourceId) && 'Monokle');
return;
}
if (isInPreviewMode && previewType === 'helm') {
remote.getCurrentWindow().setTitle(`${previewValuesFile?.name} for ${helmChart?.name} Helm chart`);
return;
}
if (fileMap && fileMap[ROOT_FILE_ENTRY] && fileMap[ROOT_FILE_ENTRY].filePath) {
remote.getCurrentWindow().setTitle(fileMap[ROOT_FILE_ENTRY].filePath);
return;
}
remote.getCurrentWindow().setTitle('Monokle');
}, [isInPreviewMode, previewType, previewResource, previewResourceId, previewValuesFile, helmChart, fileMap]);

ipcRenderer.on('missing-dependency-result', (_, {dependencies}) => {
const alert: AlertType = {
Expand Down
4 changes: 3 additions & 1 deletion src/redux/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ const initialAppConfigState: AppConfig = {
recentFolders: electronStore.get('appConfig.recentFolders') || [],
newVersion: {
code: electronStore.get('appConfig.newVersion') || NewVersionCode.Idle,
data: null,
data: {
initial: true,
},
},
navigators,
};
Expand Down

0 comments on commit 927770b

Please sign in to comment.