2019-01-24 11:53:57 +01:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2019-02-01 10:07:00 +01:00
|
|
|
import { Button, SubmitButton, Modal } from "@scm-manager/ui-components";
|
2019-01-24 11:53:57 +01:00
|
|
|
import { translate } from "react-i18next";
|
2019-01-25 13:10:04 +01:00
|
|
|
import PermissionCheckbox from "../components/PermissionCheckbox";
|
2019-01-24 11:53:57 +01:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-01-25 13:55:04 +01:00
|
|
|
readOnly: boolean,
|
2019-01-24 11:53:57 +01:00
|
|
|
availableVerbs: string[],
|
|
|
|
|
selectedVerbs: string[],
|
|
|
|
|
onSubmit: (string[]) => void,
|
|
|
|
|
onClose: () => void,
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
verbs: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class AdvancedPermissionsDialog extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
const verbs = {};
|
|
|
|
|
props.availableVerbs.forEach(
|
|
|
|
|
verb => (verbs[verb] = props.selectedVerbs.includes(verb))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.state = { verbs };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-01-25 13:55:04 +01:00
|
|
|
const { t, onClose, readOnly } = this.props;
|
2019-01-24 11:53:57 +01:00
|
|
|
const { verbs } = this.state;
|
|
|
|
|
|
|
|
|
|
const verbSelectBoxes = Object.entries(verbs).map(e => (
|
2019-01-25 13:10:04 +01:00
|
|
|
<PermissionCheckbox
|
2019-02-01 10:07:00 +01:00
|
|
|
key={e[0]}
|
2019-01-25 13:55:04 +01:00
|
|
|
disabled={readOnly}
|
2019-01-24 11:53:57 +01:00
|
|
|
name={e[0]}
|
|
|
|
|
checked={e[1]}
|
|
|
|
|
onChange={this.handleChange}
|
|
|
|
|
/>
|
|
|
|
|
));
|
|
|
|
|
|
2019-01-25 13:55:04 +01:00
|
|
|
const submitButton = !readOnly ? (
|
|
|
|
|
<SubmitButton label={t("permission.advanced.dialog.submit")} />
|
|
|
|
|
) : null;
|
|
|
|
|
|
2019-02-01 10:07:00 +01:00
|
|
|
const closeButton = (
|
|
|
|
|
<button className="delete" aria-label="close" onClick={() => onClose()} />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const body = (
|
|
|
|
|
<>
|
|
|
|
|
<div className="content">{verbSelectBoxes}</div>
|
|
|
|
|
<form onSubmit={this.onSubmit}>
|
|
|
|
|
{submitButton}
|
|
|
|
|
<Button
|
|
|
|
|
label={t("permission.advanced.dialog.abort")}
|
|
|
|
|
action={onClose}
|
|
|
|
|
/>
|
|
|
|
|
</form>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
2019-01-24 11:53:57 +01:00
|
|
|
return (
|
2019-02-01 10:07:00 +01:00
|
|
|
<Modal
|
|
|
|
|
title={t("permission.advanced.dialog.title")}
|
|
|
|
|
closeButton={closeButton}
|
|
|
|
|
body={body}
|
|
|
|
|
active={true}
|
|
|
|
|
/>
|
2019-01-24 11:53:57 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleChange = (value: boolean, name: string) => {
|
|
|
|
|
const { verbs } = this.state;
|
|
|
|
|
const newVerbs = { ...verbs, [name]: value };
|
|
|
|
|
this.setState({ verbs: newVerbs });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onSubmit = () => {
|
|
|
|
|
this.props.onSubmit(
|
|
|
|
|
Object.entries(this.state.verbs)
|
|
|
|
|
.filter(e => e[1])
|
|
|
|
|
.map(e => e[0])
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 08:01:32 +01:00
|
|
|
export default translate("repos")(AdvancedPermissionsDialog);
|