@atlaskit/link-picker 1.22.2 → 1.23.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 (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/common/utils/date.js +16 -0
  3. package/dist/cjs/common/utils/dateUtils.js +72 -0
  4. package/dist/cjs/i18n/languages.js +38 -0
  5. package/dist/cjs/ui/link-picker/index.js +4 -4
  6. package/dist/cjs/ui/link-picker/link-search-list/index.js +15 -2
  7. package/dist/cjs/ui/link-picker/link-search-list/link-search-no-results/styled.js +5 -3
  8. package/dist/cjs/ui/link-picker/list-item/index.js +1 -4
  9. package/dist/cjs/ui/link-picker/messages.js +11 -16
  10. package/dist/cjs/ui/link-picker/transformTimeStamp.js +27 -22
  11. package/dist/cjs/ui/link-picker/utils.js +1 -2
  12. package/dist/cjs/version.json +1 -1
  13. package/dist/es2019/common/utils/date.js +9 -0
  14. package/dist/es2019/common/utils/dateUtils.js +61 -0
  15. package/dist/es2019/i18n/languages.js +31 -0
  16. package/dist/es2019/ui/link-picker/index.js +4 -4
  17. package/dist/es2019/ui/link-picker/link-search-list/index.js +14 -1
  18. package/dist/es2019/ui/link-picker/link-search-list/link-search-no-results/styled.js +3 -0
  19. package/dist/es2019/ui/link-picker/list-item/index.js +1 -4
  20. package/dist/es2019/ui/link-picker/messages.js +9 -14
  21. package/dist/es2019/ui/link-picker/transformTimeStamp.js +29 -23
  22. package/dist/es2019/ui/link-picker/utils.js +1 -2
  23. package/dist/es2019/version.json +1 -1
  24. package/dist/esm/common/utils/date.js +9 -0
  25. package/dist/esm/common/utils/dateUtils.js +63 -0
  26. package/dist/esm/i18n/languages.js +31 -0
  27. package/dist/esm/ui/link-picker/index.js +4 -4
  28. package/dist/esm/ui/link-picker/link-search-list/index.js +15 -2
  29. package/dist/esm/ui/link-picker/link-search-list/link-search-no-results/styled.js +3 -2
  30. package/dist/esm/ui/link-picker/list-item/index.js +1 -4
  31. package/dist/esm/ui/link-picker/messages.js +9 -14
  32. package/dist/esm/ui/link-picker/transformTimeStamp.js +28 -23
  33. package/dist/esm/ui/link-picker/utils.js +1 -2
  34. package/dist/esm/version.json +1 -1
  35. package/dist/types/common/utils/date.d.ts +1 -0
  36. package/dist/types/common/utils/dateUtils.d.ts +8 -0
  37. package/dist/types/i18n/languages.d.ts +32 -0
  38. package/dist/types/index.d.ts +1 -1
  39. package/dist/types/ui/link-picker/link-search-list/index.d.ts +2 -1
  40. package/dist/types/ui/link-picker/link-search-list/link-search-no-results/styled.d.ts +1 -0
  41. package/dist/types/ui/link-picker/messages.d.ts +3 -8
  42. package/dist/types/ui/link-picker/transformTimeStamp.d.ts +1 -2
  43. package/dist/types/ui/types.d.ts +3 -5
  44. package/dist/types-ts4.5/common/utils/date.d.ts +1 -0
  45. package/dist/types-ts4.5/common/utils/dateUtils.d.ts +8 -0
  46. package/dist/types-ts4.5/i18n/languages.d.ts +32 -0
  47. package/dist/types-ts4.5/index.d.ts +1 -1
  48. package/dist/types-ts4.5/ui/link-picker/link-search-list/index.d.ts +2 -1
  49. package/dist/types-ts4.5/ui/link-picker/link-search-list/link-search-no-results/styled.d.ts +1 -0
  50. package/dist/types-ts4.5/ui/link-picker/messages.d.ts +3 -8
  51. package/dist/types-ts4.5/ui/link-picker/transformTimeStamp.d.ts +1 -2
  52. package/dist/types-ts4.5/ui/types.d.ts +3 -5
  53. package/package.json +13 -4
  54. package/report.api.md +4 -0
  55. package/tmp/api-report-tmp.d.ts +4 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/link-picker
2
2
 
3
+ ## 1.23.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1d9bcdf92d8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1d9bcdf92d8) - EDM-5278: refactor timestamp in link-picker to remove string concatenation, to switch between relative and absolute time with correct display values and add new atlas kit example to test translations for link-picker
8
+
9
+ ## 1.23.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`5b744a84924`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5b744a84924) - [ux] Support for an empty state in LinkPicker, and implementation of empty state for the link-picker-atlassian-plugin
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 1.22.2
4
20
 
5
21
  ### Patch Changes
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isMoreThanOneWeekAgo = isMoreThanOneWeekAgo;
8
+ var _isBefore = _interopRequireDefault(require("date-fns/isBefore"));
9
+ var _startOfDay = _interopRequireDefault(require("date-fns/startOfDay"));
10
+ var _subWeeks = _interopRequireDefault(require("date-fns/subWeeks"));
11
+ function isMoreThanOneWeekAgo(date) {
12
+ return (0, _isBefore.default)(new Date(date), startOfOneWeekAgo());
13
+ }
14
+ function startOfOneWeekAgo() {
15
+ return (0, _startOfDay.default)((0, _subWeeks.default)(new Date(), 1));
16
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DEFAULT_THRESHOLDS = void 0;
8
+ exports.selectUnit = selectUnit;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+ 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) { (0, _defineProperty2.default)(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; }
12
+ //copied from packages/activity-platform/recent-work-ui/src/common/ui/activity-event-type-message/utils.ts
13
+
14
+ var MS_PER_SECOND = 1e3;
15
+ var SECS_PER_MIN = 60;
16
+ var SECS_PER_HOUR = SECS_PER_MIN * 60;
17
+ var SECS_PER_DAY = SECS_PER_HOUR * 24;
18
+ var SECS_PER_WEEK = SECS_PER_DAY * 7;
19
+
20
+ // This function is a direct copy from https://github.com/formatjs/formatjs-old/blob/master/packages/intl-utils/src/diff.ts
21
+ // If the year between 'from' and 'to' is different and there is more than a week between them, the function returns
22
+ // 'year' as the unit. This means some activities display a '1 year ago' even though its 10 days old.
23
+ //
24
+ // In the below, we have removed the check for 'year' and 'month' as we display absolute dates for those periods.
25
+ function selectUnit(from) {
26
+ var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
27
+ var thresholds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
28
+ var resolvedThresholds = _objectSpread(_objectSpread({}, DEFAULT_THRESHOLDS), thresholds || {});
29
+ var secs = (+from - +to) / MS_PER_SECOND;
30
+ if (Math.abs(secs) < resolvedThresholds.second) {
31
+ return {
32
+ value: Math.round(secs),
33
+ unit: 'second'
34
+ };
35
+ }
36
+ var mins = secs / SECS_PER_MIN;
37
+ if (Math.abs(mins) < resolvedThresholds.minute) {
38
+ return {
39
+ value: Math.round(mins),
40
+ unit: 'minute'
41
+ };
42
+ }
43
+ var hours = secs / SECS_PER_HOUR;
44
+ if (Math.abs(hours) < resolvedThresholds.hour) {
45
+ return {
46
+ value: Math.round(hours),
47
+ unit: 'hour'
48
+ };
49
+ }
50
+ var days = secs / SECS_PER_DAY;
51
+ if (Math.abs(days) < resolvedThresholds.day) {
52
+ return {
53
+ value: Math.round(days),
54
+ unit: 'day'
55
+ };
56
+ }
57
+ var weeks = secs / SECS_PER_WEEK;
58
+ return {
59
+ value: Math.round(weeks),
60
+ unit: 'week'
61
+ };
62
+ }
63
+ var DEFAULT_THRESHOLDS = {
64
+ second: 45,
65
+ // seconds to minute
66
+ minute: 45,
67
+ // minutes to hour
68
+ hour: 22,
69
+ // hour to day
70
+ day: 5 // day to week
71
+ };
72
+ exports.DEFAULT_THRESHOLDS = DEFAULT_THRESHOLDS;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ zh: 'Chinese',
9
+ zh_TW: 'Chinese (Traditional)',
10
+ cs: 'Czech',
11
+ nl: 'Dutch',
12
+ da: 'Danish',
13
+ en: 'English',
14
+ en_GB: 'English (United Kingdom)',
15
+ et: 'Estonian',
16
+ fi: 'Finnish',
17
+ fr: 'French',
18
+ de: 'German',
19
+ hu: 'Hungarian',
20
+ is: 'Icelandic',
21
+ it: 'Italian',
22
+ ja: 'Japanese',
23
+ ko: 'Korean',
24
+ nb: 'Norwegian Bokmål',
25
+ pl: 'Polish',
26
+ pt_BR: 'Portuguese (Brazil)',
27
+ pt_PT: 'Portuguese (Portugal)',
28
+ ro: 'Romanian',
29
+ ru: 'Russian',
30
+ sk: 'Slovak',
31
+ es: 'Spanish',
32
+ sv: 'Swedish',
33
+ th: 'Thai',
34
+ tr: 'Turkish',
35
+ uk: 'Ukrainian',
36
+ vi: 'Vietnamese'
37
+ };
38
+ exports.default = _default;
@@ -88,7 +88,7 @@ var LinkInputField = (0, _analytics2.withInputFieldTracking)(_textInput.default,
88
88
  });
