@atlaskit/link-picker 1.7.0 → 1.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/link-picker
2
2
 
3
+ ## 1.8.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`afd2368145a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/afd2368145a) - Added link picker mount/unmount analytic events
8
+
9
+ ## 1.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`89fffde2a59`](https://bitbucket.org/atlassian/atlassian-frontend/commits/89fffde2a59) - Wrap link picker in native form element
14
+
15
+ ## 1.7.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [`e900714203d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e900714203d) - Add "form submitted" analytics event.
20
+
3
21
  ## 1.7.0
4
22
 
5
23
  ### Minor Changes
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
10
+ *
11
+ * Generates analytics utilities from the package analytics spec yaml
12
+ *
13
+ * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
14
+ * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
15
+ */
16
+ function createEventPayload(eventKey, attributes) {
17
+ var event = eventKey.split('.');
18
+ return {
19
+ eventType: event[0],
20
+ actionSubject: event[1],
21
+ action: event[2],
22
+ actionSubjectId: event[3],
23
+ attributes: attributes
24
+ };
25
+ }
26
+
27
+ var _default = createEventPayload;
28
+ exports.default = _default;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.COMPONENT_NAME = exports.ANALYTICS_CHANNEL = void 0;
7
+ var ANALYTICS_CHANNEL = 'media';
8
+ exports.ANALYTICS_CHANNEL = ANALYTICS_CHANNEL;
9
+ var COMPONENT_NAME = 'LinkPicker';
10
+ exports.COMPONENT_NAME = COMPONENT_NAME;
@@ -15,6 +15,8 @@ var _analyticsNext = require("@atlaskit/analytics-next");
15
15
 
16
16
  var _reactLooselyLazy = require("react-loosely-lazy");
17
17
 
18
+ var _constants = require("../common/constants");
19
+
18
20
  var _version = require("../version.json");
19
21
 
20
22
  var _errorBoundaryFallback = require("./error-boundary-fallback");
@@ -25,12 +27,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
25
27
 
