@atlaskit/teams-public 0.49.0 → 0.50.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/controllers/hooks/use-requested-container/index.js +196 -51
- package/dist/cjs/controllers/hooks/use-requested-container/utils.js +41 -4
- package/dist/cjs/controllers/hooks/use-team-containers/index.js +18 -9
- package/dist/cjs/ui/team-containers/main.js +1 -0
- package/dist/es2019/controllers/hooks/use-requested-container/index.js +140 -42
- package/dist/es2019/controllers/hooks/use-requested-container/utils.js +40 -4
- package/dist/es2019/controllers/hooks/use-team-containers/index.js +2 -1
- package/dist/es2019/ui/team-containers/main.js +1 -0
- package/dist/esm/controllers/hooks/use-requested-container/index.js +195 -52
- package/dist/esm/controllers/hooks/use-requested-container/utils.js +39 -3
- package/dist/esm/controllers/hooks/use-team-containers/index.js +18 -9
- package/dist/esm/ui/team-containers/main.js +1 -0
- package/dist/types/controllers/hooks/use-requested-container/index.d.ts +3 -4
- package/dist/types/controllers/hooks/use-requested-container/utils.d.ts +13 -2
- package/dist/types/controllers/hooks/use-team-containers/index.d.ts +1 -1
- package/dist/types-ts4.5/controllers/hooks/use-requested-container/index.d.ts +3 -4
- package/dist/types-ts4.5/controllers/hooks/use-requested-container/utils.d.ts +13 -2
- package/dist/types-ts4.5/controllers/hooks/use-team-containers/index.d.ts +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/teams-public
|
|
2
2
|
|
|
3
|
+
## 0.50.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#189223](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/189223)
|
|
8
|
+
[`2b465d07bf40a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2b465d07bf40a) -
|
|
9
|
+
Update useRequestedContainers to support try again behaviour
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 0.49.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.useRequestedContainers = useRequestedContainers;
|
|
8
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
-
var _react = require("react");
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _reactIntlNext = require("react-intl-next");
|
|
14
|
+
var _linkExternal = _interopRequireDefault(require("@atlaskit/icon/core/link-external"));
|
|
15
|
+
var _compiled = require("@atlaskit/primitives/compiled");
|
|
16
|
+
var _teamsClient = require("@atlaskit/teams-client");
|
|
14
17
|
var _useTeamContainers2 = require("../use-team-containers");
|
|
15
18
|
var _utils = require("./utils");
|
|
19
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
16
20
|
/**
|
|
17
21
|
* Hook to track and poll for requested product containers (such as a Jira Project).
|
|
18
22
|
* The initial list of requested containers is derived from the URL parameters, however it can be updated based on user interactions.
|
|
@@ -27,48 +31,198 @@ var _utils = require("./utils");
|
|
|
27
31
|
*/
|
|
28
32
|
function useRequestedContainers(_ref) {
|
|
29
33
|
var teamId = _ref.teamId,
|
|
34
|
+
cloudId = _ref.cloudId,
|
|
30
35
|
onRequestedContainerTimeout = _ref.onRequestedContainerTimeout;
|
|
31
36
|
var _useIntl = (0, _reactIntlNext.useIntl)(),
|
|
32
37
|
formatMessage = _useIntl.formatMessage;
|
|
33
38
|
var _useTeamContainers = (0, _useTeamContainers2.useTeamContainers)(teamId),
|
|
34
39
|
refetchTeamContainers = _useTeamContainers.refetchTeamContainers,
|
|
35
40
|
teamContainers = _useTeamContainers.teamContainers;
|
|
36
|
-
var _useState = (0, _react.useState)(
|
|
37
|
-
return (0, _utils.userCanAccessFeature)() ? (0, _utils.getRequestedContainersFromUrl)() : [];
|
|
38
|
-
}),
|
|
41
|
+
var _useState = (0, _react.useState)(false),
|
|
39
42
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
isTryingAgain = _useState2[0],
|
|
44
|
+
setIsTryingAgain = _useState2[1];
|
|
45
|
+
var tryAgainCountRef = (0, _react.useRef)(0);
|
|
46
|
+
var _useState3 = (0, _react.useState)(0),
|
|
47
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
48
|
+
refetchErrorCount = _useState4[0],
|
|
49
|
+
setRefetchErrorCount = _useState4[1];
|
|
50
|
+
var _useState5 = (0, _react.useState)(function () {
|
|
51
|
+
return (0, _utils.getRequestedContainersFromUrl)();
|
|
52
|
+
}),
|
|
53
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
54
|
+
requestedContainers = _useState6[0],
|
|
55
|
+
setRequestedContainers = _useState6[1];
|
|
42
56
|
var checkContainers = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
43
57
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
44
58
|
while (1) switch (_context.prev = _context.next) {
|
|
45
59
|
case 0:
|
|
46
|
-
_context.
|
|
60
|
+
_context.prev = 0;
|
|
61
|
+
_context.next = 3;
|
|
47
62
|
return refetchTeamContainers();
|
|
48
|
-
case
|
|
63
|
+
case 3:
|
|
64
|
+
_context.next = 8;
|
|
65
|
+
break;
|
|
66
|
+
case 5:
|
|
67
|
+
_context.prev = 5;
|
|
68
|
+
_context.t0 = _context["catch"](0);
|
|
69
|
+
setRefetchErrorCount(function (prev) {
|
|
70
|
+
return prev + 1;
|
|
71
|
+
});
|
|
72
|
+
case 8:
|
|
49
73
|
case "end":
|
|
50
74
|
return _context.stop();
|
|
51
75
|
}
|
|
52
|
-
}, _callee);
|
|
76
|
+
}, _callee, null, [[0, 5]]);
|
|
53
77
|
})), [refetchTeamContainers]);
|
|
54
|
-
var
|
|
78
|
+
var onTimeout = (0, _react.useCallback)(function (_ref3) {
|
|
79
|
+
var startPolling = _ref3.startPolling,
|
|
80
|
+
reset = _ref3.reset;
|
|
81
|
+
if (!onRequestedContainerTimeout) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
var flagId = "requested-container-timeout-".concat(requestedContainers.join('-'), "-").concat(tryAgainCountRef.current);
|
|
85
|
+
var createTryAgainFlag = function createTryAgainFlag(_ref4) {
|
|
86
|
+
var onAction = _ref4.onAction;
|
|
87
|
+
return {
|
|
88
|
+
id: flagId,
|
|
89
|
+
title: requestedContainers.length === 1 ? formatMessage(messages.timeoutTitle, {
|
|
90
|
+
container: (0, _utils.containerDisplayName)(requestedContainers[0])
|
|
91
|
+
}) : formatMessage(messages.timeoutTitleMultiple),
|
|
92
|
+
description: formatMessage(messages.timeoutDescription),
|
|
93
|
+
actions: [{
|
|
94
|
+
content: formatMessage(messages.timeoutAction),
|
|
95
|
+
onClick: function onClick() {
|
|
96
|
+
onAction(flagId);
|
|
97
|
+
_tryAgainAction();
|
|
98
|
+
}
|
|
99
|
+
}]
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
var createContactSupportFlag = function createContactSupportFlag(_ref5) {
|
|
103
|
+
var onAction = _ref5.onAction;
|
|
104
|
+
return {
|
|
105
|
+
id: flagId,
|
|
106
|
+
title: formatMessage(messages.noConnectionTitle),
|
|
107
|
+
description: formatMessage(messages.noConnectionDescription),
|
|
108
|
+
actions: [{
|
|
109
|
+
content: /*#__PURE__*/_react.default.createElement(_compiled.Flex, {
|
|
110
|
+
alignItems: "center",
|
|
111
|
+
columnGap: "space.100"
|
|
112
|
+
}, formatMessage(messages.noConnectionAction), /*#__PURE__*/_react.default.createElement(_linkExternal.default, {
|
|
113
|
+
label: ""
|
|
114
|
+
})),
|
|
115
|
+
onClick: function onClick() {
|
|
116
|
+
onAction(flagId);
|
|
117
|
+
},
|
|
118
|
+
href: 'https://support.atlassian.com/contact/#/&support_type=customer'
|
|
119
|
+
}]
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
var _tryAgainAction = /*#__PURE__*/function () {
|
|
123
|
+
var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
124
|
+
var containers, response, containersNotCreated;
|
|
125
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
126
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
setIsTryingAgain(true);
|
|
129
|
+
tryAgainCountRef.current = tryAgainCountRef.current + 1;
|
|
130
|
+
|
|
131
|
+
//todo: add analytics event here
|
|
132
|
+
containers = requestedContainers.map(function (container) {
|
|
133
|
+
return {
|
|
134
|
+
type: (0, _utils.convertContainerToType)(container),
|
|
135
|
+
containerSiteId: cloudId
|
|
136
|
+
};
|
|
137
|
+
}).filter(function (_ref7) {
|
|
138
|
+
var type = _ref7.type;
|
|
139
|
+
return Boolean(type);
|
|
140
|
+
});
|
|
141
|
+
_context2.prev = 3;
|
|
142
|
+
_context2.next = 6;
|
|
143
|
+
return _teamsClient.teamsClient.createTeamContainers({
|
|
144
|
+
teamId: teamId,
|
|
145
|
+
containers: containers
|
|
146
|
+
});
|
|
147
|
+
case 6:
|
|
148
|
+
response = _context2.sent;
|
|
149
|
+
containersNotCreated = requestedContainers.filter(function (containerType) {
|
|
150
|
+
var _response$containersC;
|
|
151
|
+
return !((_response$containersC = response.containersCreated) !== null && _response$containersC !== void 0 && _response$containersC.some(function (container) {
|
|
152
|
+
return container.containerType === (0, _utils.convertContainerToType)(containerType);
|
|
153
|
+
}));
|
|
154
|
+
}); //containers are still being created
|
|
155
|
+
if (!(containersNotCreated.length > 0)) {
|
|
156
|
+
_context2.next = 12;
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
startPolling();
|
|
160
|
+
_context2.next = 15;
|
|
161
|
+
break;
|
|
162
|
+
case 12:
|
|
163
|
+
//all containers created so reset and update state
|
|
164
|
+
reset();
|
|
165
|
+
_context2.next = 15;
|
|
166
|
+
return refetchTeamContainers();
|
|
167
|
+
case 15:
|
|
168
|
+
_context2.next = 24;
|
|
169
|
+
break;
|
|
170
|
+
case 17:
|
|
171
|
+
_context2.prev = 17;
|
|
172
|
+
_context2.t0 = _context2["catch"](3);
|
|
173
|
+
if (!(_context2.t0 instanceof _teamsClient.HttpError)) {
|
|
174
|
+
_context2.next = 23;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
if (!(_context2.t0.status === 500)) {
|
|
178
|
+
_context2.next = 23;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (!(tryAgainCountRef.current < 2)) {
|
|
182
|
+
_context2.next = 23;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
return _context2.abrupt("return", setTimeout(function () {
|
|
186
|
+
//bug: this can cause two flags to be shown
|
|
187
|
+
_tryAgainAction();
|
|
188
|
+
}, _utils.POLLING_INTERVAL));
|
|
189
|
+
case 23:
|
|
190
|
+
onRequestedContainerTimeout(createContactSupportFlag);
|
|
191
|
+
case 24:
|
|
192
|
+
_context2.prev = 24;
|
|
193
|
+
setIsTryingAgain(false);
|
|
194
|
+
return _context2.finish(24);
|
|
195
|
+
case 27:
|
|
196
|
+
case "end":
|
|
197
|
+
return _context2.stop();
|
|
198
|
+
}
|
|
199
|
+
}, _callee2, null, [[3, 17, 24, 27]]);
|
|
200
|
+
}));
|
|
201
|
+
return function tryAgainAction() {
|
|
202
|
+
return _ref6.apply(this, arguments);
|
|
203
|
+
};
|
|
204
|
+
}();
|
|
205
|
+
onRequestedContainerTimeout(tryAgainCountRef.current === 0 ? createTryAgainFlag : createContactSupportFlag);
|
|
206
|
+
}, [cloudId, formatMessage, onRequestedContainerTimeout, refetchTeamContainers, requestedContainers, teamId]);
|
|
207
|
+
var _useAsyncPolling = (0, _utils.useAsyncPolling)(checkContainers, {
|
|
208
|
+
onTimeout: onTimeout
|
|
209
|
+
}),
|
|
55
210
|
startPolling = _useAsyncPolling.startPolling,
|
|
56
211
|
stopPolling = _useAsyncPolling.stopPolling,
|
|
57
212
|
isPolling = _useAsyncPolling.isPolling,
|
|
58
213
|
hasTimedOut = _useAsyncPolling.hasTimedOut;
|
|
59
|
-
var checkForContainer = function checkForContainer(container) {
|
|
60
|
-
if (!requestedContainers.includes(container)) {
|
|
61
|
-
setRequestedContainers(function (prev) {
|
|
62
|
-
return [].concat((0, _toConsumableArray2.default)(prev), [container]);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
startPolling();
|
|
66
|
-
};
|
|
67
214
|
(0, _react.useEffect)(function () {
|
|
68
215
|
if (!(0, _utils.userCanAccessFeature)()) {
|
|
69
216
|
return;
|
|
70
217
|
}
|
|
71
|
-
|
|
218
|
+
|
|
219
|
+
//stop gap to prevent sending too many failed errors
|
|
220
|
+
if (refetchErrorCount > 3) {
|
|
221
|
+
stopPolling();
|
|
222
|
+
//todo: add analytics event here
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (hasTimedOut || isTryingAgain) {
|
|
72
226
|
return;
|
|
73
227
|
}
|
|
74
228
|
var containerCount = requestedContainers.length;
|
|
@@ -77,9 +231,10 @@ function useRequestedContainers(_ref) {
|
|
|
77
231
|
return;
|
|
78
232
|
}
|
|
79
233
|
if (!isPolling && containerCount > 0) {
|
|
234
|
+
setIsTryingAgain(false);
|
|
80
235
|
startPolling();
|
|
81
236
|
}
|
|
82
|
-
}, [isPolling, requestedContainers.length, hasTimedOut, startPolling, stopPolling]);
|
|
237
|
+
}, [isPolling, refetchErrorCount, requestedContainers.length, hasTimedOut, startPolling, stopPolling, isTryingAgain]);
|
|
83
238
|
(0, _react.useEffect)(function () {
|
|
84
239
|
var containersNotFound = requestedContainers.filter(function (containerType) {
|
|
85
240
|
return !teamContainers.some(function (teamContainer) {
|
|
@@ -90,36 +245,11 @@ function useRequestedContainers(_ref) {
|
|
|
90
245
|
setRequestedContainers(containersNotFound);
|
|
91
246
|
}
|
|
92
247
|
}, [requestedContainers, checkContainers, teamContainers]);
|
|
93
|
-
(0, _react.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// @todo: send request to retry creating containers
|
|
97
|
-
// This will be implemented in the next pull request
|
|
98
|
-
};
|
|
99
|
-
var flagId = "requested-container-timeout-".concat(requestedContainers.join('-'));
|
|
100
|
-
var _createFlag = function _createFlag(_ref3) {
|
|
101
|
-
var onAction = _ref3.onAction;
|
|
102
|
-
return {
|
|
103
|
-
id: flagId,
|
|
104
|
-
title: requestedContainers.length === 1 ? formatMessage(messages.timeoutTitle, {
|
|
105
|
-
container: (0, _utils.containerDisplayName)(requestedContainers[0])
|
|
106
|
-
}) : formatMessage(messages.timeoutTitleMultiple),
|
|
107
|
-
description: formatMessage(messages.timeoutDescription),
|
|
108
|
-
actions: [{
|
|
109
|
-
content: formatMessage(messages.timeoutAction),
|
|
110
|
-
onClick: function onClick() {
|
|
111
|
-
action();
|
|
112
|
-
onAction(flagId);
|
|
113
|
-
}
|
|
114
|
-
}]
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
onRequestedContainerTimeout(_createFlag);
|
|
118
|
-
}
|
|
119
|
-
}, [hasTimedOut, onRequestedContainerTimeout, requestedContainers, formatMessage]);
|
|
248
|
+
var containersLoading = (0, _react.useMemo)(function () {
|
|
249
|
+
return hasTimedOut && !isTryingAgain || refetchErrorCount > 3 ? [] : requestedContainers;
|
|
250
|
+
}, [hasTimedOut, requestedContainers, isTryingAgain, refetchErrorCount]);
|
|
120
251
|
return {
|
|
121
|
-
requestedContainers:
|
|
122
|
-
checkForContainer: checkForContainer
|
|
252
|
+
requestedContainers: containersLoading
|
|
123
253
|
};
|
|
124
254
|
}
|
|
125
255
|
var messages = (0, _reactIntlNext.defineMessages)({
|
|
@@ -134,7 +264,7 @@ var messages = (0, _reactIntlNext.defineMessages)({
|
|
|
134
264
|
description: 'Title for the timeout flag'
|
|
135
265
|
},
|
|
136
266
|
timeoutDescription: {
|
|
137
|
-
id: 'teams-public
|
|
267
|
+
id: 'teams-public.team-containers.timeout-description',
|
|
138
268
|
defaultMessage: 'Something went wrong. Verify your connection and retry.',
|
|
139
269
|
description: 'Description for the timeout flag'
|
|
140
270
|
},
|
|
@@ -142,5 +272,20 @@ var messages = (0, _reactIntlNext.defineMessages)({
|
|
|
142
272
|
id: 'teams-public.team-containers.timeout-action',
|
|
143
273
|
defaultMessage: 'Try again',
|
|
144
274
|
description: 'Action text for the timeout flag'
|
|
275
|
+
},
|
|
276
|
+
noConnectionTitle: {
|
|
277
|
+
id: 'teams-public.team-containers.timeout-no-connection-title',
|
|
278
|
+
defaultMessage: 'Connection failed',
|
|
279
|
+
description: 'Title for the no connection flag'
|
|
280
|
+
},
|
|
281
|
+
noConnectionDescription: {
|
|
282
|
+
id: 'teams-public.team-containers.timeout-no-connection-description',
|
|
283
|
+
defaultMessage: 'Try manually creating the space yourself.',
|
|
284
|
+
description: 'Description for the no connection flag'
|
|
285
|
+
},
|
|
286
|
+
noConnectionAction: {
|
|
287
|
+
id: 'teams-public.team-containers.timeout-no-connection-action',
|
|
288
|
+
defaultMessage: 'Contact support',
|
|
289
|
+
description: 'Action text for the no connection flag'
|
|
145
290
|
}
|
|
146
291
|
});
|
|
@@ -4,9 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.POLLING_INTERVAL = exports.POLLING_DURATION = void 0;
|
|
7
|
+
exports.POLLING_INTERVAL = exports.POLLING_DURATION = exports.CONTAINER_MAP = void 0;
|
|
8
8
|
exports.containerDisplayName = containerDisplayName;
|
|
9
9
|
exports.containersEqual = containersEqual;
|
|
10
|
+
exports.convertContainerToType = convertContainerToType;
|
|
10
11
|
exports.getRequestedContainersFromUrl = getRequestedContainersFromUrl;
|
|
11
12
|
exports.useAsyncPolling = useAsyncPolling;
|
|
12
13
|
exports.userCanAccessFeature = userCanAccessFeature;
|
|
@@ -19,7 +20,7 @@ var _react = require("react");
|
|
|
19
20
|
var _featureGateJsClient = _interopRequireDefault(require("@atlaskit/feature-gate-js-client"));
|
|
20
21
|
var _frontendUtilities = require("@atlaskit/frontend-utilities");
|
|
21
22
|
var _types = require("@atlaskit/teams-client/types");
|
|
22
|
-
var CONTAINER_MAP = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.ContainerType.CONFLUENCE_SPACE, 'ConfluenceSpace'), _types.ContainerType.JIRA_PROJECT, 'JiraProject'), _types.ContainerType.LOOM_SPACE, 'LoomSpace');
|
|
23
|
+
var CONTAINER_MAP = exports.CONTAINER_MAP = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.ContainerType.CONFLUENCE_SPACE, 'ConfluenceSpace'), _types.ContainerType.JIRA_PROJECT, 'JiraProject'), _types.ContainerType.LOOM_SPACE, 'LoomSpace');
|
|
23
24
|
var CONTAINER_HUMAN_NAMES = {
|
|
24
25
|
ConfluenceSpace: 'Confluence space',
|
|
25
26
|
JiraProject: 'Jira project',
|
|
@@ -32,15 +33,31 @@ function getRequestedContainersFromUrl() {
|
|
|
32
33
|
var _searchParams$get;
|
|
33
34
|
var searchParams = new URLSearchParams(window.location.search);
|
|
34
35
|
var values = ((_searchParams$get = searchParams.get('requestedContainers')) === null || _searchParams$get === void 0 ? void 0 : _searchParams$get.split(',').filter(Boolean)) || [];
|
|
35
|
-
|
|
36
|
+
var containers = values.filter(function (value) {
|
|
36
37
|
return Object.values(_types.ContainerType).includes(value);
|
|
37
38
|
}).map(function (value) {
|
|
38
39
|
return CONTAINER_MAP[value];
|
|
39
40
|
});
|
|
41
|
+
if (containers.length === 0) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return userCanAccessFeature() ? containers : [];
|
|
40
45
|
}
|
|
41
46
|
function containerDisplayName(container) {
|
|
42
47
|
return CONTAINER_HUMAN_NAMES[container];
|
|
43
48
|
}
|
|
49
|
+
function convertContainerToType(container) {
|
|
50
|
+
switch (container) {
|
|
51
|
+
case 'ConfluenceSpace':
|
|
52
|
+
return _types.ContainerType.CONFLUENCE_SPACE;
|
|
53
|
+
case 'JiraProject':
|
|
54
|
+
return _types.ContainerType.JIRA_PROJECT;
|
|
55
|
+
case 'LoomSpace':
|
|
56
|
+
return _types.ContainerType.LOOM_SPACE;
|
|
57
|
+
default:
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
44
61
|
function userCanAccessFeature() {
|
|
45
62
|
if (_featureGateJsClient.default.initializeCalled()) {
|
|
46
63
|
var value = _featureGateJsClient.default.getExperimentValue('teams_app_auto_container_creation', 'cohort', 'control');
|
|
@@ -60,9 +77,12 @@ var POLLING_DURATION = exports.POLLING_DURATION = 10000;
|
|
|
60
77
|
* Ensures only one callback is pending at a time.
|
|
61
78
|
*
|
|
62
79
|
* @param callback - The async function to poll.
|
|
80
|
+
* @param onTimeout - Optional callback to execute when polling times out.
|
|
63
81
|
* @returns An object with polling controls and state: startPolling, stopPolling, isPolling, hasTimedOut.
|
|
64
82
|
*/
|
|
65
83
|
function useAsyncPolling(callback) {
|
|
84
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
85
|
+
onTimeout = _ref.onTimeout;
|
|
66
86
|
var _useState = (0, _react.useState)(false),
|
|
67
87
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
68
88
|
hasTimedOut = _useState2[0],
|
|
@@ -85,6 +105,15 @@ function useAsyncPolling(callback) {
|
|
|
85
105
|
setHasTimedOut(false);
|
|
86
106
|
setIsPending(false);
|
|
87
107
|
}, []);
|
|
108
|
+
var reset = (0, _react.useCallback)(function () {
|
|
109
|
+
if (timeoutRef.current) {
|
|
110
|
+
clearTimeout(timeoutRef.current);
|
|
111
|
+
timeoutRef.current = null;
|
|
112
|
+
}
|
|
113
|
+
setHasTimedOut(false);
|
|
114
|
+
setIsPolling(false);
|
|
115
|
+
setIsPending(false);
|
|
116
|
+
}, []);
|
|
88
117
|
var startPolling = (0, _react.useCallback)(function () {
|
|
89
118
|
if (timeoutRef.current) {
|
|
90
119
|
clearTimeout(timeoutRef.current);
|
|
@@ -96,8 +125,15 @@ function useAsyncPolling(callback) {
|
|
|
96
125
|
timeoutRef.current = setTimeout(function () {
|
|
97
126
|
stopPolling();
|
|
98
127
|
setHasTimedOut(true);
|
|
128
|
+
if (onTimeout) {
|
|
129
|
+
onTimeout({
|
|
130
|
+
startPolling: startPolling,
|
|
131
|
+
stopPolling: stopPolling,
|
|
132
|
+
reset: reset
|
|
133
|
+
});
|
|
134
|
+
}
|
|
99
135
|
}, POLLING_DURATION);
|
|
100
|
-
}, [stopPolling]);
|
|
136
|
+
}, [stopPolling, onTimeout, reset]);
|
|
101
137
|
var wrappedCallback = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
102
138
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
103
139
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -124,6 +160,7 @@ function useAsyncPolling(callback) {
|
|
|
124
160
|
})), [callback, isPending]);
|
|
125
161
|
(0, _frontendUtilities.useInterval)(isPolling ? wrappedCallback : function () {}, isPolling ? POLLING_INTERVAL : null);
|
|
126
162
|
return {
|
|
163
|
+
reset: reset,
|
|
127
164
|
startPolling: startPolling,
|
|
128
165
|
stopPolling: stopPolling,
|
|
129
166
|
isPolling: isPolling,
|
|
@@ -428,14 +428,23 @@ var useTeamContainers = exports.useTeamContainers = function useTeamContainers(t
|
|
|
428
428
|
actions.fetchTeamContainers(teamId, fireOperationalAnalytics);
|
|
429
429
|
}
|
|
430
430
|
}, [teamId, actions, enable, fireOperationalAnalytics]);
|
|
431
|
+
var refetchTeamContainers = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7() {
|
|
432
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
433
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
434
|
+
case 0:
|
|
435
|
+
return _context7.abrupt("return", actions.refetchTeamContainers(fireOperationalAnalytics));
|
|
436
|
+
case 1:
|
|
437
|
+
case "end":
|
|
438
|
+
return _context7.stop();
|
|
439
|
+
}
|
|
440
|
+
}, _callee7);
|
|
441
|
+
})), [actions, fireOperationalAnalytics]);
|
|
431
442
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
432
443
|
addTeamContainer: actions.addTeamContainer,
|
|
433
444
|
unlinkTeamContainers: function unlinkTeamContainers(containerId) {
|
|
434
445
|
return actions.unlinkTeamContainers(teamId, containerId);
|
|
435
446
|
},
|
|
436
|
-
refetchTeamContainers:
|
|
437
|
-
return actions.refetchTeamContainers(fireOperationalAnalytics);
|
|
438
|
-
}
|
|
447
|
+
refetchTeamContainers: refetchTeamContainers
|
|
439
448
|
});
|
|
440
449
|
};
|
|
441
450
|
var useConnectedTeams = exports.useConnectedTeams = function useConnectedTeams() {
|
|
@@ -447,12 +456,12 @@ var useConnectedTeams = exports.useConnectedTeams = function useConnectedTeams()
|
|
|
447
456
|
fireOperationalEvent = _usePeopleAndTeamAnal2.fireOperationalEvent;
|
|
448
457
|
var _useAnalyticsEvents2 = (0, _analyticsNext.useAnalyticsEvents)(),
|
|
449
458
|
createAnalyticsEvent = _useAnalyticsEvents2.createAnalyticsEvent;
|
|
450
|
-
var fireOperationalAnalytics = (0, _react.useCallback)(function (
|
|
451
|
-
var action =
|
|
452
|
-
actionSubject =
|
|
453
|
-
containerId =
|
|
454
|
-
numberOfTeams =
|
|
455
|
-
error =
|
|
459
|
+
var fireOperationalAnalytics = (0, _react.useCallback)(function (_ref12) {
|
|
460
|
+
var action = _ref12.action,
|
|
461
|
+
actionSubject = _ref12.actionSubject,
|
|
462
|
+
containerId = _ref12.containerId,
|
|
463
|
+
numberOfTeams = _ref12.numberOfTeams,
|
|
464
|
+
error = _ref12.error;
|
|
456
465
|
fireOperationalEvent(createAnalyticsEvent, {
|
|
457
466
|
action: action,
|
|
458
467
|
actionSubject: actionSubject,
|
|
@@ -63,6 +63,7 @@ var TeamContainers = exports.TeamContainers = function TeamContainers(_ref) {
|
|
|
63
63
|
iconHasLoaded = _useTeamLinksAndConta.iconHasLoaded;
|
|
64
64
|
var _useRequestedContaine = (0, _useRequestedContainer.useRequestedContainers)({
|
|
65
65
|
teamId: teamId,
|
|
66
|
+
cloudId: cloudId,
|
|
66
67
|
onRequestedContainerTimeout: onRequestedContainerTimeout
|
|
67
68
|
}),
|
|
68
69
|
requestedContainers = _useRequestedContaine.requestedContainers;
|