@rpcbase/client 0.227.0 → 0.231.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/package.json +11 -113
  2. package/src/apiClient/getServerApiClient.ts +131 -0
  3. package/src/apiClient/index.ts +86 -0
  4. package/src/index.ts +3 -0
  5. package/src/initClient.ts +32 -0
  6. package/src/types.ts +7 -0
  7. package/AppProvider/AnalyticsContainer.js +0 -56
  8. package/AppProvider/debug.js +0 -4
  9. package/AppProvider/index.tsx +0 -79
  10. package/access-control/ACLForm/components/GrantField/OpSelector.tsx +0 -129
  11. package/access-control/ACLForm/components/GrantField/ResourceSelector.tsx +0 -86
  12. package/access-control/ACLForm/components/GrantField/UsersSelector.tsx +0 -96
  13. package/access-control/ACLForm/components/GrantField/grant-field.scss +0 -26
  14. package/access-control/ACLForm/components/GrantField/icons/CheckMark.tsx +0 -16
  15. package/access-control/ACLForm/components/GrantField/icons/CollapseArrow.tsx +0 -14
  16. package/access-control/ACLForm/components/GrantField/icons/ExpandArrow.tsx +0 -14
  17. package/access-control/ACLForm/components/GrantField/index.tsx +0 -91
  18. package/access-control/ACLForm/components/GrantsList.tsx +0 -48
  19. package/access-control/ACLForm/components/RoleForm.tsx +0 -134
  20. package/access-control/ACLForm/components/RoleView.tsx +0 -115
  21. package/access-control/ACLForm/components/RolesList.tsx +0 -79
  22. package/access-control/ACLForm/components/constants.tsx +0 -1
  23. package/access-control/ACLForm/components/resolver.ts +0 -57
  24. package/access-control/ACLForm/components/role-form.scss +0 -19
  25. package/access-control/ACLForm/index.tsx +0 -48
  26. package/access-control/ACLModal/acl-modal.scss +0 -7
  27. package/access-control/ACLModal/index.tsx +0 -66
  28. package/access-control/PolicyEditor/TargetSelector/QueryBuilder.tsx +0 -48
  29. package/access-control/PolicyEditor/TargetSelector/index.tsx +0 -5
  30. package/access-control/PolicyEditor/TargetSelector/query-builder.scss +0 -9
  31. package/access-control/PolicyEditor/index.tsx +0 -165
  32. package/access-control/index.ts +0 -3
  33. package/apiClient.js +0 -15
  34. package/auth/authProps.js +0 -8
  35. package/auth/components/AccountsList/AccountListItem.js +0 -61
  36. package/auth/components/AccountsList/account-list-item.scss +0 -5
  37. package/auth/components/AccountsList/index.js +0 -17
  38. package/auth/components/Footer/index.js +0 -11
  39. package/auth/components/ForgotPassword/forgot-password.scss +0 -37
  40. package/auth/components/ForgotPassword/index.js +0 -114
  41. package/auth/components/SetNewPassword/index.js +0 -130
  42. package/auth/components/SetNewPassword/set-new-password.scss +0 -47
  43. package/auth/components/SignIn/SignInEmailForm.tsx +0 -115
  44. package/auth/components/SignIn/index.js +0 -69
  45. package/auth/components/SignIn/sign-in.scss +0 -56
  46. package/auth/components/SignOut/index.js +0 -144
  47. package/auth/components/SignOut/sign-out.scss +0 -34
  48. package/auth/components/SignUp/SignUpEmailForm.tsx +0 -98
  49. package/auth/components/SignUp/index.js +0 -66
  50. package/auth/components/SignUp/sign-up.scss +0 -56
  51. package/auth/getTenantId.js +0 -12
  52. package/auth/getUid.js +0 -11
  53. package/auth/helpers/redirectSignIn.native.js +0 -9
  54. package/auth/helpers/redirectSignIn.web.js +0 -7
  55. package/auth/index.js +0 -146
  56. package/auth/signOut.js +0 -20
  57. package/auth/useAuthRouter.js +0 -56
  58. package/env.d.ts +0 -3
  59. package/firebase/index.js +0 -1
  60. package/firebase/sw.js +0 -1
  61. package/form/FileInput/FileUploadContext.tsx +0 -162
  62. package/form/FileInput/FileUploadForm/index.tsx +0 -139
  63. package/form/FileInput/FileUploadForm/usePreventUnload.js +0 -21
  64. package/form/FileInput/UploadButton.tsx +0 -23
  65. package/form/FileInput/constants.ts +0 -16
  66. package/form/FileInput/file-input.scss +0 -1
  67. package/form/FileInput/index.tsx +0 -21
  68. package/form/FileInput/upload-worker/get_file_hash.js +0 -63
  69. package/form/FileInput/upload-worker/index.js +0 -16
  70. package/form/FileInput/upload-worker/no_compress_exts.ts +0 -33
  71. package/form/FileInput/upload-worker/upload_file.js +0 -129
  72. package/form/Form.tsx +0 -23
  73. package/form/Input.tsx +0 -62
  74. package/form/SubmitButton/index.tsx +0 -58
  75. package/form/hook-form.tsx +0 -7
  76. package/form/index.tsx +0 -5
  77. package/getBaseUrl.js +0 -14
  78. package/getObjectId.ts +0 -31
  79. package/hashState.js +0 -158
  80. package/helpers/createBatcher/index.js +0 -36
  81. package/helpers/getInitials.js +0 -39
  82. package/helpers/onReady.js +0 -15
  83. package/helpers/post.js +0 -18
  84. package/helpers/postRPC.js +0 -42
  85. package/helpers/useRPC.js +0 -41
  86. package/helpers/useStoredValue/batchedGetStoredValues.js +0 -30
  87. package/helpers/useStoredValue/index.js +0 -107
  88. package/helpers/useStoredValue/setStoredValues.js +0 -14
  89. package/i18n/en/rb.nav.json +0 -13
  90. package/i18n/en/rb.sign_in.json +0 -11
  91. package/i18n/en/rb.sign_out.json +0 -5
  92. package/i18n/fr/rb.sign_in.json +0 -11
  93. package/i18n/fr/rb.sign_out.json +0 -5
  94. package/i18n/index.js +0 -63
  95. package/index.js +0 -6
  96. package/isEqualValues.js +0 -47
  97. package/jest.config.js +0 -16
  98. package/notifications/Notification/index.js +0 -36
  99. package/notifications/Notification/notification.scss +0 -1
  100. package/notifications/NotificationItem/HeaderStatus.js +0 -93
  101. package/notifications/NotificationItem/index.js +0 -65
  102. package/notifications/NotificationItem/notification-item.scss +0 -25
  103. package/notifications/NotificationsContainer/index.js +0 -37
  104. package/notifications/NotificationsContainer/notifications-container.scss +0 -38
  105. package/notifications/NotificationsContainer/useLLTs.js +0 -28
  106. package/notifications/NotificationsContext/index.js +0 -71
  107. package/notifications/NotificationsContext/useNotificationsList.js +0 -75
  108. package/notifications/NotificationsSettingsModal/SettingsForm.js +0 -52
  109. package/notifications/NotificationsSettingsModal/index.js +0 -48
  110. package/notifications/NotificationsSettingsModal/notifications-settings.scss +0 -1
  111. package/notifications/config.js +0 -1
  112. package/notifications/index.js +0 -4
  113. package/page.js +0 -9
  114. package/publish-output.txt +0 -0
  115. package/rpc.js +0 -32
  116. package/rr-trace/get_fingerprint.js +0 -10
  117. package/rr-trace/get_perf_vitals.js +0 -24
  118. package/rr-trace/get_session_id.js +0 -29
  119. package/rr-trace/index.js +0 -138
  120. package/rr-trace/write_session_data.js +0 -86
  121. package/rts/boot.js +0 -3
  122. package/rts/getUseDocument.js +0 -21
  123. package/rts/getUseQuery/index.js +0 -233
  124. package/rts/getUseQuery/useData.js +0 -55
  125. package/rts/index.js +0 -10
  126. package/rts/rts.js +0 -243
  127. package/rts/signout.ts +0 -8
  128. package/rts/store/constants.js +0 -3
  129. package/rts/store/debug.js +0 -24
  130. package/rts/store/get_collection.js +0 -55
  131. package/rts/store/index.js +0 -100
  132. package/rts/store/replace_query_keys.js +0 -30
  133. package/rts/store/satisfies_projection.js +0 -32
  134. package/rts/store/update_docs.js +0 -47
  135. package/storage/index.jest.js +0 -15
  136. package/storage/index.native.js +0 -38
  137. package/storage/index.web.js +0 -25
  138. package/types.ts +0 -6
  139. package/ui/ActivityIndicator/index.js +0 -113
  140. package/ui/Avatar/index.native.js +0 -31
  141. package/ui/Avatar/index.web.js +0 -37
  142. package/ui/Avatar/styles.js +0 -41
  143. package/ui/ErrorBoundary/index.js +0 -12
  144. package/ui/ExpandableFloatView/exp.scss +0 -15
  145. package/ui/ExpandableFloatView/index.tsx +0 -123
  146. package/ui/ExpandableFloatView/useBackdrop.js +0 -45
  147. package/ui/LottiePlayer/LottiePlayer.js +0 -4
  148. package/ui/LottiePlayer/index.js +0 -8
  149. package/ui/Modal/HashStateModal.js +0 -30
  150. package/ui/Modal/Modal.js +0 -93
  151. package/ui/Modal/ModalForm/AlertBanner.js +0 -82
  152. package/ui/Modal/ModalForm/index.js +0 -188
  153. package/ui/Modal/ModalForm/modal-form.scss +0 -63
  154. package/ui/Modal/index.js +0 -10
  155. package/ui/Modal/modal.scss +0 -101
  156. package/ui/Modal/withHashStateModal.js +0 -24
  157. package/ui/RedboxError/index.js +0 -3
  158. package/ui/Search/SearchHistory/index.js +0 -45
  159. package/ui/Search/SearchHistory/search-history.scss +0 -9
  160. package/ui/Search/SearchHistory/useSearchHistory.tsx +0 -57
  161. package/ui/Search/SearchResults/index.tsx +0 -90
  162. package/ui/Search/index.tsx +0 -298
  163. package/ui/Search/search.scss +0 -0
  164. package/ui/SelectPills/index.tsx +0 -96
  165. package/ui/SelectPills/select-pills.scss +0 -66
  166. package/ui/Tabs/index.tsx +0 -161
  167. package/ui/Tabs/tabs.scss +0 -53
  168. package/ui/Tree/index.js +0 -257
  169. package/ui/Tree/model.js +0 -71
  170. package/ui/Tree/node.js +0 -112
  171. package/ui/Tree/tree.scss +0 -98
  172. package/ui/UserAvatar/default_colors.json +0 -82
  173. package/ui/UserAvatar/index.js +0 -55
  174. package/ui/View/index.tsx +0 -17
  175. package/ui/View/index.web.js +0 -44
  176. package/ui/animations/checkmark.json +0 -1
  177. package/ui/helpers/SizeContext/index.tsx +0 -11
  178. package/ui/helpers/helpers.scss +0 -61
  179. package/ui/helpers/index.ts +0 -6
  180. package/ui/helpers/stopEventPropagation.js +0 -5
  181. package/ui/helpers/useActiveListItemIndex/index.tsx +0 -45
  182. package/ui/helpers/useScrollSelectorIntoView/index.tsx +0 -14
  183. package/ui/helpers/useThrottledMeasure/index.js +0 -47
  184. package/ui/helpers/withSuspense/index.js +0 -37
  185. package/ui/icons/AddAccount.tsx +0 -5
  186. package/ui/icons/Billing.tsx +0 -6
  187. package/ui/icons/Close.tsx +0 -14
  188. package/ui/icons/Organization.tsx +0 -5
  189. package/ui/icons/Signout.tsx +0 -5
  190. package/ui/icons/index.tsx +0 -6
  191. package/ui/nav/AccountsDropdown/SwitchAccounts.tsx +0 -28
  192. package/ui/nav/AccountsDropdown/accounts-dropdown.scss +0 -51
  193. package/ui/nav/AccountsDropdown/index.tsx +0 -90
  194. package/ui/nav/AccountsToggle/index.tsx +0 -24
  195. package/ui/nav/ContentView/ContentViewContext.ts +0 -23
  196. package/ui/nav/ContentView/index.tsx +0 -115
  197. package/ui/nav/HeaderContainer/header.scss +0 -52
  198. package/ui/nav/HeaderContainer/index.tsx +0 -23
  199. package/ui/nav/HeaderContainer/variables.scss +0 -1
  200. package/ui/nav/MorphingDropdown/MorphingDropdownContext.tsx +0 -151
  201. package/ui/nav/MorphingDropdown/MorphingDropdownMenu.tsx +0 -38
  202. package/ui/nav/MorphingDropdown/MorphingDropdownPortal.tsx +0 -166
  203. package/ui/nav/MorphingDropdown/MorphingDropdownToggle.tsx +0 -34
  204. package/ui/nav/MorphingDropdown/index.tsx +0 -16
  205. package/ui/nav/MorphingDropdown/morphing-dropdown.scss +0 -35
  206. package/ui/nav/NotificationsDropdown/index.tsx +0 -52
  207. package/ui/nav/NotificationsDropdown/notifications-dropdown.scss +0 -5
  208. package/ui/nav/NotificationsToggle/NotificationsGlyph.tsx +0 -54
  209. package/ui/nav/NotificationsToggle/index.tsx +0 -12
  210. package/ui/nav/NotificationsToggle/notification-animation.json +0 -1
  211. package/ui/nav/NotificationsToggle/notifications-toggle.scss +0 -26
  212. package/ui/nav/SidebarContainer/index.tsx +0 -48
  213. package/ui/nav/SidebarContainer/sidebar-container.scss +0 -21
  214. package/ui/nav/SlideoutContainer/components/Body.tsx +0 -19
  215. package/ui/nav/SlideoutContainer/components/Header.tsx +0 -23
  216. package/ui/nav/SlideoutContainer/components/Wrapper.tsx +0 -46
  217. package/ui/nav/SlideoutContainer/index.tsx +0 -50
  218. package/ui/nav/SlideoutContainer/slideout-container.scss +0 -40
  219. package/ui/nav/index.ts +0 -13
  220. package/ui/oauth/GitHub.js +0 -38
  221. package/ui/oauth/getGitHubSigninUrl.js +0 -30
  222. package/ui/oauth/index.js +0 -9
  223. package/ui/oauth/oauth.scss +0 -16
  224. package/ui/sortable-hoc/AutoScroller.js +0 -76
  225. package/ui/sortable-hoc/DragHandle.js +0 -31
  226. package/ui/sortable-hoc/Manager.js +0 -54
  227. package/ui/sortable-hoc/README.md +0 -1
  228. package/ui/sortable-hoc/SortableContainer/defaultGetHelperDimensions.js +0 -7
  229. package/ui/sortable-hoc/SortableContainer/defaultShouldCancelStart.js +0 -24
  230. package/ui/sortable-hoc/SortableContainer/index.js +0 -994
  231. package/ui/sortable-hoc/SortableContainer/props.js +0 -81
  232. package/ui/sortable-hoc/SortableElement.js +0 -111
  233. package/ui/sortable-hoc/SortableHandle.js +0 -45
  234. package/ui/sortable-hoc/drag-handle.scss +0 -14
  235. package/ui/sortable-hoc/index.js +0 -9
  236. package/ui/sortable-hoc/utils.js +0 -292
  237. package/ui/springs.ts +0 -17
