state.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {Component} from 'react';
  2. import upperFirst from 'lodash/upperFirst';
  3. import ClippedBox from 'sentry/components/clippedBox';
  4. import ContextBlock from 'sentry/components/events/contexts/contextBlock';
  5. import {getMeta} from 'sentry/components/events/meta/metaProxy';
  6. import {t} from 'sentry/locale';
  7. type KeyValueListData = React.ComponentProps<typeof ContextBlock>['data'];
  8. type StateDescription = {
  9. value: Record<string, any>;
  10. type?: string;
  11. };
  12. type Props = {
  13. alias: string;
  14. data: {
  15. [state: string]: StateDescription;
  16. state: StateDescription;
  17. };
  18. };
  19. class StateContextType extends Component<Props> {
  20. getStateTitle(name: string, type?: string) {
  21. return `${name}${type ? ` (${upperFirst(type)})` : ''}`;
  22. }
  23. getKnownData(): KeyValueListData {
  24. const primaryState = this.props.data.state;
  25. if (!primaryState) {
  26. return [];
  27. }
  28. return [
  29. {
  30. key: 'state',
  31. subject: this.getStateTitle(t('State'), primaryState.type),
  32. value: primaryState.value,
  33. },
  34. ];
  35. }
  36. getUnknownData(): KeyValueListData {
  37. const {data} = this.props;
  38. return Object.entries(data)
  39. .filter(([key]) => !['type', 'title', 'state'].includes(key))
  40. .map(([name, state]) => ({
  41. key: name,
  42. value: state.value,
  43. subject: this.getStateTitle(name, state.type),
  44. meta: getMeta(data, name),
  45. }));
  46. }
  47. render() {
  48. return (
  49. <ClippedBox clipHeight={250}>
  50. <ContextBlock data={this.getKnownData()} />
  51. <ContextBlock data={this.getUnknownData()} />
  52. </ClippedBox>
  53. );
  54. }
  55. }
  56. export default StateContextType;