Skip to content

Commit

Permalink
Merge pull request #1462 from kubeshop/devcatalin/fix/no-plugins-inst…
Browse files Browse the repository at this point in the history
…alled

refactor: installation of default templates plugin
  • Loading branch information
devcatalin authored Mar 14, 2022
2 parents fccf4e6 + 5ddfcbb commit b9d7a0d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
8 changes: 7 additions & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ import {
APP_MIN_HEIGHT,
APP_MIN_WIDTH,
DEFAULT_PLUGINS,
DEFAULT_TEMPLATES_PLUGIN_URL,
DEPENDENCIES_HELP_URL,
ROOT_FILE_ENTRY,
} from '@constants/constants';
import {DOWNLOAD_PLUGIN, DOWNLOAD_PLUGIN_RESULT, DOWNLOAD_TEMPLATE, DOWNLOAD_TEMPLATE_RESULT, DOWNLOAD_TEMPLATE_PACK, DOWNLOAD_TEMPLATE_PACK_RESULT, UPDATE_EXTENSIONS, UPDATE_EXTENSIONS_RESULT} from '@constants/ipcEvents';
import ElectronStore from 'electron-store';
import utilsElectronStore from '@utils/electronStore';
import {
changeCurrentProjectName,
setUserDirs,
Expand Down Expand Up @@ -367,7 +369,7 @@ export const createWindow = (givenPath?: string) => {
win.webContents.on('dom-ready', async () => {
const dispatch = createDispatchForWindow(win);

Nucleus.appStarted();
Nucleus.appStarted();

subscribeToStoreStateChanges(win.webContents, (storeState) => {
createMenu(storeState, dispatch);
Expand Down Expand Up @@ -417,7 +419,11 @@ export const createWindow = (givenPath?: string) => {
const pluginMap = await loadPluginMap(pluginsDir);
const uniquePluginNames = Object.values(pluginMap).map((plugin) => `${plugin.repository.owner}-${plugin.repository.name}`);

const hasDeletedDefaultTemplatesPlugin = Boolean(utilsElectronStore.get('appConfig.hasDeletedDefaultTemplatesPlugin'));
const defaultPluginsToLoad = DEFAULT_PLUGINS.filter((defaultPlugin) => {
if (hasDeletedDefaultTemplatesPlugin && defaultPlugin.url === DEFAULT_TEMPLATES_PLUGIN_URL) {
return false;
}
return !uniquePluginNames.includes(`${defaultPlugin.owner}-${defaultPlugin.name}`);
});

Expand Down
22 changes: 20 additions & 2 deletions src/components/organisms/PluginManager/PluginManager.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {useCallback, useMemo, useState} from 'react';

import {Button, Skeleton, Tooltip} from 'antd';
import {Button, Skeleton, Tooltip, Typography} from 'antd';

import {PlusOutlined, ReloadOutlined} from '@ant-design/icons';

import {DEFAULT_TEMPLATES_PLUGIN_URL} from '@constants/constants';
import {PluginManagerDrawerReloadTooltip} from '@constants/tooltips';

import {useAppDispatch, useAppSelector} from '@redux/hooks';
Expand All @@ -13,6 +14,8 @@ import PluginInformation from './PluginInformation';
import PluginInstallModal from './PluginInstallModal';
import * as S from './PluginManager.styled';

const {Text} = Typography;

const PluginManagerDrawer: React.FC = () => {
const dispatch = useAppDispatch();
const isLoadingExistingPlugins = useAppSelector(state => state.extension.isLoadingExistingPlugins);
Expand Down Expand Up @@ -67,7 +70,22 @@ const PluginManagerDrawer: React.FC = () => {
</S.ButtonsContainer>
<S.Container>
{sortedPluginEntries.length === 0 ? (
<>{isLoadingExistingPlugins ? <Skeleton /> : <p>No plugins installed yet.</p>}</>
<>
{isLoadingExistingPlugins ? (
<Skeleton />
) : (
<div>
<p>No plugins installed yet.</p>
<p>
Reinstall the default Templates plugin using the below URL in the Plugin Installation modal by
clicking on the Install button.
</p>
<Text code copyable>
{DEFAULT_TEMPLATES_PLUGIN_URL}
</Text>
</div>
)}
</>
) : (
<>
{sortedPluginEntries.length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const SortableList = () => {};

export default SortableList;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './SortableList';
3 changes: 2 additions & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export const DEFAULT_KUBECONFIG_DEBOUNCE = 1000;
export const ACTIONS_PANE_FOOTER_DEFAULT_HEIGHT = 43;
export const ACTIONS_PANE_FOOTER_EXPANDED_DEFAULT_HEIGHT = 150;
export const MIN_SPLIT_VIEW_PANE_WIDTH = 350;
export const DEFAULT_TEMPLATES_PLUGIN_URL = 'https://github.com/kubeshop/monokle-default-templates-plugin';
export const DEFAULT_PLUGINS = [
{
owner: 'kubeshop',
name: 'monokle-default-templates-plugin',
url: 'https://github.com/kubeshop/monokle-default-templates-plugin',
url: DEFAULT_TEMPLATES_PLUGIN_URL,
},
];
export const PLUGIN_DOCS_URL = 'https://kubeshop.github.io/monokle/plugins/';
Expand Down
10 changes: 10 additions & 0 deletions src/redux/services/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import asyncLib from 'async';
import fs from 'fs';
import log from 'loglevel';

import {DEFAULT_TEMPLATES_PLUGIN_URL} from '@constants/constants';

import {AlertEnum, AlertType} from '@models/alert';
import {AppDispatch} from '@models/appdispatch';
import {K8sResource} from '@models/k8sresource';
Expand All @@ -13,6 +15,8 @@ import {TemplateManifest, TemplatePack, VanillaTemplate} from '@models/template'
import {setAlert} from '@redux/reducers/alert';
import {removePlugin, removeTemplate, removeTemplatePack} from '@redux/reducers/extension';

import electronStore from '@utils/electronStore';

import {extractObjectsFromYaml} from './manifest-utils';
import {createUnsavedResource} from './unsavedResource';

Expand Down Expand Up @@ -41,6 +45,12 @@ export const deletePlugin = async (plugin: AnyPlugin, pluginPath: string, dispat
});
dispatch(removePlugin(pluginPath));

let repositoryUrl = `https://github.com/${plugin.repository.owner}/${plugin.repository.name}`;

if (repositoryUrl === DEFAULT_TEMPLATES_PLUGIN_URL) {
electronStore.set('appConfig.hasDeletedDefaultTemplatesPlugin', true);
}

const alert: AlertType = {
title: `Deleted templates (${deletedTemplates}) successfully`,
type: AlertEnum.Success,
Expand Down
1 change: 1 addition & 0 deletions src/utils/electronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const defaults = {
recentFolders: [],
newVersion: 0,
k8sVersion: PREDEFINED_K8S_VERSION,
hasDeletedDefaultTemplatesPlugin: false,
},
ui: {
isSettingsOpen: false,
Expand Down

0 comments on commit b9d7a0d

Please sign in to comment.