@contentful/field-editor-reference 5.1.1 → 5.1.4

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,24 @@
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.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.3...@contentful/field-editor-reference@5.1.4) (2022-08-30)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **EntityStore:** use fixed cache key for scheduled actions [SPA-871] ([#1224](https://github.com/contentful/field-editors/issues/1224)) ([6b78132](https://github.com/contentful/field-editors/commit/6b78132d0c7643a88c2f15f8d14563355c65f30c))
11
+
12
+ ## [5.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.2...@contentful/field-editor-reference@5.1.3) (2022-08-26)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **EntityStore:** respect environment alias ([#1223](https://github.com/contentful/field-editors/issues/1223)) ([f66a6b9](https://github.com/contentful/field-editors/commit/f66a6b994f107341251a0ea335457a6b0148439f))
17
+
18
+ ## [5.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.1...@contentful/field-editor-reference@5.1.2) (2022-08-26)
19
+
20
+ ### Bug Fixes
21
+
22
+ - change the props type definitions ([#1222](https://github.com/contentful/field-editors/issues/1222)) ([f71394b](https://github.com/contentful/field-editors/commit/f71394b3653c4e84bb45ed5745ba81eb0522e680))
23
+
6
24
  ## [5.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.1.0...@contentful/field-editor-reference@5.1.1) (2022-08-25)
7
25
 
8
26
  ### Bug Fixes
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { ReferenceEditorProps } from '../common/ReferenceEditor';
3
- declare type EditorProps = Omit<ReferenceEditorProps, 'hasCardEditActions'>;
3
+ declare type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
4
4
  export declare function MultipleMediaEditor(props: EditorProps): JSX.Element;
5
5
  export declare namespace MultipleMediaEditor {
6
6
  var defaultProps: {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { ReferenceEditorProps } from '../common/ReferenceEditor';
3
- declare type EditorProps = Omit<ReferenceEditorProps, 'hasCardEditActions'>;
3
+ declare type EditorProps = Pick<ReferenceEditorProps, Exclude<keyof ReferenceEditorProps, 'hasCardEditActions'>>;
4
4
  export declare function SingleMediaEditor(props: EditorProps): JSX.Element;
5
5
  export declare namespace SingleMediaEditor {
6
6
  var defaultProps: {
@@ -1844,7 +1844,7 @@ var formatDateAndTime = function formatDateAndTime(date, _short2) {
1844
1844
  var getScheduleTooltipContent = function getScheduleTooltipContent(_ref) {
1845
1845
  var job = _ref.job,
1846
1846
  jobsCount = _ref.jobsCount;
1847
- return "Will " + job.action.toLowerCase() + " " + formatDateAndTime(job.scheduledFor.datetime).toLowerCase() + "\n " + (jobsCount > 1 && "+ " + (jobsCount - 1) + " more");
1847
+ return "Will " + job.action.toLowerCase() + " " + formatDateAndTime(job.scheduledFor.datetime).toLowerCase() + "\n " + (jobsCount > 1 ? "+ " + (jobsCount - 1) + " more" : '');
1848
1848
  };
1849
1849
  var ScheduleTooltip = function ScheduleTooltip(_ref2) {
1850
1850
  var job = _ref2.job,
@@ -2054,8 +2054,10 @@ function _fetchContentfulEntry() {
2054
2054
  }
2055
2055
 
2056
2056
  var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2057
+ var _props$sdk$ids$enviro;
2058
+
2057
2059
  var currentSpaceId = props.sdk.ids.space;
2058
- var currentEnvironmentId = props.sdk.ids.environment;
2060
+ var currentEnvironmentId = (_props$sdk$ids$enviro = props.sdk.ids.environmentAlias) != null ? _props$sdk$ids$enviro : props.sdk.ids.environment;
2059
2061
  var queryClient = reactQuery.useQueryClient();
2060
2062
  var queryCache = queryClient.getQueryCache();
2061
2063
  var entityChangeUnsubscribers = React.useRef({});
@@ -2122,12 +2124,38 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2122
2124
  throw new UnsupportedError('Unsupported entity type');
2123
2125
  }, options);
2124
2126
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2127
+ /**
2128
+ * Fetch all scheduled actions for a given entity.
2129
+ * This function fetches all schedules for all entries and then returns
2130
+ * a filtered result based on the entityID provided.
2131
+ *
2132
+ * The result is then reused/cached for subsequent calls to this function.
2133
+ */
2134
+
2135
+ /**
2136
+ * Fetch all scheduled actions for a given entity.
2137
+ * This function fetches all schedules for all entries and then returns
2138
+ * a filtered result based on the entityID provided.
2139
+ *
2140
+ * The result is then reused/cached for subsequent calls to this function.
2141
+ */
2125
2142
  var getEntityScheduledActions = React.useCallback(function getEntityScheduledActions(entityType, entityId, options) {
2126
2143
  var _options$spaceId2, _options$environmentI2;
2127
2144
 
2145
+ // This is fixed to force the cache to reuse previous results
2146
+ var fixedEntityCacheId = 'scheduledActionEntityId'; // A space+environment combo can only have up to 500 scheduled actions
2147
+ // With this request we fetch all schedules and can reuse the results.
2148
+ // See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
2149
+
2150
+ // A space+environment combo can only have up to 500 scheduled actions
2151
+ // With this request we fetch all schedules and can reuse the results.
2152
+ // See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
2153
+ var maxScheduledActions = 500;
2128
2154
  var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
2129
2155
  var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
2130
- var queryKey = ['scheduled-actions', entityType, entityId, spaceId, environmentId];
2156
+ var queryKey = ['scheduled-actions', entityType, fixedEntityCacheId, spaceId, environmentId]; // Fetch + Filter by entity ID in the end
2157
+
2158
+ // Fetch + Filter by entity ID in the end
2131
2159
  return fetch(queryKey, /*#__PURE__*/function () {
2132
2160
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
2133
2161
  var cmaClient, response;
@@ -2141,9 +2169,9 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2141
2169
  spaceId: spaceId,
2142
2170
  query: {
2143
2171
  'environment.sys.id': environmentId,
2144
- 'entity.sys.id': entityId,
2145
2172
  'sys.status[in]': 'scheduled',
2146
- order: 'scheduledFor.datetime'
2173
+ order: 'scheduledFor.datetime',
2174
+ limit: maxScheduledActions
2147
2175
  }
2148
2176
  });
2149
2177
 
@@ -2162,7 +2190,11 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2162
2190
  return function (_x2) {
2163
2191
  return _ref3.apply(this, arguments);
2164
2192
  };
2165
- }(), options);
2193
+ }(), options).then(function (items) {
2194
+ return items.filter(function (action) {
2195
+ return action.entity.sys.id === entityId;
2196
+ });
2197
+ });
2166
2198
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2167
2199
  var getResource = React.useCallback(function getResource(resourceType, urn, options) {
2168
2200
  var queryKey = ['Resource', resourceType, urn];