ApplicationsPage.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 2018 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 { DataList, DataListItem, DataListItemRow, DataListCell, DataListToggle, DataListContent, DataListItemCells, Grid, GridItem, Button } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js";
  19. import { InfoAltIcon, CheckIcon, ExternalLinkAltIcon } from "../../../../common/keycloak/web_modules/@patternfly/react-icons.js";
  20. import { ContentPage } from "../ContentPage.js";
  21. import { ContinueCancelModal } from "../../widgets/ContinueCancelModal.js";
  22. import { AccountServiceContext } from "../../account-service/AccountServiceContext.js";
  23. import { Msg } from "../../widgets/Msg.js";
  24. export class ApplicationsPage extends React.Component {
  25. constructor(props, context) {
  26. super(props);
  27. _defineProperty(this, "context", void 0);
  28. _defineProperty(this, "removeConsent", clientId => {
  29. this.context.doDelete("/applications/" + clientId + "/consent").then(() => {
  30. this.fetchApplications();
  31. });
  32. });
  33. _defineProperty(this, "onToggle", row => {
  34. const newIsRowOpen = this.state.isRowOpen;
  35. newIsRowOpen[row] = !newIsRowOpen[row];
  36. this.setState({
  37. isRowOpen: newIsRowOpen
  38. });
  39. });
  40. this.context = context;
  41. this.state = {
  42. isRowOpen: [],
  43. applications: []
  44. };
  45. this.fetchApplications();
  46. }
  47. fetchApplications() {
  48. this.context.doGet("/applications").then(response => {
  49. const applications = response.data || [];
  50. this.setState({
  51. isRowOpen: new Array(applications.length).fill(false),
  52. applications: applications
  53. });
  54. });
  55. }
  56. elementId(item, application) {
  57. return `application-${item}-${application.clientId}`;
  58. }
  59. render() {
  60. return React.createElement(ContentPage, {
  61. title: Msg.localize('applicationsPageTitle')
  62. }, React.createElement(DataList, {
  63. id: "applications-list",
  64. "aria-label": Msg.localize('applicationsPageTitle'),
  65. isCompact: true
  66. }, React.createElement(DataListItem, {
  67. id: "applications-list-header",
  68. "aria-labelledby": "Columns names"
  69. }, React.createElement(DataListItemRow, null, "// invisible toggle allows headings to line up properly", React.createElement("span", {
  70. style: {
  71. visibility: 'hidden'
  72. }
  73. }, React.createElement(DataListToggle, {
  74. isExpanded: false,
  75. id: "applications-list-header-invisible-toggle",
  76. "aria-controls": "hidden"
  77. })), React.createElement(DataListItemCells, {
  78. dataListCells: [React.createElement(DataListCell, {
  79. key: "applications-list-client-id-header",
  80. width: 2
  81. }, React.createElement("strong", null, React.createElement(Msg, {
  82. msgKey: "applicationName"
  83. }))), React.createElement(DataListCell, {
  84. key: "applications-list-app-type-header",
  85. width: 2
  86. }, React.createElement("strong", null, React.createElement(Msg, {
  87. msgKey: "applicationType"
  88. }))), React.createElement(DataListCell, {
  89. key: "applications-list-status",
  90. width: 2
  91. }, React.createElement("strong", null, React.createElement(Msg, {
  92. msgKey: "status"
  93. })))]
  94. }))), this.state.applications.map((application, appIndex) => {
  95. return React.createElement(DataListItem, {
  96. id: this.elementId("client-id", application),
  97. key: 'application-' + appIndex,
  98. "aria-labelledby": "applications-list",
  99. isExpanded: this.state.isRowOpen[appIndex]
  100. }, React.createElement(DataListItemRow, null, React.createElement(DataListToggle, {
  101. onClick: () => this.onToggle(appIndex),
  102. isExpanded: this.state.isRowOpen[appIndex],
  103. id: this.elementId('toggle', application),
  104. "aria-controls": this.elementId("expandable", application)
  105. }), React.createElement(DataListItemCells, {
  106. dataListCells: [React.createElement(DataListCell, {
  107. id: this.elementId('name', application),
  108. width: 2,
  109. key: 'app-' + appIndex
  110. }, React.createElement(Button, {
  111. component: "a",
  112. variant: "link",
  113. onClick: () => window.open(application.effectiveUrl)
  114. }, application.clientName || application.clientId, " ", React.createElement(ExternalLinkAltIcon, null))), React.createElement(DataListCell, {
  115. id: this.elementId('internal', application),
  116. width: 2,
  117. key: 'internal-' + appIndex
  118. }, application.userConsentRequired ? Msg.localize('thirdPartyApp') : Msg.localize('internalApp'), application.offlineAccess ? ', ' + Msg.localize('offlineAccess') : ''), React.createElement(DataListCell, {
  119. id: this.elementId('status', application),
  120. width: 2,
  121. key: 'status-' + appIndex
  122. }, application.inUse ? Msg.localize('inUse') : Msg.localize('notInUse'))]
  123. })), React.createElement(DataListContent, {
  124. noPadding: false,
  125. "aria-label": Msg.localize('applicationDetails'),
  126. id: this.elementId("expandable", application),
  127. isHidden: !this.state.isRowOpen[appIndex]
  128. }, React.createElement(Grid, {
  129. sm: 6,
  130. md: 6,
  131. lg: 6
  132. }, React.createElement("div", {
  133. className: "pf-c-content"
  134. }, React.createElement(GridItem, null, React.createElement("strong", null, Msg.localize('client') + ': '), " ", application.clientId), application.description && React.createElement(GridItem, null, React.createElement("strong", null, Msg.localize('description') + ': '), " ", application.description), application.effectiveUrl && React.createElement(GridItem, null, React.createElement("strong", null, "URL: "), " ", React.createElement("span", {
  135. id: this.elementId('effectiveurl', application)
  136. }, application.effectiveUrl.split('"'))), application.consent && React.createElement(React.Fragment, null, React.createElement(GridItem, {
  137. span: 12
  138. }, React.createElement("strong", null, "Has access to:")), application.consent.grantedScopes.map((scope, scopeIndex) => {
  139. return React.createElement(React.Fragment, {
  140. key: 'scope-' + scopeIndex
  141. }, React.createElement(GridItem, {
  142. offset: 1
  143. }, React.createElement(CheckIcon, null), " ", scope.name));
  144. }), application.tosUri && React.createElement(GridItem, null, React.createElement("strong", null, Msg.localize('termsOfService') + ': '), application.tosUri), application.policyUri && React.createElement(GridItem, null, React.createElement("strong", null, Msg.localize('policy') + ': '), application.policyUri), React.createElement(GridItem, null, React.createElement("strong", null, Msg.localize('accessGrantedOn') + ': '), new Intl.DateTimeFormat(locale, {
  145. year: 'numeric',
  146. month: 'long',
  147. day: 'numeric',
  148. hour: 'numeric',
  149. minute: 'numeric',
  150. second: 'numeric'
  151. }).format(application.consent.createDate)))), application.logoUri && React.createElement("div", {
  152. className: "pf-c-content"
  153. }, React.createElement("img", {
  154. src: application.logoUri
  155. }))), (application.consent || application.offlineAccess) && React.createElement(Grid, {
  156. gutter: "sm"
  157. }, React.createElement("hr", null), React.createElement(GridItem, null, React.createElement(React.Fragment, null, React.createElement(ContinueCancelModal, {
  158. buttonTitle: Msg.localize('removeButton') // required
  159. ,
  160. buttonVariant: "secondary" // defaults to 'primary'
  161. ,
  162. modalTitle: Msg.localize('removeModalTitle') // required
  163. ,
  164. modalMessage: Msg.localize('removeModalMessage', [application.clientId]),
  165. modalContinueButtonLabel: Msg.localize('confirmButton') // defaults to 'Continue'
  166. ,
  167. onContinue: () => this.removeConsent(application.clientId) // required
  168. }))), React.createElement(GridItem, null, React.createElement(InfoAltIcon, null), " ", Msg.localize('infoMessage')))));
  169. })));
  170. }
  171. }
  172. _defineProperty(ApplicationsPage, "contextType", AccountServiceContext);
  173. ;
  174. //# sourceMappingURL=ApplicationsPage.js.map