@webiny/app-security-access-management 5.27.0 → 5.28.0-beta.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.
- package/components/GroupAutocomplete/graphql.js +14 -3
- package/components/GroupAutocomplete/graphql.js.map +1 -1
- package/components/GroupAutocomplete/index.js +23 -8
- package/components/GroupAutocomplete/index.js.map +1 -1
- package/components/NotAuthorizedError/NotAuthorizedError.js +39 -18
- package/components/NotAuthorizedError/NotAuthorizedError.js.map +1 -1
- package/components/NotAuthorizedError/index.js +13 -1
- package/components/NotAuthorizedError/index.js.map +1 -1
- package/index.js +57 -32
- package/index.js.map +1 -1
- package/package.json +12 -12
- package/plugins/constants.js +9 -2
- package/plugins/constants.js.map +1 -1
- package/plugins/index.js +20 -6
- package/plugins/index.js.map +1 -1
- package/plugins/installation.js +47 -25
- package/plugins/installation.js.map +1 -1
- package/plugins/permissionRenderer/SecurityPermissions.js +69 -46
- package/plugins/permissionRenderer/SecurityPermissions.js.map +1 -1
- package/plugins/permissionRenderer/index.js +33 -15
- package/plugins/permissionRenderer/index.js.map +1 -1
- package/plugins/routes.js +37 -19
- package/plugins/routes.js.map +1 -1
- package/plugins/secureRouteError.js +16 -4
- package/plugins/secureRouteError.js.map +1 -1
- package/types.js +5 -1
- package/types.js.map +1 -1
- package/ui/elements/GroupAutocompleteElement.js +34 -18
- package/ui/elements/GroupAutocompleteElement.js.map +1 -1
- package/ui/views/ApiKeys/ApiKeyForm.js +122 -81
- package/ui/views/ApiKeys/ApiKeyForm.js.map +1 -1
- package/ui/views/ApiKeys/ApiKeys.js +22 -7
- package/ui/views/ApiKeys/ApiKeys.js.map +1 -1
- package/ui/views/ApiKeys/ApiKeysDataList.js +101 -66
- package/ui/views/ApiKeys/ApiKeysDataList.js.map +1 -1
- package/ui/views/ApiKeys/graphql.js +22 -7
- package/ui/views/ApiKeys/graphql.js.map +1 -1
- package/ui/views/ApiKeys/index.js +18 -1
- package/ui/views/ApiKeys/index.js.map +1 -1
- package/ui/views/ApiKeys/utils.js +18 -5
- package/ui/views/ApiKeys/utils.js.map +1 -1
- package/ui/views/Groups/Groups.js +22 -7
- package/ui/views/Groups/Groups.js.map +1 -1
- package/ui/views/Groups/GroupsDataList.js +107 -71
- package/ui/views/Groups/GroupsDataList.js.map +1 -1
- package/ui/views/Groups/GroupsForm.js +125 -84
- package/ui/views/Groups/GroupsForm.js.map +1 -1
- package/ui/views/Groups/graphql.js +22 -7
- package/ui/views/Groups/graphql.js.map +1 -1
- package/ui/views/Groups/index.js +18 -1
- package/ui/views/Groups/index.js.map +1 -1
- package/ui/views/utils.js +16 -4
- package/ui/views/utils.js.map +1 -1
|
@@ -1,52 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.ApiKeyForm = void 0;
|
|
11
|
+
|
|
12
|
+
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
13
|
+
|
|
14
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
15
|
+
|
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
+
|
|
18
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
21
|
+
|
|
22
|
+
var _reactHooks = require("@apollo/react-hooks");
|
|
23
|
+
|
|
24
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
25
|
+
|
|
26
|
+
var _reactRouter = require("@webiny/react-router");
|
|
27
|
+
|
|
28
|
+
var _i18n = require("@webiny/app/i18n");
|
|
29
|
+
|
|
30
|
+
var _form = require("@webiny/form");
|
|
31
|
+
|
|
32
|
+
var _Grid = require("@webiny/ui/Grid");
|
|
33
|
+
|
|
34
|
+
var _Input = require("@webiny/ui/Input");
|
|
35
|
+
|
|
36
|
+
var _Button = require("@webiny/ui/Button");
|
|
37
|
+
|
|
38
|
+
var _Progress = require("@webiny/ui/Progress");
|
|
39
|
+
|
|
40
|
+
var _FormElementMessage = require("@webiny/ui/FormElementMessage");
|
|
41
|
+
|
|
42
|
+
var _Permissions = require("@webiny/app-admin/components/Permissions");
|
|
43
|
+
|
|
44
|
+
var _validation = require("@webiny/validation");
|
|
45
|
+
|
|
46
|
+
var _SimpleForm = require("@webiny/app-admin/components/SimpleForm");
|
|
47
|
+
|
|
48
|
+
var _Typography = require("@webiny/ui/Typography");
|
|
49
|
+
|
|
50
|
+
var _useSnackbar2 = require("@webiny/app-admin/hooks/useSnackbar");
|
|
51
|
+
|
|
52
|
+
var _utils = require("./utils");
|
|
53
|
+
|
|
54
|
+
var GQL = _interopRequireWildcard(require("./graphql"));
|
|
55
|
+
|
|
56
|
+
var _Snackbar = require("@webiny/ui/Snackbar");
|
|
57
|
+
|
|
58
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
59
|
+
|
|
60
|
+
var _EmptyView = _interopRequireDefault(require("@webiny/app-admin/components/EmptyView"));
|
|
61
|
+
|
|
62
|
+
var _add18px = require("@webiny/app-admin/assets/icons/add-18px.svg");
|
|
63
|
+
|
|
64
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
4
65
|
|
|
5
66
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
6
67
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import get from "lodash/get";
|
|
11
|
-
import { useRouter } from "@webiny/react-router";
|
|
12
|
-
import { i18n } from "@webiny/app/i18n";
|
|
13
|
-
import { Form } from "@webiny/form";
|
|
14
|
-
import { Grid, Cell } from "@webiny/ui/Grid";
|
|
15
|
-
import { Input } from "@webiny/ui/Input";
|
|
16
|
-
import { ButtonDefault, ButtonIcon, ButtonPrimary, CopyButton } from "@webiny/ui/Button";
|
|
17
|
-
import { CircularProgress } from "@webiny/ui/Progress";
|
|
18
|
-
import { FormElementMessage } from "@webiny/ui/FormElementMessage";
|
|
19
|
-
import { Permissions } from "@webiny/app-admin/components/Permissions";
|
|
20
|
-
import { validation } from "@webiny/validation";
|
|
21
|
-
import { SimpleForm, SimpleFormFooter, SimpleFormContent, SimpleFormHeader } from "@webiny/app-admin/components/SimpleForm";
|
|
22
|
-
import { Typography } from "@webiny/ui/Typography";
|
|
23
|
-
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
|
|
24
|
-
import { pickDataForAPI } from "./utils";
|
|
25
|
-
import * as GQL from "./graphql";
|
|
26
|
-
import { SnackbarAction } from "@webiny/ui/Snackbar";
|
|
27
|
-
import isEmpty from "lodash/isEmpty";
|
|
28
|
-
import EmptyView from "@webiny/app-admin/components/EmptyView";
|
|
29
|
-
import { ReactComponent as AddIcon } from "@webiny/app-admin/assets/icons/add-18px.svg";
|
|
30
|
-
import styled from "@emotion/styled";
|
|
31
|
-
var t = i18n.ns("app-security-admin-users/admin/api-keys/form");
|
|
32
|
-
var ButtonWrapper = /*#__PURE__*/styled("div", {
|
|
68
|
+
var t = _i18n.i18n.ns("app-security-admin-users/admin/api-keys/form");
|
|
69
|
+
|
|
70
|
+
var ButtonWrapper = /*#__PURE__*/(0, _styled.default)("div", {
|
|
33
71
|
target: "e18bg2x40",
|
|
34
72
|
label: "ButtonWrapper"
|
|
35
73
|
})({
|
|
36
74
|
display: "flex",
|
|
37
75
|
justifyContent: "space-between"
|
|
38
76
|
});
|
|
39
|
-
|
|
40
|
-
|
|
77
|
+
|
|
78
|
+
var ApiKeyForm = function ApiKeyForm() {
|
|
79
|
+
var _useRouter = (0, _reactRouter.useRouter)(),
|
|
41
80
|
location = _useRouter.location,
|
|
42
81
|
history = _useRouter.history;
|
|
43
82
|
|
|
44
|
-
var _useSnackbar = useSnackbar(),
|
|
83
|
+
var _useSnackbar = (0, _useSnackbar2.useSnackbar)(),
|
|
45
84
|
showSnackbar = _useSnackbar.showSnackbar;
|
|
46
85
|
|
|
47
86
|
var newEntry = new URLSearchParams(location.search).get("new") === "true";
|
|
48
87
|
var id = new URLSearchParams(location.search).get("id");
|
|
49
|
-
var getQuery = useQuery(GQL.READ_API_KEY, {
|
|
88
|
+
var getQuery = (0, _reactHooks.useQuery)(GQL.READ_API_KEY, {
|
|
50
89
|
variables: {
|
|
51
90
|
id: id
|
|
52
91
|
},
|
|
@@ -65,32 +104,32 @@ export var ApiKeyForm = function ApiKeyForm() {
|
|
|
65
104
|
}
|
|
66
105
|
});
|
|
67
106
|
|
|
68
|
-
var _useMutation = useMutation(GQL.CREATE_API_KEY, {
|
|
107
|
+
var _useMutation = (0, _reactHooks.useMutation)(GQL.CREATE_API_KEY, {
|
|
69
108
|
refetchQueries: [{
|
|
70
109
|
query: GQL.LIST_API_KEYS
|
|
71
110
|
}]
|
|
72
111
|
}),
|
|
73
|
-
_useMutation2 =
|
|
112
|
+
_useMutation2 = (0, _slicedToArray2.default)(_useMutation, 2),
|
|
74
113
|
create = _useMutation2[0],
|
|
75
114
|
createMutation = _useMutation2[1];
|
|
76
115
|
|
|
77
|
-
var _useMutation3 = useMutation(GQL.UPDATE_API_KEY, {
|
|
116
|
+
var _useMutation3 = (0, _reactHooks.useMutation)(GQL.UPDATE_API_KEY, {
|
|
78
117
|
refetchQueries: [{
|
|
79
118
|
query: GQL.LIST_API_KEYS
|
|
80
119
|
}]
|
|
81
120
|
}),
|
|
82
|
-
_useMutation4 =
|
|
121
|
+
_useMutation4 = (0, _slicedToArray2.default)(_useMutation3, 2),
|
|
83
122
|
update = _useMutation4[0],
|
|
84
123
|
updateMutation = _useMutation4[1];
|
|
85
124
|
|
|
86
125
|
var loading = [getQuery, createMutation, updateMutation].find(function (item) {
|
|
87
126
|
return item.loading;
|
|
88
127
|
});
|
|
89
|
-
var onSubmit = useCallback( /*#__PURE__*/function () {
|
|
90
|
-
var _ref =
|
|
128
|
+
var onSubmit = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
129
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(data) {
|
|
91
130
|
var isUpdate, _ref2, _ref3, operation, args, response, error, id;
|
|
92
131
|
|
|
93
|
-
return
|
|
132
|
+
return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
|
|
94
133
|
while (1) {
|
|
95
134
|
switch (_context.prev = _context.next) {
|
|
96
135
|
case 0:
|
|
@@ -99,10 +138,10 @@ export var ApiKeyForm = function ApiKeyForm() {
|
|
|
99
138
|
break;
|
|
100
139
|
}
|
|
101
140
|
|
|
102
|
-
showSnackbar(t(_templateObject || (_templateObject =
|
|
141
|
+
showSnackbar(t(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["You must configure permissions before saving!"]))), {
|
|
103
142
|
timeout: 60000,
|
|
104
143
|
dismissesOnAction: true,
|
|
105
|
-
action: /*#__PURE__*/
|
|
144
|
+
action: /*#__PURE__*/_react.default.createElement(_Snackbar.SnackbarAction, {
|
|
106
145
|
label: "OK"
|
|
107
146
|
})
|
|
108
147
|
});
|
|
@@ -113,13 +152,13 @@ export var ApiKeyForm = function ApiKeyForm() {
|
|
|
113
152
|
_ref2 = isUpdate ? [update, {
|
|
114
153
|
variables: {
|
|
115
154
|
id: data.id,
|
|
116
|
-
data: pickDataForAPI(data)
|
|
155
|
+
data: (0, _utils.pickDataForAPI)(data)
|
|
117
156
|
}
|
|
118
157
|
}] : [create, {
|
|
119
158
|
variables: {
|
|
120
|
-
data: pickDataForAPI(data)
|
|
159
|
+
data: (0, _utils.pickDataForAPI)(data)
|
|
121
160
|
}
|
|
122
|
-
}], _ref3 =
|
|
161
|
+
}], _ref3 = (0, _slicedToArray2.default)(_ref2, 2), operation = _ref3[0], args = _ref3[1];
|
|
123
162
|
_context.next = 7;
|
|
124
163
|
return operation(args);
|
|
125
164
|
|
|
@@ -137,7 +176,7 @@ export var ApiKeyForm = function ApiKeyForm() {
|
|
|
137
176
|
case 11:
|
|
138
177
|
id = response.data.security.apiKey.data.id;
|
|
139
178
|
!isUpdate && history.push("/access-management/api-keys?id=".concat(id));
|
|
140
|
-
showSnackbar(t(_templateObject2 || (_templateObject2 =
|
|
179
|
+
showSnackbar(t(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["API key saved successfully."]))));
|
|
141
180
|
|
|
142
181
|
case 14:
|
|
143
182
|
case "end":
|
|
@@ -151,93 +190,95 @@ export var ApiKeyForm = function ApiKeyForm() {
|
|
|
151
190
|
return _ref.apply(this, arguments);
|
|
152
191
|
};
|
|
153
192
|
}(), [id]);
|
|
154
|
-
var data =
|
|
155
|
-
var showEmptyView = !newEntry && !loading &&
|
|
193
|
+
var data = (0, _get.default)(getQuery, "data.security.apiKey.data", {});
|
|
194
|
+
var showEmptyView = !newEntry && !loading && (0, _isEmpty.default)(data); // Render "No content" selected view.
|
|
156
195
|
|
|
157
196
|
if (showEmptyView) {
|
|
158
|
-
return /*#__PURE__*/
|
|
159
|
-
title: t(_templateObject3 || (_templateObject3 =
|
|
160
|
-
action: /*#__PURE__*/
|
|
197
|
+
return /*#__PURE__*/_react.default.createElement(_EmptyView.default, {
|
|
198
|
+
title: t(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["Click on the left side list to display API key details or create a..."]))),
|
|
199
|
+
action: /*#__PURE__*/_react.default.createElement(_Button.ButtonDefault, {
|
|
161
200
|
"data-testid": "new-record-button",
|
|
162
201
|
onClick: function onClick() {
|
|
163
202
|
return history.push("/access-management/api-keys?new=true");
|
|
164
203
|
}
|
|
165
|
-
}, /*#__PURE__*/
|
|
166
|
-
icon: /*#__PURE__*/
|
|
167
|
-
}), " ", t(_templateObject4 || (_templateObject4 =
|
|
204
|
+
}, /*#__PURE__*/_react.default.createElement(_Button.ButtonIcon, {
|
|
205
|
+
icon: /*#__PURE__*/_react.default.createElement(_add18px.ReactComponent, null)
|
|
206
|
+
}), " ", t(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["New API Key"]))))
|
|
168
207
|
});
|
|
169
208
|
}
|
|
170
209
|
|
|
171
|
-
return /*#__PURE__*/
|
|
210
|
+
return /*#__PURE__*/_react.default.createElement(_form.Form, {
|
|
172
211
|
data: data,
|
|
173
212
|
onSubmit: onSubmit
|
|
174
213
|
}, function (_ref4) {
|
|
175
214
|
var data = _ref4.data,
|
|
176
215
|
form = _ref4.form,
|
|
177
216
|
Bind = _ref4.Bind;
|
|
178
|
-
return /*#__PURE__*/
|
|
217
|
+
return /*#__PURE__*/_react.default.createElement(_SimpleForm.SimpleForm, null, loading && /*#__PURE__*/_react.default.createElement(_Progress.CircularProgress, null), /*#__PURE__*/_react.default.createElement(_SimpleForm.SimpleFormHeader, {
|
|
179
218
|
title: data.name ? data.name : "Untitled"
|
|
180
|
-
}), /*#__PURE__*/
|
|
219
|
+
}), /*#__PURE__*/_react.default.createElement(_SimpleForm.SimpleFormContent, null, /*#__PURE__*/_react.default.createElement(_Grid.Grid, null, /*#__PURE__*/_react.default.createElement(_Grid.Cell, {
|
|
181
220
|
span: 12
|
|
182
|
-
}, /*#__PURE__*/
|
|
221
|
+
}, /*#__PURE__*/_react.default.createElement(Bind, {
|
|
183
222
|
name: "name",
|
|
184
|
-
validators: validation.create("required")
|
|
185
|
-
}, /*#__PURE__*/
|
|
186
|
-
label: t(_templateObject5 || (_templateObject5 =
|
|
187
|
-
})))), /*#__PURE__*/
|
|
223
|
+
validators: _validation.validation.create("required")
|
|
224
|
+
}, /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
225
|
+
label: t(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["Name"])))
|
|
226
|
+
})))), /*#__PURE__*/_react.default.createElement(_Grid.Grid, null, /*#__PURE__*/_react.default.createElement(_Grid.Cell, {
|
|
188
227
|
span: 12
|
|
189
|
-
}, /*#__PURE__*/
|
|
228
|
+
}, /*#__PURE__*/_react.default.createElement(Bind, {
|
|
190
229
|
name: "description",
|
|
191
|
-
validators: validation.create("required")
|
|
192
|
-
}, /*#__PURE__*/
|
|
193
|
-
label: t(_templateObject6 || (_templateObject6 =
|
|
230
|
+
validators: _validation.validation.create("required")
|
|
231
|
+
}, /*#__PURE__*/_react.default.createElement(_Input.Input, {
|
|
232
|
+
label: t(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["Description"]))),
|
|
194
233
|
rows: 4
|
|
195
|
-
})))), /*#__PURE__*/
|
|
234
|
+
})))), /*#__PURE__*/_react.default.createElement(_Grid.Grid, null, /*#__PURE__*/_react.default.createElement(_Grid.Cell, {
|
|
196
235
|
span: 12
|
|
197
|
-
}, /*#__PURE__*/
|
|
236
|
+
}, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_Typography.Typography, {
|
|
198
237
|
use: "subtitle1"
|
|
199
|
-
}, t(_templateObject7 || (_templateObject7 =
|
|
238
|
+
}, t(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["Token"])))), data.token ? /*#__PURE__*/_react.default.createElement("div", {
|
|
200
239
|
style: {
|
|
201
240
|
background: "var(--mdc-theme-background)",
|
|
202
241
|
padding: "8px",
|
|
203
242
|
paddingLeft: "16px"
|
|
204
243
|
}
|
|
205
|
-
}, /*#__PURE__*/
|
|
244
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
206
245
|
style: {
|
|
207
246
|
lineHeight: "48px",
|
|
208
247
|
verticalAlign: "middle"
|
|
209
248
|
}
|
|
210
|
-
}, data.token), /*#__PURE__*/
|
|
249
|
+
}, data.token), /*#__PURE__*/_react.default.createElement("span", {
|
|
211
250
|
style: {
|
|
212
251
|
position: "absolute",
|
|
213
252
|
right: "32px"
|
|
214
253
|
}
|
|
215
|
-
}, /*#__PURE__*/
|
|
254
|
+
}, /*#__PURE__*/_react.default.createElement(_Button.CopyButton, {
|
|
216
255
|
value: data.token,
|
|
217
256
|
onCopy: function onCopy() {
|
|
218
257
|
return showSnackbar("Successfully copied!");
|
|
219
258
|
}
|
|
220
|
-
}))) : /*#__PURE__*/
|
|
259
|
+
}))) : /*#__PURE__*/_react.default.createElement(_FormElementMessage.FormElementMessage, null, "Your token will be shown once you submit the form.")))), /*#__PURE__*/_react.default.createElement(_Grid.Grid, null, /*#__PURE__*/_react.default.createElement(_Grid.Cell, {
|
|
221
260
|
span: 12
|
|
222
|
-
}, /*#__PURE__*/
|
|
261
|
+
}, /*#__PURE__*/_react.default.createElement(_Typography.Typography, {
|
|
223
262
|
use: "subtitle1"
|
|
224
|
-
}, t(_templateObject8 || (_templateObject8 =
|
|
263
|
+
}, t(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["Permissions"]))))), /*#__PURE__*/_react.default.createElement(_Grid.Cell, {
|
|
225
264
|
span: 12
|
|
226
|
-
}, /*#__PURE__*/
|
|
265
|
+
}, /*#__PURE__*/_react.default.createElement(Bind, {
|
|
227
266
|
name: "permissions",
|
|
228
267
|
defaultValue: []
|
|
229
268
|
}, function (bind) {
|
|
230
|
-
return /*#__PURE__*/
|
|
269
|
+
return /*#__PURE__*/_react.default.createElement(_Permissions.Permissions, Object.assign({
|
|
231
270
|
id: data.id || "new"
|
|
232
271
|
}, bind));
|
|
233
|
-
})))), /*#__PURE__*/
|
|
272
|
+
})))), /*#__PURE__*/_react.default.createElement(_SimpleForm.SimpleFormFooter, null, /*#__PURE__*/_react.default.createElement(ButtonWrapper, null, /*#__PURE__*/_react.default.createElement(_Button.ButtonDefault, {
|
|
234
273
|
onClick: function onClick() {
|
|
235
274
|
return history.push("/access-management/api-keys");
|
|
236
275
|
}
|
|
237
|
-
}, t(_templateObject9 || (_templateObject9 =
|
|
276
|
+
}, t(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["Cancel"])))), /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
|
|
238
277
|
onClick: function onClick(ev) {
|
|
239
278
|
form.submit(ev);
|
|
240
279
|
}
|
|
241
|
-
}, t(_templateObject10 || (_templateObject10 =
|
|
280
|
+
}, t(_templateObject10 || (_templateObject10 = (0, _taggedTemplateLiteral2.default)(["Save API key"])))))));
|
|
242
281
|
});
|
|
243
|
-
};
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
exports.ApiKeyForm = ApiKeyForm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ApiKeyForm.tsx"],"names":["React","useCallback","useMutation","useQuery","get","useRouter","i18n","Form","Grid","Cell","Input","ButtonDefault","ButtonIcon","ButtonPrimary","CopyButton","CircularProgress","FormElementMessage","Permissions","validation","SimpleForm","SimpleFormFooter","SimpleFormContent","SimpleFormHeader","Typography","useSnackbar","pickDataForAPI","GQL","SnackbarAction","isEmpty","EmptyView","ReactComponent","AddIcon","styled","t","ns","ButtonWrapper","display","justifyContent","ApiKeyForm","location","history","showSnackbar","newEntry","URLSearchParams","search","id","getQuery","READ_API_KEY","variables","skip","onCompleted","data","error","security","apiKey","push","message","CREATE_API_KEY","refetchQueries","query","LIST_API_KEYS","create","createMutation","UPDATE_API_KEY","update","updateMutation","loading","find","item","onSubmit","permissions","length","timeout","dismissesOnAction","action","isUpdate","createdOn","operation","args","response","showEmptyView","form","Bind","name","token","background","padding","paddingLeft","lineHeight","verticalAlign","position","right","bind","ev","submit"],"mappings":";;;;;;;AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,SAASC,WAAT,EAAsBC,QAAtB,QAAsC,qBAAtC;AACA,OAA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,sBAAD,CADR;AAAA;AAFZ,MAHJ,CAfJ,CADH,gBA4BG,oBAAC,kBAAD,6DA9BR,CADJ,CADJ,CAlBJ,eAyDI,oBAAC,IAAD,qBACI,oBAAC,IAAD;AAAM,MAAA,IAAI,EAAE;AAAZ,oBACI,oBAAC,UAAD;AAAY,MAAA,GAAG,EAAE;AAAjB,OAA+BR,CAA/B,mFADJ,CADJ,eAII,oBAAC,IAAD;AAAM,MAAA,IAAI,EAAE;AAAZ,oBACI,oBAAC,IAAD;AAAM,MAAA,IAAI,EAAE,aAAZ;AAA2B,MAAA,YAAY,EAAE;AAAzC,OACK,UAAA2D,IAAI;AAAA,0BAAI,oBAAC,WAAD;AAAa,QAAA,EAAE,EAAEzC,IAAI,CAACN,EAAL,IAAW;AAA5B,SAAuC+C,IAAvC,EAAJ;AAAA,KADT,CADJ,CAJJ,CAzDJ,CAHJ,eAuEI,oBAAC,gBAAD,qBACI,oBAAC,aAAD,qBACI,oBAAC,aAAD;AACI,MAAA,OAAO,EAAE;AAAA,eAAMpD,OAAO,CAACe,IAAR,CAAa,6BAAb,CAAN;AAAA;AADb,OAEEtB,CAFF,8EADJ,eAII,oBAAC,aAAD;AACI,MAAA,OAAO,EAAE,iBAAA4D,EAAE,EAAI;AACXZ,QAAAA,IAAI,CAACa,MAAL,CAAYD,EAAZ;AACH;AAHL,OAIE5D,CAJF,sFAJJ,CADJ,CAvEJ,CADJ;AAsFH,GAxFL,CADJ;AA4FH,CA/KM","sourcesContent":["import React, { useCallback } from \"react\";\nimport { useMutation, useQuery } from \"@apollo/react-hooks\";\nimport get from \"lodash/get\";\nimport { useRouter } from \"@webiny/react-router\";\nimport { i18n } from \"@webiny/app/i18n\";\nimport { Form } from \"@webiny/form\";\nimport { Grid, Cell } from \"@webiny/ui/Grid\";\nimport { Input } from \"@webiny/ui/Input\";\nimport { ButtonDefault, ButtonIcon, ButtonPrimary, CopyButton } from \"@webiny/ui/Button\";\nimport { CircularProgress } from \"@webiny/ui/Progress\";\nimport { FormElementMessage } from \"@webiny/ui/FormElementMessage\";\nimport { Permissions } from \"@webiny/app-admin/components/Permissions\";\nimport { validation } from \"@webiny/validation\";\nimport {\n SimpleForm,\n SimpleFormFooter,\n SimpleFormContent,\n SimpleFormHeader\n} from \"@webiny/app-admin/components/SimpleForm\";\nimport { Typography } from \"@webiny/ui/Typography\";\nimport { useSnackbar } from \"@webiny/app-admin/hooks/useSnackbar\";\nimport { pickDataForAPI } from \"./utils\";\nimport * as GQL from \"./graphql\";\nimport { SnackbarAction } from \"@webiny/ui/Snackbar\";\nimport isEmpty from \"lodash/isEmpty\";\nimport EmptyView from \"@webiny/app-admin/components/EmptyView\";\nimport { ReactComponent as AddIcon } from \"@webiny/app-admin/assets/icons/add-18px.svg\";\nimport styled from \"@emotion/styled\";\nimport { ApiKey } from \"~/types\";\n\nconst t = i18n.ns(\"app-security-admin-users/admin/api-keys/form\");\n\nconst ButtonWrapper = styled(\"div\")({\n display: \"flex\",\n justifyContent: \"space-between\"\n});\nexport interface ApiKeyFormProps {\n // TODO @ts-refactor delete and go up the tree and sort it out\n [key: string]: any;\n}\nexport const ApiKeyForm: React.FC<ApiKeyFormProps> = () => {\n const { location, history } = useRouter();\n const { showSnackbar } = useSnackbar();\n const newEntry = new URLSearchParams(location.search).get(\"new\") === \"true\";\n const id = new URLSearchParams(location.search).get(\"id\");\n\n const getQuery = useQuery(GQL.READ_API_KEY, {\n variables: { id },\n skip: !id,\n onCompleted: data => {\n if (!data) {\n return;\n }\n\n const { error } = data.security.apiKey;\n if (error) {\n history.push(\"/access-management/api-keys\");\n showSnackbar(error.message);\n }\n }\n });\n\n const [create, createMutation] = useMutation(GQL.CREATE_API_KEY, {\n refetchQueries: [{ query: GQL.LIST_API_KEYS }]\n });\n\n const [update, updateMutation] = useMutation(GQL.UPDATE_API_KEY, {\n refetchQueries: [{ query: GQL.LIST_API_KEYS }]\n });\n\n const loading = [getQuery, createMutation, updateMutation].find(item => item.loading);\n\n const onSubmit = useCallback(\n async data => {\n if (!data.permissions || !data.permissions.length) {\n showSnackbar(t`You must configure permissions before saving!`, {\n timeout: 60000,\n dismissesOnAction: true,\n action: <SnackbarAction label={\"OK\"} />\n });\n return;\n }\n\n const isUpdate = data.createdOn;\n const [operation, args] = isUpdate\n ? [update, { variables: { id: data.id, data: pickDataForAPI(data) } }]\n : [create, { variables: { data: pickDataForAPI(data) } }];\n\n const response = await operation(args);\n\n const { error } = response.data.security.apiKey;\n if (error) {\n return showSnackbar(error.message);\n }\n\n const { id } = response.data.security.apiKey.data;\n\n !isUpdate && history.push(`/access-management/api-keys?id=${id}`);\n showSnackbar(t`API key saved successfully.`);\n },\n [id]\n );\n\n const data: ApiKey[] = get(getQuery, \"data.security.apiKey.data\", {});\n\n const showEmptyView = !newEntry && !loading && isEmpty(data);\n // Render \"No content\" selected view.\n if (showEmptyView) {\n return (\n <EmptyView\n title={t`Click on the left side list to display API key details or create a...`}\n action={\n <ButtonDefault\n data-testid=\"new-record-button\"\n onClick={() => history.push(\"/access-management/api-keys?new=true\")}\n >\n <ButtonIcon icon={<AddIcon />} /> {t`New API Key`}\n </ButtonDefault>\n }\n />\n );\n }\n\n return (\n <Form data={data} onSubmit={onSubmit}>\n {({ data, form, Bind }) => {\n return (\n <SimpleForm>\n {loading && <CircularProgress />}\n <SimpleFormHeader title={data.name ? data.name : \"Untitled\"} />\n <SimpleFormContent>\n <Grid>\n <Cell span={12}>\n <Bind name=\"name\" validators={validation.create(\"required\")}>\n <Input label={t`Name`} />\n </Bind>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <Bind\n name=\"description\"\n validators={validation.create(\"required\")}\n >\n <Input label={t`Description`} rows={4} />\n </Bind>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <div>\n <Typography use={\"subtitle1\"}>{t`Token`}</Typography>\n {data.token ? (\n <div\n style={{\n background: \"var(--mdc-theme-background)\",\n padding: \"8px\",\n paddingLeft: \"16px\"\n }}\n >\n <span\n style={{\n lineHeight: \"48px\",\n verticalAlign: \"middle\"\n }}\n >\n {data.token}\n </span>\n <span\n style={{ position: \"absolute\", right: \"32px\" }}\n >\n <CopyButton\n value={data.token}\n onCopy={() =>\n showSnackbar(\"Successfully copied!\")\n }\n />\n </span>\n </div>\n ) : (\n <FormElementMessage>\n Your token will be shown once you submit the form.\n </FormElementMessage>\n )}\n </div>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <Typography use={\"subtitle1\"}>{t`Permissions`}</Typography>\n </Cell>\n <Cell span={12}>\n <Bind name={\"permissions\"} defaultValue={[]}>\n {bind => <Permissions id={data.id || \"new\"} {...bind} />}\n </Bind>\n </Cell>\n </Grid>\n </SimpleFormContent>\n <SimpleFormFooter>\n <ButtonWrapper>\n <ButtonDefault\n onClick={() => history.push(\"/access-management/api-keys\")}\n >{t`Cancel`}</ButtonDefault>\n <ButtonPrimary\n onClick={ev => {\n form.submit(ev);\n }}\n >{t`Save API key`}</ButtonPrimary>\n </ButtonWrapper>\n </SimpleFormFooter>\n </SimpleForm>\n );\n }}\n </Form>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"names":["t","i18n","ns","ButtonWrapper","styled","display","justifyContent","ApiKeyForm","useRouter","location","history","useSnackbar","showSnackbar","newEntry","URLSearchParams","search","get","id","getQuery","useQuery","GQL","READ_API_KEY","variables","skip","onCompleted","data","error","security","apiKey","push","message","useMutation","CREATE_API_KEY","refetchQueries","query","LIST_API_KEYS","create","createMutation","UPDATE_API_KEY","update","updateMutation","loading","find","item","onSubmit","useCallback","permissions","length","timeout","dismissesOnAction","action","isUpdate","createdOn","pickDataForAPI","operation","args","response","showEmptyView","isEmpty","form","Bind","name","validation","token","background","padding","paddingLeft","lineHeight","verticalAlign","position","right","bind","ev","submit"],"sources":["ApiKeyForm.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { useMutation, useQuery } from \"@apollo/react-hooks\";\nimport get from \"lodash/get\";\nimport { useRouter } from \"@webiny/react-router\";\nimport { i18n } from \"@webiny/app/i18n\";\nimport { Form } from \"@webiny/form\";\nimport { Grid, Cell } from \"@webiny/ui/Grid\";\nimport { Input } from \"@webiny/ui/Input\";\nimport { ButtonDefault, ButtonIcon, ButtonPrimary, CopyButton } from \"@webiny/ui/Button\";\nimport { CircularProgress } from \"@webiny/ui/Progress\";\nimport { FormElementMessage } from \"@webiny/ui/FormElementMessage\";\nimport { Permissions } from \"@webiny/app-admin/components/Permissions\";\nimport { validation } from \"@webiny/validation\";\nimport {\n SimpleForm,\n SimpleFormFooter,\n SimpleFormContent,\n SimpleFormHeader\n} from \"@webiny/app-admin/components/SimpleForm\";\nimport { Typography } from \"@webiny/ui/Typography\";\nimport { useSnackbar } from \"@webiny/app-admin/hooks/useSnackbar\";\nimport { pickDataForAPI } from \"./utils\";\nimport * as GQL from \"./graphql\";\nimport { SnackbarAction } from \"@webiny/ui/Snackbar\";\nimport isEmpty from \"lodash/isEmpty\";\nimport EmptyView from \"@webiny/app-admin/components/EmptyView\";\nimport { ReactComponent as AddIcon } from \"@webiny/app-admin/assets/icons/add-18px.svg\";\nimport styled from \"@emotion/styled\";\nimport { ApiKey } from \"~/types\";\n\nconst t = i18n.ns(\"app-security-admin-users/admin/api-keys/form\");\n\nconst ButtonWrapper = styled(\"div\")({\n display: \"flex\",\n justifyContent: \"space-between\"\n});\nexport interface ApiKeyFormProps {\n // TODO @ts-refactor delete and go up the tree and sort it out\n [key: string]: any;\n}\nexport const ApiKeyForm: React.FC<ApiKeyFormProps> = () => {\n const { location, history } = useRouter();\n const { showSnackbar } = useSnackbar();\n const newEntry = new URLSearchParams(location.search).get(\"new\") === \"true\";\n const id = new URLSearchParams(location.search).get(\"id\");\n\n const getQuery = useQuery(GQL.READ_API_KEY, {\n variables: { id },\n skip: !id,\n onCompleted: data => {\n if (!data) {\n return;\n }\n\n const { error } = data.security.apiKey;\n if (error) {\n history.push(\"/access-management/api-keys\");\n showSnackbar(error.message);\n }\n }\n });\n\n const [create, createMutation] = useMutation(GQL.CREATE_API_KEY, {\n refetchQueries: [{ query: GQL.LIST_API_KEYS }]\n });\n\n const [update, updateMutation] = useMutation(GQL.UPDATE_API_KEY, {\n refetchQueries: [{ query: GQL.LIST_API_KEYS }]\n });\n\n const loading = [getQuery, createMutation, updateMutation].find(item => item.loading);\n\n const onSubmit = useCallback(\n async data => {\n if (!data.permissions || !data.permissions.length) {\n showSnackbar(t`You must configure permissions before saving!`, {\n timeout: 60000,\n dismissesOnAction: true,\n action: <SnackbarAction label={\"OK\"} />\n });\n return;\n }\n\n const isUpdate = data.createdOn;\n const [operation, args] = isUpdate\n ? [update, { variables: { id: data.id, data: pickDataForAPI(data) } }]\n : [create, { variables: { data: pickDataForAPI(data) } }];\n\n const response = await operation(args);\n\n const { error } = response.data.security.apiKey;\n if (error) {\n return showSnackbar(error.message);\n }\n\n const { id } = response.data.security.apiKey.data;\n\n !isUpdate && history.push(`/access-management/api-keys?id=${id}`);\n showSnackbar(t`API key saved successfully.`);\n },\n [id]\n );\n\n const data: ApiKey[] = get(getQuery, \"data.security.apiKey.data\", {});\n\n const showEmptyView = !newEntry && !loading && isEmpty(data);\n // Render \"No content\" selected view.\n if (showEmptyView) {\n return (\n <EmptyView\n title={t`Click on the left side list to display API key details or create a...`}\n action={\n <ButtonDefault\n data-testid=\"new-record-button\"\n onClick={() => history.push(\"/access-management/api-keys?new=true\")}\n >\n <ButtonIcon icon={<AddIcon />} /> {t`New API Key`}\n </ButtonDefault>\n }\n />\n );\n }\n\n return (\n <Form data={data} onSubmit={onSubmit}>\n {({ data, form, Bind }) => {\n return (\n <SimpleForm>\n {loading && <CircularProgress />}\n <SimpleFormHeader title={data.name ? data.name : \"Untitled\"} />\n <SimpleFormContent>\n <Grid>\n <Cell span={12}>\n <Bind name=\"name\" validators={validation.create(\"required\")}>\n <Input label={t`Name`} />\n </Bind>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <Bind\n name=\"description\"\n validators={validation.create(\"required\")}\n >\n <Input label={t`Description`} rows={4} />\n </Bind>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <div>\n <Typography use={\"subtitle1\"}>{t`Token`}</Typography>\n {data.token ? (\n <div\n style={{\n background: \"var(--mdc-theme-background)\",\n padding: \"8px\",\n paddingLeft: \"16px\"\n }}\n >\n <span\n style={{\n lineHeight: \"48px\",\n verticalAlign: \"middle\"\n }}\n >\n {data.token}\n </span>\n <span\n style={{ position: \"absolute\", right: \"32px\" }}\n >\n <CopyButton\n value={data.token}\n onCopy={() =>\n showSnackbar(\"Successfully copied!\")\n }\n />\n </span>\n </div>\n ) : (\n <FormElementMessage>\n Your token will be shown once you submit the form.\n </FormElementMessage>\n )}\n </div>\n </Cell>\n </Grid>\n <Grid>\n <Cell span={12}>\n <Typography use={\"subtitle1\"}>{t`Permissions`}</Typography>\n </Cell>\n <Cell span={12}>\n <Bind name={\"permissions\"} defaultValue={[]}>\n {bind => <Permissions id={data.id || \"new\"} {...bind} />}\n </Bind>\n </Cell>\n </Grid>\n </SimpleFormContent>\n <SimpleFormFooter>\n <ButtonWrapper>\n <ButtonDefault\n onClick={() => history.push(\"/access-management/api-keys\")}\n >{t`Cancel`}</ButtonDefault>\n <ButtonPrimary\n onClick={ev => {\n form.submit(ev);\n }}\n >{t`Save API key`}</ButtonPrimary>\n </ButtonWrapper>\n </SimpleFormFooter>\n </SimpleForm>\n );\n }}\n </Form>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;AAGA,IAAMA,CAAC,GAAGC,UAAA,CAAKC,EAAL,CAAQ,8CAAR,CAAV;;AAEA,IAAMC,aAAa,oBAAGC,eAAH,EAAU,KAAV;EAAA;EAAA;AAAA,GAAiB;EAChCC,OAAO,EAAE,MADuB;EAEhCC,cAAc,EAAE;AAF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H,gBA4BG,6BAAC,sCAAD,6DA9BR,CADJ,CADJ,CAlBJ,eAyDI,6BAAC,UAAD,qBACI,6BAAC,UAAD;MAAM,IAAI,EAAE;IAAZ,gBACI,6BAAC,sBAAD;MAAY,GAAG,EAAE;IAAjB,GAA+BZ,CAA/B,iGADJ,CADJ,eAII,6BAAC,UAAD;MAAM,IAAI,EAAE;IAAZ,gBACI,6BAAC,IAAD;MAAM,IAAI,EAAE,aAAZ;MAA2B,YAAY,EAAE;IAAzC,GACK,UAAAuE,IAAI;MAAA,oBAAI,6BAAC,wBAAD;QAAa,EAAE,EAAE9C,IAAI,CAACR,EAAL,IAAW;MAA5B,GAAuCsD,IAAvC,EAAJ;IAAA,CADT,CADJ,CAJJ,CAzDJ,CAHJ,eAuEI,6BAAC,4BAAD,qBACI,6BAAC,aAAD,qBACI,6BAAC,qBAAD;MACI,OAAO,EAAE;QAAA,OAAM7D,OAAO,CAACmB,IAAR,CAAa,6BAAb,CAAN;MAAA;IADb,GAEE7B,CAFF,4FADJ,eAII,6BAAC,qBAAD;MACI,OAAO,EAAE,iBAAAwE,EAAE,EAAI;QACXb,IAAI,CAACc,MAAL,CAAYD,EAAZ;MACH;IAHL,GAIExE,CAJF,oGAJJ,CADJ,CAvEJ,CADJ;EAsFH,CAxFL,CADJ;AA4FH,CA/KM"}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ApiKeys = void 0;
|
|
9
|
+
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _SplitView = require("@webiny/app-admin/components/SplitView");
|
|
13
|
+
|
|
14
|
+
var _ApiKeysDataList = require("./ApiKeysDataList");
|
|
15
|
+
|
|
16
|
+
var _ApiKeyForm = require("./ApiKeyForm");
|
|
17
|
+
|
|
18
|
+
var ApiKeys = function ApiKeys(_ref) {
|
|
6
19
|
var _ref$formProps = _ref.formProps,
|
|
7
20
|
formProps = _ref$formProps === void 0 ? {} : _ref$formProps,
|
|
8
21
|
_ref$listProps = _ref.listProps,
|
|
9
22
|
listProps = _ref$listProps === void 0 ? {} : _ref$listProps;
|
|
10
|
-
return /*#__PURE__*/React.createElement(SplitView, null, /*#__PURE__*/React.createElement(LeftPanel, null, /*#__PURE__*/React.createElement(ApiKeysDataList, listProps)), /*#__PURE__*/React.createElement(RightPanel, null, /*#__PURE__*/React.createElement(ApiKeyForm, formProps)));
|
|
11
|
-
};
|
|
23
|
+
return /*#__PURE__*/React.createElement(_SplitView.SplitView, null, /*#__PURE__*/React.createElement(_SplitView.LeftPanel, null, /*#__PURE__*/React.createElement(_ApiKeysDataList.ApiKeysDataList, listProps)), /*#__PURE__*/React.createElement(_SplitView.RightPanel, null, /*#__PURE__*/React.createElement(_ApiKeyForm.ApiKeyForm, formProps)));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.ApiKeys = ApiKeys;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["ApiKeys","formProps","listProps"],"sources":["ApiKeys.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { SplitView, LeftPanel, RightPanel } from \"@webiny/app-admin/components/SplitView\";\nimport { ApiKeysDataList, ApiKeysDataListProps } from \"./ApiKeysDataList\";\nimport { ApiKeyForm, ApiKeyFormProps } from \"./ApiKeyForm\";\n\nexport interface ApiKeysProps {\n listProps?: ApiKeysDataListProps;\n formProps?: ApiKeyFormProps;\n}\nexport const ApiKeys: React.FC<ApiKeysProps> = ({ formProps = {}, listProps = {} }) => {\n return (\n <SplitView>\n <LeftPanel>\n <ApiKeysDataList {...listProps} />\n </LeftPanel>\n <RightPanel>\n <ApiKeyForm {...formProps} />\n </RightPanel>\n </SplitView>\n );\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAMO,IAAMA,OAA+B,GAAG,SAAlCA,OAAkC,OAAwC;EAAA,0BAArCC,SAAqC;EAAA,IAArCA,SAAqC,+BAAzB,EAAyB;EAAA,0BAArBC,SAAqB;EAAA,IAArBA,SAAqB,+BAAT,EAAS;EACnF,oBACI,oBAAC,oBAAD,qBACI,oBAAC,oBAAD,qBACI,oBAAC,gCAAD,EAAqBA,SAArB,CADJ,CADJ,eAII,oBAAC,qBAAD,qBACI,oBAAC,sBAAD,EAAgBD,SAAhB,CADJ,CAJJ,CADJ;AAUH,CAXM"}
|