@contentful/field-editor-reference 5.1.3 → 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,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.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
+
6
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)
7
13
 
8
14
  ### Bug Fixes
@@ -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,
@@ -2124,12 +2124,38 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2124
2124
  throw new UnsupportedError('Unsupported entity type');
2125
2125
  }, options);
2126
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
+ */
2127
2142
  var getEntityScheduledActions = React.useCallback(function getEntityScheduledActions(entityType, entityId, options) {
2128
2143
  var _options$spaceId2, _options$environmentI2;
2129
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;
2130
2154
  var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
2131
2155
  var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
2132
- 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
2133
2159
  return fetch(queryKey, /*#__PURE__*/function () {
2134
2160
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
2135
2161
  var cmaClient, response;
@@ -2143,9 +2169,9 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2143
2169
  spaceId: spaceId,
2144
2170
  query: {
2145
2171
  'environment.sys.id': environmentId,
2146
- 'entity.sys.id': entityId,
2147
2172
  'sys.status[in]': 'scheduled',
2148
- order: 'scheduledFor.datetime'
2173
+ order: 'scheduledFor.datetime',
2174
+ limit: maxScheduledActions
2149
2175
  }
2150
2176
  });
2151
2177
 
@@ -2164,7 +2190,11 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2164
2190
  return function (_x2) {
2165
2191
  return _ref3.apply(this, arguments);
2166
2192
  };
2167
- }(), options);
2193
+ }(), options).then(function (items) {
2194
+ return items.filter(function (action) {
2195
+ return action.entity.sys.id === entityId;
2196
+ });
2197
+ });
2168
2198
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2169
2199
  var getResource = React.useCallback(function getResource(resourceType, urn, options) {
2170
2200
  var queryKey = ['Resource', resourceType, urn];