@atlaskit/teams-public 0.70.5 → 0.70.7

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/common/ui/container-icon/index.compiled.css +0 -14
  3. package/dist/cjs/common/ui/container-icon/index.js +23 -55
  4. package/dist/cjs/common/ui/loom-avatar/main.js +1 -1
  5. package/dist/cjs/common/ui/separator/index.js +1 -1
  6. package/dist/cjs/common/ui/team-containers-skeleton/index.js +1 -1
  7. package/dist/cjs/common/ui/team-containers-skeleton/linked-container-card-skeleton/index.js +1 -1
  8. package/dist/cjs/common/ui/team-link-card-actions/index.js +1 -1
  9. package/dist/cjs/common/utils/get-container-properties.js +1 -1
  10. package/dist/cjs/next/common/ui/team-container-skeleton/index.js +1 -1
  11. package/dist/cjs/next/ui/team-containers/add-container-card/index.js +1 -1
  12. package/dist/cjs/next/ui/team-containers/team-link-card/index.js +1 -1
  13. package/dist/cjs/ui/team-containers/add-container-card/index.js +1 -1
  14. package/dist/cjs/ui/team-containers/linked-container-card/index.js +1 -1
  15. package/dist/cjs/ui/team-containers/main.js +7 -16
  16. package/dist/cjs/ui/team-containers/no-product-access-empty-state/index.js +1 -1
  17. package/dist/cjs/ui/team-containers/no-product-access-empty-state/no-product-access-icon/index.js +1 -1
  18. package/dist/cjs/ui/team-containers/team-link-card/index.js +4 -18
  19. package/dist/cjs/ui/team-containers/team-link-card/team-link-card-title.js +1 -1
  20. package/dist/es2019/common/ui/container-icon/index.compiled.css +0 -14
  21. package/dist/es2019/common/ui/container-icon/index.js +16 -47
  22. package/dist/es2019/common/ui/loom-avatar/main.js +1 -1
  23. package/dist/es2019/common/ui/separator/index.js +1 -1
  24. package/dist/es2019/common/ui/team-containers-skeleton/index.js +1 -1
  25. package/dist/es2019/common/ui/team-containers-skeleton/linked-container-card-skeleton/index.js +1 -1
  26. package/dist/es2019/common/ui/team-link-card-actions/index.js +1 -1
  27. package/dist/es2019/common/utils/get-container-properties.js +1 -1
  28. package/dist/es2019/next/common/ui/team-container-skeleton/index.js +1 -1
  29. package/dist/es2019/next/ui/team-containers/add-container-card/index.js +1 -1
  30. package/dist/es2019/next/ui/team-containers/team-link-card/index.js +1 -1
  31. package/dist/es2019/ui/team-containers/add-container-card/index.js +1 -1
  32. package/dist/es2019/ui/team-containers/linked-container-card/index.js +1 -1
  33. package/dist/es2019/ui/team-containers/main.js +7 -16
  34. package/dist/es2019/ui/team-containers/no-product-access-empty-state/index.js +1 -1
  35. package/dist/es2019/ui/team-containers/no-product-access-empty-state/no-product-access-icon/index.js +1 -1
  36. package/dist/es2019/ui/team-containers/team-link-card/index.js +4 -18
  37. package/dist/es2019/ui/team-containers/team-link-card/team-link-card-title.js +1 -1
  38. package/dist/esm/common/ui/container-icon/index.compiled.css +0 -14
  39. package/dist/esm/common/ui/container-icon/index.js +23 -55
  40. package/dist/esm/common/ui/loom-avatar/main.js +1 -1
  41. package/dist/esm/common/ui/separator/index.js +1 -1
  42. package/dist/esm/common/ui/team-containers-skeleton/index.js +1 -1
  43. package/dist/esm/common/ui/team-containers-skeleton/linked-container-card-skeleton/index.js +1 -1
  44. package/dist/esm/common/ui/team-link-card-actions/index.js +1 -1
  45. package/dist/esm/common/utils/get-container-properties.js +1 -1
  46. package/dist/esm/next/common/ui/team-container-skeleton/index.js +1 -1
  47. package/dist/esm/next/ui/team-containers/add-container-card/index.js +1 -1
  48. package/dist/esm/next/ui/team-containers/team-link-card/index.js +1 -1
  49. package/dist/esm/ui/team-containers/add-container-card/index.js +1 -1
  50. package/dist/esm/ui/team-containers/linked-container-card/index.js +1 -1
  51. package/dist/esm/ui/team-containers/main.js +7 -16
  52. package/dist/esm/ui/team-containers/no-product-access-empty-state/index.js +1 -1
  53. package/dist/esm/ui/team-containers/no-product-access-empty-state/no-product-access-icon/index.js +1 -1
  54. package/dist/esm/ui/team-containers/team-link-card/index.js +4 -18
  55. package/dist/esm/ui/team-containers/team-link-card/team-link-card-title.js +1 -1
  56. package/dist/types/common/ui/container-icon/index.d.ts +1 -1
  57. package/dist/types/ui/team-containers/main.d.ts +1 -1
  58. package/dist/types/ui/team-containers/types.d.ts +0 -5
  59. package/dist/types-ts4.5/common/ui/container-icon/index.d.ts +1 -1
  60. package/dist/types-ts4.5/ui/team-containers/main.d.ts +1 -1
  61. package/dist/types-ts4.5/ui/team-containers/types.d.ts +0 -5
  62. package/package.json +1 -7
  63. package/dist/cjs/controllers/hooks/use-requested-container/index.js +0 -358
  64. package/dist/cjs/controllers/hooks/use-requested-container/utils.js +0 -165
  65. package/dist/es2019/controllers/hooks/use-requested-container/index.js +0 -288
  66. package/dist/es2019/controllers/hooks/use-requested-container/utils.js +0 -126
  67. package/dist/esm/controllers/hooks/use-requested-container/index.js +0 -350
  68. package/dist/esm/controllers/hooks/use-requested-container/utils.js +0 -153
  69. package/dist/types/controllers/hooks/use-requested-container/index.d.ts +0 -25
  70. package/dist/types/controllers/hooks/use-requested-container/utils.d.ts +0 -34
  71. package/dist/types-ts4.5/controllers/hooks/use-requested-container/index.d.ts +0 -25
  72. package/dist/types-ts4.5/controllers/hooks/use-requested-container/utils.d.ts +0 -34