89
89
  var DisplayTextInputField = (0, _analytics2.withInputFieldTracking)(_textInput.default, 'displayText');
90
90
  function LinkPicker(_ref) {
91
- var _errorFallback;
91
+ var _activePlugin$errorFa, _activePlugin$errorFa2;
92
92
  var onSubmit = _ref.onSubmit,
93
93
  onCancel = _ref.onCancel,
94
94
  onContentResize = _ref.onContentResize,
@@ -122,7 +122,6 @@ function LinkPicker(_ref) {
122
122
  tabs = _usePlugins.tabs,
123
123
  error = _usePlugins.error,
124
124
  retry = _usePlugins.retry,
125
- errorFallback = _usePlugins.errorFallback,
126
125
  pluginAction = _usePlugins.pluginAction;
127
126
  var fixListHeightProps = (0, _useFixHeight.default)(isLoading);
128
127
  var isEditing = !!initUrl;
@@ -368,8 +367,9 @@ function LinkPicker(_ref) {
368
367
  onSelect: handleSelected,
369
368
  onChange: handleSearchListOnChange,
370
369
  onKeyDown: handleKeyDown,
371
- hasSearchTerm: !!(queryState !== null && queryState !== void 0 && queryState.query.length)
372
- }), error && ((_errorFallback = errorFallback === null || errorFallback === void 0 ? void 0 : errorFallback(error, retry)) !== null && _errorFallback !== void 0 ? _errorFallback : (0, _react2.jsx)(_linkSearchError.default, null)))), (0, _react2.jsx)(_formFooter.default, {
370
+ hasSearchTerm: !!(queryState !== null && queryState !== void 0 && queryState.query.length),
371
+ activePlugin: activePlugin
372
+ }), error && ((_activePlugin$errorFa = activePlugin === null || activePlugin === void 0 ? void 0 : (_activePlugin$errorFa2 = activePlugin.errorFallback) === null || _activePlugin$errorFa2 === void 0 ? void 0 : _activePlugin$errorFa2.call(activePlugin, error, retry)) !== null && _activePlugin$errorFa !== void 0 ? _activePlugin$errorFa : (0, _react2.jsx)(_linkSearchError.default, null)))), (0, _react2.jsx)(_formFooter.default, {
373
373
  error: error,
374
374
  items: items,
375
375
  state: queryState,
@@ -11,6 +11,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
11
11
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
12
  var _react = require("react");
13
13
  var _react2 = require("@emotion/react");
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
15
  var _reactIntlNext = require("react-intl-next");
15
16
  var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
16
17
  var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
@@ -19,7 +20,8 @@ var _styled = require("./styled");
19
20
  var _linkSearchNoResults = _interopRequireWildcard(require("./link-search-no-results"));
20
21
  var _useTrackResultsShown = require("./use-track-results-shown");
21
22
  var _utils = require("../utils");
22
- var _excluded = ["onChange", "onSelect", "onKeyDown", "items", "activeIndex", "selectedIndex", "isLoading", "ariaControls", "ariaLabelledBy", "role", "id", "hasSearchTerm"];
23
+ var _styled2 = require("./link-search-no-results/styled");
24
+ var _excluded = ["onChange", "onSelect", "onKeyDown", "items", "activeIndex", "selectedIndex", "isLoading", "ariaControls", "ariaLabelledBy", "role", "id", "hasSearchTerm", "activePlugin"];
23
25
  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); }
