@atlaskit/link-picker 1.13.0 → 1.13.1

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 (26) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/analytics.codegen.js +1 -1
  3. package/dist/cjs/common/analytics/context.js +3 -1
  4. package/dist/cjs/ui/link-picker/index.js +7 -7
  5. package/dist/cjs/ui/link-picker/link-search-list/index.js +3 -0
  6. package/dist/cjs/ui/link-picker/link-search-list/use-track-results-shown/index.js +58 -0
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/analytics.codegen.js +1 -1
  9. package/dist/es2019/common/analytics/context.js +5 -1
  10. package/dist/es2019/ui/link-picker/index.js +7 -7
  11. package/dist/es2019/ui/link-picker/link-search-list/index.js +2 -0
  12. package/dist/es2019/ui/link-picker/link-search-list/use-track-results-shown/index.js +34 -0
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/analytics.codegen.js +1 -1
  15. package/dist/esm/common/analytics/context.js +3 -1
  16. package/dist/esm/ui/link-picker/index.js +7 -7
  17. package/dist/esm/ui/link-picker/link-search-list/index.js +2 -0
  18. package/dist/esm/ui/link-picker/link-search-list/use-track-results-shown/index.js +40 -0
  19. package/dist/esm/version.json +1 -1
  20. package/dist/types/analytics.codegen.d.ts +9 -1
  21. package/dist/types/common/analytics/context.d.ts +2 -1
  22. package/dist/types/ui/link-picker/link-search-list/use-track-results-shown/index.d.ts +2 -0
  23. package/dist/types-ts4.0/analytics.codegen.d.ts +9 -1
  24. package/dist/types-ts4.0/common/analytics/context.d.ts +2 -1
  25. package/dist/types-ts4.0/ui/link-picker/link-search-list/use-track-results-shown/index.d.ts +2 -0
  26. package/package.json +2 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/link-picker
2
2
 
3
+ ## 1.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2933e4ddeb0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2933e4ddeb0) - Add searchResults shown analytic event for pre-query and post-query results
8
+
3
9
  ## 1.13.0
4
10
 
5
11
  ### Minor Changes
@@ -10,7 +10,7 @@ exports.default = void 0;
10
10
  *
11
11
  * Generates analytics utilities from the package analytics spec yaml
12
12
  *
13
- * @codegen <<SignedSource::c0fb3bb39f50f3a7c35ebd90e8903280>>
13
+ * @codegen <<SignedSource::758b8a20cae1b6d410cecd4493453a21>>
14
14
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
15
15
  */
16
16
  function createEventPayload(eventKey, attributes) {
@@ -132,8 +132,10 @@ function withLinkPickerAnalyticsContext(WrappedComponent) {
132
132
  getAttributes = _useLinkPickerAnalyti.getAttributes;
133
133
 
134
134
  var onEvent = (0, _react.useCallback)(function (event) {
135
+ var _event$payload$attrib;
136
+
135
137
  event.update({
136
- attributes: getAttributes()
138
+ attributes: _objectSpread(_objectSpread({}, getAttributes()), (_event$payload$attrib = event.payload.attributes) !== null && _event$payload$attrib !== void 0 ? _event$payload$attrib : {})
137
139
  });
138
140
  }, [getAttributes]);
139
141
  return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsListener, {
@@ -194,12 +194,12 @@ function LinkPicker(_ref) {
194
194
  dispatch({
195
195
  url: e.currentTarget.value
196
196
  });
197
- }, [trackAttribute]);
197
+ }, [dispatch, trackAttribute]);
198
198
  var handleChangeText = (0, _react.useCallback)(function (e) {
199
199
  dispatch({
200
200
  displayText: e.currentTarget.value
201
201
  });
202
- }, []);
202
+ }, [dispatch]);
203
203
  var handleKeyDown = (0, _react.useCallback)(function (event) {
204
204
  var key = event.key;
205
205
  var KEY_ARROW_DOWN = 'ArrowDown';
@@ -241,10 +241,10 @@ function LinkPicker(_ref) {
241
241
  invalidUrl: false
242
242
  });
243
243
  }
