refresh plugin list after installation

This commit is contained in:
Sebastian Sdorra
2019-08-21 15:07:56 +02:00
parent 05967aca4a
commit 707d3d2fd7
5 changed files with 35 additions and 25 deletions

View File

@@ -9,6 +9,7 @@ import classNames from "classnames";
type Props = {
plugin: Plugin,
refresh: () => void,
// context props
classes: any
@@ -73,7 +74,7 @@ class PluginEntry extends React.Component<Props, State> {
};
render() {
const { plugin } = this.props;
const { plugin, refresh } = this.props;
const { showModal } = this.state;
const avatar = this.createAvatar(plugin);
const footerLeft = this.createFooterLeft(plugin);
@@ -82,7 +83,7 @@ class PluginEntry extends React.Component<Props, State> {
const modal = showModal ? (
<PluginModal
plugin={plugin}
onSubmit={this.toggleModal}
refresh={refresh}
onClose={this.toggleModal}
/>
) : null;

View File

@@ -5,14 +5,15 @@ import type { PluginGroup } from "@scm-manager/ui-types";
import PluginEntry from "./PluginEntry";
type Props = {
group: PluginGroup
group: PluginGroup,
refresh: () => void
};
class PluginGroupEntry extends React.Component<Props> {
render() {
const { group } = this.props;
const entries = group.plugins.map((plugin, index) => {
return <PluginEntry plugin={plugin} key={index} />;
const { group, refresh } = this.props;
const entries = group.plugins.map(plugin => {
return <PluginEntry plugin={plugin} key={plugin.name} refresh={refresh} />;
});
return <CardColumnGroup name={group.name} elements={entries} />;
}

View File

@@ -5,18 +5,19 @@ import PluginGroupEntry from "../components/PluginGroupEntry";
import groupByCategory from "./groupByCategory";
type Props = {
plugins: Plugin[]
plugins: Plugin[],
refresh: () => void
};
class PluginList extends React.Component<Props> {
render() {
const { plugins } = this.props;
const { plugins, refresh } = this.props;
const groups = groupByCategory(plugins);
return (
<div className="content is-plugin-page">
{groups.map(group => {
return <PluginGroupEntry group={group} key={group.name} />;
return <PluginGroupEntry group={group} key={group.name} refresh={refresh} />;
})}
</div>
);

View File

@@ -17,7 +17,7 @@ import classNames from "classnames";
type Props = {
plugin: Plugin,
onSubmit: () => void,
refresh: () => void,
onClose: () => void,
// context props
@@ -55,7 +55,7 @@ class PluginModal extends React.Component<Props, State> {
onInstallSuccess = () => {
const { restart } = this.state;
const { onClose } = this.props;
const { refresh, onClose } = this.props;
const newState = {
loading: false,
@@ -68,7 +68,10 @@ class PluginModal extends React.Component<Props, State> {
success: true
});
} else {
this.setState(newState, onClose);
this.setState(newState, () => {
refresh();
onClose();
});
}
};

View File

@@ -9,8 +9,7 @@ import {
Title,
Subtitle,
Notification,
ErrorNotification,
Button
ErrorNotification
} from "@scm-manager/ui-components";
import {
fetchPluginsByLink,
@@ -25,7 +24,7 @@ import {
} from "../../../modules/indexResource";
import PluginTopActions from "../components/PluginTopActions";
import PluginBottomActions from "../components/PluginBottomActions";
import InstallPendingAction from '../components/InstallPendingAction';
import InstallPendingAction from "../components/InstallPendingAction";
type Props = {
loading: boolean,
@@ -55,18 +54,25 @@ class PluginsOverview extends React.Component<Props> {
}
componentDidUpdate(prevProps) {
const {
installed,
} = this.props;
if (prevProps.installed !== installed) {
this.fetchPlugins();
}
}
fetchPlugins = () => {
const {
installed,
fetchPluginsByLink,
availablePluginsLink,
installedPluginsLink
} = this.props;
if (prevProps.installed !== installed) {
fetchPluginsByLink(
installed ? installedPluginsLink : availablePluginsLink
);
}
}
};
renderHeader = (actions: React.Node) => {
const { installed, t } = this.props;
@@ -97,9 +103,7 @@ class PluginsOverview extends React.Component<Props> {
createActions = () => {
const { collection } = this.props;
if (collection._links.installPending) {
return (
<InstallPendingAction collection={collection} />
);
return <InstallPendingAction collection={collection} />;
}
return null;
};
@@ -130,7 +134,7 @@ class PluginsOverview extends React.Component<Props> {
const { collection, t } = this.props;
if (collection._embedded && collection._embedded.plugins.length > 0) {
return <PluginsList plugins={collection._embedded.plugins} />;
return <PluginsList plugins={collection._embedded.plugins} refresh={this.fetchPlugins} />;
}
return <Notification type="info">{t("plugins.noPlugins")}</Notification>;
}