mergeEnvMappings.tsx 845 B

12345678910111213141516171819202122232425
  1. import {MonitorBucketEnvMapping} from 'sentry/views/monitors/components/overviewTimeline/types';
  2. import {CHECKIN_STATUS_PRECEDENT} from 'sentry/views/monitors/utils/constants';
  3. /**
  4. * Given two env mappings e.g. {prod: {ok: 1, missed: 0, etc..}}
  5. * combines job status counts
  6. */
  7. export function mergeEnvMappings(
  8. envMappingA: MonitorBucketEnvMapping,
  9. envMappingB: MonitorBucketEnvMapping
  10. ) {
  11. const combinedEnvs = new Set([
  12. ...Object.keys(envMappingA),
  13. ...Object.keys(envMappingB),
  14. ]);
  15. return [...combinedEnvs].reduce((mergedEnvs, env) => {
  16. const mergedStatusCounts = {};
  17. for (const status of CHECKIN_STATUS_PRECEDENT) {
  18. mergedStatusCounts[status] =
  19. (envMappingA[env]?.[status] ?? 0) + (envMappingB[env]?.[status] ?? 0);
  20. }
  21. mergedEnvs[env] = mergedStatusCounts;
  22. return mergedEnvs;
  23. }, {});
  24. }