Skip to content
Snippets Groups Projects
Commit e286a419 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '215-min-282-plugins-refresh-plugin' into 'development'

Resolve "[MIN-282] Plugins: refresh plugin"

Closes #215

See merge request !197
parents ed89cc84 e9001852
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!197Resolve "[MIN-282] Plugins: refresh plugin"
Pipeline #90058 passed
...@@ -105,15 +105,19 @@ export const useLoadPlugin = ({ ...@@ -105,15 +105,19 @@ export const useLoadPlugin = ({
}; };
const handleReloadPlugin = async (): Promise<void> => { const handleReloadPlugin = async (): Promise<void> => {
handleUnloadPlugin(); PluginsManager.removePluginContent({ hash });
PluginsManager.unloadActivePlugin(hash);
PluginsEventBus.dispatchEvent('onPluginUnload', { hash });
await handleLoadPlugin(); await handleLoadPlugin();
}; };
const togglePlugin = (): void => { const togglePlugin = async (): Promise<void> => {
if (isPluginActive) { if (isPluginActive) {
handleUnloadPlugin(); handleUnloadPlugin();
} else { } else {
handleLoadPlugin(); await handleLoadPlugin();
} }
}; };
......
...@@ -80,26 +80,16 @@ describe('PluginHeaderInfo - component', () => { ...@@ -80,26 +80,16 @@ describe('PluginHeaderInfo - component', () => {
}); });
it('reload plugin on reload button', async () => { it('reload plugin on reload button', async () => {
const { store } = renderComponent(STATE, PLUGIN); renderComponent(STATE, PLUGIN);
mockedAxiosClient.onGet(PLUGIN.urls[FIRST_ARRAY_ELEMENT]).reply(HttpStatusCode.Ok, ''); mockedAxiosClient.onGet(PLUGIN.urls[FIRST_ARRAY_ELEMENT]).reply(HttpStatusCode.Ok, '');
const button = screen.getByRole(RELOAD_PLUGIN_DRAWER_BUTTON_ROLE); const button = screen.getByRole(RELOAD_PLUGIN_DRAWER_BUTTON_ROLE);
button.click(); button.click();
const actions = store.getActions();
expect(removePluginContentSpy).toHaveBeenCalledWith({ expect(removePluginContentSpy).toHaveBeenCalledWith({
hash: PLUGIN.hash, hash: PLUGIN.hash,
}); });
expect(actions).toEqual([
{ payload: { pluginId: '5e3fcb59588cc311ef9839feea6382eb' }, type: 'plugins/removePlugin' },
{
payload: '5e3fcb59588cc311ef9839feea6382eb',
type: 'legend/removePluginLegend',
},
]);
await waitFor(() => { await waitFor(() => {
expect(setHashedPluginSpy).toHaveBeenCalledWith({ expect(setHashedPluginSpy).toHaveBeenCalledWith({
pluginScript: '', pluginScript: '',
......
import type { ActionReducerMapBuilder } from '@reduxjs/toolkit'; import type { ActionReducerMapBuilder } from '@reduxjs/toolkit';
import { ZERO } from '@/constants/common';
import { getAllPlugins, registerPlugin } from './plugins.thunks'; import { getAllPlugins, registerPlugin } from './plugins.thunks';
import type { import type {
PluginsState, PluginsState,
...@@ -15,7 +16,9 @@ export const removePluginReducer = (state: PluginsState, action: RemovePluginAct ...@@ -15,7 +16,9 @@ export const removePluginReducer = (state: PluginsState, action: RemovePluginAct
export const registerPluginReducer = (builder: ActionReducerMapBuilder<PluginsState>): void => { export const registerPluginReducer = (builder: ActionReducerMapBuilder<PluginsState>): void => {
builder.addCase(registerPlugin.pending, (state, action) => { builder.addCase(registerPlugin.pending, (state, action) => {
const { hash } = action.meta.arg; const { hash } = action.meta.arg;
state.activePlugins.pluginsId.push(hash); if (state.activePlugins.pluginsId.indexOf(hash) < ZERO) {
state.activePlugins.pluginsId.push(hash);
}
}); });
builder.addCase(registerPlugin.fulfilled, (state, action) => { builder.addCase(registerPlugin.fulfilled, (state, action) => {
if (action.payload) { if (action.payload) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment