@atlaskit/link-datasource 7.3.1 → 7.3.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 +10 -0
- package/dist/cjs/hooks/useAssetsClient.js +56 -44
- package/dist/cjs/services/fetchIsUnitsEnabledForAssets.js +71 -0
- package/dist/cjs/types/assets/types.js +2 -0
- package/dist/es2019/hooks/useAssetsClient.js +5 -3
- package/dist/es2019/services/fetchIsUnitsEnabledForAssets.js +46 -0
- package/dist/es2019/types/assets/types.js +2 -0
- package/dist/esm/hooks/useAssetsClient.js +56 -44
- package/dist/esm/services/fetchIsUnitsEnabledForAssets.js +64 -0
- package/dist/esm/types/assets/types.js +2 -0
- package/dist/types/services/fetchIsUnitsEnabledForAssets.d.ts +1 -0
- package/dist/types/types/assets/types.d.ts +5 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/link-datasource
|
|
2
2
|
|
|
3
|
+
## 7.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`44b6d3bdeba9d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/44b6d3bdeba9d) -
|
|
8
|
+
Assets modal now resolves the primary Unit workspace only when `/assets/is-multi-site` reports
|
|
9
|
+
Units enabled for Assets, otherwise it uses the legacy current-site workspace lookup (behind
|
|
10
|
+
`astral_units_workspace_host_resolver`).
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 7.3.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -11,6 +11,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
11
11
|
var _react = require("react");
|
|
12
12
|
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
13
13
|
var _analytics = require("../analytics");
|
|
14
|
+
var _fetchIsUnitsEnabledForAssets = require("../services/fetchIsUnitsEnabledForAssets");
|
|
14
15
|
var _fetchObjectSchema = require("../services/fetchObjectSchema");
|
|
15
16
|
var _fetchObjectSchemas = require("../services/fetchObjectSchemas");
|
|
16
17
|
var _getMeta2 = require("../services/getMeta");
|
|
@@ -70,89 +71,100 @@ var useAssetsClient = exports.useAssetsClient = function useAssetsClient(initial
|
|
|
70
71
|
*/
|
|
71
72
|
(0, _react.useEffect)(function () {
|
|
72
73
|
(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
73
|
-
var _workspaceId, _yield$resolvePrimary, fetchedObjectSchema, fetchedObjectSchemasResponse, _t, _t2, _t3, _t4;
|
|
74
|
+
var _workspaceId, isUnitsEnabledForAssets, _yield$resolvePrimary, fetchedObjectSchema, fetchedObjectSchemasResponse, _t, _t2, _t3, _t4, _t5;
|
|
74
75
|
return _regenerator.default.wrap(function (_context) {
|
|
75
76
|
while (1) switch (_context.prev = _context.next) {
|
|
76
77
|
case 0:
|
|
77
78
|
setLoading(true);
|
|
78
79
|
setWorkspaceError(undefined);
|
|
79
80
|
_context.prev = 1;
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
_t = (0, _fg.fg)('astral_units_workspace_host_resolver') && !!cloudId;
|
|
82
|
+
if (!_t) {
|
|
83
|
+
_context.next = 3;
|
|
82
84
|
break;
|
|
83
85
|
}
|
|
84
|
-
_context.
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
_context.next = 2;
|
|
87
|
+
return (0, _fetchIsUnitsEnabledForAssets.fetchIsUnitsEnabledForAssets)(cloudId);
|
|
88
|
+
case 2:
|
|
89
|
+
_t = _context.sent;
|
|
87
90
|
case 3:
|
|
91
|
+
isUnitsEnabledForAssets = _t;
|
|
92
|
+
if (!isUnitsEnabledForAssets) {
|
|
93
|
+
_context.next = 9;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
_context.prev = 4;
|
|
97
|
+
_context.next = 5;
|
|
98
|
+
return (0, _resolvePrimaryWorkspace.resolvePrimaryWorkspace)(cloudId);
|
|
99
|
+
case 5:
|
|
88
100
|
_yield$resolvePrimary = _context.sent;
|
|
89
101
|
_workspaceId = _yield$resolvePrimary.workspaceId;
|
|
90
|
-
_context.next =
|
|
102
|
+
_context.next = 8;
|
|
91
103
|
break;
|
|
92
|
-
case
|
|
93
|
-
_context.prev =
|
|
94
|
-
|
|
95
|
-
_context.next =
|
|
104
|
+
case 6:
|
|
105
|
+
_context.prev = 6;
|
|
106
|
+
_t2 = _context["catch"](4);
|
|
107
|
+
_context.next = 7;
|
|
96
108
|
return (0, _getWorkspaceId.getWorkspaceId)(fireEvent);
|
|
97
|
-
case
|
|
109
|
+
case 7:
|
|
98
110
|
_workspaceId = _context.sent;
|
|
99
|
-
case
|
|
100
|
-
_context.next =
|
|
111
|
+
case 8:
|
|
112
|
+
_context.next = 11;
|
|
101
113
|
break;
|
|
102
|
-
case
|
|
103
|
-
_context.next =
|
|
114
|
+
case 9:
|
|
115
|
+
_context.next = 10;
|
|
104
116
|
return (0, _getWorkspaceId.getWorkspaceId)(fireEvent);
|
|
105
|
-
case
|
|
117
|
+
case 10:
|
|
106
118
|
_workspaceId = _context.sent;
|
|
107
|
-
case
|
|
119
|
+
case 11:
|
|
108
120
|
setWorkspaceId(_workspaceId);
|
|
109
121
|
// Check schema from initial parameters still exists and fetch name/permissions for schema select
|
|
110
122
|
if (!(initialParameters !== null && initialParameters !== void 0 && initialParameters.schemaId)) {
|
|
111
|
-
_context.next =
|
|
123
|
+
_context.next = 15;
|
|
112
124
|
break;
|
|
113
125
|
}
|
|
114
|
-
_context.prev =
|
|
115
|
-
_context.next =
|
|
126
|
+
_context.prev = 12;
|
|
127
|
+
_context.next = 13;
|
|
116
128
|
return (0, _fetchObjectSchema.fetchObjectSchema)(_workspaceId, initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId, fireEvent);
|
|
117
|
-
case
|
|
129
|
+
case 13:
|
|
118
130
|
fetchedObjectSchema = _context.sent;
|
|
119
131
|
setExistingObjectSchema(fetchedObjectSchema);
|
|
120
|
-
_context.next =
|
|
132
|
+
_context.next = 15;
|
|
121
133
|
break;
|
|
122
|
-
case 12:
|
|
123
|
-
_context.prev = 12;
|
|
124
|
-
_t2 = _context["catch"](10);
|
|
125
|
-
handleAssetsClientErrors(setExistingObjectSchemaError, _t2);
|
|
126
|
-
case 13:
|
|
127
|
-
_context.prev = 13;
|
|
128
|
-
_context.next = 14;
|
|
129
|
-
return (0, _fetchObjectSchemas.fetchObjectSchemas)(_workspaceId, undefined, fireEvent);
|
|
130
134
|
case 14:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_context.next = 16;
|
|
135
|
-
break;
|
|
135
|
+
_context.prev = 14;
|
|
136
|
+
_t3 = _context["catch"](12);
|
|
137
|
+
handleAssetsClientErrors(setExistingObjectSchemaError, _t3);
|
|
136
138
|
case 15:
|
|
137
139
|
_context.prev = 15;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
_context.next = 16;
|
|
141
|
+
return (0, _fetchObjectSchemas.fetchObjectSchemas)(_workspaceId, undefined, fireEvent);
|
|
140
142
|
case 16:
|
|
143
|
+
fetchedObjectSchemasResponse = _context.sent;
|
|
144
|
+
setObjectSchemas(fetchedObjectSchemasResponse.values);
|
|
145
|
+
setTotalObjectSchemas(fetchedObjectSchemasResponse.total);
|
|
141
146
|
_context.next = 18;
|
|
142
147
|
break;
|
|
143
148
|
case 17:
|
|
144
149
|
_context.prev = 17;
|
|
145
|
-
_t4 = _context["catch"](
|
|
146
|
-
handleAssetsClientErrors(
|
|
150
|
+
_t4 = _context["catch"](15);
|
|
151
|
+
handleAssetsClientErrors(setObjectSchemasError, _t4);
|
|
147
152
|
case 18:
|
|
148
|
-
_context.
|
|
149
|
-
|
|
150
|
-
return _context.finish(18);
|
|
153
|
+
_context.next = 20;
|
|
154
|
+
break;
|
|
151
155
|
case 19:
|
|
156
|
+
_context.prev = 19;
|
|
157
|
+
_t5 = _context["catch"](1);
|
|
158
|
+
handleAssetsClientErrors(setWorkspaceError, _t5);
|
|
159
|
+
case 20:
|
|
160
|
+
_context.prev = 20;
|
|
161
|
+
setLoading(false);
|
|
162
|
+
return _context.finish(20);
|
|
163
|
+
case 21:
|
|
152
164
|
case "end":
|
|
153
165
|
return _context.stop();
|
|
154
166
|
}
|
|
155
|
-
}, _callee, null, [[1,
|
|
167
|
+
}, _callee, null, [[1, 19, 20, 21], [4, 6], [12, 14], [15, 17]]);
|
|
156
168
|
}))();
|
|
157
169
|
}, [initialParameters, fireEvent, cloudId]);
|
|
158
170
|
return {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.fetchIsUnitsEnabledForAssets = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _api = require("@atlaskit/linking-common/api");
|
|
11
|
+
var UNITS_ENABLED_TTL_MS = 15 * 60 * 1000;
|
|
12
|
+
var UNITS_ENABLED_ERROR_TTL_MS = 60 * 1000;
|
|
13
|
+
var cache = new Map();
|
|
14
|
+
var performFetch = /*#__PURE__*/function () {
|
|
15
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(cloudId) {
|
|
16
|
+
var res, _t;
|
|
17
|
+
return _regenerator.default.wrap(function (_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
_context.prev = 0;
|
|
21
|
+
_context.next = 1;
|
|
22
|
+
return (0, _api.request)('get', '/assets/is-multi-site', undefined, {
|
|
23
|
+
'x-atlassian-cloud-id': cloudId
|
|
24
|
+
}, [200]);
|
|
25
|
+
case 1:
|
|
26
|
+
res = _context.sent;
|
|
27
|
+
return _context.abrupt("return", {
|
|
28
|
+
enabled: (res === null || res === void 0 ? void 0 : res.isUnitsEnabledForAssets) === true,
|
|
29
|
+
ttlMs: UNITS_ENABLED_TTL_MS
|
|
30
|
+
});
|
|
31
|
+
case 2:
|
|
32
|
+
_context.prev = 2;
|
|
33
|
+
_t = _context["catch"](0);
|
|
34
|
+
return _context.abrupt("return", {
|
|
35
|
+
enabled: false,
|
|
36
|
+
ttlMs: UNITS_ENABLED_ERROR_TTL_MS
|
|
37
|
+
});
|
|
38
|
+
case 3:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}, _callee, null, [[0, 2]]);
|
|
43
|
+
}));
|
|
44
|
+
return function performFetch(_x) {
|
|
45
|
+
return _ref.apply(this, arguments);
|
|
46
|
+
};
|
|
47
|
+
}();
|
|
48
|
+
|
|
49
|
+
// Whether Units is enabled for Assets on this tenant. Single-flight and cached per
|
|
50
|
+
// cloudId (short TTL after a failure). Resolves false on any failure so callers fall
|
|
51
|
+
// back to the legacy current-site lookup.
|
|
52
|
+
var fetchIsUnitsEnabledForAssets = exports.fetchIsUnitsEnabledForAssets = function fetchIsUnitsEnabledForAssets(cloudId) {
|
|
53
|
+
var cached = cache.get(cloudId);
|
|
54
|
+
if (cached && Date.now() < cached.expiresAt) {
|
|
55
|
+
return cached.promise;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Pending entries never expire, so concurrent callers share one request.
|
|
59
|
+
var entry = {
|
|
60
|
+
expiresAt: Infinity,
|
|
61
|
+
promise: Promise.resolve(false)
|
|
62
|
+
};
|
|
63
|
+
entry.promise = performFetch(cloudId).then(function (_ref2) {
|
|
64
|
+
var enabled = _ref2.enabled,
|
|
65
|
+
ttlMs = _ref2.ttlMs;
|
|
66
|
+
entry.expiresAt = Date.now() + ttlMs;
|
|
67
|
+
return enabled;
|
|
68
|
+
});
|
|
69
|
+
cache.set(cloudId, entry);
|
|
70
|
+
return entry.promise;
|
|
71
|
+
};
|
|
@@ -9,6 +9,8 @@ exports.objectSchemaKey = exports.aqlKey = void 0;
|
|
|
9
9
|
* `linkedAssetsWorkspaceId` is the workspace of the Unit's primary Assets site.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/** Wire shape of the `/assets/is-multi-site` response. */
|
|
13
|
+
|
|
12
14
|
// These are to enforce the field "name" property and keep everything typed
|
|
13
15
|
var objectSchemaKey = exports.objectSchemaKey = 'objectSchema';
|
|
14
16
|
var aqlKey = exports.aqlKey = 'aql';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
3
3
|
import { useDatasourceAnalyticsEvents } from '../analytics';
|
|
4
|
+
import { fetchIsUnitsEnabledForAssets } from '../services/fetchIsUnitsEnabledForAssets';
|
|
4
5
|
import { fetchObjectSchema } from '../services/fetchObjectSchema';
|
|
5
6
|
import { fetchObjectSchemas } from '../services/fetchObjectSchemas';
|
|
6
7
|
import { getMeta } from '../services/getMeta';
|
|
@@ -40,10 +41,11 @@ export const useAssetsClient = initialParameters => {
|
|
|
40
41
|
setLoading(true);
|
|
41
42
|
setWorkspaceError(undefined);
|
|
42
43
|
try {
|
|
43
|
-
// When the gate is on
|
|
44
|
-
// workspace; on any failure fall back to the legacy current-site lookup.
|
|
44
|
+
// When the gate is on, a cloudId is present and Units is enabled for Assets, resolve
|
|
45
|
+
// the primary Unit workspace; on any failure fall back to the legacy current-site lookup.
|
|
45
46
|
let workspaceId;
|
|
46
|
-
|
|
47
|
+
const isUnitsEnabledForAssets = fg('astral_units_workspace_host_resolver') && !!cloudId && (await fetchIsUnitsEnabledForAssets(cloudId));
|
|
48
|
+
if (isUnitsEnabledForAssets) {
|
|
47
49
|
try {
|
|
48
50
|
({
|
|
49
51
|
workspaceId
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { request } from '@atlaskit/linking-common/api';
|
|
2
|
+
const UNITS_ENABLED_TTL_MS = 15 * 60 * 1000;
|
|
3
|
+
const UNITS_ENABLED_ERROR_TTL_MS = 60 * 1000;
|
|
4
|
+
const cache = new Map();
|
|
5
|
+
const performFetch = async cloudId => {
|
|
6
|
+
try {
|
|
7
|
+
const res = await request('get', '/assets/is-multi-site', undefined, {
|
|
8
|
+
'x-atlassian-cloud-id': cloudId
|
|
9
|
+
}, [200]);
|
|
10
|
+
return {
|
|
11
|
+
enabled: (res === null || res === void 0 ? void 0 : res.isUnitsEnabledForAssets) === true,
|
|
12
|
+
ttlMs: UNITS_ENABLED_TTL_MS
|
|
13
|
+
};
|
|
14
|
+
} catch {
|
|
15
|
+
// Fail closed.
|
|
16
|
+
return {
|
|
17
|
+
enabled: false,
|
|
18
|
+
ttlMs: UNITS_ENABLED_ERROR_TTL_MS
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Whether Units is enabled for Assets on this tenant. Single-flight and cached per
|
|
24
|
+
// cloudId (short TTL after a failure). Resolves false on any failure so callers fall
|
|
25
|
+
// back to the legacy current-site lookup.
|
|
26
|
+
export const fetchIsUnitsEnabledForAssets = cloudId => {
|
|
27
|
+
const cached = cache.get(cloudId);
|
|
28
|
+
if (cached && Date.now() < cached.expiresAt) {
|
|
29
|
+
return cached.promise;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Pending entries never expire, so concurrent callers share one request.
|
|
33
|
+
const entry = {
|
|
34
|
+
expiresAt: Infinity,
|
|
35
|
+
promise: Promise.resolve(false)
|
|
36
|
+
};
|
|
37
|
+
entry.promise = performFetch(cloudId).then(({
|
|
38
|
+
enabled,
|
|
39
|
+
ttlMs
|
|
40
|
+
}) => {
|
|
41
|
+
entry.expiresAt = Date.now() + ttlMs;
|
|
42
|
+
return enabled;
|
|
43
|
+
});
|
|
44
|
+
cache.set(cloudId, entry);
|
|
45
|
+
return entry.promise;
|
|
46
|
+
};
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* `linkedAssetsWorkspaceId` is the workspace of the Unit's primary Assets site.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/** Wire shape of the `/assets/is-multi-site` response. */
|
|
7
|
+
|
|
6
8
|
// These are to enforce the field "name" property and keep everything typed
|
|
7
9
|
export const objectSchemaKey = 'objectSchema';
|
|
8
10
|
export const aqlKey = 'aql';
|
|
@@ -4,6 +4,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
4
4
|
import { useEffect, useState } from 'react';
|
|
5
5
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
6
6
|
import { useDatasourceAnalyticsEvents } from '../analytics';
|
|
7
|
+
import { fetchIsUnitsEnabledForAssets } from '../services/fetchIsUnitsEnabledForAssets';
|
|
7
8
|
import { fetchObjectSchema } from '../services/fetchObjectSchema';
|
|
8
9
|
import { fetchObjectSchemas } from '../services/fetchObjectSchemas';
|
|
9
10
|
import { getMeta } from '../services/getMeta';
|
|
@@ -63,89 +64,100 @@ export var useAssetsClient = function useAssetsClient(initialParameters) {
|
|
|
63
64
|
*/
|
|
64
65
|
useEffect(function () {
|
|
65
66
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
66
|
-
var _workspaceId, _yield$resolvePrimary, fetchedObjectSchema, fetchedObjectSchemasResponse, _t, _t2, _t3, _t4;
|
|
67
|
+
var _workspaceId, isUnitsEnabledForAssets, _yield$resolvePrimary, fetchedObjectSchema, fetchedObjectSchemasResponse, _t, _t2, _t3, _t4, _t5;
|
|
67
68
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
68
69
|
while (1) switch (_context.prev = _context.next) {
|
|
69
70
|
case 0:
|
|
70
71
|
setLoading(true);
|
|
71
72
|
setWorkspaceError(undefined);
|
|
72
73
|
_context.prev = 1;
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
_t = fg('astral_units_workspace_host_resolver') && !!cloudId;
|
|
75
|
+
if (!_t) {
|
|
76
|
+
_context.next = 3;
|
|
75
77
|
break;
|
|
76
78
|
}
|
|
77
|
-
_context.
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
_context.next = 2;
|
|
80
|
+
return fetchIsUnitsEnabledForAssets(cloudId);
|
|
81
|
+
case 2:
|
|
82
|
+
_t = _context.sent;
|
|
80
83
|
case 3:
|
|
84
|
+
isUnitsEnabledForAssets = _t;
|
|
85
|
+
if (!isUnitsEnabledForAssets) {
|
|
86
|
+
_context.next = 9;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
_context.prev = 4;
|
|
90
|
+
_context.next = 5;
|
|
91
|
+
return resolvePrimaryWorkspace(cloudId);
|
|
92
|
+
case 5:
|
|
81
93
|
_yield$resolvePrimary = _context.sent;
|
|
82
94
|
_workspaceId = _yield$resolvePrimary.workspaceId;
|
|
83
|
-
_context.next =
|
|
95
|
+
_context.next = 8;
|
|
84
96
|
break;
|
|
85
|
-
case
|
|
86
|
-
_context.prev =
|
|
87
|
-
|
|
88
|
-
_context.next =
|
|
97
|
+
case 6:
|
|
98
|
+
_context.prev = 6;
|
|
99
|
+
_t2 = _context["catch"](4);
|
|
100
|
+
_context.next = 7;
|
|
89
101
|
return getWorkspaceId(fireEvent);
|
|
90
|
-
case
|
|
102
|
+
case 7:
|
|
91
103
|
_workspaceId = _context.sent;
|
|
92
|
-
case
|
|
93
|
-
_context.next =
|
|
104
|
+
case 8:
|
|
105
|
+
_context.next = 11;
|
|
94
106
|
break;
|
|
95
|
-
case
|
|
96
|
-
_context.next =
|
|
107
|
+
case 9:
|
|
108
|
+
_context.next = 10;
|
|
97
109
|
return getWorkspaceId(fireEvent);
|
|
98
|
-
case
|
|
110
|
+
case 10:
|
|
99
111
|
_workspaceId = _context.sent;
|
|
100
|
-
case
|
|
112
|
+
case 11:
|
|
101
113
|
setWorkspaceId(_workspaceId);
|
|
102
114
|
// Check schema from initial parameters still exists and fetch name/permissions for schema select
|
|
103
115
|
if (!(initialParameters !== null && initialParameters !== void 0 && initialParameters.schemaId)) {
|
|
104
|
-
_context.next =
|
|
116
|
+
_context.next = 15;
|
|
105
117
|
break;
|
|
106
118
|
}
|
|
107
|
-
_context.prev =
|
|
108
|
-
_context.next =
|
|
119
|
+
_context.prev = 12;
|
|
120
|
+
_context.next = 13;
|
|
109
121
|
return fetchObjectSchema(_workspaceId, initialParameters === null || initialParameters === void 0 ? void 0 : initialParameters.schemaId, fireEvent);
|
|
110
|
-
case
|
|
122
|
+
case 13:
|
|
111
123
|
fetchedObjectSchema = _context.sent;
|
|
112
124
|
setExistingObjectSchema(fetchedObjectSchema);
|
|
113
|
-
_context.next =
|
|
125
|
+
_context.next = 15;
|
|
114
126
|
break;
|
|
115
|
-
case 12:
|
|
116
|
-
_context.prev = 12;
|
|
117
|
-
_t2 = _context["catch"](10);
|
|
118
|
-
handleAssetsClientErrors(setExistingObjectSchemaError, _t2);
|
|
119
|
-
case 13:
|
|
120
|
-
_context.prev = 13;
|
|
121
|
-
_context.next = 14;
|
|
122
|
-
return fetchObjectSchemas(_workspaceId, undefined, fireEvent);
|
|
123
127
|
case 14:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
_context.next = 16;
|
|
128
|
-
break;
|
|
128
|
+
_context.prev = 14;
|
|
129
|
+
_t3 = _context["catch"](12);
|
|
130
|
+
handleAssetsClientErrors(setExistingObjectSchemaError, _t3);
|
|
129
131
|
case 15:
|
|
130
132
|
_context.prev = 15;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
_context.next = 16;
|
|
134
|
+
return fetchObjectSchemas(_workspaceId, undefined, fireEvent);
|
|
133
135
|
case 16:
|
|
136
|
+
fetchedObjectSchemasResponse = _context.sent;
|
|
137
|
+
setObjectSchemas(fetchedObjectSchemasResponse.values);
|
|
138
|
+
setTotalObjectSchemas(fetchedObjectSchemasResponse.total);
|
|
134
139
|
_context.next = 18;
|
|
135
140
|
break;
|
|
136
141
|
case 17:
|
|
137
142
|
_context.prev = 17;
|
|
138
|
-
_t4 = _context["catch"](
|
|
139
|
-
handleAssetsClientErrors(
|
|
143
|
+
_t4 = _context["catch"](15);
|
|
144
|
+
handleAssetsClientErrors(setObjectSchemasError, _t4);
|
|
140
145
|
case 18:
|
|
141
|
-
_context.
|
|
142
|
-
|
|
143
|
-
return _context.finish(18);
|
|
146
|
+
_context.next = 20;
|
|
147
|
+
break;
|
|
144
148
|
case 19:
|
|
149
|
+
_context.prev = 19;
|
|
150
|
+
_t5 = _context["catch"](1);
|
|
151
|
+
handleAssetsClientErrors(setWorkspaceError, _t5);
|
|
152
|
+
case 20:
|
|
153
|
+
_context.prev = 20;
|
|
154
|
+
setLoading(false);
|
|
155
|
+
return _context.finish(20);
|
|
156
|
+
case 21:
|
|
145
157
|
case "end":
|
|
146
158
|
return _context.stop();
|
|
147
159
|
}
|
|
148
|
-
}, _callee, null, [[1,
|
|
160
|
+
}, _callee, null, [[1, 19, 20, 21], [4, 6], [12, 14], [15, 17]]);
|
|
149
161
|
}))();
|
|
150
162
|
}, [initialParameters, fireEvent, cloudId]);
|
|
151
163
|
return {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { request } from '@atlaskit/linking-common/api';
|
|
4
|
+
var UNITS_ENABLED_TTL_MS = 15 * 60 * 1000;
|
|
5
|
+
var UNITS_ENABLED_ERROR_TTL_MS = 60 * 1000;
|
|
6
|
+
var cache = new Map();
|
|
7
|
+
var performFetch = /*#__PURE__*/function () {
|
|
8
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(cloudId) {
|
|
9
|
+
var res, _t;
|
|
10
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
11
|
+
while (1) switch (_context.prev = _context.next) {
|
|
12
|
+
case 0:
|
|
13
|
+
_context.prev = 0;
|
|
14
|
+
_context.next = 1;
|
|
15
|
+
return request('get', '/assets/is-multi-site', undefined, {
|
|
16
|
+
'x-atlassian-cloud-id': cloudId
|
|
17
|
+
}, [200]);
|
|
18
|
+
case 1:
|
|
19
|
+
res = _context.sent;
|
|
20
|
+
return _context.abrupt("return", {
|
|
21
|
+
enabled: (res === null || res === void 0 ? void 0 : res.isUnitsEnabledForAssets) === true,
|
|
22
|
+
ttlMs: UNITS_ENABLED_TTL_MS
|
|
23
|
+
});
|
|
24
|
+
case 2:
|
|
25
|
+
_context.prev = 2;
|
|
26
|
+
_t = _context["catch"](0);
|
|
27
|
+
return _context.abrupt("return", {
|
|
28
|
+
enabled: false,
|
|
29
|
+
ttlMs: UNITS_ENABLED_ERROR_TTL_MS
|
|
30
|
+
});
|
|
31
|
+
case 3:
|
|
32
|
+
case "end":
|
|
33
|
+
return _context.stop();
|
|
34
|
+
}
|
|
35
|
+
}, _callee, null, [[0, 2]]);
|
|
36
|
+
}));
|
|
37
|
+
return function performFetch(_x) {
|
|
38
|
+
return _ref.apply(this, arguments);
|
|
39
|
+
};
|
|
40
|
+
}();
|
|
41
|
+
|
|
42
|
+
// Whether Units is enabled for Assets on this tenant. Single-flight and cached per
|
|
43
|
+
// cloudId (short TTL after a failure). Resolves false on any failure so callers fall
|
|
44
|
+
// back to the legacy current-site lookup.
|
|
45
|
+
export var fetchIsUnitsEnabledForAssets = function fetchIsUnitsEnabledForAssets(cloudId) {
|
|
46
|
+
var cached = cache.get(cloudId);
|
|
47
|
+
if (cached && Date.now() < cached.expiresAt) {
|
|
48
|
+
return cached.promise;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Pending entries never expire, so concurrent callers share one request.
|
|
52
|
+
var entry = {
|
|
53
|
+
expiresAt: Infinity,
|
|
54
|
+
promise: Promise.resolve(false)
|
|
55
|
+
};
|
|
56
|
+
entry.promise = performFetch(cloudId).then(function (_ref2) {
|
|
57
|
+
var enabled = _ref2.enabled,
|
|
58
|
+
ttlMs = _ref2.ttlMs;
|
|
59
|
+
entry.expiresAt = Date.now() + ttlMs;
|
|
60
|
+
return enabled;
|
|
61
|
+
});
|
|
62
|
+
cache.set(cloudId, entry);
|
|
63
|
+
return entry.promise;
|
|
64
|
+
};
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* `linkedAssetsWorkspaceId` is the workspace of the Unit's primary Assets site.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/** Wire shape of the `/assets/is-multi-site` response. */
|
|
7
|
+
|
|
6
8
|
// These are to enforce the field "name" property and keep everything typed
|
|
7
9
|
export var objectSchemaKey = 'objectSchema';
|
|
8
10
|
export var aqlKey = 'aql';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fetchIsUnitsEnabledForAssets: (cloudId: string) => Promise<boolean>;
|
|
@@ -14,6 +14,11 @@ export type ResolvePrimaryWorkspaceResponse = {
|
|
|
14
14
|
linkedAssetsWorkspaceId?: string;
|
|
15
15
|
siteWithJiraUrl?: string;
|
|
16
16
|
};
|
|
17
|
+
/** Wire shape of the `/assets/is-multi-site` response. */
|
|
18
|
+
export type AssetsMultiSiteResponse = {
|
|
19
|
+
isUnitsEnabledForAssets?: boolean;
|
|
20
|
+
multiSite?: boolean;
|
|
21
|
+
};
|
|
17
22
|
export type ObjectSchema = {
|
|
18
23
|
id: string;
|
|
19
24
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-datasource",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.2",
|
|
4
4
|
"description": "UI Components to support linking platform dataset feature",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"ak-postbuild": "ls -d dist/* | xargs -n 1 copyfiles -u 1 -V 'src/**/*.{svg,png}'"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@atlaskit/adf-schema": "^57.
|
|
41
|
+
"@atlaskit/adf-schema": "^57.7.0",
|
|
42
42
|
"@atlaskit/afm-i18n-platform-linking-platform-link-datasource": "2.271.0",
|
|
43
43
|
"@atlaskit/analytics-cross-product": "^2.2.0",
|
|
44
44
|
"@atlaskit/analytics-next": "^12.5.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/badge": "^22.0.0",
|
|
49
49
|
"@atlaskit/button": "^25.4.0",
|
|
50
50
|
"@atlaskit/css": "^1.1.0",
|
|
51
|
-
"@atlaskit/datetime-picker": "^19.
|
|
51
|
+
"@atlaskit/datetime-picker": "^19.1.0",
|
|
52
52
|
"@atlaskit/dropdown-menu": "^21.0.0",
|
|
53
53
|
"@atlaskit/editor-prosemirror": "^9.0.0",
|
|
54
54
|
"@atlaskit/empty-state": "^12.2.0",
|