@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.
@@ -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,
@@ -2047,8 +2047,10 @@ function _fetchContentfulEntry() {
2047
2047
  }
2048
2048
 
2049
2049
  var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2050
+ var _props$sdk$ids$enviro;
2051
+
2050
2052
  var currentSpaceId = props.sdk.ids.space;
2051
- var currentEnvironmentId = props.sdk.ids.environment;
2053
+ var currentEnvironmentId = (_props$sdk$ids$enviro = props.sdk.ids.environmentAlias) != null ? _props$sdk$ids$enviro : props.sdk.ids.environment;
2052
2054
  var queryClient = useQueryClient();
2053
2055
  var queryCache = queryClient.getQueryCache();
2054
2056
  var entityChangeUnsubscribers = useRef({});
@@ -2115,12 +2117,38 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2115
2117
  throw new UnsupportedError('Unsupported entity type');
2116
2118
  }, options);
2117
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
+ */
2118
2135
  var getEntityScheduledActions = useCallback(function getEntityScheduledActions(entityType, entityId, options) {
2119
2136
  var _options$spaceId2, _options$environmentI2;
2120
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;
2121
2147
  var spaceId = (_options$spaceId2 = options == null ? void 0 : options.spaceId) != null ? _options$spaceId2 : currentSpaceId;
2122
2148
  var environmentId = (_options$environmentI2 = options == null ? void 0 : options.environmentId) != null ? _options$environmentI2 : currentEnvironmentId;
2123
- 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
2124
2152
  return fetch(queryKey, /*#__PURE__*/function () {
2125
2153
  var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref2) {
2126
2154
  var cmaClient, response;
@@ -2134,9 +2162,9 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2134
2162
  spaceId: spaceId,
2135
2163
  query: {
2136
2164
  'environment.sys.id': environmentId,
2137
- 'entity.sys.id': entityId,
2138
2165
  'sys.status[in]': 'scheduled',
2139
- order: 'scheduledFor.datetime'
2166
+ order: 'scheduledFor.datetime',
2167
+ limit: maxScheduledActions
2140
2168
  }
2141
2169
  });
2142
2170
 
@@ -2155,7 +2183,11 @@ var _constate = /*#__PURE__*/constate(function useInitServices(props) {
2155
2183
  return function (_x2) {
2156
2184
  return _ref3.apply(this, arguments);
2157
2185
  };
2158
- }(), options);
2186
+ }(), options).then(function (items) {
2187
+ return items.filter(function (action) {
2188
+ return action.entity.sys.id === entityId;
2189
+ });
2190
+ });
2159
2191
  }, [fetch, currentSpaceId, currentEnvironmentId]);
2160
2192
  var getResource = useCallback(function getResource(resourceType, urn, options) {
2161
2193
  var queryKey = ['Resource', resourceType, urn];