24
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
25
27
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -62,6 +64,7 @@ var LinkSearchList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
62
64
  role = _ref.role,
63
65
  id = _ref.id,
64
66
  hasSearchTerm = _ref.hasSearchTerm,
67
+ activePlugin = _ref.activePlugin,
65
68
  restProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
66
69
  var itemsContent;
67
70
  var loadingContent;
@@ -109,7 +112,17 @@ var LinkSearchList = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
109
112
  }
110
113
  }, [activeIndex, items, onChange, onKeyDown]);
111
114
  if ((items === null || items === void 0 ? void 0 : items.length) === 0) {
112
- return (0, _react2.jsx)(_linkSearchNoResults.default, null);
115
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.link-picker.enable-empty-state')) {
116
+ if (hasSearchTerm) {
117
+ return (0, _react2.jsx)(_linkSearchNoResults.default, null);
118
+ } else {
119
+ return (0, _react2.jsx)("div", {
120
+ css: _styled2.emptyStateNoResultsWrapper
121
+ }, activePlugin !== null && activePlugin !== void 0 && activePlugin.emptyStateNoResults ? activePlugin.emptyStateNoResults() : null);
122
+ }
123
+ } else {
124
+ return (0, _react2.jsx)(_linkSearchNoResults.default, null);
125
+ }
113
126
  }
