@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.
@@ -1837,7 +1837,7 @@ var formatDateAndTime = function formatDateAndTime(date, _short2) {
1837
1837
  var getScheduleTooltipContent = function getScheduleTooltipContent(_ref) {
1838
1838
  var job = _ref.job,
1839
1839
  jobsCount = _ref.jobsCount;
1840
- return "Will " + job.action.toLowerCase() + " " + formatDateAndTime(job.scheduledFor.datetime).toLowerCase() + "\n " + (jobsCount > 1 && "+ " + (jobsCount - 1) + " more");
1840
+ return "Will " + job.action.toLowerCase() + " " + formatDateAndTime(job.scheduledFor.datetime).toLowerCase() + "\n " + (jobsCount > 1 ? "+ " + (jobsCount - 1) + " more" : '');
1841
1841
  };
1842
1842
  var ScheduleTooltip = function ScheduleTooltip(_ref2) {
1843
1843
  var job = _ref2.job,
@@ -2117,12 +2117,38 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2117
2117
  throw new UnsupportedError('Unsupported entity type');
2118
2118
  }, options);
2119
2119
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2120
+ /**
2121
+ * Fetch all scheduled actions for a given entity.
2122
+ * This function fetches all schedules for all entries and then returns
2123
+ * a filtered result based on the entityID provided.
2124
+ *
2125
+ * The result is then reused/cached for subsequent calls to this function.
2126
+ */
2127
+
2128
+ /**
2129
+ * Fetch all scheduled actions for a given entity.
2130
+ * This function fetches all schedules for all entries and then returns
2131
+ * a filtered result based on the entityID provided.
2132
+ *
2133
+ * The result is then reused/cached for subsequent calls to this function.
2134
+ */
2120
2135
  var getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
2121
2136
  var _options$spaceId2, _options$environmentI2;
2122
2137
 
2138
+ // This is fixed to force the cache to reuse previous results
2139
+ var fixedEntityCacheId = 'scheduledActionEntityId'; // A space+environment combo can only have up to 500 scheduled actions
2140
+ // With this request we fetch all schedules and can reuse the results.
2141
+ // See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
2142
+
2143
+ // A space+environment combo can only have up to 500 scheduled actions
2144
+ // With this request we fetch all schedules and can reuse the results.
2145
+ // See https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/limitations
2146
+ var maxScheduledActions = 500;
2123
2147
  var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
2124
2148
  var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
2125
- var queryKey = ['scheduled-actions', entityType, entityId, spaceId, environmentId];
2149
+ var queryKey = ['scheduled-actions', entityType, fixedEntityCacheId, spaceId, environmentId]; // Fetch + Filter by entity ID in the end
2150
+
2151
+ // Fetch + Filter by entity ID in the end
2126
2152
  return fetch(queryKey, /*#__PURE__*/function () {
2127
2153
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
2128
2154
  var cmaClient, response;
@@ -2136,9 +2162,9 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2136
2162
  spaceId: spaceId,
2137
2163
  query: {
2138
2164
  'environment.sys.id': environmentId,
2139
- 'entity.sys.id': entityId,
2140
2165
  'sys.status[in]': 'scheduled',
2141
- order: 'scheduledFor.datetime'
2166
+ order: 'scheduledFor.datetime',
2167
+ limit: maxScheduledActions
2142
2168
  }
2143
2169
  });
2144
2170
 
@@ -2157,7 +2183,11 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2157
2183
  return function (_x2) {
2158
2184
  return _ref3.apply(this, arguments);
2159
2185
  };
2160
- }(), options);
2186
+ }(), options).then(function (items) {
2187
+ return items.filter(function (action) {
2188
+ return action.entity.sys.id === entityId;
2189
+ });
2190
+ });
2161
2191
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2162
2192
  var getResource = useCallback(function getResource(resourceType, urn, options) {
2163
2193
  var queryKey = ['Resource', resourceType, urn];