state.tsx 1.5 KB

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