@atlaskit/link-datasource 1.17.0 → 1.17.2
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 +13 -0
- package/dist/cjs/analytics/constants.js +1 -1
- package/dist/cjs/hooks/useAssetsClient.js +7 -4
- package/dist/cjs/hooks/useValidateAqlText.js +5 -2
- package/dist/cjs/services/cmdbService.js +50 -35
- package/dist/cjs/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +8 -0
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +59 -34
- package/dist/cjs/ui/jira-issues-modal/basic-filters/ui/index.js +18 -6
- package/dist/cjs/ui/jira-issues-modal/basic-filters/utils/index.js +2 -1
- package/dist/es2019/analytics/constants.js +1 -1
- package/dist/es2019/hooks/useAssetsClient.js +8 -4
- package/dist/es2019/hooks/useValidateAqlText.js +6 -2
- package/dist/es2019/services/cmdbService.js +27 -12
- package/dist/es2019/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +8 -0
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +57 -27
- package/dist/es2019/ui/jira-issues-modal/basic-filters/ui/index.js +16 -6
- package/dist/es2019/ui/jira-issues-modal/basic-filters/utils/index.js +2 -1
- package/dist/esm/analytics/constants.js +1 -1
- package/dist/esm/hooks/useAssetsClient.js +7 -4
- package/dist/esm/hooks/useValidateAqlText.js +5 -2
- package/dist/esm/services/cmdbService.js +50 -35
- package/dist/esm/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.js +8 -0
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.js +60 -35
- package/dist/esm/ui/jira-issues-modal/basic-filters/ui/index.js +18 -6
- package/dist/esm/ui/jira-issues-modal/basic-filters/utils/index.js +2 -1
- package/dist/types/analytics/generated/analytics.types.d.ts +41 -1
- package/dist/types/services/cmdbService.d.ts +8 -4
- package/dist/types/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.d.ts +1 -0
- package/dist/types/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.d.ts +2 -1
- package/dist/types/ui/jira-issues-modal/basic-filters/ui/index.d.ts +1 -1
- package/dist/types-ts4.5/analytics/generated/analytics.types.d.ts +41 -1
- package/dist/types-ts4.5/services/cmdbService.d.ts +8 -4
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/hooks/useFilterOptions.d.ts +1 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/ui/async-popup-select/index.d.ts +2 -1
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/ui/index.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { request } from '@atlaskit/linking-common';
|
|
2
2
|
import { FetchError, getStatusCodeGroup, mapFetchErrors, PermissionError } from './cmdbService.utils';
|
|
3
|
-
export const getWorkspaceId = async
|
|
3
|
+
export const getWorkspaceId = async fireEvent => {
|
|
4
4
|
const url = '/rest/servicedesk/cmdb/latest/workspace';
|
|
5
5
|
try {
|
|
6
6
|
var _workspaceDetailsResp;
|
|
@@ -8,12 +8,15 @@ export const getWorkspaceId = async () => {
|
|
|
8
8
|
if (!((_workspaceDetailsResp = workspaceDetailsResponse.results) !== null && _workspaceDetailsResp !== void 0 && _workspaceDetailsResp.length)) {
|
|
9
9
|
throw new PermissionError('No workspace results found');
|
|
10
10
|
}
|
|
11
|
+
fireEvent && fireEvent('operational.getWorkspaceId.success', {});
|
|
11
12
|
return workspaceDetailsResponse.results[0].id;
|
|
12
13
|
} catch (err) {
|
|
13
14
|
let error = mapFetchErrors(err);
|
|
14
15
|
if (error instanceof FetchError) {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
fireEvent && fireEvent('operational.getWorkspaceId.failed', {
|
|
17
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
18
|
+
});
|
|
19
|
+
// Only 429 and5xx errors will be treated as FetchErrors otherwise PermissionError
|
|
17
20
|
if (getStatusCodeGroup(error) !== '5xx' && error.statusCode !== 429) {
|
|
18
21
|
error = new PermissionError('Failed to fetch workspace');
|
|
19
22
|
}
|
|
@@ -21,17 +24,21 @@ export const getWorkspaceId = async () => {
|
|
|
21
24
|
throw error;
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
|
-
export const validateAql = async (workspaceId, data) => {
|
|
27
|
+
export const validateAql = async (workspaceId, data, fireEvent) => {
|
|
25
28
|
const url = `/gateway/api/jsm/assets/workspace/${workspaceId}/v1/aql/validate`;
|
|
26
29
|
try {
|
|
27
|
-
|
|
30
|
+
const response = await request('post', url, {
|
|
28
31
|
qlQuery: data.qlQuery,
|
|
29
32
|
context: 'SMART_LINKS'
|
|
30
33
|
}, undefined, [200, 201, 202, 203, 204]);
|
|
34
|
+
fireEvent && fireEvent('operational.validateAql.success', {});
|
|
35
|
+
return response;
|
|
31
36
|
} catch (err) {
|
|
32
37
|
let error = mapFetchErrors(err);
|
|
33
38
|
if (error instanceof FetchError) {
|
|
34
|
-
|
|
39
|
+
fireEvent && fireEvent('operational.validateAql.failed', {
|
|
40
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
41
|
+
});
|
|
35
42
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
36
43
|
error = new PermissionError('Failed to fetch object schemas');
|
|
37
44
|
}
|
|
@@ -39,14 +46,18 @@ export const validateAql = async (workspaceId, data) => {
|
|
|
39
46
|
throw error;
|
|
40
47
|
}
|
|
41
48
|
};
|
|
42
|
-
export const fetchObjectSchema = async (workspaceId, schemaId) => {
|
|
49
|
+
export const fetchObjectSchema = async (workspaceId, schemaId, fireEvent) => {
|
|
43
50
|
const url = `/gateway/api/jsm/assets/workspace/${workspaceId}/v1/objectschema/${schemaId}`;
|
|
44
51
|
try {
|
|
45
|
-
|
|
52
|
+
const response = await request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
53
|
+
fireEvent && fireEvent('operational.objectSchema.success', {});
|
|
54
|
+
return response;
|
|
46
55
|
} catch (err) {
|
|
47
56
|
let error = mapFetchErrors(err);
|
|
48
57
|
if (error instanceof FetchError) {
|
|
49
|
-
|
|
58
|
+
fireEvent && fireEvent('operational.objectSchema.failed', {
|
|
59
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
60
|
+
});
|
|
50
61
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
51
62
|
error = new PermissionError('Failed to fetch object schemas');
|
|
52
63
|
}
|
|
@@ -54,18 +65,22 @@ export const fetchObjectSchema = async (workspaceId, schemaId) => {
|
|
|
54
65
|
throw error;
|
|
55
66
|
}
|
|
56
67
|
};
|
|
57
|
-
export const fetchObjectSchemas = async (workspaceId, query) => {
|
|
68
|
+
export const fetchObjectSchemas = async (workspaceId, query, fireEvent) => {
|
|
58
69
|
const queryParams = new URLSearchParams();
|
|
59
70
|
queryParams.set('maxResults', '20');
|
|
60
71
|
queryParams.set('includeCounts', 'false');
|
|
61
72
|
query && queryParams.set('query', query);
|
|
62
73
|
const url = `/gateway/api/jsm/assets/workspace/${workspaceId}/v1/objectschema/list?${queryParams}`;
|
|
63
74
|
try {
|
|
64
|
-
|
|
75
|
+
const response = await request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
76
|
+
fireEvent && fireEvent('operational.objectSchemas.success', {});
|
|
77
|
+
return response;
|
|
65
78
|
} catch (err) {
|
|
66
79
|
let error = mapFetchErrors(err);
|
|
67
80
|
if (error instanceof FetchError) {
|
|
68
|
-
|
|
81
|
+
fireEvent && fireEvent('operational.objectSchemas.failed', {
|
|
82
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
83
|
+
});
|
|
69
84
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
70
85
|
error = new PermissionError('Failed to fetch object schemas');
|
|
71
86
|
}
|
|
@@ -57,12 +57,20 @@ export const useFilterOptions = ({
|
|
|
57
57
|
setStatus('rejected');
|
|
58
58
|
}
|
|
59
59
|
}, [cloudId, filterOptions, filterType, getFieldValues]);
|
|
60
|
+
const reset = useCallback(() => {
|
|
61
|
+
setStatus('empty');
|
|
62
|
+
setFilterOptions([]);
|
|
63
|
+
setTotalCount(0);
|
|
64
|
+
setNextPageCursor(undefined);
|
|
65
|
+
initialData.current = undefined;
|
|
66
|
+
}, []);
|
|
60
67
|
return {
|
|
61
68
|
filterOptions,
|
|
62
69
|
fetchFilterOptions,
|
|
63
70
|
totalCount,
|
|
64
71
|
pageCursor: nextPageCursor,
|
|
65
72
|
status,
|
|
73
|
+
reset,
|
|
66
74
|
errors: status === 'rejected' ? errors : []
|
|
67
75
|
};
|
|
68
76
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
3
4
|
import { useIntl } from 'react-intl-next';
|
|
4
5
|
import { useDebouncedCallback } from 'use-debounce';
|
|
5
6
|
import { CheckboxOption, PopupSelect } from '@atlaskit/select';
|
|
@@ -19,6 +20,7 @@ const AsyncPopupSelect = ({
|
|
|
19
20
|
cloudId,
|
|
20
21
|
selection,
|
|
21
22
|
onSelectionChange = () => {},
|
|
23
|
+
onReset: resetSelection = () => {},
|
|
22
24
|
isDisabled = false
|
|
23
25
|
}) => {
|
|
24
26
|
const {
|
|
@@ -26,13 +28,17 @@ const AsyncPopupSelect = ({
|
|
|
26
28
|
} = useIntl();
|
|
27
29
|
const [searchTerm, setSearchTerm] = useState('');
|
|
28
30
|
const [selectedOptions, setSelectedOptions] = useState(selection);
|
|
29
|
-
const [sortedOptions, setSortedOptions] = useState(
|
|
31
|
+
const [sortedOptions, setSortedOptions] = useState([]);
|
|
32
|
+
const currentSiteCloudId = useRef(cloudId);
|
|
33
|
+
const sortPaginatedResults = useRef(false); // this is to track pagination for sorting purpose
|
|
34
|
+
|
|
30
35
|
const {
|
|
31
36
|
filterOptions,
|
|
32
37
|
fetchFilterOptions,
|
|
33
38
|
totalCount,
|
|
34
39
|
status,
|
|
35
40
|
pageCursor,
|
|
41
|
+
reset: resetHook,
|
|
36
42
|
errors
|
|
37
43
|
} = useFilterOptions({
|
|
38
44
|
filterType,
|
|
@@ -49,38 +55,46 @@ const AsyncPopupSelect = ({
|
|
|
49
55
|
handleDebouncedFetchFilterOptions(newSearchTerm);
|
|
50
56
|
}
|
|
51
57
|
}, [handleDebouncedFetchFilterOptions, searchTerm]);
|
|
52
|
-
const handleOptionSelection = newValue => {
|
|
53
|
-
setSelectedOptions(newValue);
|
|
58
|
+
const handleOptionSelection = useCallback(newValue => {
|
|
54
59
|
onSelectionChange(newValue);
|
|
55
|
-
};
|
|
60
|
+
}, [onSelectionChange]);
|
|
56
61
|
const sortOptionsOnPopupOpen = useCallback(() => {
|
|
57
62
|
if (selectedOptions.length === 0) {
|
|
58
|
-
setSortedOptions(filterOptions);
|
|
59
|
-
return;
|
|
63
|
+
return setSortedOptions(filterOptions);
|
|
60
64
|
}
|
|
61
65
|
const nonSelectedOptions = filterOptions.filter(option => !selectedOptions.find(selectedOption => selectedOption.value === option.value));
|
|
62
66
|
const newOptions = [...selectedOptions, ...nonSelectedOptions];
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
if (!isEqual(newOptions, sortedOptions)) {
|
|
68
|
+
setSortedOptions(newOptions);
|
|
69
|
+
}
|
|
70
|
+
}, [selectedOptions, filterOptions, sortedOptions]);
|
|
65
71
|
const sortOptionsOnResolve = useCallback(() => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
shouldSetSortOptions = true;
|
|
70
|
-
} else {
|
|
71
|
-
sortedOptions.forEach(sortedOption => {
|
|
72
|
-
if (!filterOptions.some(filterOption => filterOption.value === sortedOption.value)) {
|
|
73
|
-
shouldSetSortOptions = true;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
72
|
+
// sortedOptions is empty initially, this will take care of setting the initial value and bring the selected items to the top
|
|
73
|
+
if (sortedOptions.length === 0) {
|
|
74
|
+
return sortOptionsOnPopupOpen();
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
|
|
77
|
+
// when the user is searching, we want the search result to be displayed as it is, and the select component will take care of marking the selected items
|
|
78
|
+
if (searchTerm) {
|
|
79
|
+
sortPaginatedResults.current = false; // set to false to indicate pagination resolve action is completed from the sorting perspective
|
|
80
|
+
return setSortedOptions(filterOptions);
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
// this block handles the pagination, where on pagination, we will just append newOptions to the current list
|
|
84
|
+
if (sortPaginatedResults.current) {
|
|
85
|
+
const newOptions = filterOptions.filter(option => !sortedOptions.find(sortedOption => sortedOption.value === option.value));
|
|
86
|
+
if (newOptions.length > 0) {
|
|
87
|
+
setSortedOptions([...sortedOptions, ...newOptions]);
|
|
88
|
+
}
|
|
89
|
+
sortPaginatedResults.current = false; // set to false to indicate pagination resolve action is completed from the sorting perspective
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
sortPaginatedResults.current = false; // set to false to indicate pagination resolve action is completed from the sorting perspective
|
|
93
|
+
sortOptionsOnPopupOpen();
|
|
94
|
+
}, [filterOptions, searchTerm, sortOptionsOnPopupOpen, sortedOptions]);
|
|
82
95
|
const handleShowMore = useCallback(() => {
|
|
83
96
|
if (pageCursor) {
|
|
97
|
+
sortPaginatedResults.current = true;
|
|
84
98
|
fetchFilterOptions({
|
|
85
99
|
pageCursor,
|
|
86
100
|
searchString: searchTerm
|
|
@@ -101,15 +115,31 @@ const AsyncPopupSelect = ({
|
|
|
101
115
|
if (status === 'resolved') {
|
|
102
116
|
sortOptionsOnResolve();
|
|
103
117
|
}
|
|
104
|
-
|
|
118
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
119
|
+
}, [status]); // we only want the sortOptionsOnResolve to run when there is a status change
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (currentSiteCloudId.current !== cloudId) {
|
|
123
|
+
currentSiteCloudId.current = cloudId;
|
|
124
|
+
setSortedOptions([]);
|
|
125
|
+
setSearchTerm('');
|
|
126
|
+
resetHook();
|
|
127
|
+
resetSelection();
|
|
128
|
+
}
|
|
129
|
+
}, [cloudId, resetHook, resetSelection]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!isEqual(selection, selectedOptions)) {
|
|
132
|
+
setSelectedOptions(selection);
|
|
133
|
+
}
|
|
134
|
+
}, [selectedOptions, selection]);
|
|
105
135
|
const filterOptionsLength = filterOptions.length;
|
|
106
136
|
const isError = status === 'rejected';
|
|
107
137
|
const isLoading = status === 'loading' || status === 'empty';
|
|
108
138
|
const isLoadingMore = status === 'loadingMore';
|
|
109
139
|
const isEmpty = status === 'resolved' && filterOptionsLength === 0;
|
|
110
140
|
const popupSelectOptions = isLoading || isError ? [] : sortedOptions; // if not set to [], then on loading, no loading UI will be shown
|
|
111
|
-
const areAllResultsLoaded =
|
|
112
|
-
const shouldShowFooter = (status === 'resolved' || isLoadingMore) &&
|
|
141
|
+
const areAllResultsLoaded = filterOptionsLength === totalCount;
|
|
142
|
+
const shouldShowFooter = (status === 'resolved' || isLoadingMore) && filterOptionsLength > 0; // footer should not disappear when there is an inline spinner for loading more data
|
|
113
143
|
const shouldDisplayShowMoreButton = status === 'resolved' && !!pageCursor && !areAllResultsLoaded;
|
|
114
144
|
return /*#__PURE__*/React.createElement(PopupSelect, {
|
|
115
145
|
isMulti: true,
|
|
@@ -165,7 +195,7 @@ const AsyncPopupSelect = ({
|
|
|
165
195
|
isDisabled: isDisabled
|
|
166
196
|
})),
|
|
167
197
|
footer: shouldShowFooter && /*#__PURE__*/React.createElement(PopupFooter, {
|
|
168
|
-
currentDisplayCount:
|
|
198
|
+
currentDisplayCount: popupSelectOptions.length,
|
|
169
199
|
totalCount: totalCount
|
|
170
200
|
})
|
|
171
201
|
});
|
|
@@ -10,15 +10,24 @@ const BasicFilterContainer = ({
|
|
|
10
10
|
jql,
|
|
11
11
|
cloudId
|
|
12
12
|
}) => {
|
|
13
|
-
const [selection, setSelection] = useState(
|
|
13
|
+
const [selection, setSelection] = useState({});
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (isValidJql(jql)) {
|
|
16
16
|
// hydrate hook call goes in here
|
|
17
17
|
}
|
|
18
18
|
}, [jql]);
|
|
19
|
-
const handleSelectionChange = useCallback(options => {
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const handleSelectionChange = useCallback((options, filter) => {
|
|
20
|
+
const updatedSelection = {
|
|
21
|
+
...selection,
|
|
22
|
+
[filter]: options
|
|
23
|
+
};
|
|
24
|
+
setSelection(updatedSelection);
|
|
25
|
+
}, [selection]);
|
|
26
|
+
const handleReset = useCallback(() => {
|
|
27
|
+
if (Object.keys(selection).length > 0) {
|
|
28
|
+
setSelection({});
|
|
29
|
+
}
|
|
30
|
+
}, [selection]);
|
|
22
31
|
return /*#__PURE__*/React.createElement(Flex, {
|
|
23
32
|
xcss: basicFilterContainerStyles,
|
|
24
33
|
gap: "space.100",
|
|
@@ -27,9 +36,10 @@ const BasicFilterContainer = ({
|
|
|
27
36
|
cloudId: cloudId,
|
|
28
37
|
filterType: filter,
|
|
29
38
|
key: filter,
|
|
30
|
-
selection: selection,
|
|
39
|
+
selection: selection[filter] || [],
|
|
31
40
|
isDisabled: !cloudId,
|
|
32
|
-
onSelectionChange: handleSelectionChange
|
|
41
|
+
onSelectionChange: options => handleSelectionChange(options, filter),
|
|
42
|
+
onReset: handleReset
|
|
33
43
|
})));
|
|
34
44
|
};
|
|
35
45
|
export default BasicFilterContainer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JastBuilder } from '@atlaskit/jql-ast';
|
|
2
2
|
export const isValidJql = jql => {
|
|
3
|
+
var _jast$errors;
|
|
3
4
|
const jast = new JastBuilder().build(jql);
|
|
4
|
-
return jast.errors.length === 0;
|
|
5
|
+
return (jast === null || jast === void 0 ? void 0 : (_jast$errors = jast.errors) === null || _jast$errors === void 0 ? void 0 : _jast$errors.length) === 0;
|
|
5
6
|
};
|
|
@@ -2,6 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import { useEffect, useState } from 'react';
|
|
5
|
+
import { useDatasourceAnalyticsEvents } from '../analytics';
|
|
5
6
|
import { fetchObjectSchema, fetchObjectSchemas, getWorkspaceId } from '../services/cmdbService';
|
|
6
7
|
var handleAssetsClientErrors = function handleAssetsClientErrors(errorSetter, error) {
|
|
7
8
|
if (error instanceof Error) {
|
|
@@ -43,6 +44,8 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
43
44
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
44
45
|
objectSchemasError = _useState16[0],
|
|
45
46
|
setObjectSchemasError = _useState16[1];
|
|
47
|
+
var _useDatasourceAnalyti = useDatasourceAnalyticsEvents(),
|
|
48
|
+
fireEvent = _useDatasourceAnalyti.fireEvent;
|
|
46
49
|
|
|
47
50
|
/*
|
|
48
51
|
* We wrap this in nested try/catch blocks because we want to handle
|
|
@@ -59,7 +62,7 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
59
62
|
setWorkspaceError(undefined);
|
|
60
63
|
_context.prev = 2;
|
|
61
64
|
_context.next = 5;
|
|
62
|
-
return getWorkspaceId();
|
|
65
|
+
return getWorkspaceId(fireEvent);
|
|
63
66
|
case 5:
|
|
64
67
|
_workspaceId = _context.sent;
|
|
65
68
|
setWorkspaceId(_workspaceId);
|
|
@@ -70,7 +73,7 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
70
73
|
}
|
|
71
74
|
_context.prev = 8;
|
|
72
75
|
_context.next = 11;
|
|
73
|
-
return fetchObjectSchema(_workspaceId, initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId);
|
|
76
|
+
return fetchObjectSchema(_workspaceId, initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId, fireEvent);
|
|
74
77
|
case 11:
|
|
75
78
|
fetchedObjectSchema = _context.sent;
|
|
76
79
|
setExistingObjectSchema(fetchedObjectSchema);
|
|
@@ -83,7 +86,7 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
83
86
|
case 18:
|
|
84
87
|
_context.prev = 18;
|
|
85
88
|
_context.next = 21;
|
|
86
|
-
return fetchObjectSchemas(_workspaceId);
|
|
89
|
+
return fetchObjectSchemas(_workspaceId, undefined, fireEvent);
|
|
87
90
|
case 21:
|
|
88
91
|
fetchedObjectSchemasResponse = _context.sent;
|
|
89
92
|
setObjectSchemas(fetchedObjectSchemasResponse.values);
|
|
@@ -111,7 +114,7 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
111
114
|
}
|
|
112
115
|
}, _callee, null, [[2, 31, 34, 37], [8, 15], [18, 26]]);
|
|
113
116
|
}))();
|
|
114
|
-
}, [initialParameters]);
|
|
117
|
+
}, [initialParameters, fireEvent]);
|
|
115
118
|
return {
|
|
116
119
|
workspaceId: workspaceId,
|
|
117
120
|
workspaceError: workspaceError,
|
|
@@ -2,6 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import { useCallback, useState } from 'react';
|
|
5
|
+
import { useDatasourceAnalyticsEvents } from '../analytics';
|
|
5
6
|
import { validateAql } from '../services/cmdbService';
|
|
6
7
|
export var useValidateAqlText = function useValidateAqlText(workspaceId) {
|
|
7
8
|
var _useState = useState(false),
|
|
@@ -16,6 +17,8 @@ export var useValidateAqlText = function useValidateAqlText(workspaceId) {
|
|
|
16
17
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
17
18
|
error = _useState6[0],
|
|
18
19
|
setError = _useState6[1];
|
|
20
|
+
var _useDatasourceAnalyti = useDatasourceAnalyticsEvents(),
|
|
21
|
+
fireEvent = _useDatasourceAnalyti.fireEvent;
|
|
19
22
|
var validateAqlText = useCallback( /*#__PURE__*/function () {
|
|
20
23
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(aql) {
|
|
21
24
|
var isValid, message, _validateAqlResponse$, validateAqlResponse;
|
|
@@ -30,7 +33,7 @@ export var useValidateAqlText = function useValidateAqlText(workspaceId) {
|
|
|
30
33
|
_context.next = 7;
|
|
31
34
|
return validateAql(workspaceId, {
|
|
32
35
|
qlQuery: aql
|
|
33
|
-
});
|
|
36
|
+
}, fireEvent);
|
|
34
37
|
case 7:
|
|
35
38
|
validateAqlResponse = _context.sent;
|
|
36
39
|
setIsValidAqlText(validateAqlResponse.isValid);
|
|
@@ -64,7 +67,7 @@ export var useValidateAqlText = function useValidateAqlText(workspaceId) {
|
|
|
64
67
|
return function (_x) {
|
|
65
68
|
return _ref.apply(this, arguments);
|
|
66
69
|
};
|
|
67
|
-
}(), [workspaceId]);
|
|
70
|
+
}(), [workspaceId, fireEvent]);
|
|
68
71
|
return {
|
|
69
72
|
isValidAqlText: isValidAqlText,
|
|
70
73
|
validateAqlText: validateAqlText,
|
|
@@ -3,7 +3,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
3
3
|
import { request } from '@atlaskit/linking-common';
|
|
4
4
|
import { FetchError, getStatusCodeGroup, mapFetchErrors, PermissionError } from './cmdbService.utils';
|
|
5
5
|
export var getWorkspaceId = /*#__PURE__*/function () {
|
|
6
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
6
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fireEvent) {
|
|
7
7
|
var url, _workspaceDetailsResp, workspaceDetailsResponse, error;
|
|
8
8
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
9
9
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -20,32 +20,35 @@ export var getWorkspaceId = /*#__PURE__*/function () {
|
|
|
20
20
|
}
|
|
21
21
|
throw new PermissionError('No workspace results found');
|
|
22
22
|
case 7:
|
|
23
|
+
fireEvent && fireEvent('operational.getWorkspaceId.success', {});
|
|
23
24
|
return _context.abrupt("return", workspaceDetailsResponse.results[0].id);
|
|
24
|
-
case
|
|
25
|
-
_context.prev =
|
|
25
|
+
case 11:
|
|
26
|
+
_context.prev = 11;
|
|
26
27
|
_context.t0 = _context["catch"](1);
|
|
27
28
|
error = mapFetchErrors(_context.t0);
|
|
28
29
|
if (error instanceof FetchError) {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
fireEvent && fireEvent('operational.getWorkspaceId.failed', {
|
|
31
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
32
|
+
});
|
|
33
|
+
// Only 429 and5xx errors will be treated as FetchErrors otherwise PermissionError
|
|
31
34
|
if (getStatusCodeGroup(error) !== '5xx' && error.statusCode !== 429) {
|
|
32
35
|
error = new PermissionError('Failed to fetch workspace');
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
throw error;
|
|
36
|
-
case
|
|
39
|
+
case 16:
|
|
37
40
|
case "end":
|
|
38
41
|
return _context.stop();
|
|
39
42
|
}
|
|
40
|
-
}, _callee, null, [[1,
|
|
43
|
+
}, _callee, null, [[1, 11]]);
|
|
41
44
|
}));
|
|
42
|
-
return function getWorkspaceId() {
|
|
45
|
+
return function getWorkspaceId(_x) {
|
|
43
46
|
return _ref.apply(this, arguments);
|
|
44
47
|
};
|
|
45
48
|
}();
|
|
46
49
|
export var validateAql = /*#__PURE__*/function () {
|
|
47
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(workspaceId, data) {
|
|
48
|
-
var url, error;
|
|
50
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(workspaceId, data, fireEvent) {
|
|
51
|
+
var url, response, error;
|
|
49
52
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
50
53
|
while (1) switch (_context2.prev = _context2.next) {
|
|
51
54
|
case 0:
|
|
@@ -57,31 +60,35 @@ export var validateAql = /*#__PURE__*/function () {
|
|
|
57
60
|
context: 'SMART_LINKS'
|
|
58
61
|
}, undefined, [200, 201, 202, 203, 204]);
|
|
59
62
|
case 4:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
_context2.
|
|
63
|
+
response = _context2.sent;
|
|
64
|
+
fireEvent && fireEvent('operational.validateAql.success', {});
|
|
65
|
+
return _context2.abrupt("return", response);
|
|
66
|
+
case 9:
|
|
67
|
+
_context2.prev = 9;
|
|
63
68
|
_context2.t0 = _context2["catch"](1);
|
|
64
69
|
error = mapFetchErrors(_context2.t0);
|
|
65
70
|
if (error instanceof FetchError) {
|
|
66
|
-
|
|
71
|
+
fireEvent && fireEvent('operational.validateAql.failed', {
|
|
72
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
73
|
+
});
|
|
67
74
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
68
75
|
error = new PermissionError('Failed to fetch object schemas');
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
throw error;
|
|
72
|
-
case
|
|
79
|
+
case 14:
|
|
73
80
|
case "end":
|
|
74
81
|
return _context2.stop();
|
|
75
82
|
}
|
|
76
|
-
}, _callee2, null, [[1,
|
|
83
|
+
}, _callee2, null, [[1, 9]]);
|
|
77
84
|
}));
|
|
78
|
-
return function validateAql(
|
|
85
|
+
return function validateAql(_x2, _x3, _x4) {
|
|
79
86
|
return _ref2.apply(this, arguments);
|
|
80
87
|
};
|
|
81
88
|
}();
|
|
82
89
|
export var fetchObjectSchema = /*#__PURE__*/function () {
|
|
83
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(workspaceId, schemaId) {
|
|
84
|
-
var url, error;
|
|
90
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(workspaceId, schemaId, fireEvent) {
|
|
91
|
+
var url, response, error;
|
|
85
92
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
86
93
|
while (1) switch (_context3.prev = _context3.next) {
|
|
87
94
|
case 0:
|
|
@@ -90,31 +97,35 @@ export var fetchObjectSchema = /*#__PURE__*/function () {
|
|
|
90
97
|
_context3.next = 4;
|
|
91
98
|
return request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
92
99
|
case 4:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_context3.
|
|
100
|
+
response = _context3.sent;
|
|
101
|
+
fireEvent && fireEvent('operational.objectSchema.success', {});
|
|
102
|
+
return _context3.abrupt("return", response);
|
|
103
|
+
case 9:
|
|
104
|
+
_context3.prev = 9;
|
|
96
105
|
_context3.t0 = _context3["catch"](1);
|
|
97
106
|
error = mapFetchErrors(_context3.t0);
|
|
98
107
|
if (error instanceof FetchError) {
|
|
99
|
-
|
|
108
|
+
fireEvent && fireEvent('operational.objectSchema.failed', {
|
|
109
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
110
|
+
});
|
|
100
111
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
101
112
|
error = new PermissionError('Failed to fetch object schemas');
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
throw error;
|
|
105
|
-
case
|
|
116
|
+
case 14:
|
|
106
117
|
case "end":
|
|
107
118
|
return _context3.stop();
|
|
108
119
|
}
|
|
109
|
-
}, _callee3, null, [[1,
|
|
120
|
+
}, _callee3, null, [[1, 9]]);
|
|
110
121
|
}));
|
|
111
|
-
return function fetchObjectSchema(
|
|
122
|
+
return function fetchObjectSchema(_x5, _x6, _x7) {
|
|
112
123
|
return _ref3.apply(this, arguments);
|
|
113
124
|
};
|
|
114
125
|
}();
|
|
115
126
|
export var fetchObjectSchemas = /*#__PURE__*/function () {
|
|
116
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(workspaceId, query) {
|
|
117
|
-
var queryParams, url, error;
|
|
127
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(workspaceId, query, fireEvent) {
|
|
128
|
+
var queryParams, url, response, error;
|
|
118
129
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
119
130
|
while (1) switch (_context4.prev = _context4.next) {
|
|
120
131
|
case 0:
|
|
@@ -127,25 +138,29 @@ export var fetchObjectSchemas = /*#__PURE__*/function () {
|
|
|
127
138
|
_context4.next = 8;
|
|
128
139
|
return request('get', url, undefined, undefined, [200, 201, 202, 203, 204]);
|
|
129
140
|
case 8:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
_context4.
|
|
141
|
+
response = _context4.sent;
|
|
142
|
+
fireEvent && fireEvent('operational.objectSchemas.success', {});
|
|
143
|
+
return _context4.abrupt("return", response);
|
|
144
|
+
case 13:
|
|
145
|
+
_context4.prev = 13;
|
|
133
146
|
_context4.t0 = _context4["catch"](5);
|
|
134
147
|
error = mapFetchErrors(_context4.t0);
|
|
135
148
|
if (error instanceof FetchError) {
|
|
136
|
-
|
|
149
|
+
fireEvent && fireEvent('operational.objectSchemas.failed', {
|
|
150
|
+
statusCodeGroup: getStatusCodeGroup(error)
|
|
151
|
+
});
|
|
137
152
|
if (error.statusCode === 401 || error.statusCode === 403) {
|
|
138
153
|
error = new PermissionError('Failed to fetch object schemas');
|
|
139
154
|
}
|
|
140
155
|
}
|
|
141
156
|
throw error;
|
|
142
|
-
case
|
|
157
|
+
case 18:
|
|
143
158
|
case "end":
|
|
144
159
|
return _context4.stop();
|
|
145
160
|
}
|
|
146
|
-
}, _callee4, null, [[5,
|
|
161
|
+
}, _callee4, null, [[5, 13]]);
|
|
147
162
|
}));
|
|
148
|
-
return function fetchObjectSchemas(
|
|
163
|
+
return function fetchObjectSchemas(_x8, _x9, _x10) {
|
|
149
164
|
return _ref4.apply(this, arguments);
|
|
150
165
|
};
|
|
151
166
|
}();
|
|
@@ -105,12 +105,20 @@ export var useFilterOptions = function useFilterOptions(_ref) {
|
|
|
105
105
|
}
|
|
106
106
|
}, _callee, null, [[5, 24]]);
|
|
107
107
|
})), [cloudId, filterOptions, filterType, getFieldValues]);
|
|
108
|
+
var reset = useCallback(function () {
|
|
109
|
+
setStatus('empty');
|
|
110
|
+
setFilterOptions([]);
|
|
111
|
+
setTotalCount(0);
|
|
112
|
+
setNextPageCursor(undefined);
|
|
113
|
+
initialData.current = undefined;
|
|
114
|
+
}, []);
|
|
108
115
|
return {
|
|
109
116
|
filterOptions: filterOptions,
|
|
110
117
|
fetchFilterOptions: fetchFilterOptions,
|
|
111
118
|
totalCount: totalCount,
|
|
112
119
|
pageCursor: nextPageCursor,
|
|
113
120
|
status: status,
|
|
121
|
+
reset: reset,
|
|
114
122
|
errors: status === 'rejected' ? errors : []
|
|
115
123
|
};
|
|
116
124
|
};
|