@@ -1,350 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
5
- import { defineMessages, useIntl } from 'react-intl-next';
6
- import { useAnalyticsEvents as useAnalyticsEventsDEPRECATED } from '@atlaskit/analytics-next';
7
- import LinkExternalIcon from '@atlaskit/icon/core/link-external';
8
- import { fg } from '@atlaskit/platform-feature-flags';
9
- import { Flex } from '@atlaskit/primitives/compiled';
10
- import { useAnalyticsEvents } from '@atlaskit/teams-app-internal-analytics';
11
- import { HttpError, teamsClient } from '@atlaskit/teams-client';
12
- import { usePeopleAndTeamAnalytics } from '../../../common/utils/analytics';
13
- import { useTeamContainers } from '../use-team-containers';
14
- import { containerDisplayName, containersEqual, convertContainerToType, getRequestedContainersFromUrl, POLLING_INTERVAL, removeRequestedContainersFromUrl, useAsyncPolling } from './utils';
15
- /**
16
- * Hook to track and poll for requested product containers (such as a Jira Project).
17
- * The initial list of requested containers is derived from the URL parameters, however it can be updated based on user interactions.
18
- *
19
- * Manages a list of requested containers, polls for updates, and removes found containers from the list.
20
- *
21
- * Supported container types: CONFLUENCE_SPACE, JIRA_PROJECT, LOOM_SPACE.
22
- *
23
- * @param teamId - The ID of the team whose containers are being tracked.
24
- * @param onRequestedContainerTimeout - Optional callback to handle timeout events for requested containers.
25
- * @returns The current list of requested containers and a function to add a container.
26
- */
27
- function useRequestedContainers(_ref) {
28
- var teamId = _ref.teamId,
29
- cloudId = _ref.cloudId,
30
- onRequestedContainerTimeout = _ref.onRequestedContainerTimeout;
31
- var _useIntl = useIntl(),
32
- formatMessage = _useIntl.formatMessage;
33
- var _useTeamContainers = useTeamContainers(teamId),
34
- refetchTeamContainers = _useTeamContainers.refetchTeamContainers,
35
- teamContainers = _useTeamContainers.teamContainers;
36
- var _useState = useState(false),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- isTryingAgain = _useState2[0],
39
- setIsTryingAgain = _useState2[1];
40
- var tryAgainCountRef = useRef(0);
41
- var _useState3 = useState(0),
42
- _useState4 = _slicedToArray(_useState3, 2),
43
- refetchErrorCount = _useState4[0],
44
- setRefetchErrorCount = _useState4[1];
45
- var _usePeopleAndTeamAnal = usePeopleAndTeamAnalytics(),
46
- fireTrackEvent = _usePeopleAndTeamAnal.fireTrackEvent;
47
- var _useAnalyticsEventsDE = useAnalyticsEventsDEPRECATED(),
48
- createAnalyticsEvent = _useAnalyticsEventsDE.createAnalyticsEvent;
49
- var _useAnalyticsEvents = useAnalyticsEvents(),
50
- fireEvent = _useAnalyticsEvents.fireEvent;
51
- var _useState5 = useState([]),
52
- _useState6 = _slicedToArray(_useState5, 2),
53
- requestedContainers = _useState6[0],
54
- setRequestedContainers = _useState6[1];
55
- var requestedContainersRef = useRef([]);
56
- var checkContainers = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
57
- return _regeneratorRuntime.wrap(function _callee$(_context) {
58
- while (1) switch (_context.prev = _context.next) {
59
- case 0:
60
- _context.prev = 0;
61
- _context.next = 3;
62
- return refetchTeamContainers();
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:
73
- case "end":
74
- return _context.stop();
75
- }
76
- }, _callee, null, [[0, 5]]);
77
- })), [refetchTeamContainers]);
78
- var onTimeout = useCallback(function (_ref3) {
79
- var startPolling = _ref3.startPolling,
80
- reset = _ref3.reset;
81
- if (!onRequestedContainerTimeout) {
82
- return;
83
- }
84
- var reqContainers = requestedContainersRef.current;
85
- var flagId = "requested-container-timeout-".concat(reqContainers.join('-'), "-").concat(tryAgainCountRef.current);
86
- var createTryAgainFlag = function createTryAgainFlag(_ref4) {
87
- var onAction = _ref4.onAction;
88
- return {
89
- id: flagId,
90
- title: reqContainers.length === 1 ? formatMessage(messages.timeoutTitle, {
91
- container: containerDisplayName(reqContainers[0])
92
- }) : formatMessage(messages.timeoutTitleMultiple),
93
- description: formatMessage(messages.timeoutDescription),
94
- appearance: 'error',
95
- type: 'error',
96
- actions: [{
97
- content: formatMessage(messages.timeoutAction),
98
- onClick: function onClick() {
99
- onAction(flagId);
100
- _tryAgainAction();
101
- }
102
- }]
103
- };
104
- };
105
- var createContactSupportFlag = function createContactSupportFlag(_ref5) {
106
- var onAction = _ref5.onAction;
107
- return {
108
- id: flagId,
109
- title: formatMessage(messages.noConnectionTitle),
110
- description: formatMessage(messages.noConnectionDescription),
111
- appearance: 'error',
112
- type: 'error',
113
- actions: [{
114
- content: /*#__PURE__*/React.createElement(Flex, {
115
- alignItems: "center",
116
- columnGap: "space.100"
117
- }, formatMessage(messages.noConnectionAction), /*#__PURE__*/React.createElement(LinkExternalIcon, {
118
- label: ""
119
- })),
120
- onClick: function onClick() {
121
- onAction(flagId);
122
- },
123
- href: 'https://support.atlassian.com/contact/#/&support_type=customer'
124
- }]
125
- };
126
- };
127
- var _tryAgainAction = /*#__PURE__*/function () {
128
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
129
- var containers, response, containersNotCreated;
130
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
131
- while (1) switch (_context2.prev = _context2.next) {
132
- case 0:
133
- setIsTryingAgain(true);
134
- tryAgainCountRef.current = tryAgainCountRef.current + 1;
135
- containers = reqContainers.map(function (container) {
136
- return {
137
- type: convertContainerToType(container),
138
- containerSiteId: cloudId
139
- };
140
- }).filter(function (_ref7) {
141
- var type = _ref7.type;
142
- return Boolean(type);
143
- });
144
- if (fg('ptc-missed-analytics-migration-events')) {
145
- fireEvent('track.requestedContainers.tryAgain', {
146
- containers: reqContainers,
147
- teamId: teamId
148
- });
149
- } else {
150
- fireTrackEvent(createAnalyticsEvent, {
151
- action: 'tryAgain',
152
- actionSubject: 'requestedContainers',
153
- // @ts-ignore
154
- attributes: {
155
- containers: reqContainers,
156
- teamId: teamId
157
- }
158
- });
159
- }
160
- _context2.prev = 4;
161
- _context2.next = 7;
162
- return teamsClient.createTeamContainers({
163
- teamId: teamId,
164
- containers: containers
165
- });
166
- case 7:
167
- response = _context2.sent;
168
- containersNotCreated = reqContainers.filter(function (containerType) {
169
- var _response$containersC;
170
- return !((_response$containersC = response.containersCreated) !== null && _response$containersC !== void 0 && _response$containersC.some(function (container) {
171
- return container.containerType === convertContainerToType(containerType);
172
- }));
173
- }); //containers are still being created
174
- if (!(containersNotCreated.length > 0)) {
175
- _context2.next = 13;
176
- break;
177
- }
178
- startPolling();
179
- _context2.next = 16;
180
- break;
181
- case 13:
182
- //all containers created so reset and update state
183
- reset();
184
- _context2.next = 16;
185
- return refetchTeamContainers();
186
- case 16:
187
- _context2.next = 25;
188
- break;
189
- case 18:
190
- _context2.prev = 18;
191
- _context2.t0 = _context2["catch"](4);
192
- if (!(_context2.t0 instanceof HttpError)) {
193
- _context2.next = 24;
194
- break;
195
- }
196
- if (!(_context2.t0.status === 500)) {
197
- _context2.next = 24;
198
- break;
199
- }
200
- if (!(tryAgainCountRef.current <= 2)) {
201
- _context2.next = 24;
202
- break;
203
- }
204
- return _context2.abrupt("return", setTimeout(function () {
205
- //bug: this can cause two flags to be shown
206
- _tryAgainAction();
207
- }, POLLING_INTERVAL));
208
- case 24:
209
- onRequestedContainerTimeout(createContactSupportFlag);
210
- case 25:
211
- _context2.prev = 25;
212
- setIsTryingAgain(false);
213
- return _context2.finish(25);
214
- case 28:
215
- case "end":
216
- return _context2.stop();
217
- }
218
- }, _callee2, null, [[4, 18, 25, 28]]);
219
- }));
220
- return function tryAgainAction() {
221
- return _ref6.apply(this, arguments);
222
- };
223
- }();
224
- if (fg('ptc-missed-analytics-migration-events')) {
225
- fireEvent('track.requestedContainers.failed', {
226
- containers: reqContainers,
227
- teamId: teamId,
228
- tryAgainCount: tryAgainCountRef.current
229
- });
230
- } else {
231
- fireTrackEvent(createAnalyticsEvent, {
232
- action: 'failed',
233
- actionSubject: 'requestedContainers',
234
- attributes: {
235
- // @ts-ignore
236
- containers: reqContainers,
237
- teamId: teamId,
238
- tryAgainCount: tryAgainCountRef.current
239
- }
240
- });
241
- }
242
- removeRequestedContainersFromUrl();
243
- onRequestedContainerTimeout(tryAgainCountRef.current === 0 ? createTryAgainFlag : createContactSupportFlag);
244
- }, [cloudId, formatMessage, onRequestedContainerTimeout, refetchTeamContainers, teamId, createAnalyticsEvent, fireTrackEvent, fireEvent]);
245
- var _useAsyncPolling = useAsyncPolling(checkContainers, {
246
- onTimeout: onTimeout
247
- }),
248
- startPolling = _useAsyncPolling.startPolling,
249
- stopPolling = _useAsyncPolling.stopPolling,
250
- isPolling = _useAsyncPolling.isPolling,
251
- hasTimedOut = _useAsyncPolling.hasTimedOut;
252
- useEffect(function () {
253
- var containers = getRequestedContainersFromUrl();
254
- if (containers.length > 0 && isPolling === false) {
255
- setRequestedContainers(containers);
256
- startPolling();
257
- }
258
- // eslint-disable-next-line react-hooks/exhaustive-deps
259
- }, []);
260
- useEffect(function () {
261
- requestedContainersRef.current = requestedContainers;
262
- }, [requestedContainers]);
263
- useEffect(function () {
264
- //stop gap to prevent sending too many failed errors
265
- if (refetchErrorCount > 3) {
266
- stopPolling();
267
- if (fg('ptc-missed-analytics-migration-events')) {
268
- fireEvent('track.requestedContainers.failed', {
269
- containers: requestedContainers,
270
- teamId: teamId,
271
- tryAgainCount: null
272
- });
273
- } else {
274
- fireTrackEvent(createAnalyticsEvent, {
275
- action: 'failed',
276
- actionSubject: 'requestedContainers',
277
- attributes: {
278
- // @ts-ignore
279
- containers: requestedContainers,
280
- teamId: teamId
281
- }
282
- });
283
- }
284
- return;
285
- }
286
- if (hasTimedOut || isTryingAgain) {
287
- return;
288
- }
289
- var containerCount = requestedContainers.length;
290
- if (isPolling && containerCount === 0) {
291
- removeRequestedContainersFromUrl();
292
- stopPolling();
293
- return;
294
- }
295
- }, [isPolling, refetchErrorCount, requestedContainers, hasTimedOut, startPolling, stopPolling, isTryingAgain, teamId, createAnalyticsEvent, fireTrackEvent, fireEvent]);
296
- useEffect(function () {
297
- var containersNotFound = requestedContainers.filter(function (containerType) {
298
- return !teamContainers.some(function (teamContainer) {
299
- return teamContainer.type === containerType;
300
- });
301
- });
302
- if (!containersEqual(containersNotFound, requestedContainers)) {
303
- setRequestedContainers(containersNotFound);
304
- }
305
- }, [requestedContainers, checkContainers, teamContainers, isPolling]);
306
- var containersLoading = useMemo(function () {
307
- return hasTimedOut && !isTryingAgain || refetchErrorCount > 3 ? [] : requestedContainers;
308
- }, [hasTimedOut, requestedContainers, isTryingAgain, refetchErrorCount]);
309
- return {
310
- requestedContainers: containersLoading
311
- };
312
- }
313
- var messages = defineMessages({
314
- timeoutTitle: {
315
- id: 'teams-public.team-containers.timeout-title',
316
- defaultMessage: 'We’re couldn’t connect your {container}',
317
- description: 'Title for the timeout flag'
318
- },
319
- timeoutTitleMultiple: {
320
- id: 'teams-public.team-containers.timeout-title',
321
- defaultMessage: 'We’re couldn’t connect your spaces',
322
- description: 'Title for the timeout flag'
323
- },
324
- timeoutDescription: {
325
- id: 'teams-public.team-containers.timeout-description',
326
- defaultMessage: 'Something went wrong. Verify your connection and retry.',
327
- description: 'Description for the timeout flag'
328
- },
329
- timeoutAction: {
330
- id: 'teams-public.team-containers.timeout-action',
331
- defaultMessage: 'Try again',
332
- description: 'Action text for the timeout flag'
333
- },
334
- noConnectionTitle: {
335
- id: 'teams-public.team-containers.timeout-no-connection-title',
336
- defaultMessage: 'Connection failed',
337
- description: 'Title for the no connection flag'
338
- },
339
- noConnectionDescription: {
340
- id: 'teams-public.team-containers.timeout-no-connection-description',
341
- defaultMessage: 'Try manually creating the space yourself.',
342
- description: 'Description for the no connection flag'
343
- },
344
- noConnectionAction: {
345
- id: 'teams-public.team-containers.timeout-no-connection-action',
346
- defaultMessage: 'Contact support',
347
- description: 'Action text for the no connection flag'
348
- }
349
- });
350
- export { useRequestedContainers };
@@ -1,153 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
- import _regeneratorRuntime from "@babel/runtime/regenerator";
6
- import { useCallback, useRef, useState } from 'react';
7
- import { useInterval } from '@atlaskit/frontend-utilities';
8
- import { ContainerType } from '@atlaskit/teams-client/types';
9
- var CONTAINER_MAP = _defineProperty(_defineProperty(_defineProperty({}, ContainerType.CONFLUENCE_SPACE, 'ConfluenceSpace'), ContainerType.JIRA_PROJECT, 'JiraProject'), ContainerType.LOOM_SPACE, 'LoomSpace');
10
- var CONTAINER_HUMAN_NAMES = {
11
- ConfluenceSpace: 'Confluence space',
12
- JiraProject: 'Jira project',
13
- LoomSpace: 'Loom space'
14
- };
15
- var SEARCH_PARAM_NAME = 'requestedContainers';
16
- function containersEqual(arr1, arr2) {
17
- return JSON.stringify(_toConsumableArray(arr1).sort()) === JSON.stringify(_toConsumableArray(arr2).sort());
18
- }
19
- function getRequestedContainersFromUrl() {
20
- var _searchParams$get;
21
- var searchParams = new URLSearchParams(window.location.search);
22
- var values = ((_searchParams$get = searchParams.get(SEARCH_PARAM_NAME)) === null || _searchParams$get === void 0 ? void 0 : _searchParams$get.split(',').filter(Boolean)) || [];
23
- var containers = values.filter(function (value) {
24
- return Object.values(ContainerType).includes(value);
25
- }).map(function (value) {
26
- return CONTAINER_MAP[value];
27
- });
28
- if (containers.length === 0) {
29
- return [];
30
- }
31
- return containers || [];
32
- }
33
- function removeRequestedContainersFromUrl() {
34
- var searchParams = new URLSearchParams(window.location.search);
35
- searchParams.delete(SEARCH_PARAM_NAME);
36
- window.history.replaceState({}, '', "".concat(window.location.pathname, "?").concat(searchParams.toString()));
37
- }
38
- function containerDisplayName(container) {
39
- return CONTAINER_HUMAN_NAMES[container];
40
- }
41
- function convertContainerToType(container) {
42
- switch (container) {
43
- case 'ConfluenceSpace':
44
- return ContainerType.CONFLUENCE_SPACE;
45
- case 'JiraProject':
46
- return ContainerType.JIRA_PROJECT;
47
- case 'LoomSpace':
48
- return ContainerType.LOOM_SPACE;
49
- default:
50
- return null;
51
- }
52
- }
53
- var POLLING_INTERVAL = 1000;
54
- var POLLING_DURATION = 15000;
55
-
56
- /**
57
- * Hook for polling an async callback at a fixed interval, with timeout and pending state management.
58
- *
59
- * Starts polling the provided callback and stops after a set duration or when stopped manually.
60
- * Ensures only one callback is pending at a time.
61
- *
62
- * @param callback - The async function to poll.
63
- * @param onTimeout - Optional callback to execute when polling times out.
64
- * @returns An object with polling controls and state: startPolling, stopPolling, isPolling, hasTimedOut.
65
- */
66
- function useAsyncPolling(callback) {
67
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
68
- onTimeout = _ref.onTimeout;
69
- var _useState = useState(false),
70
- _useState2 = _slicedToArray(_useState, 2),
71
- hasTimedOut = _useState2[0],
72
- setHasTimedOut = _useState2[1];
73
- var timeoutRef = useRef(null);
74
- var _useState3 = useState(false),
75
- _useState4 = _slicedToArray(_useState3, 2),
76
- isPolling = _useState4[0],
77
- setIsPolling = _useState4[1];
78
- var _useState5 = useState(false),
79
- _useState6 = _slicedToArray(_useState5, 2),
80
- isPending = _useState6[0],
81
- setIsPending = _useState6[1];
82
- var stopPolling = useCallback(function () {
83
- if (timeoutRef.current) {
84
- clearTimeout(timeoutRef.current);
85
- timeoutRef.current = null;
86
- }
87
- setIsPolling(false);
88
- setHasTimedOut(false);
89
- setIsPending(false);
90
- }, []);
91
- var reset = useCallback(function () {
92
- if (timeoutRef.current) {
93
- clearTimeout(timeoutRef.current);
94
- timeoutRef.current = null;
95
- }
96
- setHasTimedOut(false);
97
- setIsPolling(false);
98
- setIsPending(false);
99
- }, []);
100
- var startPolling = useCallback(function () {
101
- if (timeoutRef.current) {
102
- clearTimeout(timeoutRef.current);
103
- timeoutRef.current = null;
104
- }
105
- setHasTimedOut(false);
106
- setIsPolling(true);
107
- setIsPending(false);
108
- timeoutRef.current = setTimeout(function () {
109
- stopPolling();
110
- setHasTimedOut(true);
111
- if (onTimeout) {
112
- onTimeout({
113
- startPolling: startPolling,
114
- stopPolling: stopPolling,
115
- reset: reset
116
- });
117
- }
118
- }, POLLING_DURATION);
119
- }, [stopPolling, onTimeout, reset]);
120
- var wrappedCallback = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
121
- return _regeneratorRuntime.wrap(function _callee$(_context) {
122
- while (1) switch (_context.prev = _context.next) {
123
- case 0:
124
- if (!isPending) {
125
- _context.next = 2;
126
- break;
127
- }
128
- return _context.abrupt("return");
129
- case 2:
130
- setIsPending(true);
131
- _context.prev = 3;
132
- _context.next = 6;
133
- return callback();
134
- case 6:
135
- _context.prev = 6;
136
- setIsPending(false);
137
- return _context.finish(6);
138
- case 9:
139
- case "end":
140
- return _context.stop();
141
- }
142
- }, _callee, null, [[3,, 6, 9]]);
143
- })), [callback, isPending]);
144
- useInterval(isPolling ? wrappedCallback : function () {}, isPolling ? POLLING_INTERVAL : null);
145
- return {
146
- reset: reset,
147
- startPolling: startPolling,
148
- stopPolling: stopPolling,
149
- isPolling: isPolling,
150
- hasTimedOut: hasTimedOut
151
- };
152
- }
153
- export { useAsyncPolling, POLLING_INTERVAL, POLLING_DURATION, containersEqual, getRequestedContainersFromUrl, containerDisplayName, CONTAINER_MAP, convertContainerToType, removeRequestedContainersFromUrl };
@@ -1,25 +0,0 @@
1
- import { type FlagProps } from '@atlaskit/flag';
2
- import { type ContainerTypes } from '../../../common/types';
3
- type OnRequestedContainerTimeout = (createFlag: ({ onAction }: {
4
- onAction: (flagId: string) => void;
5
- }) => FlagProps) => void;
6
- /**
7
- * Hook to track and poll for requested product containers (such as a Jira Project).
8
- * The initial list of requested containers is derived from the URL parameters, however it can be updated based on user interactions.
9
- *
10
- * Manages a list of requested containers, polls for updates, and removes found containers from the list.
11
- *
12
- * Supported container types: CONFLUENCE_SPACE, JIRA_PROJECT, LOOM_SPACE.
13
- *
14
- * @param teamId - The ID of the team whose containers are being tracked.
15
- * @param onRequestedContainerTimeout - Optional callback to handle timeout events for requested containers.
16
- * @returns The current list of requested containers and a function to add a container.
17
- */
18
- declare function useRequestedContainers({ teamId, cloudId, onRequestedContainerTimeout, }: {
19
- teamId: string;
20
- cloudId: string;
21
- onRequestedContainerTimeout?: OnRequestedContainerTimeout;
22
- }): {
23
- requestedContainers: ContainerTypes[];
24
- };
25
- export { useRequestedContainers, type OnRequestedContainerTimeout };
@@ -1,34 +0,0 @@
1
- import { ContainerType } from '@atlaskit/teams-client/types';
2
- import { type ContainerTypes } from '../../../common/types';
3
- declare const CONTAINER_MAP: Record<ContainerType, ContainerTypes>;
4
- declare function containersEqual<T>(arr1: T[], arr2: T[]): boolean;
5
- declare function getRequestedContainersFromUrl(): ContainerTypes[];
6
- declare function removeRequestedContainersFromUrl(): void;
7
- declare function containerDisplayName(container: ContainerTypes): string;
8
- declare function convertContainerToType(container: ContainerTypes): ContainerType | null;
9
- declare let POLLING_INTERVAL: number;
10
- declare let POLLING_DURATION: number;
11
- /**
12
- * Hook for polling an async callback at a fixed interval, with timeout and pending state management.
13
- *
14
- * Starts polling the provided callback and stops after a set duration or when stopped manually.
15
- * Ensures only one callback is pending at a time.
16
- *
17
- * @param callback - The async function to poll.
18
- * @param onTimeout - Optional callback to execute when polling times out.
19
- * @returns An object with polling controls and state: startPolling, stopPolling, isPolling, hasTimedOut.
20
- */
21
- declare function useAsyncPolling(callback: () => Promise<void> | void, { onTimeout, }?: {
22
- onTimeout?: ({ startPolling, stopPolling, reset, }: {
23
- startPolling: () => void;
24
- stopPolling: () => void;
25
- reset: () => void;
26
- }) => void;
27
- }): {
28
- reset: () => void;
29
- startPolling: () => void;
30
- stopPolling: () => void;
31
- isPolling: boolean;
32
- hasTimedOut: boolean;
33
- };
34
- export { useAsyncPolling, POLLING_INTERVAL, POLLING_DURATION, containersEqual, getRequestedContainersFromUrl, containerDisplayName, CONTAINER_MAP, convertContainerToType, removeRequestedContainersFromUrl, };
@@ -1,25 +0,0 @@
1
- import { type FlagProps } from '@atlaskit/flag';
2
- import { type ContainerTypes } from '../../../common/types';
3
- type OnRequestedContainerTimeout = (createFlag: ({ onAction }: {
4
- onAction: (flagId: string) => void;
5
- }) => FlagProps) => void;
6
- /**
7
- * Hook to track and poll for requested product containers (such as a Jira Project).
8
- * The initial list of requested containers is derived from the URL parameters, however it can be updated based on user interactions.
9
- *
10
- * Manages a list of requested containers, polls for updates, and removes found containers from the list.
11
- *
12
- * Supported container types: CONFLUENCE_SPACE, JIRA_PROJECT, LOOM_SPACE.
13
- *
14
- * @param teamId - The ID of the team whose containers are being tracked.
15
- * @param onRequestedContainerTimeout - Optional callback to handle timeout events for requested containers.
16
- * @returns The current list of requested containers and a function to add a container.
17
- */
18
- declare function useRequestedContainers({ teamId, cloudId, onRequestedContainerTimeout, }: {
19
- teamId: string;
20
- cloudId: string;
21
- onRequestedContainerTimeout?: OnRequestedContainerTimeout;
22
- }): {
23
- requestedContainers: ContainerTypes[];
24
- };
25
- export { useRequestedContainers, type OnRequestedContainerTimeout };
@@ -1,34 +0,0 @@
1
- import { ContainerType } from '@atlaskit/teams-client/types';
2
- import { type ContainerTypes } from '../../../common/types';
3
- declare const CONTAINER_MAP: Record<ContainerType, ContainerTypes>;
4
- declare function containersEqual<T>(arr1: T[], arr2: T[]): boolean;
5
- declare function getRequestedContainersFromUrl(): ContainerTypes[];
6
- declare function removeRequestedContainersFromUrl(): void;
7
- declare function containerDisplayName(container: ContainerTypes): string;
8
- declare function convertContainerToType(container: ContainerTypes): ContainerType | null;
9
- declare let POLLING_INTERVAL: number;
10
- declare let POLLING_DURATION: number;
11
- /**
12
- * Hook for polling an async callback at a fixed interval, with timeout and pending state management.
13
- *
14
- * Starts polling the provided callback and stops after a set duration or when stopped manually.
15
- * Ensures only one callback is pending at a time.
16
- *
17
- * @param callback - The async function to poll.
18
- * @param onTimeout - Optional callback to execute when polling times out.
19
- * @returns An object with polling controls and state: startPolling, stopPolling, isPolling, hasTimedOut.
20
- */
21
- declare function useAsyncPolling(callback: () => Promise<void> | void, { onTimeout, }?: {
22
- onTimeout?: ({ startPolling, stopPolling, reset, }: {
23
- startPolling: () => void;
24
- stopPolling: () => void;
25
- reset: () => void;
26
- }) => void;
27
- }): {
28
- reset: () => void;
29
- startPolling: () => void;
30
- stopPolling: () => void;
31
- isPolling: boolean;
32
- hasTimedOut: boolean;
33
- };
34
- export { useAsyncPolling, POLLING_INTERVAL, POLLING_DURATION, containersEqual, getRequestedContainersFromUrl, containerDisplayName, CONTAINER_MAP, convertContainerToType, removeRequestedContainersFromUrl, };