@atlaskit/link-picker 1.23.0 → 1.23.2

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 (38) hide show
  1. package/CHANGELOG.md +12 -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/list-item/index.js +1 -4
  6. package/dist/cjs/ui/link-picker/messages.js +11 -16
  7. package/dist/cjs/ui/link-picker/transformTimeStamp.js +27 -22
  8. package/dist/cjs/ui/link-picker/utils.js +1 -2
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/common/utils/date.js +9 -0
  11. package/dist/es2019/common/utils/dateUtils.js +61 -0
  12. package/dist/es2019/i18n/languages.js +31 -0
  13. package/dist/es2019/ui/link-picker/list-item/index.js +1 -4
  14. package/dist/es2019/ui/link-picker/messages.js +9 -14
  15. package/dist/es2019/ui/link-picker/transformTimeStamp.js +29 -23
  16. package/dist/es2019/ui/link-picker/utils.js +1 -2
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/common/utils/date.js +9 -0
  19. package/dist/esm/common/utils/dateUtils.js +63 -0
  20. package/dist/esm/i18n/languages.js +31 -0
  21. package/dist/esm/ui/link-picker/list-item/index.js +1 -4
  22. package/dist/esm/ui/link-picker/messages.js +9 -14
  23. package/dist/esm/ui/link-picker/transformTimeStamp.js +28 -23
  24. package/dist/esm/ui/link-picker/utils.js +1 -2
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/common/utils/date.d.ts +1 -0
  27. package/dist/types/common/utils/dateUtils.d.ts +8 -0
  28. package/dist/types/i18n/languages.d.ts +32 -0
  29. package/dist/types/ui/link-picker/messages.d.ts +3 -8
  30. package/dist/types/ui/link-picker/transformTimeStamp.d.ts +1 -2
  31. package/dist/types/ui/types.d.ts +0 -5
  32. package/dist/types-ts4.5/common/utils/date.d.ts +1 -0
  33. package/dist/types-ts4.5/common/utils/dateUtils.d.ts +8 -0
  34. package/dist/types-ts4.5/i18n/languages.d.ts +32 -0
  35. package/dist/types-ts4.5/ui/link-picker/messages.d.ts +3 -8
  36. package/dist/types-ts4.5/ui/link-picker/transformTimeStamp.d.ts +1 -2
  37. package/dist/types-ts4.5/ui/types.d.ts +0 -5
  38. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/link-picker
2
2
 
3
+ ## 1.23.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`44d226ae268`](https://bitbucket.org/atlassian/atlassian-frontend/commits/44d226ae268) - [ux] This adds support for Confluence Whiteboards in Link Picker search. This also adds a new scope in `@atlassian/search-client`, which contains pages, blogs and whiteboards.
8
+
9
+ ## 1.23.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`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
14
+
3
15
  ## 1.23.0
4
16
 
5
17
  ### Minor 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;
@@ -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.23.0",
3
+ "version": "1.23.2",
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
+ };
@@ -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
  });
