SigningInPage.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 { withRouter } from "../../../../common/keycloak/web_modules/react-router-dom.js";
  19. import { Button, DataList, DataListAction, DataListItemCells, DataListCell, DataListItem, DataListItemRow, Stack, StackItem, Title, TitleLevel, DataListActionVisibility, Dropdown, DropdownPosition, KebabToggle } from "../../../../common/keycloak/web_modules/@patternfly/react-core.js";
  20. import { AIACommand } from "../../util/AIACommand.js";
  21. import TimeUtil from "../../util/TimeUtil.js";
  22. import { AccountServiceContext } from "../../account-service/AccountServiceContext.js";
  23. import { ContinueCancelModal } from "../../widgets/ContinueCancelModal.js";
  24. import { Msg } from "../../widgets/Msg.js";
  25. import { ContentPage } from "../ContentPage.js";
  26. import { ContentAlert } from "../ContentAlert.js";
  27. import { KeycloakContext } from "../../keycloak-service/KeycloakContext.js";
  28. import { css } from "../../../../common/keycloak/web_modules/@patternfly/react-styles.js";
  29. /**
  30. * @author Stan Silvert ssilvert@redhat.com (C) 2018 Red Hat Inc.
  31. */
  32. class SigningInPage extends React.Component {
  33. constructor(props, context) {
  34. super(props);
  35. _defineProperty(this, "context", void 0);
  36. _defineProperty(this, "handleRemove", (credentialId, userLabel) => {
  37. this.context.doDelete("/credentials/" + credentialId).then(() => {
  38. this.getCredentialContainers();
  39. ContentAlert.success('successRemovedMessage', [userLabel]);
  40. });
  41. });
  42. this.context = context;
  43. this.state = {
  44. credentialContainers: new Map()
  45. };
  46. this.getCredentialContainers();
  47. }
  48. getCredentialContainers() {
  49. this.context.doGet("/credentials").then(response => {
  50. const allContainers = new Map();
  51. const containers = response.data || [];
  52. containers.forEach(container => {
  53. let categoryMap = allContainers.get(container.category);
  54. if (!categoryMap) {
  55. categoryMap = new Map();
  56. allContainers.set(container.category, categoryMap);
  57. }
  58. categoryMap.set(container.type, container);
  59. });
  60. this.setState({
  61. credentialContainers: allContainers
  62. });
  63. console.log({
  64. allContainers
  65. });
  66. });
  67. }
  68. static credElementId(credType, credId, item) {
  69. return `${credType}-${item}-${credId.substring(0, 8)}`;
  70. }
  71. render() {
  72. return React.createElement(ContentPage, {
  73. title: "signingIn",
  74. introMessage: "signingInSubMessage"
  75. }, React.createElement(Stack, {
  76. gutter: "md"
  77. }, this.renderCategories()));
  78. }
  79. renderCategories() {
  80. return React.createElement(React.Fragment, null, " ", Array.from(this.state.credentialContainers.keys()).map(category => React.createElement(StackItem, {
  81. key: category,
  82. isFilled: true
  83. }, React.createElement(Title, {
  84. id: `${category}-categ-title`,
  85. headingLevel: TitleLevel.h2,
  86. size: "2xl"
  87. }, React.createElement("strong", null, React.createElement(Msg, {
  88. msgKey: category
  89. }))), React.createElement(DataList, {
  90. "aria-label": "foo"
  91. }, this.renderTypes(this.state.credentialContainers.get(category))))));
  92. }
  93. renderTypes(credTypeMap) {
  94. return React.createElement(KeycloakContext.Consumer, null, keycloak => React.createElement(React.Fragment, null, Array.from(credTypeMap.keys()).map((credType, index, typeArray) => [this.renderCredTypeTitle(credTypeMap.get(credType), keycloak), this.renderUserCredentials(credTypeMap, credType, keycloak), this.renderEmptyRow(credTypeMap.get(credType).type, index === typeArray.length - 1)])));
  95. }
  96. renderEmptyRow(type, isLast) {
  97. if (isLast) return; // don't put empty row at the end
  98. return React.createElement(DataListItem, {
  99. "aria-labelledby": 'empty-list-item-' + type
  100. }, React.createElement(DataListItemRow, {
  101. key: 'empty-row-' + type
  102. }, React.createElement(DataListItemCells, {
  103. dataListCells: [React.createElement(DataListCell, null)]
  104. })));
  105. }
  106. renderUserCredentials(credTypeMap, credType, keycloak) {
  107. const credContainer = credTypeMap.get(credType);
  108. const userCredentials = credContainer.userCredentials;
  109. const removeable = credContainer.removeable;
  110. const type = credContainer.type;
  111. const displayName = credContainer.displayName;
  112. if (!userCredentials || userCredentials.length === 0) {
  113. const localizedDisplayName = Msg.localize(displayName);
  114. return React.createElement(DataListItem, {
  115. key: "no-credentials-list-item",
  116. "aria-labelledby": "no-credentials-list-item"
  117. }, React.createElement(DataListItemRow, {
  118. key: "no-credentials-list-item-row"
  119. }, React.createElement(DataListItemCells, {
  120. dataListCells: [React.createElement(DataListCell, {
  121. key: 'no-credentials-cell-0'
  122. }), React.createElement("strong", {
  123. id: `${type}-not-set-up`,
  124. key: 'no-credentials-cell-1'
  125. }, React.createElement(Msg, {
  126. msgKey: "notSetUp",
  127. params: [localizedDisplayName]
  128. })), React.createElement(DataListCell, {
  129. key: 'no-credentials-cell-2'
  130. })]
  131. })));
  132. }
  133. userCredentials.forEach(credential => {
  134. if (!credential.userLabel) credential.userLabel = Msg.localize(credential.type);
  135. if (credential.hasOwnProperty('createdDate') && credential.createdDate && credential.createdDate > 0) {
  136. credential.strCreatedDate = TimeUtil.format(credential.createdDate);
  137. }
  138. });
  139. let updateAIA;
  140. if (credContainer.updateAction) {
  141. updateAIA = new AIACommand(keycloak, credContainer.updateAction);
  142. }
  143. return React.createElement(React.Fragment, {
  144. key: "userCredentials"
  145. }, " ", userCredentials.map(credential => React.createElement(DataListItem, {
  146. id: `${SigningInPage.credElementId(type, credential.id, 'row')}`,
  147. key: 'credential-list-item-' + credential.id,
  148. "aria-labelledby": 'credential-list-item-' + credential.userLabel
  149. }, React.createElement(DataListItemRow, {
  150. key: 'userCredentialRow-' + credential.id
  151. }, React.createElement(DataListItemCells, {
  152. dataListCells: this.credentialRowCells(credential, type)
  153. }), React.createElement(CredentialAction, {
  154. credential: credential,
  155. removeable: removeable,
  156. updateAction: updateAIA,
  157. credRemover: this.handleRemove
  158. })))));
  159. }
  160. credentialRowCells(credential, type) {
  161. const credRowCells = [];
  162. credRowCells.push(React.createElement(DataListCell, {
  163. id: `${SigningInPage.credElementId(type, credential.id, 'label')}`,
  164. key: 'userLabel-' + credential.id
  165. }, credential.userLabel));
  166. if (credential.strCreatedDate) {
  167. credRowCells.push(React.createElement(DataListCell, {
  168. id: `${SigningInPage.credElementId(type, credential.id, 'created-at')}`,
  169. key: 'created-' + credential.id
  170. }, React.createElement("strong", null, React.createElement(Msg, {
  171. msgKey: "credentialCreatedAt"
  172. }), ": "), credential.strCreatedDate));
  173. credRowCells.push(React.createElement(DataListCell, {
  174. key: 'spacer-' + credential.id
  175. }));
  176. }
  177. return credRowCells;
  178. }
  179. renderCredTypeTitle(credContainer, keycloak) {
  180. if (!credContainer.hasOwnProperty('helptext') && !credContainer.hasOwnProperty('createAction')) return;
  181. let setupAction;
  182. if (credContainer.createAction) {
  183. setupAction = new AIACommand(keycloak, credContainer.createAction);
  184. }
  185. const credContainerDisplayName = Msg.localize(credContainer.displayName);
  186. return React.createElement(React.Fragment, {
  187. key: 'credTypeTitle-' + credContainer.type
  188. }, React.createElement(DataListItem, {
  189. "aria-labelledby": 'type-datalistitem-' + credContainer.type
  190. }, React.createElement(DataListItemRow, {
  191. key: 'credTitleRow-' + credContainer.type
  192. }, React.createElement(DataListItemCells, {
  193. dataListCells: [React.createElement(DataListCell, {
  194. width: 5,
  195. key: 'credTypeTitle-' + credContainer.type
  196. }, React.createElement(Title, {
  197. headingLevel: TitleLevel.h3,
  198. size: "2xl"
  199. }, React.createElement("strong", {
  200. id: `${credContainer.type}-cred-title`
  201. }, React.createElement(Msg, {
  202. msgKey: credContainer.displayName
  203. }))), React.createElement("span", {
  204. id: `${credContainer.type}-cred-help`
  205. }, credContainer.helptext && React.createElement(Msg, {
  206. msgKey: credContainer.helptext
  207. })))]
  208. }), credContainer.createAction && React.createElement(DataListAction, {
  209. "aria-labelledby": "create",
  210. "aria-label": "create action",
  211. id: 'mob-setUpAction-' + credContainer.type,
  212. className: DataListActionVisibility.hiddenOnLg
  213. }, React.createElement(Dropdown, {
  214. isPlain: true,
  215. position: DropdownPosition.right,
  216. toggle: React.createElement(KebabToggle, {
  217. onToggle: isOpen => {
  218. credContainer.open = isOpen;
  219. this.setState({
  220. credentialContainers: new Map(this.state.credentialContainers)
  221. });
  222. }
  223. }),
  224. isOpen: credContainer.open,
  225. dropdownItems: [React.createElement("button", {
  226. id: `mob-${credContainer.type}-set-up`,
  227. className: "pf-c-button pf-m-link",
  228. type: "button",
  229. onClick: () => setupAction.execute()
  230. }, React.createElement("span", {
  231. className: "pf-c-button__icon"
  232. }, React.createElement("i", {
  233. className: "fas fa-plus-circle",
  234. "aria-hidden": "true"
  235. })), React.createElement(Msg, {
  236. msgKey: "setUpNew",
  237. params: [credContainerDisplayName]
  238. }))]
  239. })), credContainer.createAction && React.createElement(DataListAction, {
  240. "aria-labelledby": "create",
  241. "aria-label": "create action",
  242. id: 'setUpAction-' + credContainer.type,
  243. className: css(DataListActionVisibility.visibleOnLg, DataListActionVisibility.hidden)
  244. }, React.createElement("button", {
  245. id: `${credContainer.type}-set-up`,
  246. className: "pf-c-button pf-m-link",
  247. type: "button",
  248. onClick: () => setupAction.execute()
  249. }, React.createElement("span", {
  250. className: "pf-c-button__icon"
  251. }, React.createElement("i", {
  252. className: "fas fa-plus-circle",
  253. "aria-hidden": "true"
  254. })), React.createElement(Msg, {
  255. msgKey: "setUpNew",
  256. params: [credContainerDisplayName]
  257. }))))));
  258. }
  259. }
  260. _defineProperty(SigningInPage, "contextType", AccountServiceContext);
  261. ;
  262. ;
  263. class CredentialAction extends React.Component {
  264. render() {
  265. if (this.props.updateAction) {
  266. return React.createElement(DataListAction, {
  267. "aria-labelledby": "foo",
  268. "aria-label": "foo action",
  269. id: 'updateAction-' + this.props.credential.id
  270. }, React.createElement(Button, {
  271. id: `${SigningInPage.credElementId(this.props.credential.type, this.props.credential.id, 'update')}`,
  272. variant: "primary",
  273. onClick: () => this.props.updateAction.execute()
  274. }, React.createElement(Msg, {
  275. msgKey: "update"
  276. })));
  277. }
  278. if (this.props.removeable) {
  279. const userLabel = this.props.credential.userLabel;
  280. return React.createElement(DataListAction, {
  281. "aria-labelledby": "foo",
  282. "aria-label": "foo action",
  283. id: 'removeAction-' + this.props.credential.id
  284. }, React.createElement(ContinueCancelModal, {
  285. buttonTitle: "remove",
  286. buttonId: `${SigningInPage.credElementId(this.props.credential.type, this.props.credential.id, 'remove')}`,
  287. modalTitle: Msg.localize('removeCred', [userLabel]),
  288. modalMessage: Msg.localize('stopUsingCred', [userLabel]),
  289. onContinue: () => this.props.credRemover(this.props.credential.id, userLabel)
  290. }));
  291. }
  292. return React.createElement(React.Fragment, null);
  293. }
  294. }
  295. const SigningInPageWithRouter = withRouter(SigningInPage);
  296. export { SigningInPageWithRouter as SigningInPage };
  297. //# sourceMappingURL=SigningInPage.js.map