@@ -1,86 +0,0 @@
1
- /* @flow */
2
- import _get from "lodash/get"
3
- import {useState, useEffect} from "react"
4
-
5
- import {useFormContext} from "react-hook-form"
6
- import {Typeahead} from "react-bootstrap-typeahead"
7
- import Form from "react-bootstrap/Form"
8
-
9
- import {GRANTS_FIELD} from "../constants"
10
-
11
-
12
- export const ResourceSelector = ({field, index, update}) => {
13
- const {
14
- formState: {errors},
15
- setValue,
16
- } = useFormContext()
17
-
18
- const fieldKey = `${GRANTS_FIELD}.${index}.resources`
19
-
20
- const err = _get(errors, fieldKey, null)
21
-
22
- // const [selectedAll, setSelectedAll] = useState(field.resources?.[0] === "*")
23
- const [selectedAll, setSelectedAll] = useState(false)
24
-
25
- const [users, setUsers] = useState([])
26
- const [selected, setSelected] = useState([])
27
-
28
- useEffect(() => {
29
- setUsers([{name: "tmp res 1"}, {name: "tmp res 2"}])
30
- }, [setUsers])
31
-
32
- const updateValue = (val) => {
33
- setValue(fieldKey, val, {
34
- shouldTouch: true,
35
- shouldValidate: !!err, // revalidate if there is an error
36
- })
37
- }
38
-
39
- const onChangeSelectedAll = (e) => {
40
- const {checked} = e.target
41
- console.log("Ochahge", checked)
42
- setSelectedAll(checked)
43
- updateValue(checked ? ["*"] : null)
44
- }
45
-
46
- const onSelectResource = (sel) => {
47
- setSelected(sel)
48
- updateValue(sel)
49
- }
50
-
51
- return (
52
- <div className="mb-3">
53
- <div className="h6 fw-bold">On Resources:</div>
54
- <div>
55
- All and any new resources in this group:
56
- <Form.Check
57
- className="d-block w-100"
58
- type="switch"
59
- id={`field-${field.id}-${index}-res-all-switch`}
60
- label={selectedAll ? "Grant applies to every resource in this group" : "Not applied"}
61
- // TODO: is this a bug ? why does it need both value and checked
62
- // this was fixed by using field.id and not index I think
63
- checked={selectedAll}
64
- value={selectedAll}
65
- onChange={onChangeSelectedAll}
66
- />
67
- <div className={cx({"text-secondary": selectedAll})}>
68
- <i>OR:</i> Select Resources:
69
- </div>
70
- <Typeahead
71
- id={`field-${field.id}-${index}-input-role-resources`}
72
- isInvalid={!!err}
73
- labelKey="name"
74
- multiple
75
- highlightOnlyResult
76
- disabled={selectedAll}
77
- onChange={onSelectResource}
78
- options={users}
79
- placeholder="Select items..."
80
- selected={selected}
81
- />
82
- {!!err && <p className="text-danger">{err.message}</p>}
83
- </div>
84
- </div>
85
- )
86
- }
@@ -1,96 +0,0 @@
1
- /* @flow */
2
- import assert from "assert"
3
- import _get from "lodash/get"
4
- import {useState, useEffect} from "react"
5
-
6
- import {useFormContext} from "react-hook-form"
7
- import {Typeahead} from "react-bootstrap-typeahead"
8
- import Form from "react-bootstrap/Form"
9
-
10
- import {GRANTS_FIELD} from "../constants"
11
-
12
- // import list_users from "rpc!server/users/list_users"
13
-
14
- // TODO: user selector render avatar next to name
15
- export const UsersSelector = ({field, index}) => {
16
- const {
17
- formState: {errors},
18
- setValue,
19
- } = useFormContext()
20
-
21
- const fieldKey = `${GRANTS_FIELD}.${index}.users`
22
-
23
- const err = _get(errors, fieldKey, null)
24
-
25
- const [selectedAll, setSelectedAll] = useState(field.resources?.[0] === "*")
26
-
27
- const [users, setUsers] = useState([])
28
- const [selected, setSelected] = useState([])
29
-
30
- useEffect(() => {
31
- const load = async() => {
32
- console.log("LOAD LIST USERS NOT IMPLEMENTED")
33
- // const res = await list_users()
34
-
35
- // assert(res.status === "ok")
36
- // // map user props to get a label, if no name, fallback to email
37
- // const result = res.users.map((user) => {
38
- // const name = `${user.first_name} ${user.last_name}`.trim()
39
- // user.label = name || user.email
40
- // return user
41
- // })
42
- // setUsers(result)
43
- }
44
- load()
45
- }, [setUsers])
46
-
47
- const updateValue = (val) => {
48
- setValue(fieldKey, val, {
49
- shouldTouch: true,
50
- shouldValidate: !!err, // revalidate if there is an error
51
- })
52
- }
53
-
54
- const onChangeSelectedAll = (e) => {
55
- const {checked} = e.target
56
- setSelectedAll(checked)
57
- updateValue(checked ? ["*"] : null)
58
- }
59
-
60
- const onSelectUsers = (sel) => {
61
- setSelected(sel)
62
- updateValue(sel.map((s) => s._id))
63
- }
64
-
65
- return (
66
- <div className="mb-2">
67
- <div className="h6 fw-bold">To Users:</div>
68
- <div>
69
- All and any new users in this group:
70
- <Form.Check
71
- className="d-block w-100"
72
- type="switch"
73
- id={`field-${field.id}-${index}-users-all-switch`}
74
- label={selectedAll ? "Grant applies to every user in this group" : "Not applied"}
75
- checked={selectedAll}
76
- value={selectedAll}
77
- onChange={onChangeSelectedAll}
78
- />
79
- <div className={cx({"text-secondary": selectedAll})}>OR: Select Users:</div>
80
- <Typeahead
81
- id={`field-${field.id}-${index}-input-role-users`}
82
- isInvalid={!!err}
83
- labelKey={(option) => `${option.label} ${option.email}`}
84
- multiple
85
- highlightOnlyResult
86
- disabled={selectedAll}
87
- onChange={onSelectUsers}
88
- options={users}
89
- placeholder="Select users..."
90
- selected={selected}
91
- />
92
- {!!err && <p className="text-danger">{err.message}</p>}
93
- </div>
94
- </div>
95
- )
96
- }
@@ -1,26 +0,0 @@
1
- @import "helpers";
2
-
3
- .grant-field-card {
4
- &:not(:first-of-type) {
5
- // TODO: what is the way to reuse bootstrap classes here??
6
- margin-top: $spacer;
7
- }
8
-
9
- .grant-field-remove-button {
10
- position: absolute;
11
- width: 14px;
12
- height: 14px;
13
- right: 0;
14
- top: 0;
15
- cursor: pointer;
16
- color: $gray-500;
17
-
18
- &:hover {
19
- color: $gray-700;
20
- }
21
-
22
- &:active {
23
- color: $gray-900;
24
- }
25
- }
26
- }
@@ -1,16 +0,0 @@
1
- export const CheckMark = ({hide = true}) => (
2
- <svg
3
- style={{
4
- marginLeft: -18,
5
- marginTop: -4,
6
- marginRight: 3,
7
- visibility: hide ? "hidden" : undefined,
8
- }}
9
- xmlns="http://www.w3.org/2000/svg"
10
- viewBox="0 0 64 64"
11
- width={18}
12
- height={18}
13
- >
14
- <path fill="#0d6efd" d="M27 55L6 33 9 29 26 41 55 12 59 16z" />
15
- </svg>
16
- )
@@ -1,14 +0,0 @@
1
- export const CollapseArrow = () => (
2
- <svg
3
- style={{marginRight: 4}}
4
- xmlns="http://www.w3.org/2000/svg"
5
- viewBox="0 0 30 30"
6
- width={21}
7
- height={21}
8
- >
9
- <path
10
- fill="currentColor"
11
- d="M 14.984375 9 A 1.0001 1.0001 0 0 0 14.292969 9.2929688 L 4.2929688 19.292969 A 1.0001 1.0001 0 1 0 5.7070312 20.707031 L 15 11.414062 L 24.292969 20.707031 A 1.0001 1.0001 0 1 0 25.707031 19.292969 L 15.707031 9.2929688 A 1.0001 1.0001 0 0 0 14.984375 9 z"
12
- />
13
- </svg>
14
- )
@@ -1,14 +0,0 @@
1
- export const ExpandArrow = () => (
2
- <svg
3
- style={{marginRight: 4}}
4
- xmlns="http://www.w3.org/2000/svg"
5
- viewBox="0 0 30 30"
6
- width={21}
7
- height={21}
8
- >
9
- <path
10
- fill="currentColor"
11
- d="M 24.990234 8.9863281 A 1.0001 1.0001 0 0 0 24.292969 9.2929688 L 15 18.585938 L 5.7070312 9.2929688 A 1.0001 1.0001 0 0 0 4.9902344 8.9902344 A 1.0001 1.0001 0 0 0 4.2929688 10.707031 L 14.292969 20.707031 A 1.0001 1.0001 0 0 0 15.707031 20.707031 L 25.707031 10.707031 A 1.0001 1.0001 0 0 0 24.990234 8.9863281 z"
12
- />
13
- </svg>
14
- )
@@ -1,91 +0,0 @@
1
- import {useState} from "react"
2
- import Collapse from "react-bootstrap/Collapse"
3
-
4
- import {useFormContext} from "react-hook-form"
5
-
6
- import {CloseIcon} from "../../../../ui/icons"
7
- import {View} from "../../../../ui/View"
8
-
9
- import {OpSelector} from "./OpSelector"
10
- import {ResourceSelector} from "./ResourceSelector"
11
- import {UsersSelector} from "./UsersSelector"
12
-
13
- import {ExpandArrow} from "./icons/ExpandArrow"
14
- import {CollapseArrow} from "./icons/CollapseArrow"
15
-
16
- import "./grant-field.scss"
17
-
18
-
19
- export const GrantField = ({remove, field, index}) => {
20
- const {getValues} = useFormContext()
21
-
22
- const {_isEditing} = getValues()
23
-
24
- const shouldInitiallyBeOpen = () => {
25
- if (_isEditing && field.ops && field.resources && field.users) {
26
- return false
27
- }
28
- return true
29
- }
30
-
31
- const [isCollapseOpen, setIsCollapseOpen] = useState(shouldInitiallyBeOpen())
32
- // used to remove only after transition is complete
33
- const [scheduledRemove, setScheduledRemove] = useState(false)
34
-
35
- const removeField = () => {
36
- remove(index)
37
- }
38
-
39
- const onExited = () => {
40
- if (scheduledRemove) {
41
- removeField()
42
- }
43
- }
44
-
45
- const onClickRemove = () => {
46
- if (isCollapseOpen) {
47
- setScheduledRemove(true)
48
- setIsCollapseOpen(false)
49
- } else {
50
- removeField()
51
- }
52
- }
53
-
54
- const onClickCollapse = () => setIsCollapseOpen(!isCollapseOpen)
55
-
56
- return (
57
- <div className="card grant-field-card p-2">
58
- {/* Remove Button */}
59
- <View
60
- className="grant-field-remove-button mt-3 me-3"
61
- onClick={onClickRemove}
62
- tooltip="Remove Grant"
63
- >
64
- <CloseIcon size={14} />
65
- </View>
66
-
67
- <div className="">
68
- Allow create, read update delete on hardcoded
69
- <br />
70
- grant summary on users Test User, and Another One
71
- </div>
72
-
73
- <Collapse appear in={isCollapseOpen} onExited={onExited}>
74
- <div>
75
- <OpSelector field={field} index={index} />
76
- <ResourceSelector field={field} index={index} />
77
- <UsersSelector field={field} index={index} />
78
- </div>
79
- </Collapse>
80
-
81
- <button
82
- type="button"
83
- className="btn btn-link btn-collapse-expand d-flex flex-row align-items-center ps-0"
84
- onClick={onClickCollapse}
85
- >
86
- {isCollapseOpen ? <CollapseArrow /> : <ExpandArrow />}
87
- {isCollapseOpen ? "Collapse" : "Expand"}
88
- </button>
89
- </div>
90
- )
91
- }
@@ -1,48 +0,0 @@
1
- import {useFieldArray, useFormContext} from "react-hook-form"
2
-
3
- import {GrantField} from "./GrantField"
4
- import {GRANTS_FIELD} from "./constants"
5
-
6
-
7
- export const GrantsList = () => {
8
- // TODO: integrate sortable-hoc list
9
- // const {fields, append, prepend, remove, swap, update, move, insert} = useFieldArray({
10
- const {
11
- formState: {errors},
12
- } = useFormContext()
13
- const {fields, append, remove, update} = useFieldArray({name: GRANTS_FIELD})
14
-
15
- return (
16
- <>
17
- <div className="mt-2">
18
- <label className="h6">Grants</label>
19
- {fields.map((field, index) => (
20
- <GrantField
21
- // IMPORTANT: key must be field id to avoid rerenders
22
- key={field.id}
23
- index={index}
24
- field={field}
25
- remove={remove}
26
- update={update}
27
- />
28
- ))}
29
- {fields.length === 0 && (
30
- <div className="text-secondary">This role doesn't have any Grants</div>
31
- )}
32
- {errors.grants?.message && <div className="text-danger">{errors.grants.message}</div>}
33
- </div>
34
-
35
- <button
36
- type="button"
37
- className="btn btn-light mt-2 px-3"
38
- onClick={() => {
39
- append({})
40
- // trigger()
41
- }}
42
- style={{width: "fit-content"}}
43
- >
44
- Add {fields.length > 0 && "another"} Grant
45
- </button>
46
- </>
47
- )
48
- }
@@ -1,134 +0,0 @@
1
- /* eslint no-unused-vars: "warn" */
2
- import assert from "assert"
3
- import {useState} from "react"
4
- import {useForm, FormProvider} from "react-hook-form"
5
- import Collapse from "react-bootstrap/Collapse"
6
-
7
- import {SubmitButton} from "@rpcbase/client/form"
8
-
9
- import {CloseIcon} from "../../../ui/icons/Close"
10
- import {View} from "../../../ui/View"
11
-
12
- import {resolver} from "./resolver"
13
- import {GrantsList} from "./GrantsList"
14
-
15
- // import create_role from "rpc!server/access-control/create_role"
16
-
17
- import "./role-form.scss"
18
-
19
-
20
- export const RoleForm = ({onDone}) => {
21
- const [isLoading, setIsLoading] = useState(false)
22
-
23
- // react hook form submit on edit
24
- // https://stackoverflow.com/a/70119332
25
- const form = useForm({
26
- defaultValues: {
27
- name: "",
28
- description: "",
29
- grants: [{}],
30
- },
31
- resolver,
32
- reValidateMode: "onChange",
33
- })
34
-
35
- const {
36
- register,
37
- handleSubmit,
38
- // watch,
39
- getValues,
40
- formState: {errors},
41
- } = form
42
-
43
- const onSubmit = async(data) => {
44
- // console.log("submit", group_id, data)
45
- setIsLoading(true)
46
- // const res = await create_role({...data})
47
- // assert(res.status === "ok")
48
- // TODO: error handling here
49
- setIsLoading(false)
50
- onDone()
51
- }
52
-
53
- // TODO: ask for user confirmation is form is touched
54
- // TODO: should we save touched fields in url hashState?
55
- const onClickCancel = () => {
56
- onDone()
57
- }
58
-
59
- const onClickRemove = () => {
60
- onDone()
61
- }
62
-
63
- // useEffect(() => {
64
- // console.log("le vals", getValues())
65
- // }, [formState])
66
-
67
- return (
68
- <FormProvider {...form}>
69
- <div className="mx-3" style={{position: "relative"}}>
70
- <Collapse appear in={true}>
71
- <form className="mt-2 mb-1 card" onSubmit={handleSubmit(onSubmit)}>
72
- <div className="p-2">
73
- <div className="h6 fw-bold">Create New Role:</div>
74
- <div className="mt-2">
75
- <label htmlFor="input-role-name" className="h6">
76
- Name
77
- </label>
78
- <input
79
- type="text"
80
- className={cx("form-control", {"is-invalid": !!errors.name})}
81
- id="input-role-name"
82
- {...register("name", {required: true})}
83
- placeholder="Role Name"
84
- />
85
- {errors.name && <div className="text-danger">{errors.name.message}</div>}
86
- </div>
87
-
88
- <div className="mt-2">
89
- <label htmlFor="input-view-name" className="h6">
90
- Description
91
- </label>
92
- <input
93
- type="text"
94
- className={cx("form-control", {"is-invalid": !!errors.description})}
95
- id="input-role-description"
96
- {...register("description", {required: true})}
97
- placeholder="Description"
98
- />
99
- {errors.description && (
100
- <div className="text-danger">{errors.description.message}</div>
101
- )}
102
- </div>
103
-
104
- {/* Grants list */}
105
- <GrantsList />
106
- </div>
107
-
108
- <div className="card-footer">
109
- <SubmitButton className="me-2" isLoading={isLoading}>
110
- {isLoading ? "Saving Role..." : "Save Role"}
111
- </SubmitButton>
112
-
113
- <button
114
- type="button"
115
- className="btn btn-link link-secondary ps-0"
116
- onClick={onClickCancel}
117
- disabled={isLoading}
118
- >
119
- Cancel
120
- </button>
121
- </div>
122
- </form>
123
- </Collapse>
124
- <View
125
- className="role-remove-button mt-3 me-3"
126
- onClick={onClickRemove}
127
- tooltip="Remove Role"
128
- >
129
- <CloseIcon size={14} />
130
- </View>
131
- </div>
132
- </FormProvider>
133
- )
134
- }
@@ -1,115 +0,0 @@
1
- import assert from "assert"
2
- import {useForm, FormProvider} from "react-hook-form"
3
-
4
- import FloatingLabel from "react-bootstrap/FloatingLabel"
5
- import Form from "react-bootstrap/Form"
6
-
7
- // import {useEnvContext} from "helpers/EnvContext"
8
- import {CloseIcon} from "../../../ui/icons/Close"
9
- import {View} from "../../../ui/View"
10
-
11
- import {resolver} from "./resolver"
12
- import {GrantsList} from "./GrantsList"
13
-
14
- // import create_role from "rpc!server/access-control/create_role"
15
- // import delete_role from "rpc!server/access-control/delete_role"
16
-
17
- import "./role-form.scss"
18
-
19
-
20
- export const RoleView = ({role}) => {
21
- // const envContext = useEnvContext()
22
-
23
- // const [isLoading, setIsLoading] = useState(false)
24
- // TODO:
25
- // react hook form submit on edit
26
- // https://stackoverflow.com/a/70119332
27
- const form = useForm({
28
- defaultValues: {
29
- ...role,
30
- _isEditing: true,
31
- },
32
- resolver,
33
- reValidateMode: "onChange",
34
- })
35
-
36
- const {
37
- register,
38
- handleSubmit,
39
- // watch,
40
- // getValues,
41
- formState: {errors},
42
- } = form
43
-
44
- const onSubmit = async(data) => {
45
- const {groupId} = envContext
46
- console.log("roleview submit", groupId, data)
47
- // setIsLoading(true)
48
- // const res = await create_role({group_id: groupId, ...data})
49
- // assert(res.status === "ok")
50
- // // TODO: error handling here
51
- // setIsLoading(false)
52
- // onDone()
53
- }
54
-
55
- const onClickRemove = async() => {
56
- // const res = await delete_role({role_id: role._id})
57
- // assert(res.status === "ok")
58
- console.log("NYI DELETE ROLE", role._id)
59
- }
60
-
61
- // useEffect(() => {
62
- // console.log("le vals", getValues())
63
- // }, [formState])
64
-
65
- // TODO: WARNING: DANGER: input should be mapped to field id + index to avoid duplicates in form
66
-
67
- return (
68
- <FormProvider {...form}>
69
- <div className="w-100" style={{position: "relative"}}>
70
- <form className="mb-1 me-4 card" onSubmit={handleSubmit(onSubmit)}>
71
- <div className="p-2">
72
- <div className="d-flex flex-row w-100 mt-1">
73
- <FloatingLabel controlId="input-name" label="Name" className="me-2">
74
- <Form.Control type="text" {...register("name")} />
75
- {errors.name && <div className="text-danger">{errors.name.message}</div>}
76
- </FloatingLabel>
77
-
78
- <FloatingLabel
79
- controlId="input-description"
80
- label="Description"
81
- className="flex-grow-1"
82
- >
83
- <Form.Control type="text" {...register("description")} />
84
- {errors.description && (
85
- <div className="text-danger">{errors.description.message}</div>
86
- )}
87
- </FloatingLabel>
88
- </div>
89
-
90
- {/* Grants list */}
91
- <GrantsList />
92
- </div>
93
- </form>
94
- <View
95
- className="role-remove-button mt-1 me-1"
96
- onClick={onClickRemove}
97
- tooltip="Remove Role"
98
- >
99
- <CloseIcon size={14} />
100
- </View>
101
- </div>
102
- </FormProvider>
103
- )
104
- }
105
-
106
- // <label htmlFor="input-role-name" className="h6">
107
- // Name
108
- // </label>
109
- // <input
110
- // type="text"
111
- // className={cx("form-control", {"is-invalid": !!errors.name})}
112
- // id="input-role-name"
113
- // {...register("name")}
114
- // placeholder="Role Name"
115
- // />