utils.tsx 975 B

1234567891011121314151617181920212223242526272829303132
  1. import type {Relay, RelayActivity, RelaysByPublickey} from 'sentry/types/relay';
  2. /**
  3. * Convert list of individual relay objects into a per-file summary grouped by publicKey
  4. */
  5. export function getRelaysByPublicKey(
  6. relays: Array<Relay>,
  7. relayActivities: Array<RelayActivity>
  8. ) {
  9. return relays.reduce<RelaysByPublickey>((relaysByPublicKey, relay) => {
  10. const {name, description, created, publicKey} = relay;
  11. if (!relaysByPublicKey.hasOwnProperty(publicKey)) {
  12. relaysByPublicKey[publicKey] = {name, description, created, activities: []};
  13. }
  14. if (!relaysByPublicKey[publicKey].activities.length) {
  15. relaysByPublicKey[publicKey].activities = relayActivities.filter(
  16. activity => activity.publicKey === publicKey
  17. );
  18. }
  19. return relaysByPublicKey;
  20. }, {});
  21. }
  22. /**
  23. * Returns a short publicKey with only 20 characters
  24. */
  25. export function getShortPublicKey(publicKey: Relay['publicKey']) {
  26. return publicKey.substring(0, 20);
  27. }