theme.keycloak.v2.account.resources.content.my-resources-page.ShareTheResource.js.map Maven / Gradle / Ivy
{"version":3,"file":"ShareTheResource.js","names":["React","Button","Chip","ChipGroup","Form","FormGroup","Gallery","GalleryItem","Modal","Stack","StackItem","TextInput","ModalVariant","AccountServiceContext","Msg","ContentAlert","PermissionSelect","ShareTheResource","Component","constructor","props","context","_defineProperty","rscId","resource","_id","newPermissions","permission","state","permissionsSelected","push","name","permissions","username","usernames","scopes","handleToggleDialog","doPut","encodeURIComponent","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","createElement","Fragment","children","title","variant","large","actions","onClick","msgKey","id","handleAddPermission","isDisabled","hasGutter","isFilled","label","type","helperTextInvalid","localize","fieldId","isRequired","placeholder","onChange","handleUsernameChange","onKeyPress","handleEnterKeyInAddField","categoryName","map","currentChip","handleDeleteUsername","onSelect","selection","direction","sharedWithUsersMsg"],"sources":["../../../src/app/content/my-resources-page/ShareTheResource.tsx"],"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 Form,\n FormGroup,\n Gallery,\n GalleryItem,\n Modal,\n Stack,\n StackItem,\n TextInput,\n ModalVariant\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 [email protected] (C) 2019 Red Hat Inc.\n */\nexport class ShareTheResource extends React.Component {\n protected static defaultProps:any = {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/${encodeURIComponent(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/${encodeURIComponent(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 {this.props.sharedWithUsersMsg}\n \n\n \n \n \n );\n }\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK;AAEjB,SACIC,MAAM,EACNC,IAAI,EACJC,SAAS,EACTC,IAAI,EACJC,SAAS,EACTC,OAAO,EACPC,WAAW,EACXC,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,YAAY;AAGhB,SAASC,qBAAqB;AAE9B,SAASC,GAAG;AACZ,SAAQC,YAAY;AACpB,SAASC,gBAAgB;AAkBzB;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,SAASjB,KAAK,CAACkB,SAAS,CAA+C;EAKzFC,WAAWA,CAACC,KAA4B,EAAEC,OAAwD,EAAE;IACvG,KAAK,CAACD,KAAK,CAAC;IAACE,eAAA;IAAAA,eAAA,8BAqBa,MAAM;MAChC,MAAMC,KAAa,GAAG,IAAI,CAACH,K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