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

110 lines
2.5 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";
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,
// context props
2019-09-30 10:26:32 +02:00
t: (key: string, params?: Object) => string
};
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;
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
});
}
};
renderModal = () => {
const { showModal } = this.state;
2019-10-01 13:21:08 +02:00
const {
pendingPlugins,
installedPlugins,
actionType,
refresh
} = this.props;
if (showModal) {
return (
<MultiPluginActionModal
2019-10-01 13:21:08 +02:00
pendingPlugins={pendingPlugins}
installedPlugins={installedPlugins}
onClose={this.toggleModal}
2019-10-01 10:27:06 +02:00
refresh={refresh}
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";
}
};
render() {
return (
<>
{this.renderModal()}
<Button
color="primary"
2019-09-30 10:26:32 +02:00
reducedMobile={true}
icon={this.renderIcon()}
label={this.renderLabel()}
action={this.toggleModal}
/>
</>
);
}
}
export default translate("admin")(MultiPluginAction);