114
127
  if (items && items.length > 0) {
115
128
  itemsContent = (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)("div", {
@@ -4,9 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.emptyStateWrapperStyles = void 0;
7
+ exports.emptyStateWrapperStyles = exports.emptyStateNoResultsWrapper = void 0;
8
8
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
9
9
  var _react = require("@emotion/react");
10
- var _templateObject;
10
+ var _templateObject, _templateObject2;
11
11
  var emptyStateWrapperStyles = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n & p {\n margin: 0;\n }\n"])));
12
- exports.emptyStateWrapperStyles = emptyStateWrapperStyles;
12
+ exports.emptyStateWrapperStyles = emptyStateWrapperStyles;
13
+ var emptyStateNoResultsWrapper = (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n min-height: ", ";\n"])), "var(--ds-space-200, 16px)");
14
+ exports.emptyStateNoResultsWrapper = emptyStateNoResultsWrapper;
@@ -56,13 +56,10 @@ var LinkSearchListItem = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref
56
56
  css: _styled.listItemContainerInnerStyles
57
57
  }, container)), date && (0, _react2.jsx)("div", {
58
58
  css: _styled.listItemContainerInnerStyles
59
- }, container && (0, _react2.jsx)(_react.Fragment, null, "\xA0 \u2022\xA0 "), (0, _react2.jsx)(_react.Fragment, null, formatDate(date))))));
59
+ }, container && (0, _react2.jsx)(_react.Fragment, null, "\xA0 \u2022\xA0 "), (0, _react2.jsx)(_react.Fragment, null, date)))));
60
60
  });
61
61
  var _default = LinkSearchListItem;
62
62
  exports.default = _default;
