@contentful/field-editor-reference 5.2.1 → 5.3.0

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
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.3.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.2.1...@contentful/field-editor-reference@5.3.0) (2022-09-16)
7
+
8
+ ### Features
9
+
10
+ - use urn from entries that are fetched from api ([#1234](https://github.com/contentful/field-editors/issues/1234)) ([24e4ca2](https://github.com/contentful/field-editors/commit/24e4ca20fc18993f0eee1ee3886ff0b52ab2e8b8))
11
+
6
12
  ## [5.2.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.2.0...@contentful/field-editor-reference@5.2.1) (2022-09-15)
7
13
 
8
14
  ### Bug Fixes
@@ -4020,9 +4020,30 @@ function ResourceCard(props) {
4020
4020
  })));
4021
4021
  }
4022
4022
 
4023
+ var toLinkItem = function toLinkItem(entry) {
4024
+ return {
4025
+ sys: {
4026
+ type: 'ResourceLink',
4027
+ linkType: 'Contentful:Entry',
4028
+ urn: entry.sys.urn
4029
+ }
4030
+ };
4031
+ };
4032
+
4033
+ var getUpdatedValue = function getUpdatedValue(field, entries) {
4034
+ var multiple = field.type === 'Array';
4035
+
4036
+ if (multiple) {
4037
+ var linkItems = entries.map(toLinkItem);
4038
+ var prevValue = field.getValue() || [];
4039
+ return [].concat(prevValue, linkItems);
4040
+ } else {
4041
+ return toLinkItem(entries[0]);
4042
+ }
4043
+ };
4044
+
4023
4045
  function useResourceLinkActions(_ref) {
4024
- var apiUrl = _ref.apiUrl,
4025
- dialogs = _ref.dialogs,
4046
+ var dialogs = _ref.dialogs,
4026
4047
  field = _ref.field,
4027
4048
  onAfterLink = _ref.onAfterLink;
4028
4049
  var handleAfterLink = React.useCallback(function (entries) {
@@ -4032,39 +4053,14 @@ function useResourceLinkActions(_ref) {
4032
4053
 
4033
4054
  entries.forEach(onAfterLink);
4034
4055
  }, [onAfterLink]);
4035
- var multiple = field.type === 'Array';
4036
- var toLinkItem = React.useMemo(function () {
4037
- function toUrn(entry) {
4038
- return "crn:" + apiUrl + ":::content:spaces/" + entry.sys.space.sys.id + "/entries/" + entry.sys.id;
4039
- }
4040
-
4041
- return function (entry) {
4042
- return {
4043
- sys: {
4044
- type: 'ResourceLink',
4045
- linkType: 'Contentful:Entry',
4046
- urn: toUrn(entry)
4047
- }
4048
- };
4049
- };
4050
- }, [apiUrl]);
4051
4056
  var onLinkedExisting = React.useMemo(function () {
4052
- if (multiple) {
4053
- return function (entries) {
4054
- var linkItems = entries.map(toLinkItem);
4055
- var prevValue = field.getValue() || [];
4056
- var updatedValue = [].concat(prevValue, linkItems);
4057
- field.setValue(updatedValue);
4058
- handleAfterLink(entries);
4059
- };
4060
- } else {
4061
- return function (entries) {
4062
- var entry = entries[0];
4063
- field.setValue(toLinkItem(entry));
4064
- handleAfterLink([entry]);
4065
- };
4066
- }
4067
- }, [field, handleAfterLink, multiple, toLinkItem]);
4057
+ return function (entries) {
4058
+ var updatedValue = getUpdatedValue(field, entries);
4059
+ field.setValue(updatedValue);
4060
+ handleAfterLink(entries);
4061
+ };
4062
+ }, [field, handleAfterLink]);
4063
+ var multiple = field.type === 'Array';
4068
4064
  var onLinkExisting = React.useMemo(function () {
4069
4065
  var promptSelection = multiple ? /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
4070
4066
  return runtime_1.wrap(function _callee$(_context) {