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";
|
|
|
|
|
|
|
|
|
|
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-10-01 17:03:27 +02:00
|
|
|
onClick: () => 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
|
|
|
};
|
|
|
|
|
|
2019-10-01 17:03:27 +02:00
|
|
|
class MultiPluginAction extends React.Component<Props> {
|
2019-09-27 14:05:19 +02:00
|
|
|
|
|
|
|
|
renderLabel = () => {
|
2019-09-30 10:26:32 +02:00
|
|
|
const { t, actionType, installedPlugins } = this.props;
|
|
|
|
|
|
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-10-01 13:21:08 +02:00
|
|
|
const outdatedPlugins = installedPlugins._embedded.plugins.filter(
|
|
|
|
|
p => p._links.update
|
|
|
|
|
).length;
|
2019-09-30 10:26:32 +02:00
|
|
|
return t("plugins.outdatedPlugins", {
|
|
|
|
|
count: outdatedPlugins
|
|
|
|
|
});
|
2019-09-27 14:05:19 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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() {
|
2019-10-01 17:03:27 +02:00
|
|
|
const { onClick } = this.props;
|
2019-09-27 14:05:19 +02:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<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()}
|
2019-10-01 17:03:27 +02:00
|
|
|
action={() => onClick()}
|
2019-09-27 14:05:19 +02:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("admin")(MultiPluginAction);
|