2019-09-27 14:05:19 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { Button } from "@scm-manager/ui-components";
|
2019-09-30 10:26:32 +02:00
|
|
|
import type { PendingPlugins, PluginCollection } from "@scm-manager/ui-types";
|
2019-09-27 14:05:19 +02:00
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import MultiPluginActionModal from "./MultiPluginActionModal";
|
|
|
|
|
|
|
|
|
|
export const MultiPluginActionType = {
|
|
|
|
|
UPDATE_ALL: "updateAll",
|
|
|
|
|
CANCEL_PENDING: "cancelPending",
|
|
|
|
|
EXECUTE_PENDING: "executePending"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
actionType: string,
|
|
|
|
|
pendingPlugins?: PendingPlugins,
|
|
|
|
|
installedPlugins?: PluginCollection,
|
2019-10-01 10:27:06 +02:00
|
|
|
refresh: () => void,
|
2019-09-27 14:05:19 +02:00
|
|
|
|
|
|
|
|
// context props
|
2019-09-30 10:26:32 +02:00
|
|
|
t: (key: string, params?: Object) => string
|
2019-09-27 14:05:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
showModal: boolean
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MultiPluginAction extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
showModal: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleModal = () => {
|
|
|
|
|
this.setState(state => ({
|
|
|
|
|
showModal: !state.showModal
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderLabel = () => {
|
2019-09-30 10:26:32 +02:00
|
|
|
const { t, actionType, installedPlugins } = this.props;
|
|
|
|
|
const outdatedPlugins =
|
|
|
|
|
actionType === MultiPluginActionType.UPDATE_ALL &&
|
|
|
|
|
installedPlugins._embedded.plugins.filter(p => p._links.update).length;
|
|
|
|
|
|
2019-09-27 14:05:19 +02:00
|
|
|
if (actionType === MultiPluginActionType.EXECUTE_PENDING) {
|
|
|
|
|
return t("plugins.executePending");
|
|
|
|
|
} else if (actionType === MultiPluginActionType.CANCEL_PENDING) {
|
|
|
|
|
return t("plugins.cancelPending");
|
|
|
|
|
} else {
|
2019-09-30 10:26:32 +02:00
|
|
|
return t("plugins.outdatedPlugins", {
|
|
|
|
|
count: outdatedPlugins
|
|
|
|
|
});
|
2019-09-27 14:05:19 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderModal = () => {
|
|
|
|
|
const { showModal } = this.state;
|
2019-10-01 10:27:06 +02:00
|
|
|
const { pendingPlugins, installedPlugins, actionType, refresh } = this.props;
|
2019-09-27 14:05:19 +02:00
|
|
|
if (showModal) {
|
|
|
|
|
return (
|
|
|
|
|
<MultiPluginActionModal
|
|
|
|
|
pendingPlugins={
|
|
|
|
|
actionType === MultiPluginActionType.UPDATE_ALL
|
|
|
|
|
? null
|
|
|
|
|
: pendingPlugins
|
|
|
|
|
}
|
|
|
|
|
installedPlugins={
|
|
|
|
|
actionType !== MultiPluginActionType.UPDATE_ALL
|
|
|
|
|
? null
|
|
|
|
|
: installedPlugins
|
|
|
|
|
}
|
|
|
|
|
onClose={this.toggleModal}
|
2019-10-01 10:27:06 +02:00
|
|
|
refresh={refresh}
|
2019-09-27 14:05:19 +02:00
|
|
|
actionType={actionType}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-30 10:26:32 +02:00
|
|
|
renderIcon = () => {
|
|
|
|
|
const { actionType } = this.props;
|
|
|
|
|
|
|
|
|
|
if (actionType === MultiPluginActionType.EXECUTE_PENDING) {
|
|
|
|
|
return "arrow-circle-right";
|
|
|
|
|
} else if (actionType === MultiPluginActionType.CANCEL_PENDING) {
|
|
|
|
|
return "times";
|
|
|
|
|
} else {
|
|
|
|
|
return "sync-alt";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-27 14:05:19 +02:00
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{this.renderModal()}
|
|
|
|
|
<Button
|
|
|
|
|
color="primary"
|
2019-09-30 10:26:32 +02:00
|
|
|
reducedMobile={true}
|
|
|
|
|
icon={this.renderIcon()}
|
2019-09-27 14:05:19 +02:00
|
|
|
label={this.renderLabel()}
|
|
|
|
|
action={this.toggleModal}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("admin")(MultiPluginAction);
|