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}plugin/public`,
pluginUpdate: (pluginId) => `${urlBase}plugin/${pluginId}`,
pluginFile: (pluginName, fileKey) => `${urlBase}plugin/${pluginName}/file/${fileKey}`,
pluginPublicFile: (pluginName, fileKey) =>
Expand Down
7 changes: 6 additions & 1 deletion app/src/controllers/auth/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ 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';
Expand All @@ -74,6 +78,7 @@ import { tokenSelector } from './selectors';
// TODO: clear cookie on logout
function* handleLogout() {
yield put(resetTokenAction());
yield put(fetchPublicPluginsAction());
yield put(fetchAppInfoAction());
yield put(
redirect({
Expand Down
7 changes: 6 additions & 1 deletion app/src/controllers/initialData/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ 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 { setInitialDataReadyAction } from './actionCreators';
import { FETCH_INITIAL_DATA } from './constants';
Expand All @@ -49,6 +53,7 @@ function* fetchInitialData() {
yield put(authSuccessAction());
} else {
yield put(resetTokenAction());
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
yield put(fetchPublicPluginsAction());
}
yield put(setInitialDataReadyAction());
}
Expand Down
5 changes: 5 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 @@ -40,6 +41,10 @@ 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 Down
3 changes: 3 additions & 0 deletions app/src/controllers/plugins/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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';
Expand All @@ -43,3 +44,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
2 changes: 2 additions & 0 deletions app/src/controllers/plugins/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
REMOVE_PROJECT_INTEGRATION_SUCCESS,
REMOVE_PROJECT_INTEGRATIONS_BY_TYPE_SUCCESS,
REMOVE_GLOBAL_INTEGRATIONS_BY_TYPE_SUCCESS,
PUBLIC_PLUGINS,
} from './constants';

const addIntegration = (state, type, payload) => ({
Expand Down Expand Up @@ -119,6 +120,7 @@ export const integrationsReducer = (state = {}, { type, payload }) => {

export const pluginsReducer = combineReducers({
plugins: queueReducers(fetchReducer(NAMESPACE), updatePluginLocallyReducer),
publicPlugins: fetchReducer(PUBLIC_PLUGINS),
integrations: integrationsReducer,
uiExtensions: uiExtensionsReducer,
});
18 changes: 17 additions & 1 deletion 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 All @@ -53,7 +55,7 @@ import {
fetchGlobalIntegrationsSuccessAction,
removeGlobalIntegrationsByTypeSuccessAction,
} from './actionCreators';
import { fetchUiExtensions } from './uiExtensions';
import { fetchUiExtensions, fetchExtensionsMetadata } from './uiExtensions';

function* addIntegration({ payload: { data, isGlobal, pluginName, callback }, meta }) {
yield put(showScreenLockAction());
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,10 @@ function* watchPluginChange() {
);
}

function* watchPublicPluginChange() {
yield takeEvery(createFetchPredicate(PUBLIC_PLUGINS), fetchExtensionsMetadata);
}

export function* pluginSagas() {
yield all([
watchAddIntegration(),
Expand All @@ -260,7 +274,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
2 changes: 1 addition & 1 deletion app/src/controllers/plugins/uiExtensions/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { fetchUiExtensions } from './sagas';
export { fetchUiExtensions, fetchExtensionsMetadata } from './sagas';
export {
uiExtensionSettingsTabsSelector,
uiExtensionAdminPagesSelector,
Expand Down
21 changes: 15 additions & 6 deletions app/src/controllers/plugins/uiExtensions/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import { select, call, all, put } from 'redux-saga/effects';
import { URLS } from 'common/urls';
import { fetch } from 'common/utils/fetch';
import { activeProjectSelector } from 'controllers/user';
import { PUBLIC_PLUGINS } from 'controllers/plugins/constants';
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,
extensionLoadStartAction,
fetchExtensionsMetadataSuccessAction,
} from './actions';

function* fetchExtensionsMetadata() {
const plugins = yield select(pluginsSelector);
export function* fetchExtensionsMetadata(action) {
const isPublic = action && action.meta.namespace === PUBLIC_PLUGINS;
const plugins = yield select(isPublic ? publicPluginsSelector : pluginsSelector);
const uiExtensionPlugins = plugins.filter(
(plugin) =>
plugin.enabled &&
Expand All @@ -30,9 +32,15 @@ function* fetchExtensionsMetadata() {
const calls = uiExtensionPlugins.map((plugin) => {
const metadataFile = plugin.details.binaryData[METADATA_FILE_KEY];
// TODO: use public/private endpoint to get files based on plugin type (public/private)
return call(fetch, URLS.pluginFile(plugin.name, metadataFile), {
contentType: 'application/json',
});
return call(
fetch,
isPublic
? URLS.pluginPublicFile(plugin.name, metadataFile)
: URLS.pluginFile(plugin.name, metadataFile),
{
contentType: 'application/json',
},
);
});

if (calls.length === 0) {
Expand All @@ -44,6 +52,7 @@ function* fetchExtensionsMetadata() {
const metadataArray = results.map((metadata, index) => ({
...metadata,
pluginName: uiExtensionPlugins[index].name,
isPublic,
}));

yield put(fetchExtensionsMetadataSuccessAction(metadataArray));
Expand Down