@@ -1,28 +1,34 @@
1
- import formatDistance from 'date-fns/formatDistance';
2
- import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
3
- import format from 'date-fns/format';
4
- import { messages } from './messages';
5
- const renderAbsoluteOrRelativeDate = (timeStamp, pageAction, intl) => {
6
- let pageActionText = '';
7
- switch (pageAction) {
8
- case 'updated':
9
- pageActionText = intl.formatMessage(messages.timeUpdated);
10
- break;
11
- case 'viewed':
12
- pageActionText = intl.formatMessage(messages.timeViewed);
13
- break;
1
+ import { timeMessages } from './messages';
2
+ import { isMoreThanOneWeekAgo } from '../../common/utils/date';
3
+ import { selectUnit } from '../../common/utils/dateUtils';
4
+ import isYesterday from 'date-fns/isYesterday';
5
+ const formatTime = (timeStamp, intl) => {
6
+ const isAbsolute = isMoreThanOneWeekAgo(timeStamp);
7
+ if (isAbsolute) {
8
+ return intl.formatDate(timeStamp, {
9
+ month: 'long',
10
+ day: 'numeric',
11
+ year: 'numeric'
12
+ });
14
13
  }
15
- if (differenceInCalendarDays(timeStamp, Date.now()) < -7) {
16
- return {
17
- pageAction: pageActionText,
18
- dateString: format(timeStamp, 'MMMM dd, yyyy')
19
- };
14
+ const {
15
+ value,
16
+ unit
17
+ } = selectUnit(timeStamp, new Date(), {
18
+ day: 7 // treat a week as 7 days (default is 5)
19
+ });
20
+ //formats as 'yesterday' instead of '1 day ago'
21
+ if (isYesterday(timeStamp)) {
22
+ return intl.formatRelativeTime(value, unit, {
23
+ numeric: 'auto'
24
+ });
20
25
  }
21
- return {
22
- pageAction: pageActionText,
23
- dateString: formatDistance(timeStamp, Date.now()),
24
- timeSince: intl.formatMessage(messages.timeAgo)
25
- };
26
+ return intl.formatRelativeTime(value, unit);
27
+ };
28
+ const renderAbsoluteOrRelativeDate = (timeStamp, pageAction, intl) => {
29
+ return intl.formatMessage(timeMessages[pageAction], {
30
+ time: formatTime(timeStamp, intl)
31
+ });
26
32
  };
27
33
  export const transformTimeStamp = (intl, lastViewedDate, lastUpdatedDate) => {
28
34
  if (lastViewedDate) {
@@ -38,8 +38,7 @@ export function getScreenReaderText(items, selectedIndex, intl) {
38
38
  lastViewedDate
39
39
  } = items[selectedIndex];
40
40
  const date = transformTimeStamp(intl, lastViewedDate, lastUpdatedDate);
41
- const 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(' ');
42
- return [name, container, formattedDate].filter(Boolean).join(', ');
41
+ return [name, container, date].filter(Boolean).join(', ');
43
42
  }
44
43
  }
45
44
  export const handleNavKeyDown = (event, itemsLength, activeIndex) => {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
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,63 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ //copied from packages/activity-platform/recent-work-ui/src/common/ui/activity-event-type-message/utils.ts
5
+
6
+ var MS_PER_SECOND = 1e3;
7
+ var SECS_PER_MIN = 60;
8
+ var SECS_PER_HOUR = SECS_PER_MIN * 60;
9
+ var SECS_PER_DAY = SECS_PER_HOUR * 24;
10
+ var SECS_PER_WEEK = SECS_PER_DAY * 7;
11
+
12
+ // This function is a direct copy from https://github.com/formatjs/formatjs-old/blob/master/packages/intl-utils/src/diff.ts
13
+ // If the year between 'from' and 'to' is different and there is more than a week between them, the function returns
14
+ // 'year' as the unit. This means some activities display a '1 year ago' even though its 10 days old.
15
+ //
16
+ // In the below, we have removed the check for 'year' and 'month' as we display absolute dates for those periods.
17
+ export function selectUnit(from) {
18
+ var to = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
19
+ var thresholds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20
+ var resolvedThresholds = _objectSpread(_objectSpread({}, DEFAULT_THRESHOLDS), thresholds || {});
21
+ var secs = (+from - +to) / MS_PER_SECOND;
22
+ if (Math.abs(secs) < resolvedThresholds.second) {
23
+ return {
24
+ value: Math.round(secs),
25
+ unit: 'second'
26
+ };
27
+ }
28
+ var mins = secs / SECS_PER_MIN;
29
+ if (Math.abs(mins) < resolvedThresholds.minute) {
30
+ return {
31
+ value: Math.round(mins),
32
+ unit: 'minute'
33
+ };
34
+ }
35
+ var hours = secs / SECS_PER_HOUR;
36
+ if (Math.abs(hours) < resolvedThresholds.hour) {
37
+ return {
38
+ value: Math.round(hours),
39
+ unit: 'hour'
40
+ };
41
+ }
42
+ var days = secs / SECS_PER_DAY;
43
+ if (Math.abs(days) < resolvedThresholds.day) {
44
+ return {
45
+ value: Math.round(days),
46
+ unit: 'day'
47
+ };
48
+ }
49
+ var weeks = secs / SECS_PER_WEEK;
50
+ return {
51
+ value: Math.round(weeks),
52
+ unit: 'week'
53
+ };
54
+ }
55
+ export var DEFAULT_THRESHOLDS = {
56
+ second: 45,
57
+ // seconds to minute
58
+ minute: 45,
59
+ // minutes to hour
60
+ hour: 22,
61
+ // hour to day
62
+ day: 5 // day to week
63
+ };
@@ -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
+ };
@@ -49,12 +49,9 @@ var LinkSearchListItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
49
49
  css: listItemContainerInnerStyles
50
50
  }, container)), date && jsx("div", {
51
51
  css: listItemContainerInnerStyles
52
- }, container && jsx(Fragment, null, "\xA0 \u2022\xA0 "), jsx(Fragment, null, formatDate(date))))));
52
+ }, container && jsx(Fragment, null, "\xA0 \u2022\xA0 "), jsx(Fragment, null, date)))));
53
53
  });
