state.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import upperFirst from 'lodash/upperFirst';
  2. import {getContextKeys} from 'sentry/components/events/contexts/utils';
  3. import {t} from 'sentry/locale';
  4. import type {KeyValueListData} from 'sentry/types/group';
  5. enum StateContextKeys {
  6. STATE = 'state',
  7. }
  8. export interface StateContext {
  9. // Any custom keys users may set
  10. [key: string]: any;
  11. [StateContextKeys.STATE]: Record<string, any>;
  12. }
  13. export function getStateContextData({
  14. data,
  15. meta,
  16. }: {
  17. data: StateContext;
  18. meta?: Record<keyof StateContext, any>;
  19. }): KeyValueListData {
  20. return getContextKeys({data}).map(ctxKey => {
  21. switch (ctxKey) {
  22. case StateContextKeys.STATE:
  23. return {
  24. key: ctxKey,
  25. subject: `${t('State')}${data.state.type ? ` (${upperFirst(data.state.type)})` : ''}`,
  26. // TODO(TS): Objects cannot be rendered to dom
  27. value: data.state.value as string,
  28. meta: meta?.state?.value?.[''],
  29. };
  30. default:
  31. return {
  32. key: ctxKey,
  33. subject: ctxKey,
  34. value: data[ctxKey],
  35. meta: meta?.[ctxKey]?.[''],
  36. };
  37. }
  38. });
  39. }