Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-76241 || Plugins receiving before user login #3053

Merged
merged 9 commits into from
Apr 4, 2022
1 change: 1 addition & 0 deletions app/src/common/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const URLS = {
appInfo: () => `${compositeBase}info`,

plugin: () => `${urlBase}plugin`,
pluginPublic: () => `${urlBase}getPlugins`,
pluginUpdate: (pluginId) => `${urlBase}plugin/${pluginId}`,
pluginFile: (pluginName, fileKey) => `${urlBase}plugin/${pluginName}/file/${fileKey}`,
pluginPublicFile: (pluginName, fileKey) =>
Expand Down
9 changes: 8 additions & 1 deletion app/src/controllers/auth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ import {
userIdSelector,
} from 'controllers/user';
import { FETCH_PROJECT_SUCCESS, fetchProjectAction } from 'controllers/project';
import { fetchPluginsAction, fetchGlobalIntegrationsAction } from 'controllers/plugins';
import {
fetchPluginsAction,
fetchGlobalIntegrationsAction,
fetchPublicPluginsAction,
} from 'controllers/plugins';
import { redirect, pathToAction } from 'redux-first-router';
import qs, { stringify } from 'qs';
import routesMap from 'routes/routesMap';
import { resetPluginAction } from 'controllers/plugins/actionCreators';
import {
authSuccessAction,
resetTokenAction,
Expand All @@ -74,6 +79,8 @@ import { tokenSelector } from './selectors';
// TODO: clear cookie on logout
function* handleLogout() {
yield put(resetTokenAction());
yield put(resetPluginAction());
yield put(fetchPublicPluginsAction());
yield put(fetchAppInfoAction());
yield put(
redirect({
Expand Down
9 changes: 8 additions & 1 deletion app/src/controllers/initialData/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ import {
authSuccessAction,
} from 'controllers/auth';
import { FETCH_PROJECT_SUCCESS, fetchProjectAction } from 'controllers/project';
import { fetchGlobalIntegrationsAction, fetchPluginsAction } from 'controllers/plugins';
import {
fetchGlobalIntegrationsAction,
fetchPluginsAction,
fetchPublicPluginsAction,
} from 'controllers/plugins';
import { getStorageItem } from 'common/utils';
import { resetPluginAction } from 'controllers/plugins/actionCreators';
import { setInitialDataReadyAction } from './actionCreators';
import { FETCH_INITIAL_DATA } from './constants';

Expand All @@ -49,6 +54,8 @@ function* fetchInitialData() {
yield put(authSuccessAction());
} else {
yield put(resetTokenAction());
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
yield put(resetPluginAction());
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
yield put(fetchPublicPluginsAction());
}
yield put(setInitialDataReadyAction());
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/controllers/plugins/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
FETCH_PLUGINS,
FETCH_PUBLIC_PLUGINS,
REMOVE_PLUGIN,
UPDATE_PLUGIN_SUCCESS,
REMOVE_PLUGIN_SUCCESS,
Expand All @@ -34,12 +35,17 @@ import {
FETCH_GLOBAL_INTEGRATIONS,
FETCH_GLOBAL_INTEGRATIONS_SUCCESS,
REMOVE_GLOBAL_INTEGRATIONS_BY_TYPE_SUCCESS,
RESET_PLUGIN_SUCCESS,
} from './constants';

export const fetchPluginsAction = () => ({
type: FETCH_PLUGINS,
});

export const fetchPublicPluginsAction = () => ({
type: FETCH_PUBLIC_PLUGINS,
});

export const removePluginAction = (id, callback, pluginName) => ({
type: REMOVE_PLUGIN,
payload: { id, callback, pluginName },
Expand All @@ -55,6 +61,8 @@ export const updatePluginSuccessAction = (plugin) => ({
payload: plugin,
});

export const resetPluginAction = () => ({ type: RESET_PLUGIN_SUCCESS });

export const fetchGlobalIntegrationsAction = () => ({
type: FETCH_GLOBAL_INTEGRATIONS,
});
Expand Down
4 changes: 4 additions & 0 deletions app/src/controllers/plugins/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export const FETCH_GLOBAL_INTEGRATIONS = 'fetchGlobalIntegrations';
export const FETCH_GLOBAL_INTEGRATIONS_SUCCESS = 'fetchGlobalIntegrationsSuccess';

export const FETCH_PLUGINS = 'fetchPlugins';
export const FETCH_PUBLIC_PLUGINS = 'fetchPublicPlugins';
export const REMOVE_PLUGIN = 'removePlugin';
export const UPDATE_PLUGIN_SUCCESS = 'updatePluginSuccess';
export const REMOVE_PLUGIN_SUCCESS = 'removePluginSuccess';
export const RESET_PLUGIN_SUCCESS = 'resetPluginSuccess';

export const UPDATE_INTEGRATION = 'updateIntegration';
export const REMOVE_INTEGRATION = 'removeIntegration';
Expand All @@ -43,3 +45,5 @@ export const GLOBAL_INTEGRATIONS = 'globalIntegrations';
export const PROJECT_INTEGRATIONS = 'projectIntegrations';

export const SECRET_FIELDS_KEY = 'rp_secretFieldsToClear';

export const PUBLIC_PLUGINS = 'publicPlugins';
1 change: 1 addition & 0 deletions app/src/controllers/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export { pluginsReducer } from './reducer';
export { SECRET_FIELDS_KEY } from './constants';
export {
fetchPluginsAction,
fetchPublicPluginsAction,
removePluginAction,
removePluginSuccessAction,
updatePluginSuccessAction,
Expand Down
5 changes: 5 additions & 0 deletions app/src/controllers/plugins/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import {
REMOVE_PROJECT_INTEGRATION_SUCCESS,
REMOVE_PROJECT_INTEGRATIONS_BY_TYPE_SUCCESS,
REMOVE_GLOBAL_INTEGRATIONS_BY_TYPE_SUCCESS,
PUBLIC_PLUGINS,
RESET_PLUGIN_SUCCESS,
} from './constants';

const addIntegration = (state, type, payload) => ({
Expand Down Expand Up @@ -79,6 +81,8 @@ export const updatePluginLocallyReducer = (state, { type, payload }) => {
});
case REMOVE_PLUGIN_SUCCESS:
return state.filter((item) => item.type !== payload);
case RESET_PLUGIN_SUCCESS:
return [];
default:
return state;
}
Expand Down Expand Up @@ -119,6 +123,7 @@ export const integrationsReducer = (state = {}, { type, payload }) => {

export const pluginsReducer = combineReducers({
plugins: queueReducers(fetchReducer(NAMESPACE), updatePluginLocallyReducer),
publicPlugins: fetchReducer(PUBLIC_PLUGINS),
integrations: integrationsReducer,
uiExtensions: uiExtensionsReducer,
});
19 changes: 19 additions & 0 deletions app/src/controllers/plugins/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { userIdSelector } from 'controllers/user';
import {
NAMESPACE,
FETCH_PLUGINS,
FETCH_PUBLIC_PLUGINS,
REMOVE_PLUGIN,
REMOVE_PROJECT_INTEGRATIONS_BY_TYPE,
ADD_INTEGRATION,
Expand All @@ -38,6 +39,7 @@ import {
FETCH_GLOBAL_INTEGRATIONS,
SECRET_FIELDS_KEY,
FETCH_GLOBAL_INTEGRATIONS_SUCCESS,
PUBLIC_PLUGINS,
} from './constants';
import { resolveIntegrationUrl } from './utils';
import { pluginByNameSelector } from './selectors';
Expand Down Expand Up @@ -214,10 +216,18 @@ function* fetchPlugins() {
yield put(fetchDataAction(NAMESPACE)(URLS.plugin()));
}

function* fetchPublicPlugins() {
yield put(fetchDataAction(PUBLIC_PLUGINS)(URLS.pluginPublic()));
}

function* watchFetchPlugins() {
yield takeEvery(FETCH_PLUGINS, fetchPlugins);
}

function* watchFetchPublicPlugins() {
yield takeEvery(FETCH_PUBLIC_PLUGINS, fetchPublicPlugins);
}

function* removePlugin({ payload: { id, callback, pluginName } }) {
yield put(showScreenLockAction());
try {
Expand Down Expand Up @@ -252,6 +262,13 @@ function* watchPluginChange() {
);
}

function* watchPublicPluginChange() {
yield takeEvery(
[createFetchPredicate(PUBLIC_PLUGINS), FETCH_GLOBAL_INTEGRATIONS_SUCCESS],
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
fetchUiExtensions,
);
}

export function* pluginSagas() {
yield all([
watchAddIntegration(),
Expand All @@ -260,7 +277,9 @@ export function* pluginSagas() {
watchRemoveIntegrationsByType(),
watchFetchGlobalIntegrations(),
watchFetchPlugins(),
watchFetchPublicPlugins(),
watchRemovePlugin(),
watchPluginChange(),
watchPublicPluginChange(),
]);
}
7 changes: 6 additions & 1 deletion app/src/controllers/plugins/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {

export const domainSelector = (state) => state.plugins || {};

export const pluginsSelector = (state) => domainSelector(state).plugins;
export const pluginsSelector = (state) => {
return domainSelector(state).plugins;
};
export const publicPluginsSelector = (state) => {
return domainSelector(state).publicPlugins;
};
export const pluginByNameSelector = (state, name) =>
pluginsSelector(state).find((plugin) => plugin.name === name);

Expand Down
6 changes: 4 additions & 2 deletions app/src/controllers/plugins/uiExtensions/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { URLS } from 'common/urls';
import { fetch } from 'common/utils/fetch';
import { activeProjectSelector } from 'controllers/user';
import { COMMAND_GET_FILE, METADATA_FILE_KEY, MAIN_FILE_KEY } from './constants';
import { pluginsSelector, globalIntegrationsSelector } from '../selectors';
import { pluginsSelector, globalIntegrationsSelector, publicPluginsSelector } from '../selectors';
import { filterIntegrationsByName, isPluginSupportsCommonCommand } from '../utils';
import {
extensionLoadFinishAction,
Expand All @@ -13,7 +13,9 @@ import {

function* fetchExtensionsMetadata() {
const plugins = yield select(pluginsSelector);
const uiExtensionPlugins = plugins.filter(
const publicPlugins = yield select(publicPluginsSelector);
const currentPlugins = !plugins.length ? publicPlugins : plugins;
const uiExtensionPlugins = currentPlugins.filter(
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
(plugin) =>
plugin.enabled &&
plugin.details &&
Expand Down