@atlaskit/link-datasource 1.15.3 → 1.16.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/CHANGELOG.md +12 -0
- package/dist/cjs/analytics/constants.js +1 -1
- package/dist/cjs/hooks/useAssetsClient.js +71 -27
- package/dist/cjs/services/cmdbService.js +128 -28
- package/dist/cjs/services/cmdbService.utils.js +64 -0
- package/dist/cjs/ui/assets-modal/modal/index.js +73 -9
- package/dist/cjs/ui/assets-modal/modal/render-assets-content/index.js +25 -12
- package/dist/cjs/ui/assets-modal/search-container/index.js +2 -1
- package/dist/cjs/ui/assets-modal/search-container/object-schema-select/index.js +21 -63
- package/dist/cjs/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +14 -14
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +18 -3
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/async-popup-select/messages.js +5 -0
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/async-popup-select/showMoreButton.js +22 -0
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/menu-list/index.js +21 -4
- package/dist/es2019/analytics/constants.js +1 -1
- package/dist/es2019/hooks/useAssetsClient.js +39 -15
- package/dist/es2019/services/cmdbService.js +60 -14
- package/dist/es2019/services/cmdbService.utils.js +39 -0
- package/dist/es2019/ui/assets-modal/modal/index.js +70 -9
- package/dist/es2019/ui/assets-modal/modal/render-assets-content/index.js +24 -9
- package/dist/es2019/ui/assets-modal/search-container/index.js +2 -1
- package/dist/es2019/ui/assets-modal/search-container/object-schema-select/index.js +2 -25
- package/dist/es2019/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +2 -2
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +18 -3
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/async-popup-select/messages.js +5 -0
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/async-popup-select/showMoreButton.js +17 -0
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/menu-list/index.js +18 -3
- package/dist/esm/analytics/constants.js +1 -1
- package/dist/esm/hooks/useAssetsClient.js +72 -28
- package/dist/esm/services/cmdbService.js +128 -28
- package/dist/esm/services/cmdbService.utils.js +57 -0
- package/dist/esm/ui/assets-modal/modal/index.js +73 -9
- package/dist/esm/ui/assets-modal/modal/render-assets-content/index.js +24 -9
- package/dist/esm/ui/assets-modal/search-container/index.js +2 -1
- package/dist/esm/ui/assets-modal/search-container/object-schema-select/index.js +18 -60
- package/dist/esm/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +14 -14
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +18 -3
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/async-popup-select/messages.js +5 -0
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/async-popup-select/showMoreButton.js +15 -0
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/menu-list/index.js +21 -4
- package/dist/types/hooks/useAssetsClient.d.ts +5 -1
- package/dist/types/services/cmdbService.utils.d.ts +9 -0
- package/dist/types/ui/assets-modal/modal/render-assets-content/index.d.ts +3 -2
- package/dist/types/ui/assets-modal/search-container/index.d.ts +1 -0
- package/dist/types/ui/assets-modal/search-container/object-schema-select/index.d.ts +2 -1
- package/dist/types/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.d.ts +1 -1
- package/dist/types/ui/jira-issues-modal/basic-filters/ui/async-popup-select/messages.d.ts +5 -0
- package/dist/types/ui/jira-issues-modal/basic-filters/ui/async-popup-select/showMoreButton.d.ts +6 -0
- package/dist/types/ui/jira-issues-modal/basic-filters/ui/menu-list/index.d.ts +4 -1
- package/dist/types-ts4.5/hooks/useAssetsClient.d.ts +5 -1
- package/dist/types-ts4.5/services/cmdbService.utils.d.ts +9 -0
- package/dist/types-ts4.5/ui/assets-modal/modal/render-assets-content/index.d.ts +3 -2
- package/dist/types-ts4.5/ui/assets-modal/search-container/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/assets-modal/search-container/object-schema-select/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.d.ts +1 -1
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/ui/async-popup-select/messages.d.ts +5 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/ui/async-popup-select/showMoreButton.d.ts +6 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/ui/menu-list/index.d.ts +4 -1
- package/package.json +1 -1
|
@@ -1,51 +1,151 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { request } from '@atlaskit/linking-common';
|
|
4
|
+
import { FetchError, getStatusCodeGroup, mapFetchErrors, PermissionError } from './cmdbService.utils';
|
|
4
5
|
export var getWorkspaceId = /*#__PURE__*/function () {
|
|
5
6
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
6
|
-
var _workspaceDetailsResp;
|
|
7
|
-
var url, workspaceDetailsResponse;
|
|
7
|
+
var url, _workspaceDetailsResp, workspaceDetailsResponse, error;
|
|
8
8
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
9
9
|
while (1) switch (_context.prev = _context.next) {
|
|
10
10
|
case 0:
|
|
11
11
|
url = '/rest/servicedesk/cmdb/latest/workspace';
|
|
12
|
-
_context.
|
|
12
|
+
_context.prev = 1;
|
|
13
|
+
_context.next = 4;
|
|
13
14
|
return request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
14
|
-
case
|
|
15
|
+
case 4:
|
|
15
16
|
workspaceDetailsResponse = _context.sent;
|
|
16
17
|
if ((_workspaceDetailsResp = workspaceDetailsResponse.results) !== null && _workspaceDetailsResp !== void 0 && _workspaceDetailsResp.length) {
|
|
17
|
-
_context.next =
|
|
18
|
+
_context.next = 7;
|
|
18
19
|
break;
|
|
19
20
|
}
|
|
20
|
-
throw new
|
|
21
|
-
case 6:
|
|
22
|
-
return _context.abrupt("return", workspaceDetailsResponse.results[0].id);
|
|
21
|
+
throw new PermissionError('No workspace results found');
|
|
23
22
|
case 7:
|
|
23
|
+
return _context.abrupt("return", workspaceDetailsResponse.results[0].id);
|
|
24
|
+
case 10:
|
|
25
|
+
_context.prev = 10;
|
|
26
|
+
_context.t0 = _context["catch"](1);
|
|
27
|
+
error = mapFetchErrors(_context.t0);
|
|
28
|
+
if (error instanceof FetchError) {
|
|
29
|
+
// TODO Fire error operational event for workspace here before remapping to PermissionError
|
|
30
|
+
// Only 429 and 5xx errors will be treated as FetchErrors otherwise PermissionError
|
|
31
|
+
if (getStatusCodeGroup(error) !== '5xx' && error.statusCode !== 429) {
|
|
32
|
+
error = new PermissionError('Failed to fetch workspace');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
case 15:
|
|
24
37
|
case "end":
|
|
25
38
|
return _context.stop();
|
|
26
39
|
}
|
|
27
|
-
}, _callee);
|
|
40
|
+
}, _callee, null, [[1, 10]]);
|
|
28
41
|
}));
|
|
29
42
|
return function getWorkspaceId() {
|
|
30
43
|
return _ref.apply(this, arguments);
|
|
31
44
|
};
|
|
32
45
|
}();
|
|
33
|
-
export var validateAql = function
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
export var validateAql = /*#__PURE__*/function () {
|
|
47
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(workspaceId, data) {
|
|
48
|
+
var url, error;
|
|
49
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
50
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
url = "/gateway/api/jsm/assets/workspace/".concat(workspaceId, "/v1/aql/validate");
|
|
53
|
+
_context2.prev = 1;
|
|
54
|
+
_context2.next = 4;
|
|
55
|
+
return request('post', url, {
|
|
56
|
+
qlQuery: data.qlQuery,
|
|
57
|
+
context: 'SMART_LINKS'
|
|
58
|
+
}, undefined, [200, 201, 202, 203, 204]);
|
|
59
|
+
case 4:
|
|
60
|
+
return _context2.abrupt("return", _context2.sent);
|
|
61
|
+
case 7:
|
|
62
|
+
_context2.prev = 7;
|
|
63
|
+
_context2.t0 = _context2["catch"](1);
|
|
64
|
+
error = mapFetchErrors(_context2.t0);
|
|
65
|
+
if (error instanceof FetchError) {
|
|
66
|
+
// TODO Fire error operational event for aql here before remapping to PermissionError
|
|
67
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
68
|
+
error = new PermissionError('Failed to fetch object schemas');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
case 12:
|
|
73
|
+
case "end":
|
|
74
|
+
return _context2.stop();
|
|
75
|
+
}
|
|
76
|
+
}, _callee2, null, [[1, 7]]);
|
|
77
|
+
}));
|
|
78
|
+
return function validateAql(_x, _x2) {
|
|
79
|
+
return _ref2.apply(this, arguments);
|
|
80
|
+
};
|
|
81
|
+
}();
|
|
82
|
+
export var fetchObjectSchema = /*#__PURE__*/function () {
|
|
83
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(workspaceId, schemaId) {
|
|
84
|
+
var url, error;
|
|
85
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
86
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
87
|
+
case 0:
|
|
88
|
+
url = "/gateway/api/jsm/assets/workspace/".concat(workspaceId, "/v1/objectschema/").concat(schemaId);
|
|
89
|
+
_context3.prev = 1;
|
|
90
|
+
_context3.next = 4;
|
|
91
|
+
return request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
92
|
+
case 4:
|
|
93
|
+
return _context3.abrupt("return", _context3.sent);
|
|
94
|
+
case 7:
|
|
95
|
+
_context3.prev = 7;
|
|
96
|
+
_context3.t0 = _context3["catch"](1);
|
|
97
|
+
error = mapFetchErrors(_context3.t0);
|
|
98
|
+
if (error instanceof FetchError) {
|
|
99
|
+
// TODO Fire error operational event for object schema here before remapping to PermissionError
|
|
100
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
101
|
+
error = new PermissionError('Failed to fetch object schemas');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
case 12:
|
|
106
|
+
case "end":
|
|
107
|
+
return _context3.stop();
|
|
108
|
+
}
|
|
109
|
+
}, _callee3, null, [[1, 7]]);
|
|
110
|
+
}));
|
|
111
|
+
return function fetchObjectSchema(_x3, _x4) {
|
|
112
|
+
return _ref3.apply(this, arguments);
|
|
113
|
+
};
|
|
114
|
+
}();
|
|
115
|
+
export var fetchObjectSchemas = /*#__PURE__*/function () {
|
|
116
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(workspaceId, query) {
|
|
117
|
+
var queryParams, url, error;
|
|
118
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
119
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
120
|
+
case 0:
|
|
121
|
+
queryParams = new URLSearchParams();
|
|
122
|
+
queryParams.set('maxResults', '20');
|
|
123
|
+
queryParams.set('includeCounts', 'false');
|
|
124
|
+
query && queryParams.set('query', query);
|
|
125
|
+
url = "/gateway/api/jsm/assets/workspace/".concat(workspaceId, "/v1/objectschema/list?").concat(queryParams);
|
|
126
|
+
_context4.prev = 5;
|
|
127
|
+
_context4.next = 8;
|
|
128
|
+
return request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
129
|
+
case 8:
|
|
130
|
+
return _context4.abrupt("return", _context4.sent);
|
|
131
|
+
case 11:
|
|
132
|
+
_context4.prev = 11;
|
|
133
|
+
_context4.t0 = _context4["catch"](5);
|
|
134
|
+
error = mapFetchErrors(_context4.t0);
|
|
135
|
+
if (error instanceof FetchError) {
|
|
136
|
+
// TODO Fire error operational event for object schemas here before remapping to PermissionError
|
|
137
|
+
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
138
|
+
error = new PermissionError('Failed to fetch object schemas');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
throw error;
|
|
142
|
+
case 16:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context4.stop();
|
|
145
|
+
}
|
|
146
|
+
}, _callee4, null, [[5, 11]]);
|
|
147
|
+
}));
|
|
148
|
+
return function fetchObjectSchemas(_x5, _x6) {
|
|
149
|
+
return _ref4.apply(this, arguments);
|
|
150
|
+
};
|
|
151
|
+
}();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
9
|
+
export var mapFetchErrors = function mapFetchErrors(error) {
|
|
10
|
+
if (error instanceof Response && !error.ok) {
|
|
11
|
+
return new FetchError(error.status, "Error server response: ".concat(error.status));
|
|
12
|
+
}
|
|
13
|
+
return error;
|
|
14
|
+
};
|
|
15
|
+
export var getStatusCodeGroup = function getStatusCodeGroup(error) {
|
|
16
|
+
if (error instanceof FetchError) {
|
|
17
|
+
var statusCode = error.statusCode;
|
|
18
|
+
if (statusCode >= 100 && statusCode < 200) {
|
|
19
|
+
return '1xx';
|
|
20
|
+
}
|
|
21
|
+
if (statusCode >= 300 && statusCode < 400) {
|
|
22
|
+
return '3xx';
|
|
23
|
+
}
|
|
24
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
25
|
+
return '4xx';
|
|
26
|
+
}
|
|
27
|
+
if (statusCode >= 500 && statusCode < 600) {
|
|
28
|
+
return '5xx';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return 'unknown';
|
|
32
|
+
};
|
|
33
|
+
export var PermissionError = /*#__PURE__*/function (_Error) {
|
|
34
|
+
_inherits(PermissionError, _Error);
|
|
35
|
+
var _super = _createSuper(PermissionError);
|
|
36
|
+
function PermissionError(message) {
|
|
37
|
+
var _this;
|
|
38
|
+
_classCallCheck(this, PermissionError);
|
|
39
|
+
_this = _super.call(this, message);
|
|
40
|
+
_this.name = 'PermissionError';
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
return _createClass(PermissionError);
|
|
44
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
45
|
+
export var FetchError = /*#__PURE__*/function (_Error2) {
|
|
46
|
+
_inherits(FetchError, _Error2);
|
|
47
|
+
var _super2 = _createSuper(FetchError);
|
|
48
|
+
function FetchError(statusCode, message) {
|
|
49
|
+
var _this2;
|
|
50
|
+
_classCallCheck(this, FetchError);
|
|
51
|
+
_this2 = _super2.call(this, message || "Fetch call failed with status code: ".concat(statusCode));
|
|
52
|
+
_this2.name = 'FetchError';
|
|
53
|
+
_this2.statusCode = statusCode;
|
|
54
|
+
return _this2;
|
|
55
|
+
}
|
|
56
|
+
return _createClass(FetchError);
|
|
57
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -24,6 +24,8 @@ import { fetchMessagesForLocale } from '../../../common/utils/locale/fetch-messa
|
|
|
24
24
|
import { useAssetsClient } from '../../../hooks/useAssetsClient';
|
|
25
25
|
import { useDatasourceTableState } from '../../../hooks/useDatasourceTableState';
|
|
26
26
|
import i18nEN from '../../../i18n/en';
|
|
27
|
+
import { PermissionError } from '../../../services/cmdbService.utils';
|
|
28
|
+
import { AccessRequired } from '../../../ui/common/error-state/access-required';
|
|
27
29
|
import { ModalLoadingError } from '../../common/error-state/modal-loading-error';
|
|
28
30
|
import { AssetsSearchContainer } from '../search-container';
|
|
29
31
|
import { AssetsSearchContainerLoading } from '../search-container/loading-state';
|
|
@@ -34,6 +36,9 @@ var modalBodyWrapperStyles = css({
|
|
|
34
36
|
height: '420px',
|
|
35
37
|
overflow: 'auto'
|
|
36
38
|
});
|
|
39
|
+
var modalBodyErrorWrapperStyles = css({
|
|
40
|
+
alignItems: 'center'
|
|
41
|
+
});
|
|
37
42
|
var AssetsModalTitle = jsx(ModalTitle, null, jsx(FormattedMessage, modalMessages.insertObjectsTitle));
|
|
38
43
|
var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
39
44
|
var datasourceId = props.datasourceId,
|
|
@@ -57,17 +62,53 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
57
62
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
58
63
|
isNewSearch = _useState8[0],
|
|
59
64
|
setIsNewSearch = _useState8[1];
|
|
65
|
+
var _useState9 = useState(),
|
|
66
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
67
|
+
errorState = _useState10[0],
|
|
68
|
+
setErrorState = _useState10[1];
|
|
60
69
|
var _useDatasourceAnalyti = useDatasourceAnalyticsEvents(),
|
|
61
70
|
fireEvent = _useDatasourceAnalyti.fireEvent;
|
|
62
71
|
var _useRef = useRef(uuidv4()),
|
|
63
72
|
modalRenderInstanceId = _useRef.current;
|
|
64
|
-
|
|
65
|
-
// If a workspaceError occurs this is a critical error
|
|
66
73
|
var _useAssetsClient = useAssetsClient(initialParameters),
|
|
67
74
|
workspaceId = _useAssetsClient.workspaceId,
|
|
68
75
|
workspaceError = _useAssetsClient.workspaceError,
|
|
69
|
-
|
|
76
|
+
existingObjectSchema = _useAssetsClient.existingObjectSchema,
|
|
77
|
+
existingObjectSchemaError = _useAssetsClient.existingObjectSchemaError,
|
|
78
|
+
objectSchemas = _useAssetsClient.objectSchemas,
|
|
79
|
+
objectSchemasError = _useAssetsClient.objectSchemasError,
|
|
80
|
+
totalObjectSchemas = _useAssetsClient.totalObjectSchemas,
|
|
70
81
|
assetsClientLoading = _useAssetsClient.assetsClientLoading;
|
|
82
|
+
|
|
83
|
+
/* ------------------------------ PERMISSIONS ------------------------------ */
|
|
84
|
+
useEffect(function () {
|
|
85
|
+
if (workspaceError) {
|
|
86
|
+
// If a workspaceError occurs this is a critical error
|
|
87
|
+
if (workspaceError instanceof PermissionError) {
|
|
88
|
+
setErrorState('permission');
|
|
89
|
+
} else {
|
|
90
|
+
setErrorState('network');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, [workspaceError]);
|
|
94
|
+
useEffect(function () {
|
|
95
|
+
if (objectSchemasError) {
|
|
96
|
+
// We only care about permission errors for objectSchemas fetching as the user can retry this action
|
|
97
|
+
if (objectSchemasError instanceof PermissionError) {
|
|
98
|
+
setErrorState('permission');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, [objectSchemasError]);
|
|
102
|
+
useEffect(function () {
|
|
103
|
+
if (existingObjectSchemaError) {
|
|
104
|
+
// We only care about permission errors for existingObjectSchema fetching as the user can retry this action
|
|
105
|
+
if (existingObjectSchemaError instanceof PermissionError) {
|
|
106
|
+
setErrorState('permission');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, [existingObjectSchemaError]);
|
|
110
|
+
/* ------------------------------ END PERMISSIONS ------------------------------ */
|
|
111
|
+
|
|
71
112
|
var parameters = useMemo(function () {
|
|
72
113
|
return {
|
|
73
114
|
aql: aql || '',
|
|
@@ -105,6 +146,15 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
105
146
|
destinationObjectTypes: destinationObjectTypes
|
|
106
147
|
};
|
|
107
148
|
}, [destinationObjectTypes, extensionKey]);
|
|
149
|
+
useEffect(function () {
|
|
150
|
+
// We only want to send modal ready event once after we've fetched the schema count
|
|
151
|
+
if (totalObjectSchemas !== undefined) {
|
|
152
|
+
fireEvent('ui.modal.ready.datasource', {
|
|
153
|
+
schemasCount: totalObjectSchemas,
|
|
154
|
+
instancesCount: null
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}, [fireEvent, totalObjectSchemas]);
|
|
108
158
|
useEffect(function () {
|
|
109
159
|
fireEvent('screen.datasourceModalDialog.viewed', {});
|
|
110
160
|
}, [fireEvent]);
|
|
@@ -158,7 +208,7 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
158
208
|
setVisibleColumnKeys(defaultVisibleColumnKeys);
|
|
159
209
|
}
|
|
160
210
|
}, [defaultVisibleColumnKeys, isNewSearch]);
|
|
161
|
-
var isDisabled = !!
|
|
211
|
+
var isDisabled = !!errorState || status !== 'resolved' || assetsClientLoading || !aql || !schemaId;
|
|
162
212
|
var retrieveUrlForSmartCardRender = useCallback(function () {
|
|
163
213
|
var _data$key;
|
|
164
214
|
var _responseItems = _slicedToArray(responseItems, 1),
|
|
@@ -260,8 +310,20 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
260
310
|
return _ref.apply(this, arguments);
|
|
261
311
|
};
|
|
262
312
|
}(), [aql, reset, schemaId, status]);
|
|
313
|
+
var renderErrorState = useCallback(function () {
|
|
314
|
+
if (errorState) {
|
|
315
|
+
switch (errorState) {
|
|
316
|
+
case 'permission':
|
|
317
|
+
return jsx(AccessRequired, null);
|
|
318
|
+
case 'network':
|
|
319
|
+
return jsx(ModalLoadingError, null);
|
|
320
|
+
default:
|
|
321
|
+
return jsx(ModalLoadingError, null);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}, [errorState]);
|
|
263
325
|
var renderModalTitleContent = useCallback(function () {
|
|
264
|
-
if (
|
|
326
|
+
if (errorState) {
|
|
265
327
|
return undefined;
|
|
266
328
|
} else {
|
|
267
329
|
if (!workspaceId || assetsClientLoading) {
|
|
@@ -273,14 +335,15 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
273
335
|
workspaceId: workspaceId,
|
|
274
336
|
initialSearchData: {
|
|
275
337
|
aql: aql,
|
|
276
|
-
objectSchema:
|
|
338
|
+
objectSchema: existingObjectSchema,
|
|
339
|
+
objectSchemas: objectSchemas
|
|
277
340
|
},
|
|
278
341
|
onSearch: handleOnSearch,
|
|
279
342
|
modalTitle: AssetsModalTitle,
|
|
280
343
|
isSearching: status === 'loading'
|
|
281
344
|
});
|
|
282
345
|
}
|
|
283
|
-
}, [
|
|
346
|
+
}, [errorState, workspaceId, assetsClientLoading, aql, existingObjectSchema, objectSchemas, handleOnSearch, status]);
|
|
284
347
|
return jsx(IntlMessagesProvider, {
|
|
285
348
|
defaultMessages: i18nEN,
|
|
286
349
|
loaderFn: fetchMessagesForLocale
|
|
@@ -291,8 +354,9 @@ var PlainAssetsConfigModal = function PlainAssetsConfigModal(props) {
|
|
|
291
354
|
shouldScrollInViewport: true,
|
|
292
355
|
shouldCloseOnOverlayClick: false
|
|
293
356
|
}, jsx(ModalHeader, null, renderModalTitleContent()), jsx(ModalBody, null, jsx("div", {
|
|
294
|
-
css: modalBodyWrapperStyles
|
|
295
|
-
},
|
|
357
|
+
css: [modalBodyWrapperStyles, errorState && modalBodyErrorWrapperStyles]
|
|
358
|
+
}, errorState ? renderErrorState() : jsx(RenderAssetsContent, {
|
|
359
|
+
isFetchingInitialData: assetsClientLoading,
|
|
296
360
|
status: status,
|
|
297
361
|
responseItems: responseItems,
|
|
298
362
|
visibleColumnKeys: visibleColumnKeys,
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
2
4
|
import { AccessRequired } from '../../../common/error-state/access-required';
|
|
3
5
|
import { ModalLoadingError } from '../../../common/error-state/modal-loading-error';
|
|
4
6
|
import { NoResults } from '../../../common/error-state/no-results';
|
|
5
7
|
import { EmptyState, IssueLikeDataTableView } from '../../../issue-like-table';
|
|
6
8
|
import { InitialStateView } from './initial-state-view';
|
|
9
|
+
// This is to prevent y scrollbar when initially fetching data
|
|
10
|
+
var emptyStateOverrideStyles = css({
|
|
11
|
+
height: '420px',
|
|
12
|
+
overflow: 'hidden'
|
|
13
|
+
});
|
|
7
14
|
export var RenderAssetsContent = function RenderAssetsContent(props) {
|
|
8
15
|
var status = props.status,
|
|
9
16
|
responseItems = props.responseItems,
|
|
@@ -14,10 +21,11 @@ export var RenderAssetsContent = function RenderAssetsContent(props) {
|
|
|
14
21
|
columns = props.columns,
|
|
15
22
|
defaultVisibleColumnKeys = props.defaultVisibleColumnKeys,
|
|
16
23
|
onVisibleColumnKeysChange = props.onVisibleColumnKeysChange,
|
|
17
|
-
modalRenderInstanceId = props.modalRenderInstanceId
|
|
24
|
+
modalRenderInstanceId = props.modalRenderInstanceId,
|
|
25
|
+
isFetchingInitialData = props.isFetchingInitialData;
|
|
18
26
|
var resolvedWithNoResults = status === 'resolved' && !responseItems.length;
|
|
19
27
|
var issueLikeDataTableView = useMemo(function () {
|
|
20
|
-
return
|
|
28
|
+
return jsx(IssueLikeDataTableView, {
|
|
21
29
|
testId: "asset-datasource-table",
|
|
22
30
|
status: status,
|
|
23
31
|
columns: columns,
|
|
@@ -30,16 +38,23 @@ export var RenderAssetsContent = function RenderAssetsContent(props) {
|
|
|
30
38
|
parentContainerRenderInstanceId: modalRenderInstanceId
|
|
31
39
|
});
|
|
32
40
|
}, [columns, defaultVisibleColumnKeys, hasNextPage, loadDatasourceDetails, onNextPage, onVisibleColumnKeysChange, responseItems, status, visibleColumnKeys, modalRenderInstanceId]);
|
|
33
|
-
if (
|
|
34
|
-
|
|
41
|
+
if (isFetchingInitialData) {
|
|
42
|
+
// Placing this check first as it's a priority before all others
|
|
43
|
+
return jsx("div", {
|
|
44
|
+
css: emptyStateOverrideStyles
|
|
45
|
+
}, jsx(EmptyState, {
|
|
46
|
+
testId: "assets-aql-datasource-modal--loading-state"
|
|
47
|
+
}));
|
|
48
|
+
} else if (status === 'rejected') {
|
|
49
|
+
return jsx(ModalLoadingError, null);
|
|
35
50
|
} else if (status === 'unauthorized') {
|
|
36
|
-
return
|
|
51
|
+
return jsx(AccessRequired, null);
|
|
37
52
|
} else if (status === 'empty') {
|
|
38
|
-
return
|
|
53
|
+
return jsx(InitialStateView, null);
|
|
39
54
|
} else if (resolvedWithNoResults) {
|
|
40
|
-
return
|
|
55
|
+
return jsx(NoResults, null);
|
|
41
56
|
} else if (status === 'loading' && !columns.length) {
|
|
42
|
-
return
|
|
57
|
+
return jsx(EmptyState, {
|
|
43
58
|
testId: "assets-aql-datasource-modal--loading-state"
|
|
44
59
|
});
|
|
45
60
|
}
|
|
@@ -28,7 +28,7 @@ export var AssetsSearchContainer = function AssetsSearchContainer(props) {
|
|
|
28
28
|
return jsx(Form, {
|
|
29
29
|
onSubmit: onFormSubmit
|
|
30
30
|
}, function (_ref) {
|
|
31
|
-
var _initialSearchData$ob, _initialSearchData$aq;
|
|
31
|
+
var _initialSearchData$ob, _initialSearchData$ob2, _initialSearchData$aq;
|
|
32
32
|
var formProps = _ref.formProps;
|
|
33
33
|
return jsx(FormContainer, _extends({}, formProps, {
|
|
34
34
|
id: SEARCH_FORM_ID
|
|
@@ -37,6 +37,7 @@ export var AssetsSearchContainer = function AssetsSearchContainer(props) {
|
|
|
37
37
|
}, modalTitle, jsx(SchemaSelectContainer, null, jsx(AssetsObjectSchemaSelect, {
|
|
38
38
|
value: (_initialSearchData$ob = initialSearchData.objectSchema) !== null && _initialSearchData$ob !== void 0 ? _initialSearchData$ob : undefined,
|
|
39
39
|
workspaceId: workspaceId,
|
|
40
|
+
initialObjectSchemas: (_initialSearchData$ob2 = initialSearchData.objectSchemas) !== null && _initialSearchData$ob2 !== void 0 ? _initialSearchData$ob2 : undefined,
|
|
40
41
|
classNamePrefix: "assets-datasource-modal--object-schema-select"
|
|
41
42
|
}))), jsx(FormRowContainer, null, jsx(AqlSearchInput, {
|
|
42
43
|
value: (_initialSearchData$aq = initialSearchData.aql) !== null && _initialSearchData$aq !== void 0 ? _initialSearchData$aq : DEFAULT_AQL_QUERY,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
5
|
var _excluded = ["onChange", "onFocus"];
|
|
7
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
@@ -9,14 +8,12 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
9
8
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
9
|
/** @jsx jsx */
|
|
11
10
|
|
|
12
|
-
import { useEffect, useState } from 'react';
|
|
13
11
|
import { jsx } from '@emotion/react';
|
|
14
12
|
import debounce from 'debounce-promise';
|
|
15
13
|
import { useIntl } from 'react-intl-next';
|
|
16
14
|
import { Field } from '@atlaskit/form';
|
|
17
15
|
import { AsyncSelect } from '@atlaskit/select';
|
|
18
16
|
import { layers } from '@atlaskit/theme/constants';
|
|
19
|
-
import { useDatasourceAnalyticsEvents } from '../../../../analytics';
|
|
20
17
|
import { useObjectSchemas } from '../../../../hooks/useObjectSchemas';
|
|
21
18
|
import { objectSchemaKey } from '../../../../types/assets/types';
|
|
22
19
|
import { FieldContainer } from '../styled';
|
|
@@ -46,74 +43,35 @@ export var selectInAModalStyleFixProps = {
|
|
|
46
43
|
export var AssetsObjectSchemaSelect = function AssetsObjectSchemaSelect(_ref) {
|
|
47
44
|
var value = _ref.value,
|
|
48
45
|
workspaceId = _ref.workspaceId,
|
|
46
|
+
initialObjectSchemas = _ref.initialObjectSchemas,
|
|
49
47
|
_ref$classNamePrefix = _ref.classNamePrefix,
|
|
50
48
|
classNamePrefix = _ref$classNamePrefix === void 0 ? 'assets-datasource-modal--object-schema-select' : _ref$classNamePrefix;
|
|
51
|
-
var _useState = useState(null),
|
|
52
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
53
|
-
defaultOptions = _useState2[0],
|
|
54
|
-
setDefaultOptions = _useState2[1];
|
|
55
|
-
var _useDatasourceAnalyti = useDatasourceAnalyticsEvents(),
|
|
56
|
-
fireEvent = _useDatasourceAnalyti.fireEvent;
|
|
57
49
|
var _useIntl = useIntl(),
|
|
58
50
|
formatMessage = _useIntl.formatMessage;
|
|
59
51
|
var _useObjectSchemas = useObjectSchemas(workspaceId),
|
|
60
52
|
fetchObjectSchemas = _useObjectSchemas.fetchObjectSchemas,
|
|
61
53
|
objectSchemasLoading = _useObjectSchemas.objectSchemasLoading;
|
|
62
54
|
var selectedObjectSchema = value ? objectSchemaToSelectOption(value) : undefined;
|
|
63
|
-
useEffect(function () {
|
|
64
|
-
var fetchInitialData = /*#__PURE__*/function () {
|
|
65
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
66
|
-
var _yield$fetchObjectSch, objectSchemas, totalObjectSchemas;
|
|
67
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
68
|
-
while (1) switch (_context.prev = _context.next) {
|
|
69
|
-
case 0:
|
|
70
|
-
_context.next = 2;
|
|
71
|
-
return fetchObjectSchemas('');
|
|
72
|
-
case 2:
|
|
73
|
-
_yield$fetchObjectSch = _context.sent;
|
|
74
|
-
objectSchemas = _yield$fetchObjectSch.objectSchemas;
|
|
75
|
-
totalObjectSchemas = _yield$fetchObjectSch.totalObjectSchemas;
|
|
76
|
-
// We only want to send modal ready event once after we've fetched the schema count
|
|
77
|
-
fireEvent('ui.modal.ready.datasource', {
|
|
78
|
-
schemasCount: totalObjectSchemas !== null && totalObjectSchemas !== void 0 ? totalObjectSchemas : 0,
|
|
79
|
-
instancesCount: null
|
|
80
|
-
});
|
|
81
|
-
setDefaultOptions(mapObjectSchemasToOptions(objectSchemas));
|
|
82
|
-
case 7:
|
|
83
|
-
case "end":
|
|
84
|
-
return _context.stop();
|
|
85
|
-
}
|
|
86
|
-
}, _callee);
|
|
87
|
-
}));
|
|
88
|
-
return function fetchInitialData() {
|
|
89
|
-
return _ref2.apply(this, arguments);
|
|
90
|
-
};
|
|
91
|
-
}();
|
|
92
|
-
if (defaultOptions === null) {
|
|
93
|
-
fetchInitialData();
|
|
94
|
-
}
|
|
95
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, []);
|
|
97
55
|
var loadOptions = /*#__PURE__*/function () {
|
|
98
|
-
var
|
|
99
|
-
var _yield$
|
|
100
|
-
return _regeneratorRuntime.wrap(function
|
|
101
|
-
while (1) switch (
|
|
56
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(inputValue) {
|
|
57
|
+
var _yield$fetchObjectSch, objectSchemas;
|
|
58
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
59
|
+
while (1) switch (_context.prev = _context.next) {
|
|
102
60
|
case 0:
|
|
103
|
-
|
|
61
|
+
_context.next = 2;
|
|
104
62
|
return fetchObjectSchemas(inputValue);
|
|
105
63
|
case 2:
|
|
106
|
-
_yield$
|
|
107
|
-
objectSchemas = _yield$
|
|
108
|
-
return
|
|
64
|
+
_yield$fetchObjectSch = _context.sent;
|
|
65
|
+
objectSchemas = _yield$fetchObjectSch.objectSchemas;
|
|
66
|
+
return _context.abrupt("return", mapObjectSchemasToOptions(objectSchemas));
|
|
109
67
|
case 5:
|
|
110
68
|
case "end":
|
|
111
|
-
return
|
|
69
|
+
return _context.stop();
|
|
112
70
|
}
|
|
113
|
-
},
|
|
71
|
+
}, _callee);
|
|
114
72
|
}));
|
|
115
73
|
return function loadOptions(_x) {
|
|
116
|
-
return
|
|
74
|
+
return _ref2.apply(this, arguments);
|
|
117
75
|
};
|
|
118
76
|
}();
|
|
119
77
|
var debouncedLoadOptions = debounce(loadOptions, SEARCH_DEBOUNCE_MS);
|
|
@@ -129,16 +87,16 @@ export var AssetsObjectSchemaSelect = function AssetsObjectSchemaSelect(_ref) {
|
|
|
129
87
|
validate: function validate(value) {
|
|
130
88
|
return validateSchema(value);
|
|
131
89
|
}
|
|
132
|
-
}, function (
|
|
133
|
-
var
|
|
134
|
-
_onChange =
|
|
135
|
-
onFocus =
|
|
136
|
-
restFieldProps = _objectWithoutProperties(
|
|
90
|
+
}, function (_ref3) {
|
|
91
|
+
var _ref3$fieldProps = _ref3.fieldProps,
|
|
92
|
+
_onChange = _ref3$fieldProps.onChange,
|
|
93
|
+
onFocus = _ref3$fieldProps.onFocus,
|
|
94
|
+
restFieldProps = _objectWithoutProperties(_ref3$fieldProps, _excluded);
|
|
137
95
|
return jsx(AsyncSelect, _extends({
|
|
138
96
|
autoFocus: true,
|
|
139
97
|
classNamePrefix: classNamePrefix,
|
|
140
98
|
isLoading: objectSchemasLoading,
|
|
141
|
-
defaultOptions:
|
|
99
|
+
defaultOptions: mapObjectSchemasToOptions(initialObjectSchemas),
|
|
142
100
|
isSearchable: true,
|
|
143
101
|
loadOptions: debouncedLoadOptions,
|
|
144
102
|
placeholder: formatMessage(objectSchemaSelectMessages.placeholder),
|