63
- var formatDate = function formatDate(date) {
64
- return [date.pageAction, date.dateString, date.timeSince].filter(Boolean).join(' ');
65
- };
66
63
  var isSVG = function isSVG(icon) {
67
64
  return icon.startsWith('<svg') && icon.endsWith('</svg>');
68
65
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.searchMessages = exports.messages = exports.linkTextMessages = exports.linkMessages = exports.formMessages = void 0;
6
+ exports.timeMessages = exports.searchMessages = exports.linkTextMessages = exports.linkMessages = exports.formMessages = void 0;
7
7
  var _reactIntlNext = require("react-intl-next");
8
8
  var searchMessages = (0, _reactIntlNext.defineMessages)({
9
9
  linkLabel: {
@@ -77,21 +77,16 @@ var linkTextMessages = (0, _reactIntlNext.defineMessages)({
77
77
  }
78
78
  });
79
79
  exports.linkTextMessages = linkTextMessages;
80
- var messages = (0, _reactIntlNext.defineMessages)({
81
- timeUpdated: {
82
- id: 'fabric.linkPicker.time.updated',
83
- defaultMessage: 'Updated',
84
- description: 'Time last updated'
80
+ var timeMessages = (0, _reactIntlNext.defineMessages)({
81
+ updated: {
82
+ id: 'fabric.linkPicker.time.message.updated',
83
+ defaultMessage: 'Updated {time}',
84
+ description: 'Time last updated where {time} can be an absolute value e.g. June 5, 2023 or a relative value e.g. 3 hours ago'
85
85
  },
86
- timeViewed: {
87
- id: 'fabric.linkPicker.time.viewed',
88
- defaultMessage: 'Viewed',
89
- description: 'Time last viewed'
90
- },
91
- timeAgo: {
92
- id: 'fabric.linkPicker.time.ago',
93
- defaultMessage: 'ago',
94
- description: 'Some time ago'
86
+ viewed: {
87
+ id: 'fabric.linkPicker.time.message.viewed',
88
+ defaultMessage: 'Viewed {time}',
89
+ description: 'Time last viewed where {time} can be an absolute value e.g. June 5, 2023 or a relative value e.g. 3 hours ago'
95
90
  }
96
91
  });
97
- exports.messages = messages;
92
+ exports.timeMessages = timeMessages;
@@ -5,31 +5,36 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.transformTimeStamp = void 0;
8
- var _formatDistance = _interopRequireDefault(require("date-fns/formatDistance"));
9
- var _differenceInCalendarDays = _interopRequireDefault(require("date-fns/differenceInCalendarDays"));
10
- var _format = _interopRequireDefault(require("date-fns/format"));
11
8
  var _messages = require("./messages");
12
- var renderAbsoluteOrRelativeDate = function renderAbsoluteOrRelativeDate(timeStamp, pageAction, intl) {
13
- var pageActionText = '';
14
- switch (pageAction) {
15
- case 'updated':
16
- pageActionText = intl.formatMessage(_messages.messages.timeUpdated);
17
- break;
18
- case 'viewed':
19
- pageActionText = intl.formatMessage(_messages.messages.timeViewed);
20
- break;
9
+ var _date = require("../../common/utils/date");
10
+ var _dateUtils = require("../../common/utils/dateUtils");
11
+ var _isYesterday = _interopRequireDefault(require("date-fns/isYesterday"));
12
+ var formatTime = function formatTime(timeStamp, intl) {
13
+ var isAbsolute = (0, _date.isMoreThanOneWeekAgo)(timeStamp);
14
+ if (isAbsolute) {
15
+ return intl.formatDate(timeStamp, {
16
+ month: 'long',
17
+ day: 'numeric',
18
+ year: 'numeric'
19
+ });
21
20
  }
22
- if ((0, _differenceInCalendarDays.default)(timeStamp, Date.now()) < -7) {
23
- return {
24
- pageAction: pageActionText,
25
- dateString: (0, _format.default)(timeStamp, 'MMMM dd, yyyy')
26
- };
21
+ var _selectUnit = (0, _dateUtils.selectUnit)(timeStamp, new Date(), {
22
+ day: 7 // treat a week as 7 days (default is 5)
23
+ }),
24
+ value = _selectUnit.value,
25
+ unit = _selectUnit.unit;
26
+ //formats as 'yesterday' instead of '1 day ago'
27
+ if ((0, _isYesterday.default)(timeStamp)) {
28
+ return intl.formatRelativeTime(value, unit, {
29
+ numeric: 'auto'
30
+ });
27
31
  }
28
- return {
29
- pageAction: pageActionText,
30
- dateString: (0, _formatDistance.default)(timeStamp, Date.now()),
31
- timeSince: intl.formatMessage(_messages.messages.timeAgo)
32
- };
32
+ return intl.formatRelativeTime(value, unit);
33
+ };
34
+ var renderAbsoluteOrRelativeDate = function renderAbsoluteOrRelativeDate(timeStamp, pageAction, intl) {
35
+ return intl.formatMessage(_messages.timeMessages[pageAction], {
36
+ time: formatTime(timeStamp, intl)
37
+ });
33
38
  };
34
39
  var transformTimeStamp = function transformTimeStamp(intl, lastViewedDate, lastUpdatedDate) {
35
40
  if (lastViewedDate) {
@@ -46,8 +46,7 @@ function getScreenReaderText(items, selectedIndex, intl) {
46
46
  lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
47
47
  lastViewedDate = _items$selectedIndex.lastViewedDate;
48
48
  var date = (0, _transformTimeStamp.transformTimeStamp)(intl, lastViewedDate, lastUpdatedDate);
49
- var formattedDate = [date === null || date === void 0 ? void 0 : date.pageAction, date === null || date === void 0 ? void 0 : date.dateString, date === null || date === void 0 ? void 0 : date.timeSince].filter(Boolean).join(' ');
50
- return [name, container, formattedDate].filter(Boolean).join(', ');
49
+ return [name, container, date].filter(Boolean).join(', ');
51
50
  }
52
51
  }
53
52
  var handleNavKeyDown = function handleNavKeyDown(event, itemsLength, activeIndex) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.22.2",
3
+ "version": "1.23.1",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,9 @@
1
+ import isBefore from 'date-fns/isBefore';
2
+ import startOfDay from 'date-fns/startOfDay';
3
+ import subWeeks from 'date-fns/subWeeks';
4
+ export function isMoreThanOneWeekAgo(date) {
5
+ return isBefore(new Date(date), startOfOneWeekAgo());
6
+ }
7
+ function startOfOneWeekAgo() {
8
+ return startOfDay(subWeeks(new Date(), 1));
9
+ }
@@ -0,0 +1,61 @@
1
+ //copied from packages/activity-platform/recent-work-ui/src/common/ui/activity-event-type-message/utils.ts
2
+
3
+ const MS_PER_SECOND = 1e3;
4
+ const SECS_PER_MIN = 60;
5
+ const SECS_PER_HOUR = SECS_PER_MIN * 60;
6
+ const SECS_PER_DAY = SECS_PER_HOUR * 24;
7
+ const SECS_PER_WEEK = SECS_PER_DAY * 7;
8
+
9
+ // This function is a direct copy from https://github.com/formatjs/formatjs-old/blob/master/packages/intl-utils/src/diff.ts
10
+ // If the year between 'from' and 'to' is different and there is more than a week between them, the function returns
11
+ // 'year' as the unit. This means some activities display a '1 year ago' even though its 10 days old.
12
+ //
13
+ // In the below, we have removed the check for 'year' and 'month' as we display absolute dates for those periods.
14
+ export function selectUnit(from, to = Date.now(), thresholds = {}) {
15
+ const resolvedThresholds = {
16
+ ...DEFAULT_THRESHOLDS,
17
+ ...(thresholds || {})
18
+ };
19
+ const secs = (+from - +to) / MS_PER_SECOND;
20
+ if (Math.abs(secs) < resolvedThresholds.second) {
21
+ return {
22
+ value: Math.round(secs),
23
+ unit: 'second'
24
+ };
25
+ }
26
+ const mins = secs / SECS_PER_MIN;
27
+ if (Math.abs(mins) < resolvedThresholds.minute) {
28
+ return {
29
+ value: Math.round(mins),
30
+ unit: 'minute'
31
+ };
32
+ }
33
+ const hours = secs / SECS_PER_HOUR;
34
+ if (Math.abs(hours) < resolvedThresholds.hour) {
35
+ return {
36
+ value: Math.round(hours),
37
+ unit: 'hour'
38
+ };
39
+ }
40
+ const days = secs / SECS_PER_DAY;
41
+ if (Math.abs(days) < resolvedThresholds.day) {
42
+ return {
43
+ value: Math.round(days),
44
+ unit: 'day'
45
+ };
46
+ }
47
+ const weeks = secs / SECS_PER_WEEK;
48
+ return {
49
+ value: Math.round(weeks),
50
+ unit: 'week'
51
+ };
52
+ }
53
+ export const DEFAULT_THRESHOLDS = {
54
+ second: 45,
55
+ // seconds to minute
56
+ minute: 45,
57
+ // minutes to hour
58
+ hour: 22,
59
+ // hour to day
60
+ day: 5 // day to week
61
+ };
@@ -0,0 +1,31 @@
1
+ export default {
2
+ zh: 'Chinese',
3
+ zh_TW: 'Chinese (Traditional)',
4
+ cs: 'Czech',
5
+ nl: 'Dutch',
6
+ da: 'Danish',
7
+ en: 'English',
8
+ en_GB: 'English (United Kingdom)',
9
+ et: 'Estonian',
10
+ fi: 'Finnish',
11
+ fr: 'French',
12
+ de: 'German',
13
+ hu: 'Hungarian',
14
+ is: 'Icelandic',
15
+ it: 'Italian',
16
+ ja: 'Japanese',
17
+ ko: 'Korean',
18
+ nb: 'Norwegian Bokmål',
19
+ pl: 'Polish',
20
+ pt_BR: 'Portuguese (Brazil)',
21
+ pt_PT: 'Portuguese (Portugal)',
22
+ ro: 'Romanian',
23
+ ru: 'Russian',
24
+ sk: 'Slovak',
25
+ es: 'Spanish',
26
+ sv: 'Swedish',
27
+ th: 'Thai',
28
+ tr: 'Turkish',
29
+ uk: 'Ukrainian',
30
+ vi: 'Vietnamese'
31
+ };
@@ -89,7 +89,7 @@ function LinkPicker({
89
89
  hideDisplayText,
90
90
  featureFlags
91
91
  }) {
92
- var _errorFallback;
92
+ var _activePlugin$errorFa, _activePlugin$errorFa2;
93
93
  const {
94
94
  createAnalyticsEvent
95
95
  } = useAnalyticsEvents();
@@ -116,7 +116,6 @@ function LinkPicker({
116
116
  tabs,
117
117
  error,
118
118
  retry,
119
- errorFallback,
120
119
  pluginAction
121
120
  } = usePlugins(queryState, activeTab, plugins);
122
121
  const fixListHeightProps = useFixHeight(isLoading);
@@ -362,8 +361,9 @@ function LinkPicker({
362
361
  onSelect: handleSelected,
363
362
  onChange: handleSearchListOnChange,
364
363
  onKeyDown: handleKeyDown,
365
- hasSearchTerm: !!(queryState !== null && queryState !== void 0 && queryState.query.length)
366
- }), error && ((_errorFallback = errorFallback === null || errorFallback === void 0 ? void 0 : errorFallback(error, retry)) !== null && _errorFallback !== void 0 ? _errorFallback : jsx(LinkSearchError, null)))), jsx(FormFooter, {
364
+ hasSearchTerm: !!(queryState !== null && queryState !== void 0 && queryState.query.length),
365
+ activePlugin: activePlugin
366
+ }), error && ((_activePlugin$errorFa = activePlugin === null || activePlugin === void 0 ? void 0 : (_activePlugin$errorFa2 = activePlugin.errorFallback) === null || _activePlugin$errorFa2 === void 0 ? void 0 : _activePlugin$errorFa2.call(activePlugin, error, retry)) !== null && _activePlugin$errorFa !== void 0 ? _activePlugin$errorFa : jsx(LinkSearchError, null)))), jsx(FormFooter, {
367
367
  error: error,
368
368
  items: items,
369
369
  state: queryState,
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
3
  import { forwardRef, Fragment, useCallback, useRef } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { defineMessages, FormattedMessage } from 'react-intl-next';
6
7
  import Spinner from '@atlaskit/spinner';
7
8
  import VisuallyHidden from '@atlaskit/visually-hidden';
@@ -10,6 +11,7 @@ import { listContainerStyles, spinnerContainerStyles, listStyles, listTitleStyle
10
11
  import LinkSearchNoResults, { testIds as noResultsTestIds } from './link-search-no-results';
11
12
  import { useTrackResultsShown } from './use-track-results-shown';
12
13
  import { handleNavKeyDown } from '../utils';
14
+ import { emptyStateNoResultsWrapper } from './link-search-no-results/styled';
13
15
  export const messages = defineMessages({
14
16
  titleRecentlyViewed: {
15
17
  id: 'fabric.linkPicker.listTitle.recentlyViewed',
@@ -47,6 +49,7 @@ const LinkSearchList = /*#__PURE__*/forwardRef(({
47
49
  role,
48
50
  id,
49
51
  hasSearchTerm,
52
+ activePlugin,
50
53
  ...restProps
51
54
  }, ref) => {
52
55
  let itemsContent;
@@ -95,7 +98,17 @@ const LinkSearchList = /*#__PURE__*/forwardRef(({
95
98
  }
96
99
  }, [activeIndex, items, onChange, onKeyDown]);
97
100
  if ((items === null || items === void 0 ? void 0 : items.length) === 0) {
98
- return jsx(LinkSearchNoResults, null);
101
+ if (getBooleanFF('platform.linking-platform.link-picker.enable-empty-state')) {
102
+ if (hasSearchTerm) {
103
+ return jsx(LinkSearchNoResults, null);
104
+ } else {
105
+ return jsx("div", {
106
+ css: emptyStateNoResultsWrapper
107
+ }, activePlugin !== null && activePlugin !== void 0 && activePlugin.emptyStateNoResults ? activePlugin.emptyStateNoResults() : null);
108
+ }
109
+ } else {
110
+ return jsx(LinkSearchNoResults, null);
111
+ }
99
112
  }
100
113
  if (items && items.length > 0) {
101
114
  itemsContent = jsx(Fragment, null, jsx("div", {
@@ -3,4 +3,7 @@ export const emptyStateWrapperStyles = css`
3
3
  & p {
4
4
  margin: 0;
5
5
  }
6
+ `;
7
+ export const emptyStateNoResultsWrapper = css`
8
+ min-height: ${"var(--ds-space-200, 16px)"};
6
9
  `;
@@ -48,12 +48,9 @@ const LinkSearchListItem = /*#__PURE__*/forwardRef(({
48
48
  css: listItemContainerInnerStyles
49
49
  }, container)), date && jsx("div", {
50
50
  css: listItemContainerInnerStyles
51
- }, container && jsx(Fragment, null, "\xA0 \u2022\xA0 "), jsx(Fragment, null, formatDate(date))))));
51
+ }, container && jsx(Fragment, null, "\xA0 \u2022\xA0 "), jsx(Fragment, null, date)))));
52
52
  });
53
53
  export default LinkSearchListItem;
54
- const formatDate = date => {
55
- return [date.pageAction, date.dateString, date.timeSince].filter(Boolean).join(' ');
56
- };
57
54
  const isSVG = icon => icon.startsWith('<svg') && icon.endsWith('</svg>');
58
55
  const base64SVG = icon => `data:image/svg+xml;base64,${Buffer.from(icon).toString('base64')}`;
59
56
  const testId = 'link-search-list-item-icon';
@@ -67,20 +67,15 @@ export const linkTextMessages = defineMessages({
67
67
  description: 'Tooltip message for link input clear button'
68
68
  }
69
69
  });
70
- export const messages = defineMessages({
71
- timeUpdated: {
72
- id: 'fabric.linkPicker.time.updated',
73
- defaultMessage: 'Updated',
74
- description: 'Time last updated'
70
+ export const timeMessages = defineMessages({
71
+ updated: {
72
+ id: 'fabric.linkPicker.time.message.updated',
73
+ defaultMessage: 'Updated {time}',
74
+ description: 'Time last updated where {time} can be an absolute value e.g. June 5, 2023 or a relative value e.g. 3 hours ago'
75
75
  },
76
- timeViewed: {
77
- id: 'fabric.linkPicker.time.viewed',
78
- defaultMessage: 'Viewed',
79
- description: 'Time last viewed'
80
- },
81
- timeAgo: {
82
- id: 'fabric.linkPicker.time.ago',
83
- defaultMessage: 'ago',
84
- description: 'Some time ago'
76
+ viewed: {
77
+ id: 'fabric.linkPicker.time.message.viewed',
78
+ defaultMessage: 'Viewed {time}',
79
+ description: 'Time last viewed where {time} can be an absolute value e.g. June 5, 2023 or a relative value e.g. 3 hours ago'
85
80
  }
86
81
  });