26
28
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || (0, _typeof2.default)(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
29
 
28
- var COMPONENT_NAME = 'LinkPicker';
29
- var ANALYTICS_CHANNEL = 'media';
30
30
  var PACKAGE_DATA = {
31
31
  packageName: _version.name,
32
32
  packageVersion: _version.version,
33
- componentName: COMPONENT_NAME
33
+ componentName: _constants.COMPONENT_NAME
34
34
  };
35
35
  var LazyLinkPicker = (0, _reactLooselyLazy.lazyForPaint)(function () {
36
36
  return Promise.resolve().then(function () {
@@ -39,7 +39,7 @@ var LazyLinkPicker = (0, _reactLooselyLazy.lazyForPaint)(function () {
39
39
  });
40
40
  var ComposedLinkPicker = /*#__PURE__*/(0, _react.memo)(function (props) {
41
41
  return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsErrorBoundary, {
42
- channel: ANALYTICS_CHANNEL,
42
+ channel: _constants.ANALYTICS_CHANNEL,
43
43
  data: PACKAGE_DATA,
44
44
  ErrorComponent: _errorBoundaryFallback.ErrorBoundaryFallback
45
45
  }, /*#__PURE__*/_react.default.createElement(_reactLooselyLazy.LazySuspense, {
@@ -21,6 +21,8 @@ var _react2 = require("@emotion/react");
21
21
 
22
22
  var _reactIntlNext = require("react-intl-next");
23
23
 
24
+ var _analyticsNext = require("@atlaskit/analytics-next");
25
+
24
26
  var _button = _interopRequireWildcard(require("@atlaskit/button"));
25
27
 
26
28
  var _form = require("@atlaskit/form");
@@ -31,6 +33,10 @@ var _tabs = _interopRequireWildcard(require("@atlaskit/tabs"));
31
33
 
32
34
  var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
33
35
 
36
+ var _analytics = _interopRequireDefault(require("../../analytics.codegen"));
37
+
38
+ var _constants = require("../../common/constants");
39
+
34
40
  var _usePlugins2 = require("../../services/use-plugins");
35
41
 
36
42
  var _useSearchQuery = require("../../services/use-search-query");
@@ -116,6 +122,9 @@ function LinkPicker(_ref) {
116
122
  initUrl = _ref.url,
117
123
  initDisplayText = _ref.displayText;
118
124
 
125
+ var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
126
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
127
+
119
128
  var _useReducer = (0, _react.useReducer)(reducer, _objectSpread(_objectSpread({}, initState), {}, {
120
129
  url: (0, _url2.normalizeUrl)(initUrl) || '',
121
130
  displayText: initDisplayText || ''
@@ -145,6 +154,16 @@ function LinkPicker(_ref) {
145
154
  var isEditing = !!initUrl;
146
155
  var selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
147
156
  var isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
157
+ (0, _react.useEffect)(function () {
158
+ // Anything in here is fired on component mount.
159
+ var event = createAnalyticsEvent((0, _analytics.default)('ui.inlineDialog.viewed.linkPicker', {}));
160
+ event.fire(_constants.ANALYTICS_CHANNEL);
161
+ return function () {
162
+ // Anything in here is fired on component unmount.
163
+ var event = createAnalyticsEvent((0, _analytics.default)('ui.inlineDialog.closed.linkPicker', {}));
164
+ event.fire(_constants.ANALYTICS_CHANNEL);
165
+ };
166
+ }, [createAnalyticsEvent]);
148
167
  (0, _react.useLayoutEffect)(function () {
149
168
  if (onContentResize) {
150
169
  onContentResize();
@@ -217,6 +236,8 @@ function LinkPicker(_ref) {
217
236
  }
218
237
  }, [activeIndex, items]);
219
238
  var handleInsert = (0, _react.useCallback)(function (url, title, inputType) {
239
+ var event = createAnalyticsEvent((0, _analytics.default)('ui.form.submitted.linkPicker', {}));
240
+ event.fire(_constants.ANALYTICS_CHANNEL);
220
241
  onSubmit(_objectSpread({
221
242
  url: url,
222
243
  displayText: displayText || null,
@@ -227,7 +248,7 @@ function LinkPicker(_ref) {
227
248
  }, inputType === 'manual' ? {
228
249
  rawUrl: state.url
229
250
  } : {}));
230
- }, [displayText, onSubmit, state.url]);
251
+ }, [displayText, onSubmit, state.url, createAnalyticsEvent]);
231
252
  var handleSelected = (0, _react.useCallback)(function (objectId) {
232
253
  var selectedItem = items === null || items === void 0 ? void 0 : items.find(function (item) {
233
254
  return item.objectId === objectId;
@@ -236,10 +257,13 @@ function LinkPicker(_ref) {
236
257
  if (selectedItem) {
237
258
  var _url = selectedItem.url,
238
259
  name = selectedItem.name;
260
+ dispatchEvent(new Event('submit'));
239
261
  handleInsert(_url, name, 'typeAhead');
240
262
  }
241
263
  }, [handleInsert, items]);
242
- var handleSubmit = (0, _react.useCallback)(function () {
264
+ var handleSubmit = (0, _react.useCallback)(function (event) {
265
+ event.preventDefault();
266
+
243
267
  if (isSelectedItem && selectedItem) {
244
268
  return handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
245
269
  }
@@ -272,9 +296,10 @@ function LinkPicker(_ref) {
272
296
  size: "medium",
273
297
  label: ''
274
298
  }));
275
- return (0, _react2.jsx)("div", {
299
+ return (0, _react2.jsx)("form", {
276
300
  "data-testid": testIds.linkPicker,
277
- css: _styled.rootContainerStyles
301
+ css: _styled.rootContainerStyles,
302
+ onSubmit: handleSubmit
278
303
  }, screenReaderText && (0, _react2.jsx)(_announcer.default, {
279
304
  ariaLive: "assertive",
280
305
  text: screenReaderText,
@@ -300,7 +325,6 @@ function LinkPicker(_ref) {
300
325
  "aria-describedby": screenReaderDescriptionId,
301
326
  error: invalidUrl ? intl.formatMessage(_messages.messages.linkInvalid) : null,
302
327
  onClear: handleClear,
303
- onSubmit: handleSubmit,
304
328
  onKeyDown: handleKeyDown,
305
329
  onChange: handleChangeUrl
306
330
  }), (0, _react2.jsx)(_textInput.default, {
@@ -313,7 +337,6 @@ function LinkPicker(_ref) {
313
337
  clearLabel: intl.formatMessage(_messages.messages.clearText),
314
338
  "aria-label": intl.formatMessage(_messages.messages.linkAriaLabel),
315
339
  onClear: handleClear,
316
- onSubmit: handleSubmit,
317
340
  onKeyDown: handleKeyDown,
318
341
  onChange: handleChangeText
319
342
  }), queryState && (0, _react2.jsx)(_react.Fragment, null, tabs.length > 0 && (0, _react2.jsx)("div", {
@@ -387,7 +410,6 @@ function LinkPicker(_ref) {
387
410
  }, intl.formatMessage(_messages.messages.cancelButton)), (0, _react2.jsx)(_button.default, {
388
411
  type: "submit",
389
412
  appearance: "primary",
390
- onClick: handleSubmit,
391
413
  testId: testIds.insertButton
392
414
  }, intl.formatMessage(insertButtonMsg)))));
393
415
  }
@@ -29,13 +29,12 @@ var _styled = require("./styled");
29
29
 
30
30
  var _ = require("../");
31
31
 
32
- var _excluded = ["name", "label", "autoFocus", "onSubmit", "onRedo", "onUndo", "onChange", "onKeyDown", "onClear", "clearLabel", "error"];
32
+ var _excluded = ["name", "label", "autoFocus", "onRedo", "onUndo", "onChange", "onKeyDown", "onClear", "clearLabel", "error"];
33
33
 
34
34
  var PanelTextInput = function PanelTextInput(props) {
35
35
  var name = props.name,
36
36
  label = props.label,
37
37
  autoFocus = props.autoFocus,
38
- onSubmit = props.onSubmit,
39
38
  onRedo = props.onRedo,
40
39
  onUndo = props.onUndo,
41
40
  onChange = props.onChange,
@@ -61,13 +60,7 @@ var PanelTextInput = function PanelTextInput(props) {
61
60
  onChange(e.currentTarget.value);
62
61
  }, [onChange]);
63
62
  var handleKeydown = (0, _react.useCallback)(function (e) {
64
- var value = e.currentTarget.value;
65
-
66
- if (e.keyCode === 13 && onSubmit) {
67
- e.preventDefault(); // Prevent from submitting if an editor is inside a form.
68
-
69
- onSubmit(value);
70
- } else if (typeof onUndo === 'function' && (0, _utils.isUndoEvent)(e)) {
63
+ if (typeof onUndo === 'function' && (0, _utils.isUndoEvent)(e)) {
71
64
  e.preventDefault();
72
65
  onUndo();
73
66
  } else if (typeof onRedo === 'function' && (0, _utils.isRedoEvent)(e)) {
@@ -78,7 +71,7 @@ var PanelTextInput = function PanelTextInput(props) {
78
71
  if (onKeyDown) {
79
72
  onKeyDown(e);
80
73
  }
81
- }, [onSubmit, onUndo, onRedo, onKeyDown]);
74
+ }, [onUndo, onRedo, onKeyDown]);
82
75
  var handleClear = (0, _react.useCallback)(function () {
83
76
  if (inputRef.current && onClear) {
84
77
  inputRef.current.focus();
@@ -88,6 +81,7 @@ var PanelTextInput = function PanelTextInput(props) {
88
81
  var clearText = restProps.value !== '' && (0, _react2.jsx)(_tooltip.default, {
89
82
  content: clearLabel
90
83
  }, (0, _react2.jsx)("button", {
84
+ type: "button",
91
85
  css: _styled.clearTextButtonStyles,
92
86
  onClick: handleClear,
93
87
  "data-testid": _.testIds.clearUrlButton
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
+ *
4
+ * Generates analytics utilities from the package analytics spec yaml
5
+ *
6
+ * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
7
+ * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
+ */
9
+ function createEventPayload(eventKey, attributes) {
10
+ const event = eventKey.split('.');
11
+ return {
12
+ eventType: event[0],
13
+ actionSubject: event[1],
14
+ action: event[2],
15
+ actionSubjectId: event[3],
16
+ attributes: attributes
17
+ };
18
+ }
19
+
20
+ export default createEventPayload;
@@ -0,0 +1,2 @@
1
+ export const ANALYTICS_CHANNEL = 'media';
2
+ export const COMPONENT_NAME = 'LinkPicker';
@@ -1,11 +1,10 @@
1
1
  import React, { memo } from 'react';
2
2
  import { AnalyticsErrorBoundary } from '@atlaskit/analytics-next';
3
3
  import { LazySuspense, lazyForPaint } from 'react-loosely-lazy';
4
+ import { COMPONENT_NAME, ANALYTICS_CHANNEL } from '../common/constants';
4
5
  import { name as packageName, version as packageVersion } from '../version.json';
5
6
  import { ErrorBoundaryFallback } from './error-boundary-fallback';
6
7
  import { LoaderFallback } from './loader-fallback';
7
- const COMPONENT_NAME = 'LinkPicker';
8
- const ANALYTICS_CHANNEL = 'media';
9
8
  const PACKAGE_DATA = {
10
9
  packageName,
11
10
  packageVersion,
@@ -1,14 +1,17 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
- import { Fragment, useCallback, useLayoutEffect, useReducer } from 'react';
4
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer } from 'react';
5
5
  import { jsx } from '@emotion/react';
6
6
  import { useIntl, FormattedMessage } from 'react-intl-next';
7
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
7
8
  import Button, { ButtonGroup } from '@atlaskit/button';
8
9
  import { FormFooter } from '@atlaskit/form';
9
10
  import EditorSearchIcon from '@atlaskit/icon/glyph/editor/search';
10
11
  import Tabs, { Tab, TabList } from '@atlaskit/tabs';
11
12
  import VisuallyHidden from '@atlaskit/visually-hidden';
13
+ import createEventPayload from '../../analytics.codegen';
14
+ import { ANALYTICS_CHANNEL } from '../../common/constants';
12
15
  import { usePlugins } from '../../services/use-plugins';
13
16
  import { useSearchQuery } from '../../services/use-search-query';
14
17
  import { messages } from './messages';
@@ -74,6 +77,9 @@ function LinkPicker({
74
77
  }) {
75
78
  var _queryState$query, _items$length, _errorFallback;
76
79
 
80
+ const {
81
+ createAnalyticsEvent
82
+ } = useAnalyticsEvents();
77
83
  const [state, dispatch] = useReducer(reducer, { ...initState,
78
84
  url: normalizeUrl(initUrl) || '',
79
85
  displayText: initDisplayText || ''
@@ -100,6 +106,16 @@ function LinkPicker({
100
106
  const isEditing = !!initUrl;
101
107
  const selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
102
108
  const isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
109
+ useEffect(() => {
110
+ // Anything in here is fired on component mount.
111
+ const event = createAnalyticsEvent(createEventPayload('ui.inlineDialog.viewed.linkPicker', {}));
112
+ event.fire(ANALYTICS_CHANNEL);
113
+ return () => {
114
+ // Anything in here is fired on component unmount.
115
+ const event = createAnalyticsEvent(createEventPayload('ui.inlineDialog.closed.linkPicker', {}));
116
+ event.fire(ANALYTICS_CHANNEL);
117
+ };
118
+ }, [createAnalyticsEvent]);
103
119
  useLayoutEffect(() => {
104
120
  if (onContentResize) {
105
121
  onContentResize();
@@ -172,6 +188,8 @@ function LinkPicker({
172
188
  }
173
189
  }, [activeIndex, items]);
174
190
  const handleInsert = useCallback((url, title, inputType) => {
191
+ const event = createAnalyticsEvent(createEventPayload('ui.form.submitted.linkPicker', {}));
192
+ event.fire(ANALYTICS_CHANNEL);
175
193
  onSubmit({
176
194
  url,
177
195
  displayText: displayText || null,
@@ -183,7 +201,7 @@ function LinkPicker({
183
201
  rawUrl: state.url
184
202
  } : {})
185
203
  });
186
- }, [displayText, onSubmit, state.url]);
204
+ }, [displayText, onSubmit, state.url, createAnalyticsEvent]);
187
205
  const handleSelected = useCallback(objectId => {
188
206
  const selectedItem = items === null || items === void 0 ? void 0 : items.find(item => item.objectId === objectId);
189
207
 
@@ -192,10 +210,13 @@ function LinkPicker({
192
210
  url,
193
211
  name
194
212
  } = selectedItem;
213
+ dispatchEvent(new Event('submit'));
195
214
  handleInsert(url, name, 'typeAhead');
196
215
  }
197
216
  }, [handleInsert, items]);
198
- const handleSubmit = useCallback(() => {
217
+ const handleSubmit = useCallback(event => {
218
+ event.preventDefault();
219
+
199
220
  if (isSelectedItem && selectedItem) {
200
221
  return handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
201
222
  }
@@ -228,9 +249,10 @@ function LinkPicker({
228
249
  size: "medium",
229
250
  label: ''
230
251
  }));
231
- return jsx("div", {
252
+ return jsx("form", {
232
253
  "data-testid": testIds.linkPicker,
233
- css: rootContainerStyles
254
+ css: rootContainerStyles,
255
+ onSubmit: handleSubmit
234
256
  }, screenReaderText && jsx(Announcer, {
235
257
  ariaLive: "assertive",
236
258
  text: screenReaderText,
@@ -256,7 +278,6 @@ function LinkPicker({
256
278
  "aria-describedby": screenReaderDescriptionId,
257
279
  error: invalidUrl ? intl.formatMessage(messages.linkInvalid) : null,
258
280
  onClear: handleClear,
259
- onSubmit: handleSubmit,
260
281
  onKeyDown: handleKeyDown,
261
282
  onChange: handleChangeUrl
262
283
  }), jsx(PanelTextInput, {
@@ -269,7 +290,6 @@ function LinkPicker({
269
290
  clearLabel: intl.formatMessage(messages.clearText),
270
291
  "aria-label": intl.formatMessage(messages.linkAriaLabel),
271
292
  onClear: handleClear,
272
- onSubmit: handleSubmit,
273
293
  onKeyDown: handleKeyDown,
274
294
  onChange: handleChangeText
275
295
  }), queryState && jsx(Fragment, null, tabs.length > 0 && jsx("div", {
@@ -337,7 +357,6 @@ function LinkPicker({
337
357
  }, intl.formatMessage(messages.cancelButton)), jsx(Button, {
338
358
  type: "submit",
339
359
  appearance: "primary",
340
- onClick: handleSubmit,
341
360
  testId: testIds.insertButton
342
361
  }, intl.formatMessage(insertButtonMsg)))));
343
362
  }
@@ -16,7 +16,6 @@ const PanelTextInput = props => {
16
16
  name,
17
17
  label,
18
18
  autoFocus,
19
- onSubmit,
20
19
  onRedo,
21
20
  onUndo,
22
21
  onChange,
@@ -43,13 +42,7 @@ const PanelTextInput = props => {
43
42
  onChange(e.currentTarget.value);
44
43
  }, [onChange]);
45
44
  const handleKeydown = useCallback(e => {
46
- const value = e.currentTarget.value;
47
-
48
- if (e.keyCode === 13 && onSubmit) {
49
- e.preventDefault(); // Prevent from submitting if an editor is inside a form.
50
-
51
- onSubmit(value);
52
- } else if (typeof onUndo === 'function' && isUndoEvent(e)) {
45
+ if (typeof onUndo === 'function' && isUndoEvent(e)) {
53
46
  e.preventDefault();
54
47
  onUndo();
55
48
  } else if (typeof onRedo === 'function' && isRedoEvent(e)) {
@@ -60,7 +53,7 @@ const PanelTextInput = props => {
60
53
  if (onKeyDown) {
61
54
  onKeyDown(e);
62
55
  }
63
- }, [onSubmit, onUndo, onRedo, onKeyDown]);
56
+ }, [onUndo, onRedo, onKeyDown]);
64
57
  const handleClear = useCallback(() => {
65
58
  if (inputRef.current && onClear) {
66
59
  inputRef.current.focus();
@@ -70,6 +63,7 @@ const PanelTextInput = props => {
70
63
  const clearText = restProps.value !== '' && jsx(Tooltip, {
71
64
  content: clearLabel
72
65
  }, jsx("button", {
66
+ type: "button",
73
67
  css: clearTextButtonStyles,
74
68
  onClick: handleClear,
75
69
  "data-testid": testIds.clearUrlButton
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
+ *
4
+ * Generates analytics utilities from the package analytics spec yaml
5
+ *
6
+ * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
7
+ * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
+ */
9
+ function createEventPayload(eventKey, attributes) {
10
+ var event = eventKey.split('.');
11
+ return {
12
+ eventType: event[0],
13
+ actionSubject: event[1],
14
+ action: event[2],
15
+ actionSubjectId: event[3],
16
+ attributes: attributes
17
+ };
18
+ }
19
+
20
+ export default createEventPayload;
@@ -0,0 +1,2 @@
1
+ export var ANALYTICS_CHANNEL = 'media';
2
+ export var COMPONENT_NAME = 'LinkPicker';
@@ -1,11 +1,10 @@
1
1
  import React, { memo } from 'react';
2
2
  import { AnalyticsErrorBoundary } from '@atlaskit/analytics-next';
3
3
  import { LazySuspense, lazyForPaint } from 'react-loosely-lazy';
4
+ import { COMPONENT_NAME, ANALYTICS_CHANNEL } from '../common/constants';
4
5
  import { name as packageName, version as packageVersion } from '../version.json';
5
6
  import { ErrorBoundaryFallback } from './error-boundary-fallback';
6
7
  import { LoaderFallback } from './loader-fallback';
7
- var COMPONENT_NAME = 'LinkPicker';
8
- var ANALYTICS_CHANNEL = 'media';
9
8
  var PACKAGE_DATA = {
10
9
  packageName: packageName,
11
10
  packageVersion: packageVersion,
@@ -7,14 +7,17 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
7
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
8
 
9
9
  /** @jsx jsx */
10
- import { Fragment, useCallback, useLayoutEffect, useReducer } from 'react';
10
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer } from 'react';
11
11
  import { jsx } from '@emotion/react';
12
12
  import { useIntl, FormattedMessage } from 'react-intl-next';
13
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
13
14
  import Button, { ButtonGroup } from '@atlaskit/button';
14
15
  import { FormFooter } from '@atlaskit/form';
15
16
  import EditorSearchIcon from '@atlaskit/icon/glyph/editor/search';
16
17
  import Tabs, { Tab, TabList } from '@atlaskit/tabs';
17
18
  import VisuallyHidden from '@atlaskit/visually-hidden';
19
+ import createEventPayload from '../../analytics.codegen';
20
+ import { ANALYTICS_CHANNEL } from '../../common/constants';
18
21
  import { usePlugins } from '../../services/use-plugins';
19
22
  import { useSearchQuery } from '../../services/use-search-query';
20
23
  import { messages } from './messages';
@@ -77,6 +80,9 @@ function LinkPicker(_ref) {
77
80
  initUrl = _ref.url,
78
81
  initDisplayText = _ref.displayText;
79
82
 
83
+ var _useAnalyticsEvents = useAnalyticsEvents(),
84
+ createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
85
+
80
86
  var _useReducer = useReducer(reducer, _objectSpread(_objectSpread({}, initState), {}, {
81
87
  url: normalizeUrl(initUrl) || '',
82
88
  displayText: initDisplayText || ''
@@ -106,6 +112,16 @@ function LinkPicker(_ref) {
106
112
  var isEditing = !!initUrl;
107
113
  var selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
108
114
  var isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
115
+ useEffect(function () {
116
+ // Anything in here is fired on component mount.
117
+ var event = createAnalyticsEvent(createEventPayload('ui.inlineDialog.viewed.linkPicker', {}));
118
+ event.fire(ANALYTICS_CHANNEL);
119
+ return function () {
120
+ // Anything in here is fired on component unmount.
121
+ var event = createAnalyticsEvent(createEventPayload('ui.inlineDialog.closed.linkPicker', {}));
122
+ event.fire(ANALYTICS_CHANNEL);
123
+ };
124
+ }, [createAnalyticsEvent]);
109
125
  useLayoutEffect(function () {
110
126
  if (onContentResize) {
111
127
  onContentResize();
@@ -178,6 +194,8 @@ function LinkPicker(_ref) {
178
194
  }
179
195
  }, [activeIndex, items]);
180
196
  var handleInsert = useCallback(function (url, title, inputType) {
197
+ var event = createAnalyticsEvent(createEventPayload('ui.form.submitted.linkPicker', {}));
198
+ event.fire(ANALYTICS_CHANNEL);
181
199
  onSubmit(_objectSpread({
182
200
  url: url,
183
201
  displayText: displayText || null,
@@ -188,7 +206,7 @@ function LinkPicker(_ref) {
188
206
  }, inputType === 'manual' ? {
189
207
  rawUrl: state.url
190
208
  } : {}));
191
- }, [displayText, onSubmit, state.url]);
209
+ }, [displayText, onSubmit, state.url, createAnalyticsEvent]);
192
210
  var handleSelected = useCallback(function (objectId) {
193
211
  var selectedItem = items === null || items === void 0 ? void 0 : items.find(function (item) {
194
212
  return item.objectId === objectId;
@@ -197,10 +215,13 @@ function LinkPicker(_ref) {
197
215
  if (selectedItem) {
198
216
  var _url = selectedItem.url,
199
217
  name = selectedItem.name;
218
+ dispatchEvent(new Event('submit'));
200
219
  handleInsert(_url, name, 'typeAhead');
201
220
  }
202
221
  }, [handleInsert, items]);
203
- var handleSubmit = useCallback(function () {
222
+ var handleSubmit = useCallback(function (event) {
223
+ event.preventDefault();
224
+
204
225
  if (isSelectedItem && selectedItem) {
205
226
  return handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
206
227
  }
@@ -233,9 +254,10 @@ function LinkPicker(_ref) {
233
254
  size: "medium",
234
255
  label: ''
235
256
  }));
236
- return jsx("div", {
257
+ return jsx("form", {
237
258
  "data-testid": testIds.linkPicker,
238
- css: rootContainerStyles
259
+ css: rootContainerStyles,
260
+ onSubmit: handleSubmit
239
261
  }, screenReaderText && jsx(Announcer, {
240
262
  ariaLive: "assertive",
241
263
  text: screenReaderText,
@@ -261,7 +283,6 @@ function LinkPicker(_ref) {
261
283
  "aria-describedby": screenReaderDescriptionId,
262
284
  error: invalidUrl ? intl.formatMessage(messages.linkInvalid) : null,
263
285
  onClear: handleClear,
264
- onSubmit: handleSubmit,
265
286
  onKeyDown: handleKeyDown,
266
287
  onChange: handleChangeUrl
267
288
  }), jsx(PanelTextInput, {
@@ -274,7 +295,6 @@ function LinkPicker(_ref) {
274
295
  clearLabel: intl.formatMessage(messages.clearText),
275
296
  "aria-label": intl.formatMessage(messages.linkAriaLabel),
276
297
  onClear: handleClear,
277
- onSubmit: handleSubmit,
278
298
  onKeyDown: handleKeyDown,
279
299
  onChange: handleChangeText
280
300
  }), queryState && jsx(Fragment, null, tabs.length > 0 && jsx("div", {
@@ -348,7 +368,6 @@ function LinkPicker(_ref) {
348
368
  }, intl.formatMessage(messages.cancelButton)), jsx(Button, {
349
369
  type: "submit",
350
370
  appearance: "primary",
351
- onClick: handleSubmit,
352
371
  testId: testIds.insertButton
353
372
  }, intl.formatMessage(insertButtonMsg)))));
354
373
  }
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["name", "label", "autoFocus", "onSubmit", "onRedo", "onUndo", "onChange", "onKeyDown", "onClear", "clearLabel", "error"];
3
+ var _excluded = ["name", "label", "autoFocus", "onRedo", "onUndo", "onChange", "onKeyDown", "onClear", "clearLabel", "error"];
4
4
 
5
5
  /** @jsx jsx */
6
6
  import { useCallback, useRef, Fragment } from 'react';
@@ -17,7 +17,6 @@ var PanelTextInput = function PanelTextInput(props) {
17
17
  var name = props.name,
18
18
  label = props.label,
19
19
  autoFocus = props.autoFocus,
20
- onSubmit = props.onSubmit,
21
20
  onRedo = props.onRedo,
22
21
  onUndo = props.onUndo,
23
22
  onChange = props.onChange,
@@ -44,13 +43,7 @@ var PanelTextInput = function PanelTextInput(props) {
44
43
  onChange(e.currentTarget.value);
45
44
  }, [onChange]);
46
45
  var handleKeydown = useCallback(function (e) {
47
- var value = e.currentTarget.value;
48
-
49
- if (e.keyCode === 13 && onSubmit) {
50
- e.preventDefault(); // Prevent from submitting if an editor is inside a form.
51
-
52
- onSubmit(value);
53
- } else if (typeof onUndo === 'function' && isUndoEvent(e)) {
46
+ if (typeof onUndo === 'function' && isUndoEvent(e)) {
54
47
  e.preventDefault();
55
48
  onUndo();
56
49
  } else if (typeof onRedo === 'function' && isRedoEvent(e)) {
@@ -61,7 +54,7 @@ var PanelTextInput = function PanelTextInput(props) {
61
54
  if (onKeyDown) {
62
55
  onKeyDown(e);
63
56
  }
64
- }, [onSubmit, onUndo, onRedo, onKeyDown]);
57
+ }, [onUndo, onRedo, onKeyDown]);
65
58
  var handleClear = useCallback(function () {
66
59
  if (inputRef.current && onClear) {
67
60
  inputRef.current.focus();
@@ -71,6 +64,7 @@ var PanelTextInput = function PanelTextInput(props) {
71
64
  var clearText = restProps.value !== '' && jsx(Tooltip, {
72
65
  content: clearLabel
73
66
  }, jsx("button", {
67
+ type: "button",
74
68
  css: clearTextButtonStyles,
75
69
  onClick: handleClear,
76
70
  "data-testid": testIds.clearUrlButton
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
+ *
4
+ * Generates analytics utilities from the package analytics spec yaml
5
+ *
6
+ * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
7
+ * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
+ */
9
+ declare type FormSubmittedLinkPickerAttributesType = {};
10
+ declare type InlineDialogViewedLinkPickerAttributesType = {};
11
+ declare type InlineDialogClosedLinkPickerAttributesType = {};
12
+ declare type AnalyticsEventAttributes = {
13
+ 'ui.form.submitted.linkPicker': FormSubmittedLinkPickerAttributesType;
14
+ 'ui.inlineDialog.viewed.linkPicker': InlineDialogViewedLinkPickerAttributesType;
15
+ 'ui.inlineDialog.closed.linkPicker': InlineDialogClosedLinkPickerAttributesType;
16
+ };
17
+ declare function createEventPayload<K extends keyof AnalyticsEventAttributes>(eventKey: K, attributes: AnalyticsEventAttributes[K]): {
18
+ eventType: string;
19
+ actionSubject: string;
20
+ action: string;
21
+ actionSubjectId: string;
22
+ attributes: AnalyticsEventAttributes[K];
23
+ };
24
+ export default createEventPayload;
@@ -0,0 +1,2 @@
1
+ export declare const ANALYTICS_CHANNEL = "media";
2
+ export declare const COMPONENT_NAME = "LinkPicker";
@@ -6,7 +6,6 @@ export interface Props extends Omit<TextFieldProps, 'value' | 'onChange' | 'auto
6
6
  autoFocus?: boolean;
7
7
  value: string;
8
8
  onChange: (value: string) => void;
9
- onSubmit?: (value: string) => void;
10
9
  onUndo?: Function;
11
10
  onRedo?: Function;
12
11
  onClear?: Function;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "description": "Standalone link picker",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
@@ -26,7 +26,8 @@
26
26
  ".": "./src/index.ts"
27
27
  },
28
28
  "scripts": {
29
- "ak-postbuild": "ls -d dist/* | grep -v dist/types | xargs -n 1 copyfiles -u 1 -V src/**/*.svg"
29
+ "ak-postbuild": "ls -d dist/* | grep -v dist/types | xargs -n 1 copyfiles -u 1 -V src/**/*.svg",
30
+ "codegen-analytics": "ts-node --project ../../../tsconfig.node.json ./scripts/build/codegen-analytics"
30
31
  },
31
32
  "dependencies": {
32
33
  "@atlaskit/analytics-next": "^8.3.1",
@@ -52,6 +53,7 @@
52
53
  "react-intl-next": "npm:react-intl@^5.18.1"
53
54
  },
54
55
  "devDependencies": {
56
+ "@af/codegen": "*",
55
57
  "@atlaskit/activity-provider": "^2.3.2",
56
58
  "@atlaskit/docs": "*",
57
59
  "@atlaskit/link-test-helpers": "^1.4.0",
@@ -61,17 +63,22 @@
61
63
  "@atlaskit/visual-regression": "*",
62
64
  "@atlaskit/webdriver-runner": "*",
63
65
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
64
- "@atlassian/link-picker-atlassian-plugin": "^17.0.0",
65
- "@atlassian/link-picker-plugins": "^4.0.0",
66
+ "@atlassian/link-picker-atlassian-plugin": "^18.0.0",
67
+ "@atlassian/link-picker-plugins": "^5.1.0",
68
+ "@atlassian/recent-work-client": "^1.5.0",
66
69
  "@atlassian/search-provider": "^2.3.0",
67
70
  "@testing-library/dom": "^7.7.3",
68
71
  "@testing-library/jest-dom": "^4.1.0",
69
72
  "@testing-library/react": "^8.0.1",
70
73
  "@testing-library/react-hooks": "^1.0.4",
71
74
  "@testing-library/user-event": "10.4.0",
75
+ "@types/js-yaml": "^3.12.5",
72
76
  "enzyme": "^3.10.0",
73
77
  "fetch-mock": "^8.0.0",
78
+ "js-yaml": "^3.13.1",
79
+ "lodash": "^4.17.21",
74
80
  "mockdate": "^3.0.2",
81
+ "prettier": "^2.1.1",
75
82
  "react-dom": "^16.8.0",
76
83
  "sinon": "^2.2.0",
77
84
  "typescript": "4.2.4"