Skip to content
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
23 changes: 22 additions & 1 deletion web/client/epics/__tests__/contextcreator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,26 @@ describe('contextcreator epics', () => {
mockAxios.onPost().reply(200, "1");
mockAxios.onGet().reply(200, {});
const startActions = [saveNewContext("/")];
testEpic(saveContextResource, 4, startActions, actions => {
expect(actions.length).toBe(4);
expect(actions[0].type).toBe(LOADING);
expect(actions[1].type).toBe(CONTEXT_SAVED);
expect(actions[1].id).toBe(1);
expect(actions[2].type).toBe("@@router/CALL_HISTORY_METHOD");
expect(actions[3].type).toBe(LOADING);
}, {
contextcreator: {
resource: {
name: 'context'
}
},
map: {}
}, done);
});
it('saveContextResource saves a context with new plugin uploaded', (done) => {
mockAxios.onPost().reply(200, "1");
mockAxios.onGet().reply(200, {});
const startActions = [saveNewContext("/context-manager")];
testEpic(saveContextResource, 5, startActions, actions => {
expect(actions.length).toBe(5);
expect(actions[0].type).toBe(LOADING);
Expand All @@ -887,7 +907,8 @@ describe('contextcreator epics', () => {
contextcreator: {
resource: {
name: 'context'
}
},
uploadedPlugins: ["Sample"]
},
map: {}
}, done);
Expand Down
10 changes: 5 additions & 5 deletions web/client/epics/contextcreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {SAVE_CONTEXT, SAVE_TEMPLATE, LOAD_CONTEXT, LOAD_TEMPLATE, DELETE_TEMPLAT
enablePlugins, disablePlugins, setCfgError, changePluginsKey, changeTemplatesKey, setEditedTemplate, setTemplates, setParsedTemplate,
pluginUploaded, pluginUploading, pluginUninstalled, pluginUninstalling, loadExtensions, uploadPluginError,
setWasTutorialShown, setTutorialStep} from '../actions/contextcreator';
import {newContextSelector, resourceSelector, creationStepSelector, mapConfigSelector, mapViewerLoadedSelector, contextNameCheckedSelector,
import {resourceSelector, creationStepSelector, mapConfigSelector, mapViewerLoadedSelector, contextNameCheckedSelector,
editedPluginSelector, editedCfgSelector, validationStatusSelector, parsedCfgSelector, cfgErrorSelector,
pluginsSelector, initialEnabledPluginsSelector, templatesSelector, editedTemplateSelector, tutorialsSelector,
wasTutorialShownSelector, prefetchedDataSelector, generateContextResource } from '../selectors/contextcreator';
wasTutorialShownSelector, prefetchedDataSelector, generateContextResource, isNewPluginsUploaded } from '../selectors/contextcreator';
import {CONTEXTS_LIST_LOADED} from '../actions/contextmanager';
import {wrapStartStop} from '../observables/epics';
import {isLoggedIn} from '../selectors/security';
Expand Down Expand Up @@ -75,8 +75,8 @@ export const saveContextResource = (action$, store) => action$
.exhaustMap(({destLocation}) => {
const state = store.getState();
const resource = resourceSelector(state);
const context = newContextSelector(state);
const newResource = generateContextResource(state);
const allowLoadExtensions = isNewPluginsUploaded(state);
return (resource && resource.id ? updateResource : createResource)(newResource)
.switchMap(rid => Rx.Observable.merge(
// LOCATION_CHANGE triggers notifications clear, need to work around that
Expand All @@ -90,8 +90,8 @@ export const saveContextResource = (action$, store) => action$
}))) : Rx.Observable.empty()),
Rx.Observable.of(
contextSaved(rid),
push(destLocation || `/context/${context.name}`),
loadExtensions(),
push(destLocation || `/context/${resource.name}`),
...(allowLoadExtensions ? [loadExtensions()] : []),
loading(false, 'contextSaving')
)
))
Expand Down
10 changes: 8 additions & 2 deletions web/client/plugins/__tests__/ContextCreator-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ describe('ContextCreator plugin', () => {
contextcreator: {
stepId: 'configure-themes',
newContext: {},
plugins
plugins,
resource: {
name: "context"
}
},
map: {}
});
Expand All @@ -57,7 +60,10 @@ describe('ContextCreator plugin', () => {
const { Plugin, actions } = getPluginForTest(ContextCreator, {
contextcreator: {
stepId: 'configure-themes',
plugins
plugins,
resource: {
name: "context"
}
},
map: {}
});
Expand Down
11 changes: 11 additions & 0 deletions web/client/reducers/__tests__/contextcreator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,15 @@ describe('contextcreator reducer', () => {
expect(state).toExist();
expect(state.contextId).toBe('testId');
});
it('Track extension/plugins', () => {
// add new plugin extension
let state = contextcreator(undefined, pluginUploaded([{name: 'Sample'}]));
expect(state).toBeTruthy();
expect(state.uploadedPlugins).toEqual(['Sample']);

// remove extension
state = contextcreator({plugins: [{name: "Sample"}]}, pluginUninstalled({plugin: 'Sample'}));
expect(state).toBeTruthy();
expect(state.uploadedPlugins).toEqual([]);
});
});
8 changes: 5 additions & 3 deletions web/client/reducers/contextcreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import {get, omit, isObject, head, find, pick} from 'lodash';
import {get, omit, isObject, head, find, pick, uniq} from 'lodash';

import ConfigUtils from '../utils/ConfigUtils';

Expand Down Expand Up @@ -186,7 +186,8 @@ export default (state = {}, action) => {
uploadResult: {
result: "ok"
},
plugins: [...(state.plugins || []).filter(notDuplicate), ...plugins]
plugins: [...(state.plugins || []).filter(notDuplicate), ...plugins],
uploadedPlugins: uniq((state.uploadedPlugins ?? []).concat((action.plugins ?? []).map(p => p.name)))
};
}
case UNINSTALLING_PLUGIN: {
Expand All @@ -201,7 +202,8 @@ export default (state = {}, action) => {
case PLUGIN_UNINSTALLED: {
return {
...state,
plugins: state.plugins.filter(p => p.name !== action.plugin)
plugins: state.plugins.filter(p => p.name !== action.plugin),
uploadedPlugins: (state.uploadedPlugins ?? []).filter(p => p !== action.plugin)
};
}
case SET_RESOURCE: {
Expand Down
15 changes: 14 additions & 1 deletion web/client/selectors/__tests__/contextcreator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
isNewContext,
prefetchedDataSelector,
disableImportSelector,
generateContextResource
generateContextResource,
isNewPluginsUploaded
} from '../contextcreator';

const testState = {
Expand Down Expand Up @@ -192,4 +193,16 @@ describe('contextcreator selectors', () => {
expect(generatedSource.data.plugins).toEqual(expected.data.plugins);
expect(generatedSource.data.theme).toEqual(expected.data.theme);
});
it('loadExtensionsSelector', () => {
expect(isNewPluginsUploaded({
contextcreator: {
uploadedPlugins: ["Name"]
}
})).toBeTruthy();
expect(isNewPluginsUploaded({
contextcreator: {
uploadedPlugins: []
}
})).toBeFalsy();
});
});
5 changes: 5 additions & 0 deletions web/client/selectors/contextcreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ export const generateContextResource = (state) => {
}
};
};

export const isNewPluginsUploaded = (state) => {
const uploadedPlugins = state.contextcreator?.uploadedPlugins || [];
return uploadedPlugins.length > 0;
};