Files
SCM-Manager/scm-ui/src/admin/plugins/components/MultiPluginAction.js

72 lines
1.8 KiB
JavaScript
Raw Normal View History

// @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";
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,
// context props
2019-09-30 10:26:32 +02:00
t: (key: string, params?: Object) => string
};
2019-10-01 17:03:27 +02:00
class MultiPluginAction extends React.Component<Props> {
renderLabel = () => {
2019-09-30 10:26:32 +02:00
const { t, actionType, installedPlugins } = this.props;
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-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";
}
};
render() {
2019-10-01 17:03:27 +02:00
const { onClick } = this.props;
return (
<>
<Button
color="primary"
2019-09-30 10:26:32 +02:00
reducedMobile={true}
icon={this.renderIcon()}
label={this.renderLabel()}
2019-10-01 17:03:27 +02:00
action={() => onClick()}
/>
</>
);
}
}
export default translate("admin")(MultiPluginAction);