@webiny/app-security-access-management 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +115 -0
- package/components/GroupAutocomplete/graphql.d.ts +1 -0
- package/components/GroupAutocomplete/graphql.js +6 -0
- package/components/GroupAutocomplete/index.d.ts +2 -0
- package/components/GroupAutocomplete/index.js +16 -0
- package/components/NotAuthorizedError/NotAuthorizedError.d.ts +2 -0
- package/components/NotAuthorizedError/NotAuthorizedError.js +50 -0
- package/components/NotAuthorizedError/SecureRouteError.svg +1 -0
- package/components/NotAuthorizedError/index.d.ts +1 -0
- package/components/NotAuthorizedError/index.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/package.json +70 -0
- package/plugins/constants.d.ts +4 -0
- package/plugins/constants.js +6 -0
- package/plugins/index.d.ts +3 -0
- package/plugins/index.js +8 -0
- package/plugins/installation.d.ts +3 -0
- package/plugins/installation.js +99 -0
- package/plugins/menus.d.ts +4 -0
- package/plugins/menus.js +61 -0
- package/plugins/permissionRenderer/SecurityPermissions.d.ts +5 -0
- package/plugins/permissionRenderer/SecurityPermissions.js +176 -0
- package/plugins/permissionRenderer/index.d.ts +3 -0
- package/plugins/permissionRenderer/index.js +21 -0
- package/plugins/routes.d.ts +3 -0
- package/plugins/routes.js +38 -0
- package/plugins/secureRouteError.d.ts +7 -0
- package/plugins/secureRouteError.js +10 -0
- package/ui/elements/GroupAutocompleteElement.d.ts +5 -0
- package/ui/elements/GroupAutocompleteElement.js +35 -0
- package/ui/views/ApiKeys/ApiKeyForm.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeyForm.js +244 -0
- package/ui/views/ApiKeys/ApiKeys.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeys.js +12 -0
- package/ui/views/ApiKeys/ApiKeysDataList.d.ts +3 -0
- package/ui/views/ApiKeys/ApiKeysDataList.js +209 -0
- package/ui/views/ApiKeys/graphql.d.ts +5 -0
- package/ui/views/ApiKeys/graphql.js +11 -0
- package/ui/views/ApiKeys/index.d.ts +1 -0
- package/ui/views/ApiKeys/index.js +1 -0
- package/ui/views/ApiKeys/utils.d.ts +1 -0
- package/ui/views/ApiKeys/utils.js +5 -0
- package/ui/views/Groups/Groups.d.ts +3 -0
- package/ui/views/Groups/Groups.js +12 -0
- package/ui/views/Groups/GroupsDataList.d.ts +3 -0
- package/ui/views/Groups/GroupsDataList.js +215 -0
- package/ui/views/Groups/GroupsForm.d.ts +3 -0
- package/ui/views/Groups/GroupsForm.js +234 -0
- package/ui/views/Groups/graphql.d.ts +5 -0
- package/ui/views/Groups/graphql.js +11 -0
- package/ui/views/Groups/index.d.ts +1 -0
- package/ui/views/Groups/index.js +1 -0
- package/ui/views/utils.d.ts +2 -0
- package/ui/views/utils.js +27 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
4
|
+
|
|
5
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
|
|
6
|
+
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
9
|
+
import orderBy from "lodash/orderBy";
|
|
10
|
+
import { i18n } from "@webiny/app/i18n";
|
|
11
|
+
import { DataList, ScrollList, ListItem, ListItemText, ListItemTextSecondary, ListItemMeta, ListActions, DataListModalOverlayAction, DataListModalOverlay } from "@webiny/ui/List";
|
|
12
|
+
import { ButtonIcon, ButtonSecondary } from "@webiny/ui/Button";
|
|
13
|
+
import { DeleteIcon } from "@webiny/ui/List/DataList/icons";
|
|
14
|
+
import { Cell, Grid } from "@webiny/ui/Grid";
|
|
15
|
+
import { Select } from "@webiny/ui/Select";
|
|
16
|
+
import { useRouter } from "@webiny/react-router";
|
|
17
|
+
import SearchUI from "@webiny/app-admin/components/SearchUI";
|
|
18
|
+
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
|
|
19
|
+
import { useQuery, useMutation } from "@apollo/react-hooks";
|
|
20
|
+
import { useConfirmationDialog } from "@webiny/app-admin/hooks/useConfirmationDialog";
|
|
21
|
+
import * as GQL from "./graphql";
|
|
22
|
+
import { ReactComponent as AddIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/add-18px.svg";
|
|
23
|
+
import { ReactComponent as FilterIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/filter-24px.svg";
|
|
24
|
+
import { serializeSorters, deserializeSorters } from "../utils";
|
|
25
|
+
var t = i18n.ns("app-security/admin/groups/data-list");
|
|
26
|
+
var SORTERS = [{
|
|
27
|
+
label: t(_templateObject || (_templateObject = _taggedTemplateLiteral(["Newest to oldest"]))),
|
|
28
|
+
sorters: {
|
|
29
|
+
createdOn: "desc"
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
label: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Oldest to newest"]))),
|
|
33
|
+
sorters: {
|
|
34
|
+
createdOn: "asc"
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
label: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["Name A-Z"]))),
|
|
38
|
+
sorters: {
|
|
39
|
+
name: "asc"
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
label: t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Name Z-A"]))),
|
|
43
|
+
sorters: {
|
|
44
|
+
name: "desc"
|
|
45
|
+
}
|
|
46
|
+
}];
|
|
47
|
+
|
|
48
|
+
var ApiKeysDataList = function ApiKeysDataList() {
|
|
49
|
+
var _useState = useState(""),
|
|
50
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
51
|
+
filter = _useState2[0],
|
|
52
|
+
setFilter = _useState2[1];
|
|
53
|
+
|
|
54
|
+
var _useState3 = useState(serializeSorters(SORTERS[0].sorters)),
|
|
55
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
56
|
+
sort = _useState4[0],
|
|
57
|
+
setSort = _useState4[1];
|
|
58
|
+
|
|
59
|
+
var _useRouter = useRouter(),
|
|
60
|
+
history = _useRouter.history,
|
|
61
|
+
location = _useRouter.location;
|
|
62
|
+
|
|
63
|
+
var _useSnackbar = useSnackbar(),
|
|
64
|
+
showSnackbar = _useSnackbar.showSnackbar;
|
|
65
|
+
|
|
66
|
+
var _useConfirmationDialo = useConfirmationDialog({
|
|
67
|
+
dataTestId: "default-data-list.delete-dialog"
|
|
68
|
+
}),
|
|
69
|
+
showConfirmation = _useConfirmationDialo.showConfirmation;
|
|
70
|
+
|
|
71
|
+
var filterAPIKey = useCallback(function (_ref) {
|
|
72
|
+
var description = _ref.description,
|
|
73
|
+
name = _ref.name;
|
|
74
|
+
return description && description.toLowerCase().includes(filter) || name.toLowerCase().includes(filter);
|
|
75
|
+
}, [filter]);
|
|
76
|
+
var sortKeys = useCallback(function (list) {
|
|
77
|
+
if (!sort) {
|
|
78
|
+
return list;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var _Object$entries = Object.entries(deserializeSorters(sort)),
|
|
82
|
+
_Object$entries2 = _slicedToArray(_Object$entries, 1),
|
|
83
|
+
_Object$entries2$ = _slicedToArray(_Object$entries2[0], 2),
|
|
84
|
+
key = _Object$entries2$[0],
|
|
85
|
+
value = _Object$entries2$[1];
|
|
86
|
+
|
|
87
|
+
return orderBy(list, [key], [value]);
|
|
88
|
+
}, [sort]);
|
|
89
|
+
|
|
90
|
+
var _useQuery = useQuery(GQL.LIST_API_KEYS),
|
|
91
|
+
listResponse = _useQuery.data,
|
|
92
|
+
listLoading = _useQuery.loading;
|
|
93
|
+
|
|
94
|
+
var _useMutation = useMutation(GQL.DELETE_API_KEY, {
|
|
95
|
+
refetchQueries: [{
|
|
96
|
+
query: GQL.LIST_API_KEYS
|
|
97
|
+
}]
|
|
98
|
+
}),
|
|
99
|
+
_useMutation2 = _slicedToArray(_useMutation, 2),
|
|
100
|
+
deleteIt = _useMutation2[0],
|
|
101
|
+
deleteLoading = _useMutation2[1].loading;
|
|
102
|
+
|
|
103
|
+
var data = listLoading && !listResponse ? [] : listResponse.security.apiKeys.data;
|
|
104
|
+
var id = new URLSearchParams(location.search).get("id");
|
|
105
|
+
var deleteItem = useCallback(function (item) {
|
|
106
|
+
showConfirmation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
107
|
+
var _yield$deleteIt, data, error;
|
|
108
|
+
|
|
109
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
110
|
+
while (1) {
|
|
111
|
+
switch (_context.prev = _context.next) {
|
|
112
|
+
case 0:
|
|
113
|
+
_context.next = 2;
|
|
114
|
+
return deleteIt({
|
|
115
|
+
variables: item
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
case 2:
|
|
119
|
+
_yield$deleteIt = _context.sent;
|
|
120
|
+
data = _yield$deleteIt.data;
|
|
121
|
+
error = data.security.deleteApiKey.error;
|
|
122
|
+
|
|
123
|
+
if (!error) {
|
|
124
|
+
_context.next = 7;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return _context.abrupt("return", showSnackbar(error.message));
|
|
129
|
+
|
|
130
|
+
case 7:
|
|
131
|
+
showSnackbar(t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Api key \"{id}\" deleted."])))({
|
|
132
|
+
id: item.id
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
if (id === item.id) {
|
|
136
|
+
history.push("/access-management/api-keys");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
case 9:
|
|
140
|
+
case "end":
|
|
141
|
+
return _context.stop();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, _callee);
|
|
145
|
+
})));
|
|
146
|
+
}, [id]);
|
|
147
|
+
var groupsDataListModalOverlay = useMemo(function () {
|
|
148
|
+
return /*#__PURE__*/React.createElement(DataListModalOverlay, null, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
149
|
+
span: 12
|
|
150
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
151
|
+
value: sort,
|
|
152
|
+
onChange: setSort,
|
|
153
|
+
label: t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Sort by"])))
|
|
154
|
+
}, SORTERS.map(function (_ref3) {
|
|
155
|
+
var label = _ref3.label,
|
|
156
|
+
sorters = _ref3.sorters;
|
|
157
|
+
return /*#__PURE__*/React.createElement("option", {
|
|
158
|
+
key: label,
|
|
159
|
+
value: serializeSorters(sorters)
|
|
160
|
+
}, label);
|
|
161
|
+
})))));
|
|
162
|
+
}, [sort]);
|
|
163
|
+
var filteredData = filter === "" ? data : data.filter(filterAPIKey);
|
|
164
|
+
var list = sortKeys(filteredData);
|
|
165
|
+
return /*#__PURE__*/React.createElement(DataList, {
|
|
166
|
+
title: t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["API Keys"]))),
|
|
167
|
+
actions: /*#__PURE__*/React.createElement(ButtonSecondary, {
|
|
168
|
+
"data-testid": "new-record-button",
|
|
169
|
+
onClick: function onClick() {
|
|
170
|
+
return history.push("/access-management/api-keys?new=true");
|
|
171
|
+
}
|
|
172
|
+
}, /*#__PURE__*/React.createElement(ButtonIcon, {
|
|
173
|
+
icon: /*#__PURE__*/React.createElement(AddIcon, null)
|
|
174
|
+
}), " ", t(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["New API Key"])))),
|
|
175
|
+
data: list,
|
|
176
|
+
loading: listLoading || deleteLoading,
|
|
177
|
+
search: /*#__PURE__*/React.createElement(SearchUI, {
|
|
178
|
+
value: filter,
|
|
179
|
+
onChange: setFilter,
|
|
180
|
+
inputPlaceholder: t(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Search API keys"])))
|
|
181
|
+
}),
|
|
182
|
+
modalOverlay: groupsDataListModalOverlay,
|
|
183
|
+
modalOverlayAction: /*#__PURE__*/React.createElement(DataListModalOverlayAction, {
|
|
184
|
+
icon: /*#__PURE__*/React.createElement(FilterIcon, null),
|
|
185
|
+
"data-testid": "default-data-list.filter"
|
|
186
|
+
})
|
|
187
|
+
}, function (_ref4) {
|
|
188
|
+
var data = _ref4.data;
|
|
189
|
+
return /*#__PURE__*/React.createElement(ScrollList, {
|
|
190
|
+
"data-testid": "default-data-list"
|
|
191
|
+
}, data.map(function (item) {
|
|
192
|
+
return /*#__PURE__*/React.createElement(ListItem, {
|
|
193
|
+
key: item.id,
|
|
194
|
+
selected: item.id === id
|
|
195
|
+
}, /*#__PURE__*/React.createElement(ListItemText, {
|
|
196
|
+
onClick: function onClick() {
|
|
197
|
+
return history.push("/access-management/api-keys?id=".concat(item.id));
|
|
198
|
+
}
|
|
199
|
+
}, item.name, /*#__PURE__*/React.createElement(ListItemTextSecondary, null, item.description)), /*#__PURE__*/React.createElement(ListItemMeta, null, /*#__PURE__*/React.createElement(ListActions, null, /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
200
|
+
onClick: function onClick() {
|
|
201
|
+
return deleteItem(item);
|
|
202
|
+
},
|
|
203
|
+
"data-testid": "default-data-list.delete"
|
|
204
|
+
}))));
|
|
205
|
+
}));
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export default ApiKeysDataList;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
+
|
|
3
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
4
|
+
|
|
5
|
+
import gql from "graphql-tag";
|
|
6
|
+
var fields = "\n id\n name\n description\n token\n permissions\n createdOn\n";
|
|
7
|
+
export var LIST_API_KEYS = gql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query ListApiKeys {\n security {\n apiKeys: listApiKeys {\n data {\n ", "\n }\n }\n }\n }\n"])), fields);
|
|
8
|
+
export var READ_API_KEY = gql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n query GetApiKey($id: ID!) {\n security {\n apiKey: getApiKey(id: $id){\n data {\n ", "\n }\n error {\n code\n message\n }\n }\n }\n }\n"])), fields);
|
|
9
|
+
export var CREATE_API_KEY = gql(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n mutation CreateApiKey($data: SecurityApiKeyInput!){\n security {\n apiKey: createApiKey(data: $data) {\n data {\n ", "\n }\n error {\n code\n message\n data\n }\n }\n }\n }\n"])), fields);
|
|
10
|
+
export var UPDATE_API_KEY = gql(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n mutation UpdateApiKey($id: ID!, $data: SecurityApiKeyInput!){\n security {\n apiKey: updateApiKey(id: $id, data: $data) {\n data {\n ", "\n }\n error {\n code\n message\n data\n }\n }\n }\n }\n"])), fields);
|
|
11
|
+
export var DELETE_API_KEY = gql(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n mutation DeleteApiKey($id: ID!) {\n security {\n deleteApiKey(id: $id) {\n data\n error {\n code\n message\n }\n }\n }\n }\n"])));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ApiKeys } from "./ApiKeys";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ApiKeys } from "./ApiKeys";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pickDataForAPI: (data: any) => any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { SplitView, LeftPanel, RightPanel } from "@webiny/app-admin/components/SplitView";
|
|
3
|
+
import GroupsDataList from "./GroupsDataList";
|
|
4
|
+
import GroupsForm from "./GroupsForm";
|
|
5
|
+
|
|
6
|
+
var Groups = function Groups(_ref) {
|
|
7
|
+
var formProps = _ref.formProps,
|
|
8
|
+
listProps = _ref.listProps;
|
|
9
|
+
return /*#__PURE__*/React.createElement(SplitView, null, /*#__PURE__*/React.createElement(LeftPanel, null, /*#__PURE__*/React.createElement(GroupsDataList, listProps)), /*#__PURE__*/React.createElement(RightPanel, null, /*#__PURE__*/React.createElement(GroupsForm, formProps)));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default Groups;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
4
|
+
|
|
5
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
6
|
+
|
|
7
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
+
import React, { useCallback, useMemo, useState } from "react";
|
|
9
|
+
import orderBy from "lodash/orderBy";
|
|
10
|
+
import { i18n } from "@webiny/app/i18n";
|
|
11
|
+
import { DataList, ScrollList, ListItem, ListItemText, ListItemTextSecondary, ListItemMeta, ListActions, DataListModalOverlayAction, DataListModalOverlay } from "@webiny/ui/List";
|
|
12
|
+
import { DeleteIcon } from "@webiny/ui/List/DataList/icons";
|
|
13
|
+
import { useRouter } from "@webiny/react-router";
|
|
14
|
+
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
|
|
15
|
+
import { useQuery, useMutation } from "@apollo/react-hooks";
|
|
16
|
+
import { useConfirmationDialog } from "@webiny/app-admin/hooks/useConfirmationDialog";
|
|
17
|
+
import { LIST_GROUPS, DELETE_GROUP } from "./graphql";
|
|
18
|
+
import { Tooltip } from "@webiny/ui/Tooltip";
|
|
19
|
+
import { ButtonIcon, ButtonSecondary } from "@webiny/ui/Button";
|
|
20
|
+
import { Cell, Grid } from "@webiny/ui/Grid";
|
|
21
|
+
import { Select } from "@webiny/ui/Select";
|
|
22
|
+
import SearchUI from "@webiny/app-admin/components/SearchUI";
|
|
23
|
+
import { ReactComponent as AddIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/add-18px.svg";
|
|
24
|
+
import { ReactComponent as FilterIcon } from "@svgr/webpack!@webiny/app-admin/assets/icons/filter-24px.svg";
|
|
25
|
+
import { deserializeSorters, serializeSorters } from "../utils";
|
|
26
|
+
var t = i18n.ns("app-security/admin/groups/data-list");
|
|
27
|
+
var SORTERS = [{
|
|
28
|
+
label: t(_templateObject || (_templateObject = _taggedTemplateLiteral(["Newest to oldest"]))),
|
|
29
|
+
sorters: {
|
|
30
|
+
createdOn: "desc"
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
label: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Oldest to newest"]))),
|
|
34
|
+
sorters: {
|
|
35
|
+
createdOn: "asc"
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
label: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["Name A-Z"]))),
|
|
39
|
+
sorters: {
|
|
40
|
+
name: "asc"
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
label: t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Name Z-A"]))),
|
|
44
|
+
sorters: {
|
|
45
|
+
name: "desc"
|
|
46
|
+
}
|
|
47
|
+
}];
|
|
48
|
+
|
|
49
|
+
var GroupsDataList = function GroupsDataList() {
|
|
50
|
+
var _useState = useState(""),
|
|
51
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
52
|
+
filter = _useState2[0],
|
|
53
|
+
setFilter = _useState2[1];
|
|
54
|
+
|
|
55
|
+
var _useState3 = useState(serializeSorters(SORTERS[0].sorters)),
|
|
56
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
57
|
+
sort = _useState4[0],
|
|
58
|
+
setSort = _useState4[1];
|
|
59
|
+
|
|
60
|
+
var _useRouter = useRouter(),
|
|
61
|
+
history = _useRouter.history,
|
|
62
|
+
location = _useRouter.location;
|
|
63
|
+
|
|
64
|
+
var _useSnackbar = useSnackbar(),
|
|
65
|
+
showSnackbar = _useSnackbar.showSnackbar;
|
|
66
|
+
|
|
67
|
+
var _useConfirmationDialo = useConfirmationDialog({
|
|
68
|
+
dataTestId: "default-data-list.delete-dialog"
|
|
69
|
+
}),
|
|
70
|
+
showConfirmation = _useConfirmationDialo.showConfirmation;
|
|
71
|
+
|
|
72
|
+
var _useQuery = useQuery(LIST_GROUPS),
|
|
73
|
+
listResponse = _useQuery.data,
|
|
74
|
+
listLoading = _useQuery.loading;
|
|
75
|
+
|
|
76
|
+
var _useMutation = useMutation(DELETE_GROUP, {
|
|
77
|
+
refetchQueries: [{
|
|
78
|
+
query: LIST_GROUPS
|
|
79
|
+
}]
|
|
80
|
+
}),
|
|
81
|
+
_useMutation2 = _slicedToArray(_useMutation, 2),
|
|
82
|
+
deleteIt = _useMutation2[0],
|
|
83
|
+
deleteLoading = _useMutation2[1].loading;
|
|
84
|
+
|
|
85
|
+
var data = listLoading && !listResponse ? [] : listResponse.security.groups.data;
|
|
86
|
+
var id = new URLSearchParams(location.search).get("id");
|
|
87
|
+
var filterGroup = useCallback(function (_ref) {
|
|
88
|
+
var name = _ref.name,
|
|
89
|
+
slug = _ref.slug,
|
|
90
|
+
description = _ref.description;
|
|
91
|
+
return name.toLowerCase().includes(filter) || slug.toLowerCase().includes(filter) || description && description.toLowerCase().includes(filter);
|
|
92
|
+
}, [filter]);
|
|
93
|
+
var sortGroups = useCallback(function (groups) {
|
|
94
|
+
if (!sort) {
|
|
95
|
+
return groups;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var _Object$entries = Object.entries(deserializeSorters(sort)),
|
|
99
|
+
_Object$entries2 = _slicedToArray(_Object$entries, 1),
|
|
100
|
+
_Object$entries2$ = _slicedToArray(_Object$entries2[0], 2),
|
|
101
|
+
key = _Object$entries2$[0],
|
|
102
|
+
value = _Object$entries2$[1];
|
|
103
|
+
|
|
104
|
+
return orderBy(groups, [key], [value]);
|
|
105
|
+
}, [sort]);
|
|
106
|
+
var deleteItem = useCallback(function (item) {
|
|
107
|
+
showConfirmation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
108
|
+
var _yield$deleteIt, data, error;
|
|
109
|
+
|
|
110
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
111
|
+
while (1) {
|
|
112
|
+
switch (_context.prev = _context.next) {
|
|
113
|
+
case 0:
|
|
114
|
+
_context.next = 2;
|
|
115
|
+
return deleteIt({
|
|
116
|
+
variables: item
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
case 2:
|
|
120
|
+
_yield$deleteIt = _context.sent;
|
|
121
|
+
data = _yield$deleteIt.data;
|
|
122
|
+
error = data.security.deleteGroup.error;
|
|
123
|
+
|
|
124
|
+
if (!error) {
|
|
125
|
+
_context.next = 7;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return _context.abrupt("return", showSnackbar(error.message));
|
|
130
|
+
|
|
131
|
+
case 7:
|
|
132
|
+
showSnackbar(t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Group \"{slug}\" deleted."])))({
|
|
133
|
+
slug: item.slug
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
if (id === item.id) {
|
|
137
|
+
history.push("/access-management/groups");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
case 9:
|
|
141
|
+
case "end":
|
|
142
|
+
return _context.stop();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}, _callee);
|
|
146
|
+
})));
|
|
147
|
+
}, [id]);
|
|
148
|
+
var groupsDataListModalOverlay = useMemo(function () {
|
|
149
|
+
return /*#__PURE__*/React.createElement(DataListModalOverlay, null, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Cell, {
|
|
150
|
+
span: 12
|
|
151
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
152
|
+
value: sort,
|
|
153
|
+
onChange: setSort,
|
|
154
|
+
label: t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Sort by"])))
|
|
155
|
+
}, SORTERS.map(function (_ref3) {
|
|
156
|
+
var label = _ref3.label,
|
|
157
|
+
sorters = _ref3.sorters;
|
|
158
|
+
return /*#__PURE__*/React.createElement("option", {
|
|
159
|
+
key: label,
|
|
160
|
+
value: serializeSorters(sorters)
|
|
161
|
+
}, label);
|
|
162
|
+
})))));
|
|
163
|
+
}, [sort]);
|
|
164
|
+
var filteredData = filter === "" ? data : data.filter(filterGroup);
|
|
165
|
+
var groupList = sortGroups(filteredData);
|
|
166
|
+
return /*#__PURE__*/React.createElement(DataList, {
|
|
167
|
+
title: t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["Groups"]))),
|
|
168
|
+
actions: /*#__PURE__*/React.createElement(ButtonSecondary, {
|
|
169
|
+
"data-testid": "new-record-button",
|
|
170
|
+
onClick: function onClick() {
|
|
171
|
+
return history.push("/access-management/groups?new=true");
|
|
172
|
+
}
|
|
173
|
+
}, /*#__PURE__*/React.createElement(ButtonIcon, {
|
|
174
|
+
icon: /*#__PURE__*/React.createElement(AddIcon, null)
|
|
175
|
+
}), " ", t(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["New Group"])))),
|
|
176
|
+
data: groupList,
|
|
177
|
+
loading: listLoading || deleteLoading,
|
|
178
|
+
search: /*#__PURE__*/React.createElement(SearchUI, {
|
|
179
|
+
value: filter,
|
|
180
|
+
onChange: setFilter,
|
|
181
|
+
inputPlaceholder: t(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Search Groups"])))
|
|
182
|
+
}),
|
|
183
|
+
modalOverlay: groupsDataListModalOverlay,
|
|
184
|
+
modalOverlayAction: /*#__PURE__*/React.createElement(DataListModalOverlayAction, {
|
|
185
|
+
icon: /*#__PURE__*/React.createElement(FilterIcon, null),
|
|
186
|
+
"data-testid": "default-data-list.filter"
|
|
187
|
+
})
|
|
188
|
+
}, function (_ref4) {
|
|
189
|
+
var data = _ref4.data;
|
|
190
|
+
return /*#__PURE__*/React.createElement(ScrollList, {
|
|
191
|
+
"data-testid": "default-data-list"
|
|
192
|
+
}, data.map(function (item) {
|
|
193
|
+
return /*#__PURE__*/React.createElement(ListItem, {
|
|
194
|
+
key: item.id,
|
|
195
|
+
selected: item.id === id
|
|
196
|
+
}, /*#__PURE__*/React.createElement(ListItemText, {
|
|
197
|
+
onClick: function onClick() {
|
|
198
|
+
return history.push("/access-management/groups?id=".concat(item.id));
|
|
199
|
+
}
|
|
200
|
+
}, item.name, /*#__PURE__*/React.createElement(ListItemTextSecondary, null, item.description)), /*#__PURE__*/React.createElement(ListItemMeta, null, /*#__PURE__*/React.createElement(ListActions, null, item.slug !== "full-access" ? /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
201
|
+
onClick: function onClick() {
|
|
202
|
+
return deleteItem(item);
|
|
203
|
+
},
|
|
204
|
+
"data-testid": "default-data-list.delete"
|
|
205
|
+
}) : /*#__PURE__*/React.createElement(Tooltip, {
|
|
206
|
+
placement: "bottom",
|
|
207
|
+
content: /*#__PURE__*/React.createElement("span", null, t(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["You can't delete this group."]))))
|
|
208
|
+
}, /*#__PURE__*/React.createElement(DeleteIcon, {
|
|
209
|
+
disabled: true
|
|
210
|
+
})))));
|
|
211
|
+
}));
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export default GroupsDataList;
|