JavaKeystoreModal.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import React, {useState} from "../_snowpack/pkg/react.js";
  2. import {
  3. AlertVariant,
  4. Button,
  5. ButtonVariant,
  6. Form,
  7. FormGroup,
  8. Modal,
  9. ModalVariant,
  10. Select,
  11. SelectOption,
  12. SelectVariant,
  13. Switch,
  14. TextInput
  15. } from "../_snowpack/pkg/@patternfly/react-core.js";
  16. import {useTranslation} from "../_snowpack/pkg/react-i18next.js";
  17. import {Controller, useForm} from "../_snowpack/pkg/react-hook-form.js";
  18. import {useAdminClient} from "../context/auth/AdminClient.js";
  19. import {useAlerts} from "../components/alert/Alerts.js";
  20. import {HelpItem} from "../components/help-enabler/HelpItem.js";
  21. import {useServerInfo} from "../context/server-info/ServerInfoProvider.js";
  22. import {KEY_PROVIDER_TYPE} from "../util.js";
  23. export const JavaKeystoreModal = ({
  24. providerType,
  25. handleModalToggle,
  26. open,
  27. refresh
  28. }) => {
  29. const {t} = useTranslation("groups");
  30. const serverInfo = useServerInfo();
  31. const adminClient = useAdminClient();
  32. const {addAlert, addError} = useAlerts();
  33. const {handleSubmit, control} = useForm({});
  34. const [isEllipticCurveDropdownOpen, setIsEllipticCurveDropdownOpen] = useState(false);
  35. const allComponentTypes = serverInfo.componentTypes?.[KEY_PROVIDER_TYPE] ?? [];
  36. const save = async (component) => {
  37. try {
  38. await adminClient.components.create({
  39. ...component,
  40. parentId: component.parentId,
  41. providerId: providerType,
  42. providerType: KEY_PROVIDER_TYPE,
  43. config: {priority: ["0"]}
  44. });
  45. handleModalToggle();
  46. addAlert(t("saveProviderSuccess"), AlertVariant.success);
  47. refresh();
  48. } catch (error) {
  49. addError("groups:saveProviderError", error);
  50. }
  51. };
  52. return /* @__PURE__ */ React.createElement(Modal, {
  53. className: "add-provider-modal",
  54. variant: ModalVariant.medium,
  55. title: t("addProvider"),
  56. isOpen: open,
  57. onClose: handleModalToggle,
  58. actions: [
  59. /* @__PURE__ */ React.createElement(Button, {
  60. "data-testid": "add-provider-button",
  61. key: "confirm",
  62. variant: "primary",
  63. type: "submit",
  64. form: "add-provider"
  65. }, t("common:Add")),
  66. /* @__PURE__ */ React.createElement(Button, {
  67. id: "modal-cancel",
  68. key: "cancel",
  69. variant: ButtonVariant.link,
  70. onClick: () => {
  71. handleModalToggle();
  72. }
  73. }, t("common:cancel"))
  74. ]
  75. }, /* @__PURE__ */ React.createElement(Form, {
  76. isHorizontal: true,
  77. id: "add-provider",
  78. className: "pf-u-mt-lg",
  79. onSubmit: handleSubmit(save)
  80. }, /* @__PURE__ */ React.createElement(FormGroup, {
  81. label: t("consoleDisplayName"),
  82. fieldId: "kc-console-display-name",
  83. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  84. helpText: "realm-settings-help:displayName",
  85. fieldLabelId: "realm-settings:consoleDisplayName"
  86. })
  87. }, /* @__PURE__ */ React.createElement(Controller, {
  88. name: "name",
  89. control,
  90. defaultValue: providerType,
  91. render: ({onChange}) => /* @__PURE__ */ React.createElement(TextInput, {
  92. "aria-label": t("consoleDisplayName"),
  93. defaultValue: providerType,
  94. onChange: (value) => {
  95. onChange(value);
  96. },
  97. "data-testid": "display-name-input"
  98. })
  99. })), /* @__PURE__ */ React.createElement(FormGroup, {
  100. label: t("common:enabled"),
  101. fieldId: "kc-enabled",
  102. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  103. helpText: t("realm-settings-help:enabled"),
  104. fieldLabelId: "enabled"
  105. })
  106. }, /* @__PURE__ */ React.createElement(Controller, {
  107. name: "config.enabled",
  108. control,
  109. defaultValue: ["true"],
  110. render: ({onChange, value}) => /* @__PURE__ */ React.createElement(Switch, {
  111. id: "kc-enabled",
  112. label: t("common:on"),
  113. labelOff: t("common:off"),
  114. isChecked: value[0] === "true",
  115. "data-testid": value[0] === "true" ? "internationalization-enabled" : "internationalization-disabled",
  116. onChange: (value2) => {
  117. onChange([value2 + ""]);
  118. }
  119. })
  120. })), /* @__PURE__ */ React.createElement(FormGroup, {
  121. label: t("active"),
  122. fieldId: "kc-active",
  123. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  124. helpText: "realm-settings-help:active",
  125. fieldLabelId: "realm-settings:active"
  126. })
  127. }, /* @__PURE__ */ React.createElement(Controller, {
  128. name: "config.active",
  129. control,
  130. defaultValue: ["true"],
  131. render: ({onChange, value}) => /* @__PURE__ */ React.createElement(Switch, {
  132. id: "kc-active",
  133. label: t("common:on"),
  134. labelOff: t("common:off"),
  135. isChecked: value[0] === "true",
  136. "data-testid": value[0] === "true" ? "internationalization-enabled" : "internationalization-disabled",
  137. onChange: (value2) => {
  138. onChange([value2 + ""]);
  139. }
  140. })
  141. })), providerType === "java-keystore" && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(FormGroup, {
  142. label: t("algorithm"),
  143. fieldId: "kc-algorithm",
  144. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  145. helpText: "realm-settings-help:algorithm",
  146. fieldLabelId: "realm-settings:algorithm"
  147. })
  148. }, /* @__PURE__ */ React.createElement(Controller, {
  149. name: "config.algorithm",
  150. control,
  151. defaultValue: ["RS256"],
  152. render: ({onChange, value}) => /* @__PURE__ */ React.createElement(Select, {
  153. toggleId: "kc-elliptic",
  154. onToggle: () => setIsEllipticCurveDropdownOpen(!isEllipticCurveDropdownOpen),
  155. onSelect: (_, value2) => {
  156. onChange([value2 + ""]);
  157. setIsEllipticCurveDropdownOpen(false);
  158. },
  159. selections: [value + ""],
  160. variant: SelectVariant.single,
  161. "aria-label": t("algorithm"),
  162. isOpen: isEllipticCurveDropdownOpen,
  163. placeholderText: "Select one...",
  164. "data-testid": "select-algorithm"
  165. }, allComponentTypes[3].properties[3].options.map((p, idx) => /* @__PURE__ */ React.createElement(SelectOption, {
  166. selected: p === value,
  167. key: `algorithm-${idx}`,
  168. value: p
  169. })))
  170. })), /* @__PURE__ */ React.createElement(FormGroup, {
  171. label: t("keystore"),
  172. fieldId: "kc-login-theme",
  173. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  174. helpText: "realm-settings-help:keystore",
  175. fieldLabelId: "realm-settings:keystore"
  176. })
  177. }, /* @__PURE__ */ React.createElement(Controller, {
  178. name: "config.keystore",
  179. control,
  180. defaultValue: [],
  181. render: ({onChange}) => /* @__PURE__ */ React.createElement(TextInput, {
  182. "aria-label": t("keystore"),
  183. onChange: (value) => {
  184. onChange([value + ""]);
  185. },
  186. "data-testid": "select-display-name"
  187. })
  188. })), /* @__PURE__ */ React.createElement(FormGroup, {
  189. label: t("keystorePassword"),
  190. fieldId: "kc-login-theme",
  191. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  192. helpText: "realm-settings-help:keystorePassword",
  193. fieldLabelId: "realm-settings:keystorePassword"
  194. })
  195. }, /* @__PURE__ */ React.createElement(Controller, {
  196. name: "config.keystorePassword",
  197. control,
  198. defaultValue: [],
  199. render: ({onChange}) => /* @__PURE__ */ React.createElement(TextInput, {
  200. "aria-label": t("consoleDisplayName"),
  201. onChange: (value) => {
  202. onChange([value + ""]);
  203. },
  204. "data-testid": "select-display-name"
  205. })
  206. })), /* @__PURE__ */ React.createElement(FormGroup, {
  207. label: t("keyAlias"),
  208. fieldId: "kc-login-theme",
  209. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  210. helpText: "realm-settings-help:keyAlias",
  211. fieldLabelId: "realm-settings:keyAlias"
  212. })
  213. }, /* @__PURE__ */ React.createElement(Controller, {
  214. name: "config.keyAlias",
  215. control,
  216. defaultValue: [],
  217. render: ({onChange}) => /* @__PURE__ */ React.createElement(TextInput, {
  218. "aria-label": t("consoleDisplayName"),
  219. onChange: (value) => {
  220. onChange([value + ""]);
  221. },
  222. "data-testid": "select-display-name"
  223. })
  224. })), /* @__PURE__ */ React.createElement(FormGroup, {
  225. label: t("keyPassword"),
  226. fieldId: "kc-login-theme",
  227. labelIcon: /* @__PURE__ */ React.createElement(HelpItem, {
  228. helpText: "realm-settings-help:keyPassword",
  229. fieldLabelId: "realm-settings:keyPassword"
  230. })
  231. }, /* @__PURE__ */ React.createElement(Controller, {
  232. name: "config.keyPassword",
  233. control,
  234. defaultValue: [],
  235. render: ({onChange}) => /* @__PURE__ */ React.createElement(TextInput, {
  236. "aria-label": t("consoleDisplayName"),
  237. onChange: (value) => {
  238. onChange([value + ""]);
  239. },
  240. "data-testid": "select-display-name"
  241. })
  242. })))));
  243. };