{"version":3,"sources":["../../../src/app/content/my-resources-page/ShareTheResource.tsx"],"names":["React","Button","Chip","ChipGroup","ChipGroupToolbarItem","Form","FormGroup","Gallery","GalleryItem","Modal","Stack","StackItem","TextInput","AccountServiceContext","Msg","ContentAlert","PermissionSelect","ShareTheResource","Component","constructor","props","context","rscId","resource","_id","newPermissions","permission","state","permissionsSelected","push","name","permissions","username","usernames","scopes","handleToggleDialog","doPut","then","success","onClose","isOpen","setState","clearState","usernameInput","includes","response","doGet","params","value","data","info","event","key","preventDefault","handleAddUsername","newUsernames","filter","user","permissionsUnSelected","isAddDisabled","isAlreadyShared","isFormInvalid","length","render","children","handleAddPermission","localize","handleUsernameChange","handleEnterKeyInAddField","map","currentChip","handleDeleteUsername","selection","sharedWithUsersMsg"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAO,KAAKA,KAAZ;AAEA,SACIC,MADJ,EAEIC,IAFJ,EAGIC,SAHJ,EAIIC,oBAJJ,EAKIC,IALJ,EAMIC,SANJ,EAOIC,OAPJ,EAQIC,WARJ,EASIC,KATJ,EAUIC,KAVJ,EAWIC,SAXJ,EAYIC,SAZJ;AAeA,SAASC,qBAAT;AAEA,SAASC,GAAT;AACA,SAAQC,YAAR;AACA,SAASC,gBAAT;;AAkBA;AACA;AACA;AACA,OAAO,MAAMC,gBAAN,SAA+BjB,KAAK,CAACkB,SAArC,CAA6F;AAKzFC,EAAAA,WAAW,CAACC,KAAD,EAA+BC,OAA/B,EAAyF;AACvG,UAAMD,KAAN;;AADuG;;AAAA,iDAsB7E,MAAM;AAChC,YAAME,KAAa,GAAG,KAAKF,KAAL,CAAWG,QAAX,CAAoBC,GAA1C;AACA,YAAMC,cAAwB,GAAG,EAAjC;;AAEA,WAAK,MAAMC,UAAX,IAAyB,KAAKC,KAAL,CAAWC,mBAApC,EAAyD;AACrDH,QAAAA,cAAc,CAACI,IAAf,CAAoBH,UAAU,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;AAAW,MAAA,WAAW;AAAtB,OACI,oBAAC,oBAAD;AAAsB,MAAA,GAAG,EAAC,gBAA1B;AAA2C,MAAA,YAAY,EAAC;AAAxD,OACC,KAAKhC,KAAL,CAAWM,SAAX,CAAqBoC,GAArB,CAA0BC,WAAD,IACtB,oBAAC,IAAD;AAAM,MAAA,GAAG,EAAEA,WAAX;AAAwB,MAAA,OAAO,EAAE,MAAM,KAAKC,oBAAL,CAA0BD,WAA1B;AAAvC,OACKA,WADL,CADH,CADD,CADJ,CA3BJ,CADJ,EAsCI,oBAAC,SAAD;AACI,MAAA,KAAK,EAAC,EADV;AAEI,MAAA,OAAO,EAAC;AAFZ,OAII,oBAAC,gBAAD;AACI,MAAA,MAAM,EAAE,KAAK3C,KAAL,CAAW+B,qBADvB;AAEI,MAAA,QAAQ,EAAEc,SAAS,IAAI,KAAK/B,QAAL,CAAc;AAAEb,QAAAA,mBAAmB,EAAE4C;AAAvB,OAAd,CAF3B;AAGI,MAAA,SAAS,EAAC;AAHd,MAJJ,CAtCJ,CADA,CADJ,EAoDA,oBAAC,SAAD;AAAW,MAAA,QAAQ;AAAnB,OAAoB,+BAApB,CApDA,EAqDA,oBAAC,SAAD;AAAW,MAAA,QAAQ;AAAnB,OACK,KAAKpD,KAAL,CAAWqD,kBADhB,CArDA,CAdJ,CAHJ,CADJ;AA+EH;;AAvL+F;;gBAAvFxD,gB,kBACuB;AAACc,EAAAA,WAAW,EAAE;AAAd,C;;gBADvBd,gB,iBAEYJ,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 Chip,\n ChipGroup,\n ChipGroupToolbarItem,\n Form,\n FormGroup,\n Gallery,\n GalleryItem,\n Modal,\n Stack,\n StackItem,\n TextInput\n} from '@patternfly/react-core';\n\nimport { AccountServiceContext } from '../../account-service/AccountServiceContext';\nimport { Resource, Permission, Scope } from './resource-model';\nimport { Msg } from '../../widgets/Msg';\nimport {ContentAlert} from '../ContentAlert';\nimport { PermissionSelect } from './PermissionSelect';\n\ninterface ShareTheResourceProps {\n resource: Resource;\n permissions: Permission[];\n sharedWithUsersMsg: React.ReactNode;\n onClose: () => void;\n children: (toggle: () => void) => void;\n}\n\ninterface ShareTheResourceState {\n isOpen: boolean;\n permissionsSelected: Scope[];\n permissionsUnSelected: Scope[];\n usernames: string[];\n usernameInput: string;\n}\n\n/**\n * @author Stan Silvert ssilvert@redhat.com (C) 2019 Red Hat Inc.\n */\nexport class ShareTheResource extends React.Component {\n protected static defaultProps = {permissions: []};\n static contextType = AccountServiceContext;\n context: React.ContextType;\n\n public constructor(props: ShareTheResourceProps, context: React.ContextType) {\n super(props);\n this.context = context;\n \n this.state = {\n isOpen: false,\n permissionsSelected: [],\n permissionsUnSelected: this.props.resource.scopes,\n usernames: [],\n usernameInput: ''\n };\n }\n\n private clearState(): void {\n this.setState({\n permissionsSelected: [],\n permissionsUnSelected: this.props.resource.scopes,\n usernames: [],\n usernameInput: ''\n });\n }\n\n private handleAddPermission = () => {\n const rscId: string = this.props.resource._id;\n const newPermissions: string[] = [];\n\n for (const permission of this.state.permissionsSelected) {\n newPermissions.push(permission.name);\n }\n\n const permissions = [];\n\n for (const username of this.state.usernames) {\n permissions.push({username: username, scopes: newPermissions});\n }\n\n this.handleToggleDialog();\n\n this.context!.doPut(`/resources/${rscId}/permissions`, permissions)\n .then(() => {\n ContentAlert.success('shareSuccess');\n this.props.onClose();\n })\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 handleUsernameChange = (username: string) => {\n this.setState({usernameInput: username});\n }\n\n private handleAddUsername = async () => {\n if ((this.state.usernameInput !== '') && (!this.state.usernames.includes(this.state.usernameInput))) {\n const response = await this.context!.doGet<{username: string}>(`/resources/${this.props.resource._id}/user`, { params: { value: this.state.usernameInput } });\n if (response.data && response.data.username) {\n this.setState({ usernameInput: '', usernames: [...this.state.usernames, this.state.usernameInput] });\n } else {\n ContentAlert.info('userNotFound', [this.state.usernameInput]);\n }\n }\n }\n\n private handleEnterKeyInAddField = (event: React.KeyboardEvent) => {\n if (event.key === \"Enter\") {\n event.preventDefault();\n this.handleAddUsername();\n }\n }\n\n private handleDeleteUsername = (username: string) => {\n const newUsernames: string[] = this.state.usernames.filter(user => user !== username);\n this.setState({usernames: newUsernames});\n }\n\n private isAddDisabled(): boolean {\n return this.state.usernameInput === '' || this.isAlreadyShared();\n }\n\n private isAlreadyShared(): boolean {\n for (let permission of this.props.permissions) {\n if (permission.username === this.state.usernameInput) return true;\n }\n\n return false;\n }\n\n private isFormInvalid(): boolean {\n return (this.state.usernames.length === 0) || (this.state.permissionsSelected.length === 0);\n }\n\n public render(): React.ReactNode {\n return (\n \n {this.props.children(this.handleToggleDialog)}\n\n \n \n ,\n \n ]}\n >\n \n \n
\n \n \n \n \n \n \n \n \n\n \n \n \n {this.state.usernames.map((currentChip: string) => (\n this.handleDeleteUsername(currentChip)}>\n {currentChip}\n \n ))}\n \n \n \n \n this.setState({ permissionsSelected: selection })}\n direction=\"up\"\n />\n \n \n
\n
\n \n {this.props.sharedWithUsersMsg}\n \n\n
\n \n
\n );\n }\n}"],"file":"ShareTheResource.js"}