1 |
- {"version":3,"sources":["../../../src/app/content/my-resources-page/EditTheResource.tsx"],"names":["React","Button","Modal","Form","FormGroup","TextInput","InputGroup","OkIcon","Scope","Msg","AccountServiceContext","ContentAlert","PermissionSelect","EditTheResource","Component","constructor","props","context","state","isOpen","setState","onClose","clearState","row","changed","savePermission","permission","doPut","resource","_id","success","localize","render","children","handleToggleDialog","name","permissions","map","p","username","scopes","s","length","selection","updateChanged"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,KAAZ;AAEA,SACIC,MADJ,EAEIC,KAFJ,EAGIC,IAHJ,EAIIC,SAJJ,EAKIC,SALJ,EAMIC,UANJ;AAQA,SAASC,MAAT;AAEA,SAA+BC,KAA/B;AACA,SAASC,GAAT;AACA,SAASC,qBAAT;AACA,SAASC,YAAT;AACA,SAASC,gBAAT;AAcA,OAAO,MAAMC,eAAN,SAA8Bb,KAAK,CAACc,SAApC,CAA0F;AAKtFC,EAAAA,WAAW,CAACC,KAAD,EAA8BC,OAA9B,EAAwF;AACtG,UAAMD,KAAN;;AADsG;;AAAA,gDAc7E,MAAM;AAC/B,UAAI,KAAKE,KAAL,CAAWC,MAAf,EAAuB;AACnB,aAAKC,QAAL,CAAc;AAAED,UAAAA,MAAM,EAAE;AAAV,SAAd;AACA,aAAKH,KAAL,CAAWK,OAAX;AACH,OAHD,MAGO;AACH,aAAKC,UAAL;AACA,aAAKF,QAAL,CAAc;AAAED,UAAAA,MAAM,EAAE;AAAV,SAAd;AACH;AACJ,KAtByG;;AAAA,2CAwBjFI,GAAD,IAAiB;AACrC,YAAMC,OAAO,GAAG,KAAKN,KAAL,CAAWM,OAA3B;AACAA,MAAAA,OAAO,CAACD,GAAD,CAAP,GAAe,CAACC,OAAO,CAACD,GAAD,CAAvB;AACA,WAAKH,QAAL,CAAc;AAAEI,QAAAA;AAAF,OAAd;AACH,KA5ByG;;AAEtG,SAAKP,O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,CADJ;AAwDH;;AAjG4F;;gBAApFzB,e,kBACuB;AAAEuB,EAAAA,WAAW,EAAE;AAAf,C;;gBADvBvB,e,iBAEYH,qB","sourcesContent":["/*\n * Copyright 2019 Red Hat, Inc. and/or its affiliates.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as React from 'react';\n\nimport {\n Button,\n Modal,\n Form,\n FormGroup,\n TextInput,\n InputGroup\n} from '@patternfly/react-core';\nimport { OkIcon } from '@patternfly/react-icons';\n\nimport { Resource, Permission, Scope } from './resource-model';\nimport { Msg } from '../../widgets/Msg';\nimport { AccountServiceContext } from '../../account-service/AccountServiceContext';\nimport { ContentAlert } from '../ContentAlert';\nimport { PermissionSelect } from './PermissionSelect';\n\ninterface EditTheResourceProps {\n resource: Resource;\n permissions: Permission[];\n onClose: () => void;\n children: (toggle: () => void) => void;\n}\n\ninterface EditTheResourceState {\n changed: boolean[];\n isOpen: boolean;\n}\n\nexport class EditTheResource extends React.Component<EditTheResourceProps, EditTheResourceState> {\n protected static defaultProps = { permissions: [] };\n static contextType = AccountServiceContext;\n context: React.ContextType<typeof AccountServiceContext>;\n\n public constructor(props: EditTheResourceProps, context: React.ContextType<typeof AccountServiceContext>) {\n super(props);\n this.context = context;\n\n this.state = {\n changed: [],\n isOpen: false,\n };\n }\n\n private clearState(): void {\n this.setState({});\n }\n\n private handleToggleDialog = () => {\n if (this.state.isOpen) {\n this.setState({ isOpen: false });\n this.props.onClose();\n } else {\n this.clearState();\n this.setState({ isOpen: true });\n }\n };\n\n private updateChanged = (row: number) => {\n const changed = this.state.changed;\n changed[row] = !changed[row];\n this.setState({ changed });\n }\n\n async savePermission(permission: Permission): Promise<void> {\n await this.context!.doPut(`/resources/${this.props.resource._id}/permissions`, [permission]);\n ContentAlert.success(Msg.localize('updateSuccess'));\n }\n\n public render(): React.ReactNode {\n return (\n <React.Fragment>\n {this.props.children(this.handleToggleDialog)}\n\n <Modal\n title={'Edit the resource - ' + this.props.resource.name}\n isLarge\n isOpen={this.state.isOpen}\n onClose={this.handleToggleDialog}\n actions={[\n <Button key=\"done\" variant=\"link\" id=\"done\" onClick={this.handleToggleDialog}>\n <Msg msgKey='done' />\n </Button>,\n ]}\n >\n <Form isHorizontal>\n {this.props.permissions.map((p, row) => (\n <React.Fragment>\n <FormGroup\n fieldId={`username-${row}`}\n label={Msg.localize('User')}\n >\n <TextInput id={`username-${row}`} type=\"text\" value={p.username} isDisabled />\n\n </FormGroup>\n <FormGroup\n fieldId={`permissions-${row}`}\n label={Msg.localize('permissions')}\n isRequired\n >\n <InputGroup>\n <PermissionSelect\n scopes={this.props.resource.scopes}\n selected={(p.scopes as string[]).map(s => new Scope(s))}\n direction={row === this.props.permissions.length - 1 ? \"up\" : \"down\"}\n onSelect={selection => {\n p.scopes = selection.map(s => s.name);\n this.updateChanged(row);\n }}\n />\n <Button\n id={`save-${row}`}\n isDisabled={!this.state.changed[row]}\n onClick={() => this.savePermission(p)}\n >\n <OkIcon />\n </Button>\n </InputGroup>\n </FormGroup>\n <hr />\n </React.Fragment>\n ))}\n </Form>\n </Modal>\n </React.Fragment>\n );\n }\n}"],"file":"EditTheResource.js"}
|