// @flow import React from "react"; import { Button, SubmitButton, Modal } from "@scm-manager/ui-components"; import { translate } from "react-i18next"; import PermissionCheckbox from "../components/PermissionCheckbox"; type Props = { readOnly: boolean, availableVerbs: string[], selectedVerbs: string[], onSubmit: (string[]) => void, onClose: () => void, // context props t: string => string }; type State = { verbs: any }; class AdvancedPermissionsDialog extends React.Component { constructor(props: Props) { super(props); const verbs = {}; props.availableVerbs.forEach( verb => (verbs[verb] = props.selectedVerbs ? props.selectedVerbs.includes(verb) : false) ); this.state = { verbs }; } render() { const { t, onClose, readOnly } = this.props; const { verbs } = this.state; const verbSelectBoxes = Object.entries(verbs).map(e => ( )); const submitButton = !readOnly ? ( ) : null; const body = <>{verbSelectBoxes}; const footer = (

{submitButton}

); return ( onClose()} body={body} footer={footer} active={true} /> ); } 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]) ); }; } export default translate("repos")(AdvancedPermissionsDialog);