From e07a32e9b7c8760b64008d8cb897cfd43543aa9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Wed, 14 Feb 2018 13:47:11 +0100 Subject: [PATCH] SONAR-10432 Bring back installed filter tab in Marketplace --- server/sonar-web/src/main/js/api/plugins.ts | 7 +++ .../src/main/js/apps/marketplace/App.tsx | 48 +++++++++---------- .../main/js/apps/marketplace/PluginsList.tsx | 6 +-- .../src/main/js/apps/marketplace/Search.tsx | 5 +- .../marketplace/components/PluginActions.tsx | 12 +++-- .../components/PluginUpdateButton.tsx | 3 +- .../resources/org/sonar/l10n/core.properties | 1 + 7 files changed, 45 insertions(+), 37 deletions(-) diff --git a/server/sonar-web/src/main/js/api/plugins.ts b/server/sonar-web/src/main/js/api/plugins.ts index f9528e9ef64..0bc8cc48388 100644 --- a/server/sonar-web/src/main/js/api/plugins.ts +++ b/server/sonar-web/src/main/js/api/plugins.ts @@ -104,6 +104,13 @@ function addChangelog(update: Update, updates?: Update[]) { return { ...update, previousUpdates }; } +export function getInstalledPlugins(): Promise { + return getJSON('/api/plugins/installed', { f: 'category' }).then( + ({ plugins }) => plugins, + throwGlobalError + ); +} + export function getInstalledPluginsWithUpdates(): Promise { return Promise.all([ getJSON('/api/plugins/installed', { f: 'category' }), diff --git a/server/sonar-web/src/main/js/apps/marketplace/App.tsx b/server/sonar-web/src/main/js/apps/marketplace/App.tsx index c7256e53075..0807fd2dabf 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/App.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/App.tsx @@ -34,7 +34,8 @@ import { getPendingPlugins, getPluginUpdates, Plugin, - PluginPending + PluginPending, + getInstalledPlugins } from '../../api/plugins'; import { Edition, EditionStatus } from '../../api/marketplace'; import { RawQuery } from '../../helpers/query'; @@ -100,37 +101,32 @@ export default class App extends React.PureComponent { fetchQueryPlugins = () => { const query = parseQuery(this.props.location.query); + let fetchFunction = this.fetchAllPlugins; + if (query.filter === 'updates') { - this.fetchUpdatesOnly(); - } else { - this.fetchAllPlugins(); + fetchFunction = getPluginUpdates; + } else if (query.filter === 'installed') { + fetchFunction = getInstalledPlugins; } - }; - - fetchAllPlugins = () => { - this.setState({ loadingPlugins: true }); - Promise.all([getInstalledPluginsWithUpdates(), getAvailablePlugins()]).then( - ([installed, available]) => { - if (this.mounted) { - this.setState({ - loadingPlugins: false, - plugins: sortBy(uniqBy([...installed, ...available.plugins], 'key'), 'name') - }); - } - }, - this.stopLoadingPlugins - ); - }; - fetchUpdatesOnly = () => { this.setState({ loadingPlugins: true }); - getPluginUpdates().then(plugins => { + fetchFunction().then((plugins: Plugin[]) => { if (this.mounted) { - this.setState({ loadingPlugins: false, plugins }); + this.setState({ + loadingPlugins: false, + plugins: sortBy(plugins, 'name') + }); } }, this.stopLoadingPlugins); }; + fetchAllPlugins = (): Promise => { + return Promise.all([getInstalledPluginsWithUpdates(), getAvailablePlugins()]).then( + ([installed, available]) => uniqBy([...installed, ...available.plugins], 'key'), + this.stopLoadingPlugins + ); + }; + fetchPendingPlugins = () => getPendingPlugins().then( pending => { @@ -163,16 +159,16 @@ export default class App extends React.PureComponent {
{standaloneMode && ( - + )}
@@ -184,8 +180,8 @@ export default class App extends React.PureComponent { {loadingPlugins && } {!loadingPlugins && ( { return ( ); @@ -67,9 +67,9 @@ export default class PluginsList extends React.PureComponent { return ( ); @@ -82,7 +82,7 @@ export default class PluginsList extends React.PureComponent {
    {this.props.plugins.map(plugin => ( -
  • +
  • {this.renderPlugin(plugin)}
    diff --git a/server/sonar-web/src/main/js/apps/marketplace/Search.tsx b/server/sonar-web/src/main/js/apps/marketplace/Search.tsx index b454154b40b..61ff4137c4c 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/Search.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/Search.tsx @@ -40,6 +40,7 @@ export default class Search extends React.PureComponent { const { query, updateCenterActive } = this.props; const radioOptions = [ { label: translate('marketplace.all'), value: 'all' }, + { label: translate('marketplace.installed'), value: 'installed' }, { disabled: !updateCenterActive, label: translate('marketplace.updates_only'), @@ -48,8 +49,8 @@ export default class Search extends React.PureComponent { } ]; return ( -