mirror of
https://github.com/strapi/strapi.git
synced 2026-01-07 20:58:16 +00:00
Merge pull request #1732 from strapi/fix/installed-plugins
Fix download display
This commit is contained in:
commit
c35a89466c
@ -129,7 +129,7 @@ if (window.location.port !== '4000') {
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
console.log(err); // eslint-disable-line no-console
|
||||
});
|
||||
} else if (findIndex(plugins, ['id', 'users-permissions']) === -1) {
|
||||
store.dispatch(unsetHasUserPlugin());
|
||||
|
||||
@ -8,8 +8,10 @@ import {
|
||||
DOWNLOAD_PLUGIN,
|
||||
DOWNLOAD_PLUGIN_ERROR,
|
||||
DOWNLOAD_PLUGIN_SUCCEEDED,
|
||||
GET_PLUGINS,
|
||||
GET_PLUGINS_SUCCEEDED,
|
||||
GET_AVAILABLE_PLUGINS,
|
||||
GET_AVAILABLE_PLUGINS_SUCCEEDED,
|
||||
GET_INSTALLED_PLUGINS,
|
||||
GET_INSTALLED_PLUGINS_SUCCEEDED,
|
||||
ON_CHANGE,
|
||||
} from './constants';
|
||||
|
||||
@ -32,19 +34,32 @@ export function downloadPluginSucceeded() {
|
||||
};
|
||||
}
|
||||
|
||||
export function getPlugins() {
|
||||
export function getAvailablePlugins() {
|
||||
return {
|
||||
type: GET_PLUGINS,
|
||||
type: GET_AVAILABLE_PLUGINS,
|
||||
};
|
||||
}
|
||||
|
||||
export function getPluginsSucceeded(availablePlugins) {
|
||||
export function getAvailablePluginsSucceeded(availablePlugins) {
|
||||
return {
|
||||
type: GET_PLUGINS_SUCCEEDED,
|
||||
type: GET_AVAILABLE_PLUGINS_SUCCEEDED,
|
||||
availablePlugins,
|
||||
};
|
||||
}
|
||||
|
||||
export function getInstalledPlugins() {
|
||||
return {
|
||||
type: GET_INSTALLED_PLUGINS,
|
||||
};
|
||||
}
|
||||
|
||||
export function getInstalledPluginsSucceeded(installedPlugins) {
|
||||
return {
|
||||
type: GET_INSTALLED_PLUGINS_SUCCEEDED,
|
||||
installedPlugins,
|
||||
};
|
||||
}
|
||||
|
||||
export function onChange({ target }) {
|
||||
return {
|
||||
type: ON_CHANGE,
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
export const DOWNLOAD_PLUGIN = 'StrapiAdmin/InstallPluginPage/DOWNLOAD_PLUGIN';
|
||||
export const DOWNLOAD_PLUGIN_ERROR = 'StrapiAdmin/InstallPluginPage/DOWNLOAD_PLUGIN_ERROR';
|
||||
export const DOWNLOAD_PLUGIN_SUCCEEDED = 'StrapiAdmin/InstallPluginPage/DOWNLOAD_PLUGIN_SUCCEEDED';
|
||||
export const GET_PLUGINS = 'StrapiAdmin/InstallPluginPage/GET_PLUGINS';
|
||||
export const GET_PLUGINS_SUCCEEDED = 'StrapiAdmin/InstallPluginPage/GET_PLUGINS_SUCCEEDED';
|
||||
export const GET_AVAILABLE_PLUGINS = 'StrapiAdmin/InstallPluginPage/GET_AVAILABLE_PLUGINS';
|
||||
export const GET_AVAILABLE_PLUGINS_SUCCEEDED = 'StrapiAdmin/InstallPluginPage/GET_AVAILABLE_PLUGINS_SUCCEEDED';
|
||||
export const GET_INSTALLED_PLUGINS = 'StrapiAdmin/InstallPluginPage/GET_INSTALLED_PLUGINS';
|
||||
export const GET_INSTALLED_PLUGINS_SUCCEEDED = 'StrapiAdmin/InstallPluginPage/GET_INSTALLED_PLUGINS_SUCCEEDED';
|
||||
export const ON_CHANGE = 'StrapiAdmin/InstallPluginPage/ON_CHANGE';
|
||||
|
||||
@ -11,7 +11,7 @@ import { Helmet } from 'react-helmet';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { bindActionCreators, compose } from 'redux';
|
||||
import cn from 'classnames';
|
||||
import { get, isUndefined, map } from 'lodash';
|
||||
import { map } from 'lodash';
|
||||
|
||||
import {
|
||||
disableGlobalOverlayBlocker,
|
||||
@ -32,7 +32,8 @@ import injectReducer from 'utils/injectReducer';
|
||||
|
||||
import {
|
||||
downloadPlugin,
|
||||
getPlugins,
|
||||
getAvailablePlugins,
|
||||
getInstalledPlugins,
|
||||
onChange,
|
||||
} from './actions';
|
||||
|
||||
@ -55,8 +56,11 @@ export class InstallPluginPage extends React.Component { // eslint-disable-line
|
||||
|
||||
// Don't fetch the available plugins if it has already been done
|
||||
if (!this.props.didFetchPlugins) {
|
||||
this.props.getPlugins();
|
||||
this.props.getAvailablePlugins();
|
||||
}
|
||||
|
||||
// Get installed plugins
|
||||
this.props.getInstalledPlugins();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
@ -65,10 +69,10 @@ export class InstallPluginPage extends React.Component { // eslint-disable-line
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.props.didFetchPlugins) {
|
||||
if (!this.props.didFetchPlugins || !this.props.didFetchInstalledPlugins) {
|
||||
return <LoadingIndicatorPage />;
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<OverlayBlocker isOpen={this.props.blockApp}>
|
||||
@ -112,7 +116,7 @@ export class InstallPluginPage extends React.Component { // eslint-disable-line
|
||||
key={plugin.id}
|
||||
plugin={plugin}
|
||||
showSupportUsButton={plugin.id === 'support-us'}
|
||||
isAlreadyInstalled={!isUndefined(get(this.context.plugins.toJS(), plugin.id))}
|
||||
isAlreadyInstalled={this.props.installedPlugins.includes(plugin.id)}
|
||||
downloadPlugin={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@ -134,19 +138,18 @@ InstallPluginPage.childContextTypes = {
|
||||
downloadPlugin: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
InstallPluginPage.contextTypes = {
|
||||
plugins: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
InstallPluginPage.propTypes = {
|
||||
availablePlugins: PropTypes.array.isRequired,
|
||||
blockApp: PropTypes.bool.isRequired,
|
||||
didFetchInstalledPlugins: PropTypes.bool.isRequired,
|
||||
didFetchPlugins: PropTypes.bool.isRequired,
|
||||
disableGlobalOverlayBlocker: PropTypes.func.isRequired,
|
||||
downloadPlugin: PropTypes.func.isRequired,
|
||||
enableGlobalOverlayBlocker: PropTypes.func.isRequired,
|
||||
getPlugins: PropTypes.func.isRequired,
|
||||
getAvailablePlugins: PropTypes.func.isRequired,
|
||||
getInstalledPlugins: PropTypes.func.isRequired,
|
||||
history: PropTypes.object.isRequired,
|
||||
installedPlugins: PropTypes.array.isRequired,
|
||||
// onChange: PropTypes.func.isRequired,
|
||||
// search: PropTypes.string.isRequired,
|
||||
};
|
||||
@ -159,7 +162,8 @@ function mapDispatchToProps(dispatch) {
|
||||
disableGlobalOverlayBlocker,
|
||||
downloadPlugin,
|
||||
enableGlobalOverlayBlocker,
|
||||
getPlugins,
|
||||
getAvailablePlugins,
|
||||
getInstalledPlugins,
|
||||
onChange,
|
||||
},
|
||||
dispatch,
|
||||
|
||||
@ -9,14 +9,17 @@ import {
|
||||
DOWNLOAD_PLUGIN,
|
||||
DOWNLOAD_PLUGIN_ERROR,
|
||||
DOWNLOAD_PLUGIN_SUCCEEDED,
|
||||
GET_PLUGINS_SUCCEEDED,
|
||||
GET_AVAILABLE_PLUGINS_SUCCEEDED,
|
||||
GET_INSTALLED_PLUGINS_SUCCEEDED,
|
||||
ON_CHANGE,
|
||||
} from './constants';
|
||||
|
||||
const initialState = fromJS({
|
||||
availablePlugins: List([]),
|
||||
installedPlugins: List([]),
|
||||
blockApp: false,
|
||||
didFetchPlugins: false,
|
||||
didFetchInstalledPlugins: false,
|
||||
pluginToDownload: '',
|
||||
search: '',
|
||||
});
|
||||
@ -35,10 +38,14 @@ function installPluginPageReducer(state = initialState, action) {
|
||||
return state
|
||||
.set('blockApp', false)
|
||||
.set('pluginToDownload', '');
|
||||
case GET_PLUGINS_SUCCEEDED:
|
||||
case GET_AVAILABLE_PLUGINS_SUCCEEDED:
|
||||
return state
|
||||
.set('didFetchPlugins', true)
|
||||
.set('availablePlugins', List(action.availablePlugins));
|
||||
case GET_INSTALLED_PLUGINS_SUCCEEDED:
|
||||
return state
|
||||
.set('didFetchInstalledPlugins', true)
|
||||
.set('installedPlugins', List(action.installedPlugins));
|
||||
case ON_CHANGE:
|
||||
return state.updateIn(action.keys, () => action.value);
|
||||
default:
|
||||
|
||||
@ -15,9 +15,10 @@ import { selectLocale } from '../LanguageProvider/selectors';
|
||||
import {
|
||||
downloadPluginError,
|
||||
downloadPluginSucceeded,
|
||||
getPluginsSucceeded,
|
||||
getAvailablePluginsSucceeded,
|
||||
getInstalledPluginsSucceeded,
|
||||
} from './actions';
|
||||
import { DOWNLOAD_PLUGIN, GET_PLUGINS } from './constants';
|
||||
import { DOWNLOAD_PLUGIN, GET_AVAILABLE_PLUGINS, GET_INSTALLED_PLUGINS } from './constants';
|
||||
import { makeSelectPluginToDownload } from './selectors';
|
||||
|
||||
|
||||
@ -49,7 +50,7 @@ export function* pluginDownload() {
|
||||
}
|
||||
}
|
||||
|
||||
export function* pluginsGet() {
|
||||
export function* getAvailablePlugins() {
|
||||
try {
|
||||
// Get current locale.
|
||||
const locale = yield select(selectLocale());
|
||||
@ -73,20 +74,44 @@ export function* pluginsGet() {
|
||||
availablePlugins = [];
|
||||
}
|
||||
|
||||
yield put(getPluginsSucceeded(availablePlugins));
|
||||
yield put(getAvailablePluginsSucceeded(availablePlugins));
|
||||
} catch(err) {
|
||||
strapi.notification.error('notification.error');
|
||||
}
|
||||
}
|
||||
|
||||
export function* getInstalledPlugins() {
|
||||
try {
|
||||
const opts = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
|
||||
let installedPlugins;
|
||||
|
||||
try {
|
||||
// Retrieve plugins list.
|
||||
installedPlugins = yield call(request, '/admin/plugins', opts);
|
||||
} catch (e) {
|
||||
installedPlugins = [];
|
||||
}
|
||||
|
||||
yield put(getInstalledPluginsSucceeded(Object.keys(installedPlugins.plugins)));
|
||||
} catch(err) {
|
||||
strapi.notification.error('notification.error');
|
||||
}
|
||||
}
|
||||
|
||||
// Individual exports for testing
|
||||
export default function* defaultSaga() {
|
||||
const loadPluginsWatcher = yield fork(takeLatest, GET_PLUGINS, pluginsGet);
|
||||
const loadAvailablePluginsWatcher = yield fork(takeLatest, GET_AVAILABLE_PLUGINS, getAvailablePlugins);
|
||||
const loadInstalledPluginsWatcher = yield fork(takeLatest, GET_INSTALLED_PLUGINS, getInstalledPlugins);
|
||||
yield fork(takeLatest, DOWNLOAD_PLUGIN, pluginDownload);
|
||||
|
||||
yield take(LOCATION_CHANGE);
|
||||
|
||||
yield cancel(loadPluginsWatcher);
|
||||
yield cancel(loadAvailablePluginsWatcher);
|
||||
yield cancel(loadInstalledPluginsWatcher);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user