244
- }, [activeIndex, items, trackAttribute, activePlugin]);
244
+ }, [dispatch, activeIndex, items, trackAttribute, activePlugin]);
245
245
  var handleClear = (0, _react.useCallback)(function (field) {
246
246
  dispatch((0, _defineProperty2.default)({}, field, ''));
247
- }, []);
247
+ }, [dispatch]);
248
248
  var handleUrlClear = (0, _react.useCallback)(function () {
249
249
  trackAttribute('linkFieldContentInputSource', null);
250
250
  handleClear('url');
@@ -256,7 +256,7 @@ function LinkPicker(_ref) {
256
256
  dispatch({
257
257
  activeIndex: index !== null && index !== void 0 ? index : -1
258
258
  });
259
- }, [items]);
259
+ }, [dispatch, items]);
260
260
  var handleMouseLeaveResultItem = (0, _react.useCallback)(function (objectId) {
261
261
  var index = items === null || items === void 0 ? void 0 : items.findIndex(function (item) {
262
262
  return item.objectId === objectId;
@@ -267,7 +267,7 @@ function LinkPicker(_ref) {
267
267
  activeIndex: -1
268
268
  });
269
269
  }
270
- }, [activeIndex, items]);
270
+ }, [dispatch, activeIndex, items]);
271
271
  var handleInsert = (0, _react.useCallback)(function (url, title, inputType) {
272
272
  var event = createAnalyticsEvent((0, _analytics.default)('ui.form.submitted.linkPicker', {})); // Clone the event so that it can be emitted for consumer usage
273
273
  // This must happen BEFORE the original event is fired!
@@ -326,7 +326,7 @@ function LinkPicker(_ref) {
326
326
  return dispatch({
327
327
  invalidUrl: true
328
328
  });
329
- }, [handleInsert, isSelectedItem, selectedItem, url]);
329
+ }, [dispatch, handleInsert, isSelectedItem, selectedItem, url]);
330
330
  var handleTabChange = (0, _react.useCallback)(function (activeTab) {
331
331
  var _plugins$activeTab$ta, _plugins$activeTab;
332
332
 
@@ -31,6 +31,8 @@ var _styled = require("./styled");
31
31
 
32
32
  var _linkSearchNoResults = _interopRequireWildcard(require("./link-search-no-results"));
33
33
 
34
+ var _useTrackResultsShown = require("./use-track-results-shown");
35
+
34
36
  var _excluded = ["onSelect", "onMouseEnter", "onMouseLeave", "items", "activeIndex", "selectedIndex", "isLoading", "ariaControls", "ariaLabelledBy", "role", "id", "hasSearchTerm"];
35
37
 
36
38
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -85,6 +87,7 @@ var LinkSearchList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
85
87
  var itemsContent;
86
88
  var loadingContent;
87
89
  var linkListTitle = hasSearchTerm ? messages.titleResults : messages.titleRecentlyViewed;
90
+ (0, _useTrackResultsShown.useTrackResultsShown)(isLoading, items, hasSearchTerm);
88
91
 
89
92
  if ((items === null || items === void 0 ? void 0 : items.length) === 0) {
90
93
  return (0, _react2.jsx)(_linkSearchNoResults.default, null);
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useTrackResultsShown = void 0;
9
+
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
12
+ var _react = require("react");
13
+
14
+ var _useDebounce3 = require("use-debounce");
15
+
16
+ var _analyticsNext = require("@atlaskit/analytics-next");
17
+
18
+ var _constants = require("../../../../common/constants");
19
+
20
+ var _analytics = _interopRequireDefault(require("../../../../analytics.codegen"));
21
+
22
+ var DEBOUNCE_MS = 400;
23
+
24
+ var useTrackResultsShown = function useTrackResultsShown(isLoading, items, hasSearchTerm) {
25
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
26
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
27
+
28
+ var hasSearchTermRef = (0, _react.useRef)(hasSearchTerm); // Using ref so that not required in the dependency array
29
+ // Analytics should be entirely dependent on change of items being viewed
30
+
31
+ (0, _react.useEffect)(function () {
32
+ hasSearchTermRef.current = hasSearchTerm;
33
+ }, [hasSearchTerm]); // Filters isLoading/items to only return the array of items if no longer loading more items
34
+ // Loading state IS a factor here because some tabs will
35
+ // load intermediate results whilst loading additional results (Atlassian tab)
36
+ // Considered to only have "shown" results once we are in a final state (no longer loading)
37
+
38
+ var finalItems = (0, _react.useMemo)(function () {
39
+ return !isLoading ? items : null;
40
+ }, [isLoading, items]); // Because Atlassian tab resolves intermediate results on every keystroke (may never be loading)
41
+ // Debounce the items so that we only consider the results to have been shown
42
+ // after they have been stable for DEBOUNCE_MS
43
+
44
+ var _useDebounce = (0, _useDebounce3.useDebounce)(finalItems, DEBOUNCE_MS),
45
+ _useDebounce2 = (0, _slicedToArray2.default)(_useDebounce, 1),
46
+ debouncedItems = _useDebounce2[0];
47
+
48
+ (0, _react.useEffect)(function () {
49
+ if (debouncedItems) {
50
+ var event = !hasSearchTermRef.current ? 'ui.searchResults.shown.preQuerySearchResults' : 'ui.searchResults.shown.postQuerySearchResults';
51
+ createAnalyticsEvent((0, _analytics.default)(event, {
52
+ resultCount: debouncedItems.length
53
+ })).fire(_constants.ANALYTICS_CHANNEL);
54
+ }
55
+ }, [debouncedItems, createAnalyticsEvent]);
56
+ };
57
+
58
+ exports.useTrackResultsShown = useTrackResultsShown;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generates analytics utilities from the package analytics spec yaml
5
5
  *
6
- * @codegen <<SignedSource::c0fb3bb39f50f3a7c35ebd90e8903280>>
6
+ * @codegen <<SignedSource::758b8a20cae1b6d410cecd4493453a21>>
7
7
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
8
  */
9
9
  function createEventPayload(eventKey, attributes) {
@@ -90,8 +90,12 @@ export function withLinkPickerAnalyticsContext(WrappedComponent) {
90
90
  getAttributes
91
91
  } = useLinkPickerAnalytics();
92
92
  const onEvent = useCallback(event => {
93
+ var _event$payload$attrib;
94
+
93
95
  event.update({
94
- attributes: getAttributes()
96
+ attributes: { ...getAttributes(),
97
+ ...((_event$payload$attrib = event.payload.attributes) !== null && _event$payload$attrib !== void 0 ? _event$payload$attrib : {})
98
+ }
95
99
  });
96
100
  }, [getAttributes]);
97
101
  return /*#__PURE__*/React.createElement(AnalyticsListener, {
@@ -138,12 +138,12 @@ function LinkPicker({
138
138
  dispatch({
139
139
  url: e.currentTarget.value
140
140
  });
141
- }, [trackAttribute]);
141
+ }, [dispatch, trackAttribute]);
142
142
  const handleChangeText = useCallback(e => {
143
143
  dispatch({
144
144
  displayText: e.currentTarget.value
145
145
  });
146
- }, []);
146
+ }, [dispatch]);
147
147
  const handleKeyDown = useCallback(event => {
148
148
  const {
149
149
  key
@@ -187,12 +187,12 @@ function LinkPicker({
187
187
  invalidUrl: false
188
188
  });
189
189
  }
190
- }, [activeIndex, items, trackAttribute, activePlugin]);
190
+ }, [dispatch, activeIndex, items, trackAttribute, activePlugin]);
191
191
  const handleClear = useCallback(field => {
192
192
  dispatch({
193
193
  [field]: ''
194
194
  });
195
- }, []);
195
+ }, [dispatch]);
196
196
  const handleUrlClear = useCallback(() => {
197
197
  trackAttribute('linkFieldContentInputSource', null);
198
198
  handleClear('url');
@@ -202,7 +202,7 @@ function LinkPicker({
202
202
  dispatch({
203
203
  activeIndex: index !== null && index !== void 0 ? index : -1
204
204
  });
205
- }, [items]);
205
+ }, [dispatch, items]);
206
206
  const handleMouseLeaveResultItem = useCallback(objectId => {
207
207
  const index = items === null || items === void 0 ? void 0 : items.findIndex(item => item.objectId === objectId); // This is to avoid updating index that was set by other mouseenter event
208
208
 
@@ -211,7 +211,7 @@ function LinkPicker({
211
211
  activeIndex: -1
212
212
  });
213
213
  }
214
- }, [activeIndex, items]);
214
+ }, [dispatch, activeIndex, items]);
215
215
  const handleInsert = useCallback((url, title, inputType) => {
216
216
  const event = createAnalyticsEvent(createEventPayload('ui.form.submitted.linkPicker', {})); // Clone the event so that it can be emitted for consumer usage
217
217
  // This must happen BEFORE the original event is fired!
@@ -271,7 +271,7 @@ function LinkPicker({
271
271
  return dispatch({
272
272
  invalidUrl: true
273
273
  });
274
- }, [handleInsert, isSelectedItem, selectedItem, url]);
274
+ }, [dispatch, handleInsert, isSelectedItem, selectedItem, url]);
275
275
  const handleTabChange = useCallback(activeTab => {
276
276
  var _plugins$activeTab$ta, _plugins$activeTab;
277
277
 
@@ -9,6 +9,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
9
9
  import LinkSearchListItem from '../list-item';
10
10
  import { listContainerStyles, spinnerContainerStyles, listStyles, listTitleStyles } from './styled';
11
11
  import LinkSearchNoResults, { testIds as noResultsTestIds } from './link-search-no-results';
12
+ import { useTrackResultsShown } from './use-track-results-shown';
12
13
  export const messages = defineMessages({
13
14
  titleRecentlyViewed: {
14
15
  id: 'fabric.linkPicker.listTitle.recentlyViewed',
@@ -50,6 +51,7 @@ const LinkSearchList = /*#__PURE__*/forwardRef(({
50
51
  let itemsContent;
51
52
  let loadingContent;
52
53
  const linkListTitle = hasSearchTerm ? messages.titleResults : messages.titleRecentlyViewed;
54
+ useTrackResultsShown(isLoading, items, hasSearchTerm);
53
55
 
54
56
  if ((items === null || items === void 0 ? void 0 : items.length) === 0) {
55
57
  return jsx(LinkSearchNoResults, null);
@@ -0,0 +1,34 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+ import { useDebounce } from 'use-debounce';
3
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
4
+ import { ANALYTICS_CHANNEL } from '../../../../common/constants';
5
+ import createEventPayload from '../../../../analytics.codegen';
6
+ const DEBOUNCE_MS = 400;
7
+ export const useTrackResultsShown = (isLoading, items, hasSearchTerm) => {
8
+ const {
9
+ createAnalyticsEvent
10
+ } = useAnalyticsEvents();
11
+ const hasSearchTermRef = useRef(hasSearchTerm); // Using ref so that not required in the dependency array
12
+ // Analytics should be entirely dependent on change of items being viewed
13
+
14
+ useEffect(() => {
15
+ hasSearchTermRef.current = hasSearchTerm;
16
+ }, [hasSearchTerm]); // Filters isLoading/items to only return the array of items if no longer loading more items
17
+ // Loading state IS a factor here because some tabs will
18
+ // load intermediate results whilst loading additional results (Atlassian tab)
19
+ // Considered to only have "shown" results once we are in a final state (no longer loading)
20
+
21
+ const finalItems = useMemo(() => !isLoading ? items : null, [isLoading, items]); // Because Atlassian tab resolves intermediate results on every keystroke (may never be loading)
22
+ // Debounce the items so that we only consider the results to have been shown
23
+ // after they have been stable for DEBOUNCE_MS
24
+
25
+ const [debouncedItems] = useDebounce(finalItems, DEBOUNCE_MS);
26
+ useEffect(() => {
27
+ if (debouncedItems) {
28
+ const event = !hasSearchTermRef.current ? 'ui.searchResults.shown.preQuerySearchResults' : 'ui.searchResults.shown.postQuerySearchResults';
29
+ createAnalyticsEvent(createEventPayload(event, {
30
+ resultCount: debouncedItems.length
31
+ })).fire(ANALYTICS_CHANNEL);
32
+ }
33
+ }, [debouncedItems, createAnalyticsEvent]);
34
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generates analytics utilities from the package analytics spec yaml
5
5
  *
6
- * @codegen <<SignedSource::c0fb3bb39f50f3a7c35ebd90e8903280>>
6
+ * @codegen <<SignedSource::758b8a20cae1b6d410cecd4493453a21>>
7
7
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
8
  */
9
9
  function createEventPayload(eventKey, attributes) {
@@ -105,8 +105,10 @@ export function withLinkPickerAnalyticsContext(WrappedComponent) {
105
105
  getAttributes = _useLinkPickerAnalyti.getAttributes;
106
106
 
107
107
  var onEvent = useCallback(function (event) {
108
+ var _event$payload$attrib;
109
+
108
110
  event.update({
109
- attributes: getAttributes()
111
+ attributes: _objectSpread(_objectSpread({}, getAttributes()), (_event$payload$attrib = event.payload.attributes) !== null && _event$payload$attrib !== void 0 ? _event$payload$attrib : {})
110
112
  });
111
113
  }, [getAttributes]);
112
114
  return /*#__PURE__*/React.createElement(AnalyticsListener, {
@@ -146,12 +146,12 @@ function LinkPicker(_ref) {
146
146
  dispatch({
147
147
  url: e.currentTarget.value
148
148
  });
149
- }, [trackAttribute]);
149
+ }, [dispatch, trackAttribute]);
150
150
  var handleChangeText = useCallback(function (e) {
151
151
  dispatch({
152
152
  displayText: e.currentTarget.value
153
153
  });
154
- }, []);
154
+ }, [dispatch]);
155
155
  var handleKeyDown = useCallback(function (event) {
156
156
  var key = event.key;
157
157
  var KEY_ARROW_DOWN = 'ArrowDown';
@@ -193,10 +193,10 @@ function LinkPicker(_ref) {
193
193
  invalidUrl: false
194
194
  });
195
195
  }
196
- }, [activeIndex, items, trackAttribute, activePlugin]);
196
+ }, [dispatch, activeIndex, items, trackAttribute, activePlugin]);
197
197
  var handleClear = useCallback(function (field) {
198
198
  dispatch(_defineProperty({}, field, ''));
199
- }, []);
199
+ }, [dispatch]);
200
200
  var handleUrlClear = useCallback(function () {
201
201
  trackAttribute('linkFieldContentInputSource', null);
202
202
  handleClear('url');
@@ -208,7 +208,7 @@ function LinkPicker(_ref) {
208
208
  dispatch({
209
209
  activeIndex: index !== null && index !== void 0 ? index : -1
210
210
  });
211
- }, [items]);
211
+ }, [dispatch, items]);
212
212
  var handleMouseLeaveResultItem = useCallback(function (objectId) {
213
213
  var index = items === null || items === void 0 ? void 0 : items.findIndex(function (item) {
214
214
  return item.objectId === objectId;
@@ -219,7 +219,7 @@ function LinkPicker(_ref) {
219
219
  activeIndex: -1
220
220
  });
221
221
  }
222
- }, [activeIndex, items]);
222
+ }, [dispatch, activeIndex, items]);
223
223
  var handleInsert = useCallback(function (url, title, inputType) {
224
224
  var event = createAnalyticsEvent(createEventPayload('ui.form.submitted.linkPicker', {})); // Clone the event so that it can be emitted for consumer usage
225
225
  // This must happen BEFORE the original event is fired!
@@ -278,7 +278,7 @@ function LinkPicker(_ref) {
278
278
  return dispatch({
279
279
  invalidUrl: true
280
280
  });
281
- }, [handleInsert, isSelectedItem, selectedItem, url]);
281
+ }, [dispatch, handleInsert, isSelectedItem, selectedItem, url]);
282
282
  var handleTabChange = useCallback(function (activeTab) {
283
283
  var _plugins$activeTab$ta, _plugins$activeTab;
284
284
 
@@ -16,6 +16,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
16
16
  import LinkSearchListItem from '../list-item';
17
17
  import { listContainerStyles, spinnerContainerStyles, listStyles, listTitleStyles } from './styled';
18
18
  import LinkSearchNoResults, { testIds as noResultsTestIds } from './link-search-no-results';
19
+ import { useTrackResultsShown } from './use-track-results-shown';
19
20
  export var messages = defineMessages({
20
21
  titleRecentlyViewed: {
21
22
  id: 'fabric.linkPicker.listTitle.recentlyViewed',
@@ -57,6 +58,7 @@ var LinkSearchList = /*#__PURE__*/forwardRef(function (_ref, ref) {
57
58
  var itemsContent;
58
59
  var loadingContent;
59
60
  var linkListTitle = hasSearchTerm ? messages.titleResults : messages.titleRecentlyViewed;
61
+ useTrackResultsShown(isLoading, items, hasSearchTerm);
60
62
 
61
63
  if ((items === null || items === void 0 ? void 0 : items.length) === 0) {
62
64
  return jsx(LinkSearchNoResults, null);
@@ -0,0 +1,40 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useEffect, useMemo, useRef } from 'react';
3
+ import { useDebounce } from 'use-debounce';
4
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
5
+ import { ANALYTICS_CHANNEL } from '../../../../common/constants';
6
+ import createEventPayload from '../../../../analytics.codegen';
7
+ var DEBOUNCE_MS = 400;
8
+ export var useTrackResultsShown = function useTrackResultsShown(isLoading, items, hasSearchTerm) {
9
+ var _useAnalyticsEvents = useAnalyticsEvents(),
10
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
11
+
12
+ var hasSearchTermRef = useRef(hasSearchTerm); // Using ref so that not required in the dependency array
13
+ // Analytics should be entirely dependent on change of items being viewed
14
+
15
+ useEffect(function () {
16
+ hasSearchTermRef.current = hasSearchTerm;
17
+ }, [hasSearchTerm]); // Filters isLoading/items to only return the array of items if no longer loading more items
18
+ // Loading state IS a factor here because some tabs will
19
+ // load intermediate results whilst loading additional results (Atlassian tab)
20
+ // Considered to only have "shown" results once we are in a final state (no longer loading)
21
+
22
+ var finalItems = useMemo(function () {
23
+ return !isLoading ? items : null;
24
+ }, [isLoading, items]); // Because Atlassian tab resolves intermediate results on every keystroke (may never be loading)
25
+ // Debounce the items so that we only consider the results to have been shown
26
+ // after they have been stable for DEBOUNCE_MS
27
+
28
+ var _useDebounce = useDebounce(finalItems, DEBOUNCE_MS),
29
+ _useDebounce2 = _slicedToArray(_useDebounce, 1),
30
+ debouncedItems = _useDebounce2[0];
31
+
32
+ useEffect(function () {
33
+ if (debouncedItems) {
34
+ var event = !hasSearchTermRef.current ? 'ui.searchResults.shown.preQuerySearchResults' : 'ui.searchResults.shown.postQuerySearchResults';
35
+ createAnalyticsEvent(createEventPayload(event, {
36
+ resultCount: debouncedItems.length
37
+ })).fire(ANALYTICS_CHANNEL);
38
+ }
39
+ }, [debouncedItems, createAnalyticsEvent]);
40
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generates analytics utilities from the package analytics spec yaml
5
5
  *
6
- * @codegen <<SignedSource::c0fb3bb39f50f3a7c35ebd90e8903280>>
6
+ * @codegen <<SignedSource::758b8a20cae1b6d410cecd4493453a21>>
7
7
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
8
  */
9
9
  export declare type PackageMetaDataType = {
@@ -32,6 +32,12 @@ export declare type LinkPickerUnhandledErrorCaughtAttributesType = {
32
32
  error: string;
33
33
  componentStack: string | null;
34
34
  };
35
+ export declare type SearchResultsShownPreQuerySearchResultsAttributesType = {
36
+ resultCount: number;
37
+ };
38
+ export declare type SearchResultsShownPostQuerySearchResultsAttributesType = {
39
+ resultCount: number;
40
+ };
35
41
  export declare type ResultsResolveFailedAttributesType = {
36
42
  error: string;
37
43
  };
@@ -43,6 +49,8 @@ declare type AnalyticsEventAttributes = {
43
49
  'ui.textField.updated.displayTextField': TextFieldUpdatedDisplayTextFieldAttributesType;
44
50
  'ui.tab.viewed': TabViewedAttributesType;
45
51
  'ui.linkPicker.unhandledErrorCaught': LinkPickerUnhandledErrorCaughtAttributesType;
52
+ 'ui.searchResults.shown.preQuerySearchResults': SearchResultsShownPreQuerySearchResultsAttributesType;
53
+ 'ui.searchResults.shown.postQuerySearchResults': SearchResultsShownPostQuerySearchResultsAttributesType;
46
54
  'operational.resultsResolve.failed': ResultsResolveFailedAttributesType;
47
55
  };
48
56
  declare function createEventPayload<K extends keyof AnalyticsEventAttributes>(eventKey: K, attributes: AnalyticsEventAttributes[K]): {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { LinkPickerAnalyticsContextType } from '../../analytics.codegen';
3
- export declare type TrackAttribute = <K extends keyof LinkPickerAnalyticsContextType>(attribute: K, value: LinkPickerAnalyticsContextType[K]) => void;
3
+ declare type AnalyticsContextAttributesType = LinkPickerAnalyticsContextType;
4
+ export declare type TrackAttribute = <K extends keyof LinkPickerAnalyticsContextType>(attribute: K, value: AnalyticsContextAttributesType[K]) => void;
4
5
  interface AnalyticsContextType {
5
6
  /**
6
7
  * Update a single attribute in the analytics context
@@ -0,0 +1,2 @@
1
+ import { LinkSearchListItemData } from '../../../types';
2
+ export declare const useTrackResultsShown: (isLoading: boolean, items?: LinkSearchListItemData[] | null | undefined, hasSearchTerm?: boolean | undefined) => void;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generates analytics utilities from the package analytics spec yaml
5
5
  *
6
- * @codegen <<SignedSource::c0fb3bb39f50f3a7c35ebd90e8903280>>
6
+ * @codegen <<SignedSource::758b8a20cae1b6d410cecd4493453a21>>
7
7
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
8
  */
9
9
  export declare type PackageMetaDataType = {
@@ -32,6 +32,12 @@ export declare type LinkPickerUnhandledErrorCaughtAttributesType = {
32
32
  error: string;
33
33
  componentStack: string | null;
34
34
  };
35
+ export declare type SearchResultsShownPreQuerySearchResultsAttributesType = {
36
+ resultCount: number;
37
+ };
38
+ export declare type SearchResultsShownPostQuerySearchResultsAttributesType = {
39
+ resultCount: number;
40
+ };
35
41
  export declare type ResultsResolveFailedAttributesType = {
36
42
  error: string;
37
43
  };
@@ -43,6 +49,8 @@ declare type AnalyticsEventAttributes = {
43
49
  'ui.textField.updated.displayTextField': TextFieldUpdatedDisplayTextFieldAttributesType;
44
50
  'ui.tab.viewed': TabViewedAttributesType;
45
51
  'ui.linkPicker.unhandledErrorCaught': LinkPickerUnhandledErrorCaughtAttributesType;
52
+ 'ui.searchResults.shown.preQuerySearchResults': SearchResultsShownPreQuerySearchResultsAttributesType;
53
+ 'ui.searchResults.shown.postQuerySearchResults': SearchResultsShownPostQuerySearchResultsAttributesType;
46
54
  'operational.resultsResolve.failed': ResultsResolveFailedAttributesType;
47
55
  };
48
56
  declare function createEventPayload<K extends keyof AnalyticsEventAttributes>(eventKey: K, attributes: AnalyticsEventAttributes[K]): {
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { LinkPickerAnalyticsContextType } from '../../analytics.codegen';
3
- export declare type TrackAttribute = <K extends keyof LinkPickerAnalyticsContextType>(attribute: K, value: LinkPickerAnalyticsContextType[K]) => void;
3
+ declare type AnalyticsContextAttributesType = LinkPickerAnalyticsContextType;
4
+ export declare type TrackAttribute = <K extends keyof LinkPickerAnalyticsContextType>(attribute: K, value: AnalyticsContextAttributesType[K]) => void;
4
5
  interface AnalyticsContextType {
5
6
  /**
6
7
  * Update a single attribute in the analytics context
@@ -0,0 +1,2 @@
1
+ import { LinkSearchListItemData } from '../../../types';
2
+ export declare const useTrackResultsShown: (isLoading: boolean, items?: LinkSearchListItemData[] | null | undefined, hasSearchTerm?: boolean | undefined) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "Standalone link picker",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
@@ -59,6 +59,7 @@
59
59
  "date-fns": "^2.17.0",
60
60
  "linkify-it": "^2.0.3",
61
61
  "react-loosely-lazy": "^1.0.0",
62
+ "use-debounce": "^3.4.0",
62
63
  "uuid": "^3.1.0"
63
64
  },
64
65
  "peerDependencies": {