From 0592f5a32eabf9f63d56c9edfe3e726b3bbb8d82 Mon Sep 17 00:00:00 2001 From: soupette Date: Mon, 16 Sep 2019 12:07:05 +0200 Subject: [PATCH] Remove legacy context api in admin --- .../components/InstallPluginPopup/index.js | 93 +++++++++++++------ .../admin/src/containers/Marketplace/index.js | 39 ++++---- .../admin/src/contexts/MarketPlace/index.js | 27 ++++++ 3 files changed, 111 insertions(+), 48 deletions(-) create mode 100644 packages/strapi-admin/admin/src/contexts/MarketPlace/index.js diff --git a/packages/strapi-admin/admin/src/components/InstallPluginPopup/index.js b/packages/strapi-admin/admin/src/components/InstallPluginPopup/index.js index 7da80071dc..957b907d82 100644 --- a/packages/strapi-admin/admin/src/components/InstallPluginPopup/index.js +++ b/packages/strapi-admin/admin/src/components/InstallPluginPopup/index.js @@ -1,8 +1,8 @@ /* -* -* InstallPluginPopup -* -*/ + * + * InstallPluginPopup + * + */ import React from 'react'; import PropTypes from 'prop-types'; @@ -10,26 +10,28 @@ import { FormattedMessage } from 'react-intl'; import { Modal, ModalHeader, ModalBody } from 'reactstrap'; import { map } from 'lodash'; import cn from 'classnames'; - +import { MarketPlaceContext } from '../../contexts/MarketPlace'; import Official from '../Official'; // import StarsContainer from 'components/StarsContainer'; import styles from './styles.scss'; class InstallPluginPopup extends React.Component { + static contextType = MarketPlaceContext; + handleClick = () => { this.props.history.push({ pathname: this.props.history.location.pathname }); if (!this.props.isAlreadyInstalled) { this.context.downloadPlugin(this.props.plugin.id); } - } + }; toggle = () => { this.props.history.push({ pathname: this.props.history.location.pathname, }); - } + }; navLinks = [ { @@ -56,19 +58,42 @@ class InstallPluginPopup extends React.Component { render() { const descriptions = { - short: this.props.plugin.id === 'support-us' ? : this.props.plugin.description.short, - long: this.props.plugin.id === 'support-us' ? : this.props.plugin.description.long || this.props.plugin.description.short, + short: + this.props.plugin.id === 'support-us' ? ( + + ) : ( + this.props.plugin.description.short + ), + long: + this.props.plugin.id === 'support-us' ? ( + + ) : ( + this.props.plugin.description.long || + this.props.plugin.description.short + ), }; - const buttonName = this.props.isAlreadyInstalled ? 'app.components.PluginCard.Button.label.install' : 'app.components.InstallPluginPopup.downloads'; + const buttonName = this.props.isAlreadyInstalled + ? 'app.components.PluginCard.Button.label.install' + : 'app.components.InstallPluginPopup.downloads'; return ( - +
-
-
icon
+
+ icon +
{this.props.plugin.name}
@@ -86,8 +111,16 @@ class InstallPluginPopup extends React.Component {
- - + +
@@ -95,7 +128,10 @@ class InstallPluginPopup extends React.Component { +{this.props.plugin.downloads_nb}k  */}
-
+
@@ -110,37 +146,40 @@ class InstallPluginPopup extends React.Component {
{map(this.navLinks, link => { - const isActive = this.props.history.location.hash.split('::')[1] === link.name; + const isActive = + this.props.history.location.hash.split('::')[1] === link.name; return (
{ if (link.name === 'description') { - this.props.history.push({ pathname: this.props.history.location.pathname, hash: `${this.props.plugin.id}::${link.name}` }); + this.props.history.push({ + pathname: this.props.history.location.pathname, + hash: `${this.props.plugin.id}::${link.name}`, + }); } }} - style={isActive ? { paddingTop: '4px'} : { paddingTop: '6px' }} + style={ + isActive ? { paddingTop: '4px' } : { paddingTop: '6px' } + } >
); })}
-
- {descriptions.long} -
+
{descriptions.long}
); } } -InstallPluginPopup.contextTypes = { - downloadPlugin: PropTypes.func.isRequired, -}; - InstallPluginPopup.defaultProps = { description: { short: 'app.Components.InstallPluginPopup.noDescription', diff --git a/packages/strapi-admin/admin/src/containers/Marketplace/index.js b/packages/strapi-admin/admin/src/containers/Marketplace/index.js index 21bd74cee0..ed55356519 100644 --- a/packages/strapi-admin/admin/src/containers/Marketplace/index.js +++ b/packages/strapi-admin/admin/src/containers/Marketplace/index.js @@ -13,6 +13,7 @@ import cn from 'classnames'; import { LoadingIndicatorPage, PluginHeader } from 'strapi-helper-plugin'; +import { MarketPlaceContextProvider } from '../../contexts/MarketPlace'; // Design import PageTitle from '../../components/PageTitle'; import PluginCard from '../../components/PluginCard'; @@ -33,10 +34,6 @@ import saga from './saga'; import styles from './styles.scss'; class Marketplace extends React.Component { - getChildContext = () => ({ - downloadPlugin: this.props.downloadPlugin, - }); - componentDidMount() { // Fetch the available and installed plugins this.props.getAvailableAndInstalledPlugins(); @@ -87,29 +84,29 @@ class Marketplace extends React.Component { } return ( -
- - {this.renderHelmet} - -
- -
- {Object.keys(availablePlugins).map(this.renderPluginCard)} + +
+ + {this.renderHelmet} + +
+ +
+ {Object.keys(availablePlugins).map(this.renderPluginCard)} +
-
+ ); } } -Marketplace.childContextTypes = { - downloadPlugin: PropTypes.func.isRequired, -}; - Marketplace.defaultProps = {}; Marketplace.propTypes = { diff --git a/packages/strapi-admin/admin/src/contexts/MarketPlace/index.js b/packages/strapi-admin/admin/src/contexts/MarketPlace/index.js new file mode 100644 index 0000000000..71a6bef53c --- /dev/null +++ b/packages/strapi-admin/admin/src/contexts/MarketPlace/index.js @@ -0,0 +1,27 @@ +import React, { createContext, useContext } from 'react'; +import PropTypes from 'prop-types'; + +const MarketPlaceContext = createContext({}); + +const MarketPlaceContextProvider = ({ children, ...rest }) => { + return ( + + {children} + + ); +}; + +const useMarketPlaceContext = () => useContext(MarketPlaceContext); + +MarketPlaceContextProvider.defaultProps = {}; + +MarketPlaceContextProvider.propTypes = { + children: PropTypes.node.isRequired, + dowloadPlugin: PropTypes.func.isRequired, +}; + +export { + MarketPlaceContext, + MarketPlaceContextProvider, + useMarketPlaceContext, +};