index.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import orderBy from 'lodash/orderBy';
  2. import {Relay, RelayActivity} from 'sentry/types';
  3. import ActivityList from './activityList';
  4. import CardHeader from './cardHeader';
  5. import {getRelaysByPublicKey} from './utils';
  6. import WaitingActivity from './waitingActivity';
  7. type CardHeaderProps = React.ComponentProps<typeof CardHeader>;
  8. type WaitingActivityProps = React.ComponentProps<typeof WaitingActivity>;
  9. type Props = {
  10. disabled: boolean;
  11. relayActivities: Array<RelayActivity>;
  12. relays: Array<Relay>;
  13. } & Pick<CardHeaderProps, 'onDelete' | 'onEdit'> &
  14. Pick<WaitingActivityProps, 'onRefresh'>;
  15. function List({relays, relayActivities, onRefresh, onDelete, onEdit, disabled}: Props) {
  16. const orderedRelays = orderBy(relays, relay => relay.created, ['desc']);
  17. const relaysByPublicKey = getRelaysByPublicKey(orderedRelays, relayActivities);
  18. const renderCardContent = (activities: Array<RelayActivity>) => {
  19. if (!activities.length) {
  20. return <WaitingActivity onRefresh={onRefresh} disabled={disabled} />;
  21. }
  22. return <ActivityList activities={activities} />;
  23. };
  24. return (
  25. <div>
  26. {Object.keys(relaysByPublicKey).map(relayByPublicKey => {
  27. const {name, description, created, activities} =
  28. relaysByPublicKey[relayByPublicKey];
  29. return (
  30. <div key={relayByPublicKey}>
  31. <CardHeader
  32. publicKey={relayByPublicKey}
  33. name={name}
  34. description={description}
  35. created={created}
  36. onEdit={onEdit}
  37. onDelete={onDelete}
  38. disabled={disabled}
  39. />
  40. {renderCardContent(activities)}
  41. </div>
  42. );
  43. })}
  44. </div>
  45. );
  46. }
  47. export default List;