utils.tsx 961 B

1234567891011121314151617181920212223242526272829
  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(relays: Relay[], relayActivities: RelayActivity[]) {
  6. return relays.reduce<RelaysByPublickey>((relaysByPublicKey, relay) => {
  7. const {name, description, created, publicKey} = relay;
  8. if (!relaysByPublicKey.hasOwnProperty(publicKey)) {
  9. relaysByPublicKey[publicKey] = {name, description, created, activities: []};
  10. }
  11. if (!relaysByPublicKey[publicKey]!.activities.length) {
  12. relaysByPublicKey[publicKey]!.activities = relayActivities.filter(
  13. activity => activity.publicKey === publicKey
  14. );
  15. }
  16. return relaysByPublicKey;
  17. }, {});
  18. }
  19. /**
  20. * Returns a short publicKey with only 20 characters
  21. */
  22. export function getShortPublicKey(publicKey: Relay['publicKey']) {
  23. return publicKey.substring(0, 20);
  24. }