54
54
  export default LinkSearchListItem;
55
- var formatDate = function formatDate(date) {
56
- return [date.pageAction, date.dateString, date.timeSince].filter(Boolean).join(' ');
57
- };
58
55
  var isSVG = function isSVG(icon) {
59
56
  return icon.startsWith('<svg') && icon.endsWith('</svg>');
60
57
  };
@@ -67,20 +67,15 @@ export var linkTextMessages = defineMessages({
67
67
  description: 'Tooltip message for link input clear button'
68
68
  }
69
69
  });
70
- export var messages = defineMessages({
71
- timeUpdated: {
72
- id: 'fabric.linkPicker.time.updated',
73
- defaultMessage: 'Updated',
74
- description: 'Time last updated'
70
+ export var 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
  });
@@ -1,28 +1,33 @@
1
- import formatDistance from 'date-fns/formatDistance';
2
- import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
3
- import format from 'date-fns/format';
4
- import { messages } from './messages';
5
- var renderAbsoluteOrRelativeDate = function renderAbsoluteOrRelativeDate(timeStamp, pageAction, intl) {
6
- var pageActionText = '';
7
- switch (pageAction) {
8
- case 'updated':
9
- pageActionText = intl.formatMessage(messages.timeUpdated);
10
- break;
11
- case 'viewed':
12
- pageActionText = intl.formatMessage(messages.timeViewed);
13
- break;
1
+ import { timeMessages } from './messages';
2
+ import { isMoreThanOneWeekAgo } from '../../common/utils/date';
3
+ import { selectUnit } from '../../common/utils/dateUtils';
4
+ import isYesterday from 'date-fns/isYesterday';
5
+ var formatTime = function formatTime(timeStamp, intl) {
6
+ var isAbsolute = isMoreThanOneWeekAgo(timeStamp);
7
+ if (isAbsolute) {
8
+ return intl.formatDate(timeStamp, {
9
+ month: 'long',
10
+ day: 'numeric',
11
+ year: 'numeric'
12
+ });
14
13
  }
15
- if (differenceInCalendarDays(timeStamp, Date.now()) < -7) {
16
- return {
17
- pageAction: pageActionText,
18
- dateString: format(timeStamp, 'MMMM dd, yyyy')
19
- };
14
+ var _selectUnit = selectUnit(timeStamp, new Date(), {
15
+ day: 7 // treat a week as 7 days (default is 5)
16
+ }),
17
+ value = _selectUnit.value,
18
+ unit = _selectUnit.unit;
19
+ //formats as 'yesterday' instead of '1 day ago'
20
+ if (isYesterday(timeStamp)) {
21
+ return intl.formatRelativeTime(value, unit, {
22
+ numeric: 'auto'
23
+ });
20
24
  }
21
- return {
22
- pageAction: pageActionText,
23
- dateString: formatDistance(timeStamp, Date.now()),
24
- timeSince: intl.formatMessage(messages.timeAgo)
25
- };
25
+ return intl.formatRelativeTime(value, unit);
26
+ };
27
+ var renderAbsoluteOrRelativeDate = function renderAbsoluteOrRelativeDate(timeStamp, pageAction, intl) {
28
+ return intl.formatMessage(timeMessages[pageAction], {
29
+ time: formatTime(timeStamp, intl)
30
+ });
26
31
  };
27
32
  export var transformTimeStamp = function transformTimeStamp(intl, lastViewedDate, lastUpdatedDate) {
28
33
  if (lastViewedDate) {
@@ -35,8 +35,7 @@ export function getScreenReaderText(items, selectedIndex, intl) {
35
35
  lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
36
36
  lastViewedDate = _items$selectedIndex.lastViewedDate;
37
37
  var date = transformTimeStamp(intl, lastViewedDate, lastUpdatedDate);
38
- 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(' ');
39
- return [name, container, formattedDate].filter(Boolean).join(', ');
38
+ return [name, container, date].filter(Boolean).join(', ');
40
39
  }
41
40
  }
42
41
  export var handleNavKeyDown = function handleNavKeyDown(event, itemsLength, activeIndex) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1 @@
1
+ export declare function isMoreThanOneWeekAgo(date: string | Date): boolean;
@@ -0,0 +1,8 @@
1
+ export type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week';
2
+ export declare function selectUnit(from: Date | number, to?: Date | number, thresholds?: Partial<Thresholds>): {
3
+ value: number;
4
+ unit: Unit;
5
+ };
6
+ type Thresholds = Record<'second' | 'minute' | 'hour' | 'day', number>;
7
+ export declare const DEFAULT_THRESHOLDS: Thresholds;
8
+ export {};
@@ -0,0 +1,32 @@
1
+ declare const _default: {
2
+ zh: string;
3
+ zh_TW: string;
4
+ cs: string;
5
+ nl: string;
6
+ da: string;
7
+ en: string;
8
+ en_GB: string;
9
+ et: string;
10
+ fi: string;
11
+ fr: string;
12
+ de: string;
13
+ hu: string;
14
+ is: string;
15
+ it: string;
16
+ ja: string;
17
+ ko: string;
18
+ nb: string;
19
+ pl: string;
20
+ pt_BR: string;
21
+ pt_PT: string;
22
+ ro: string;
23
+ ru: string;
24
+ sk: string;
25
+ es: string;
26
+ sv: string;
27
+ th: string;
28
+ tr: string;
29
+ uk: string;
30
+ vi: string;
31
+ };
32
+ export default _default;
@@ -66,18 +66,13 @@ export declare const linkTextMessages: {
66
66
  description: string;
67
67
  };
68
68
  };
69
- export declare const messages: {
70
- timeUpdated: {
69
+ export declare const timeMessages: {
70
+ updated: {
71
71
  id: string;
72
72
  defaultMessage: string;
73
73
  description: string;
74
74
  };
75
- timeViewed: {
76
- id: string;
77
- defaultMessage: string;
78
- description: string;
79
- };
80
- timeAgo: {
75
+ viewed: {
81
76
  id: string;
82
77
  defaultMessage: string;
83
78
  description: string;
@@ -1,3 +1,2 @@
1
1
  import { IntlShape } from 'react-intl-next';
2
- import { ListItemTimeStamp } from '../types';
3
- export declare const transformTimeStamp: (intl: IntlShape, lastViewedDate?: Date, lastUpdatedDate?: Date) => ListItemTimeStamp | undefined;
2
+ export declare const transformTimeStamp: (intl: IntlShape, lastViewedDate?: Date, lastUpdatedDate?: Date) => string | undefined;
@@ -28,11 +28,6 @@ export interface LinkSearchListItemData {
28
28
  source?: string;
29
29
  };
30
30
  }
31
- export type ListItemTimeStamp = {
32
- pageAction: string;
33
- dateString: string;
34
- timeSince?: string | undefined;
35
- };
36
31
  export interface LinkPickerState {
37
32
  /** Current query string / URL input field value */
38
33
  query: string;
@@ -0,0 +1 @@
1
+ export declare function isMoreThanOneWeekAgo(date: string | Date): boolean;
@@ -0,0 +1,8 @@
1
+ export type Unit = 'second' | 'minute' | 'hour' | 'day' | 'week';
2
+ export declare function selectUnit(from: Date | number, to?: Date | number, thresholds?: Partial<Thresholds>): {
3
+ value: number;
4
+ unit: Unit;
5
+ };
6
+ type Thresholds = Record<'second' | 'minute' | 'hour' | 'day', number>;
7
+ export declare const DEFAULT_THRESHOLDS: Thresholds;
8
+ export {};
@@ -0,0 +1,32 @@
1
+ declare const _default: {
2
+ zh: string;
3
+ zh_TW: string;
4
+ cs: string;
5
+ nl: string;
6
+ da: string;
7
+ en: string;
8
+ en_GB: string;
9
+ et: string;
10
+ fi: string;
11
+ fr: string;
12
+ de: string;
13
+ hu: string;
14
+ is: string;
15
+ it: string;
16
+ ja: string;
17
+ ko: string;
18
+ nb: string;
19
+ pl: string;
20
+ pt_BR: string;
21
+ pt_PT: string;
22
+ ro: string;
23
+ ru: string;
24
+ sk: string;
25
+ es: string;
26
+ sv: string;
27
+ th: string;
28
+ tr: string;
29
+ uk: string;
30
+ vi: string;
31
+ };
32
+ export default _default;
@@ -66,18 +66,13 @@ export declare const linkTextMessages: {
66
66
  description: string;
67
67
  };
68
68
  };
69
- export declare const messages: {
70
- timeUpdated: {
69
+ export declare const timeMessages: {
70
+ updated: {
71
71
  id: string;
72
72
  defaultMessage: string;
73
73
  description: string;
74
74
  };
75
- timeViewed: {
76
- id: string;
77
- defaultMessage: string;
78
- description: string;
79
- };
80
- timeAgo: {
75
+ viewed: {
81
76
  id: string;
82
77
  defaultMessage: string;
83
78
  description: string;
@@ -1,3 +1,2 @@
1
1
  import { IntlShape } from 'react-intl-next';
2
- import { ListItemTimeStamp } from '../types';
3
- export declare const transformTimeStamp: (intl: IntlShape, lastViewedDate?: Date, lastUpdatedDate?: Date) => ListItemTimeStamp | undefined;
2
+ export declare const transformTimeStamp: (intl: IntlShape, lastViewedDate?: Date, lastUpdatedDate?: Date) => string | undefined;
@@ -28,11 +28,6 @@ export interface LinkSearchListItemData {
28
28
  source?: string;
29
29
  };
30
30
  }
31
- export type ListItemTimeStamp = {
32
- pageAction: string;
33
- dateString: string;
34
- timeSince?: string | undefined;
35
- };
36
31
  export interface LinkPickerState {
37
32
  /** Current query string / URL input field value */
38
33
  query: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.23.0",
3
+ "version": "1.23.2",
4
4
  "description": "Standalone link picker",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
@@ -75,6 +75,7 @@
75
75
  "devDependencies": {
76
76
  "@af/analytics-codegen": "^0.1.0",
77
77
  "@atlaskit/docs": "*",
78
+ "@atlaskit/dropdown-menu": "^11.9.0",
78
79
  "@atlaskit/link-analytics": "^8.0.0",
79
80
  "@atlaskit/link-provider": "^1.6.0",
80
81
  "@atlaskit/link-test-helpers": "^4.0.0",
@@ -85,7 +86,7 @@
85
86
  "@atlaskit/webdriver-runner": "*",
86
87
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
87
88
  "@atlassian/feature-flags-test-utils": "*",
88
- "@atlassian/link-picker-atlassian-plugin": "^33.2.0",
89
+ "@atlassian/link-picker-atlassian-plugin": "^33.3.0",
89
90
  "@atlassian/link-picker-plugins": "^22.2.0",
90
91
  "@atlassian/recent-work-client": "^1.8.0",
91
92
  "@testing-library/dom": "^8.17.1",