Remove sage from Marketplace

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-02-28 09:29:12 +01:00
parent a5cfe98c70
commit b7c09a816d
5 changed files with 176 additions and 3 deletions

View File

@ -80,7 +80,7 @@ class PluginCard extends React.Component {
} else if (currentEnvironment !== 'development') { } else if (currentEnvironment !== 'development') {
this.setState({ showModalEnv: true }); this.setState({ showModalEnv: true });
} else if (!isAlreadyInstalled) { } else if (!isAlreadyInstalled) {
downloadPlugin(e); downloadPlugin(id);
} else { } else {
push('/list-plugins'); push('/list-plugins');
} }
@ -152,6 +152,7 @@ class PluginCard extends React.Component {
<Button <Button
className={`${buttonClass} button`} className={`${buttonClass} button`}
label={buttonLabel} label={buttonLabel}
type="button"
onClick={this.handleDownloadPlugin} onClick={this.handleDownloadPlugin}
/> />
<a <a

View File

@ -28,7 +28,8 @@ import LeftMenu from '../LeftMenu';
import ListPluginsPage from '../ListPluginsPage'; import ListPluginsPage from '../ListPluginsPage';
import LocaleToggle from '../LocaleToggle'; import LocaleToggle from '../LocaleToggle';
import HomePage from '../HomePage'; import HomePage from '../HomePage';
import Marketplace from '../Marketplace'; // import Marketplace from '../Marketplace';
import Marketplace from '../MarketplacePage';
import NotFoundPage from '../NotFoundPage'; import NotFoundPage from '../NotFoundPage';
import OnboardingVideos from '../Onboarding'; import OnboardingVideos from '../Onboarding';
import SettingsPage from '../SettingsPage'; import SettingsPage from '../SettingsPage';
@ -135,7 +136,7 @@ export class Admin extends React.Component {
disableGlobalOverlayBlocker, disableGlobalOverlayBlocker,
emitEvent, emitEvent,
enableGlobalOverlayBlocker, enableGlobalOverlayBlocker,
intl: { formatMessage }, intl: { formatMessage, locale },
updatePlugin, updatePlugin,
} = this.props; } = this.props;
@ -154,6 +155,7 @@ export class Admin extends React.Component {
autoReload={autoReload} autoReload={autoReload}
emitEvent={emitEvent} emitEvent={emitEvent}
currentEnvironment={currentEnvironment} currentEnvironment={currentEnvironment}
currentLocale={locale}
disableGlobalOverlayBlocker={disableGlobalOverlayBlocker} disableGlobalOverlayBlocker={disableGlobalOverlayBlocker}
enableGlobalOverlayBlocker={enableGlobalOverlayBlocker} enableGlobalOverlayBlocker={enableGlobalOverlayBlocker}
formatMessage={formatMessage} formatMessage={formatMessage}
@ -219,6 +221,7 @@ export class Admin extends React.Component {
Admin.defaultProps = { Admin.defaultProps = {
intl: { intl: {
formatMessage: () => {}, formatMessage: () => {},
locale: 'en',
}, },
}; };
@ -240,6 +243,7 @@ Admin.propTypes = {
}).isRequired, }).isRequired,
intl: PropTypes.shape({ intl: PropTypes.shape({
formatMessage: PropTypes.func, formatMessage: PropTypes.func,
locale: PropTypes.string,
}), }),
location: PropTypes.object.isRequired, location: PropTypes.object.isRequired,
setAppError: PropTypes.func.isRequired, setAppError: PropTypes.func.isRequired,

View File

@ -0,0 +1,10 @@
import styled from 'styled-components';
const Wrapper = styled.div`
padding: 18px 30px !important;
> div:first-child {
margin-bottom: 11px;
}
`;
export default Wrapper;

View File

@ -0,0 +1,106 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
LoadingIndicatorPage,
useGlobalContext,
request,
} from 'strapi-helper-plugin';
import { Header } from '@buffetjs/custom';
import PageTitle from '../../components/PageTitle';
import PluginCard from '../../components/PluginCard';
import Wrapper from './Wrapper';
import useFetch from './useFetch';
const MarketPlacePage = ({ history }) => {
const {
autoReload,
currentEnvironment,
formatMessage,
plugins,
} = useGlobalContext();
const { isLoading, data } = useFetch();
if (isLoading) {
return <LoadingIndicatorPage />;
}
const handleDownloadPlugin = async pluginId => {
// Force the Overlayblocker to be displayed
const overlayblockerParams = {
enabled: true,
title: 'app.components.InstallPluginPage.Download.title',
description: 'app.components.InstallPluginPage.Download.description',
};
// Lock the app
strapi.lockApp(overlayblockerParams);
try {
const opts = {
method: 'POST',
body: {
plugin: pluginId,
port: window.location.port,
},
};
const response = await request(
'/admin/plugins/install',
opts,
overlayblockerParams
);
if (response.ok) {
// Reload the app
window.location.reload();
}
} catch (err) {
strapi.unlockApp();
strapi.notification.error('notification.error');
}
};
return (
<div>
<PageTitle
title={formatMessage({
id: 'app.components.InstallPluginPage.helmet',
})}
/>
<Wrapper className="container-fluid">
<Header
title={{
label: formatMessage({
id: 'app.components.InstallPluginPage.title',
}),
}}
content={formatMessage({
id: 'app.components.InstallPluginPage.description',
})}
actions={[]}
/>
<div className="row" style={{ paddingTop: '4.1rem' }}>
{data.map(plugin => {
return (
<PluginCard
autoReload={autoReload}
currentEnvironment={currentEnvironment}
downloadPlugin={handleDownloadPlugin}
key={plugin.id}
history={history}
plugin={plugin}
showSupportUsButton={false}
isAlreadyInstalled={plugins[plugin.id] !== undefined}
/>
);
})}
</div>
</Wrapper>
</div>
);
};
MarketPlacePage.propTypes = {
history: PropTypes.object.isRequired,
};
export default MarketPlacePage;

View File

@ -0,0 +1,52 @@
import { useEffect, useState } from 'react';
import axios from 'axios';
import { useGlobalContext } from 'strapi-helper-plugin';
const useFetch = () => {
const { currentLocale } = useGlobalContext();
const [state, setState] = useState({
error: false,
isLoading: true,
data: null,
});
useEffect(() => {
const CancelToken = axios.CancelToken;
const source = CancelToken.source();
const getData = async () => {
try {
const { data } = await axios.get(
'https://marketplace.strapi.io/plugins',
{
cancelToken: source.token,
params: { lang: currentLocale },
}
);
setState({
isLoading: false,
data,
error: false,
});
} catch (err) {
if (axios.isCancel(err)) {
// Silent
} else {
// handle error
setState(prev => ({ ...prev, isLoading: false, error: true }));
}
}
};
getData();
return () => {
source.cancel();
};
}, [currentLocale]);
return state;
};
export default useFetch;