EditTheResource.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  2. /*
  3. * Copyright 2019 Red Hat, Inc. and/or its affiliates.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import * as React from "../../../../common/keycloak/web_modules/react.js";
  18. import { Button, Modal, Form, FormGroup, TextInput, InputGroup } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js";
  19. import { OkIcon } from "../../../../common/keycloak/web_modules/@patternfly/react-icons.js";
  20. import { Scope } from "./resource-model.js";
  21. import { Msg } from "../../widgets/Msg.js";
  22. import { AccountServiceContext } from "../../account-service/AccountServiceContext.js";
  23. import { ContentAlert } from "../ContentAlert.js";
  24. import { PermissionSelect } from "./PermissionSelect.js";
  25. export class EditTheResource extends React.Component {
  26. constructor(props, context) {
  27. super(props);
  28. _defineProperty(this, "context", void 0);
  29. _defineProperty(this, "handleToggleDialog", () => {
  30. if (this.state.isOpen) {
  31. this.setState({
  32. isOpen: false
  33. });
  34. this.props.onClose();
  35. } else {
  36. this.clearState();
  37. this.setState({
  38. isOpen: true
  39. });
  40. }
  41. });
  42. _defineProperty(this, "updateChanged", row => {
  43. const changed = this.state.changed;
  44. changed[row] = !changed[row];
  45. this.setState({
  46. changed
  47. });
  48. });
  49. this.context = context;
  50. this.state = {
  51. changed: [],
  52. isOpen: false
  53. };
  54. }
  55. clearState() {
  56. this.setState({});
  57. }
  58. async savePermission(permission) {
  59. await this.context.doPut(`/resources/${this.props.resource._id}/permissions`, [permission]);
  60. ContentAlert.success(Msg.localize('updateSuccess'));
  61. }
  62. render() {
  63. return React.createElement(React.Fragment, null, this.props.children(this.handleToggleDialog), React.createElement(Modal, {
  64. title: 'Edit the resource - ' + this.props.resource.name,
  65. isLarge: true,
  66. isOpen: this.state.isOpen,
  67. onClose: this.handleToggleDialog,
  68. actions: [React.createElement(Button, {
  69. key: "done",
  70. variant: "link",
  71. id: "done",
  72. onClick: this.handleToggleDialog
  73. }, React.createElement(Msg, {
  74. msgKey: "done"
  75. }))]
  76. }, React.createElement(Form, {
  77. isHorizontal: true
  78. }, this.props.permissions.map((p, row) => React.createElement(React.Fragment, null, React.createElement(FormGroup, {
  79. fieldId: `username-${row}`,
  80. label: Msg.localize('User')
  81. }, React.createElement(TextInput, {
  82. id: `username-${row}`,
  83. type: "text",
  84. value: p.username,
  85. isDisabled: true
  86. })), React.createElement(FormGroup, {
  87. fieldId: `permissions-${row}`,
  88. label: Msg.localize('permissions'),
  89. isRequired: true
  90. }, React.createElement(InputGroup, null, React.createElement(PermissionSelect, {
  91. scopes: this.props.resource.scopes,
  92. selected: p.scopes.map(s => new Scope(s)),
  93. direction: row === this.props.permissions.length - 1 ? "up" : "down",
  94. onSelect: selection => {
  95. p.scopes = selection.map(s => s.name);
  96. this.updateChanged(row);
  97. }
  98. }), React.createElement(Button, {
  99. id: `save-${row}`,
  100. isDisabled: !this.state.changed[row],
  101. onClick: () => this.savePermission(p)
  102. }, React.createElement(OkIcon, null)))), React.createElement("hr", null))))));
  103. }
  104. }
  105. _defineProperty(EditTheResource, "defaultProps", {
  106. permissions: []
  107. });
  108. _defineProperty(EditTheResource, "contextType", AccountServiceContext);
  109. //# sourceMappingURL=EditTheResource.js.map