issueWidgetCard.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import styled from '@emotion/styled';
  2. import {Location} from 'history';
  3. import ErrorPanel from 'sentry/components/charts/errorPanel';
  4. import SimpleTableChart from 'sentry/components/charts/simpleTableChart';
  5. import Placeholder from 'sentry/components/placeholder';
  6. import {IconWarning} from 'sentry/icons';
  7. import space from 'sentry/styles/space';
  8. import {Organization, PageFilters} from 'sentry/types';
  9. import {defined} from 'sentry/utils';
  10. import {TableDataRow} from 'sentry/utils/discover/discoverQuery';
  11. import {eventViewFromWidget} from 'sentry/views/dashboardsV2/utils';
  12. import {getDatasetConfig} from '../datasetConfig/base';
  13. import {Widget, WidgetType} from '../types';
  14. import {ISSUE_FIELDS} from '../widgetBuilder/issueWidget/fields';
  15. type Props = {
  16. loading: boolean;
  17. location: Location;
  18. organization: Organization;
  19. selection: PageFilters;
  20. transformedResults: TableDataRow[];
  21. widget: Widget;
  22. errorMessage?: string;
  23. };
  24. export function IssueWidgetCard({
  25. organization,
  26. selection,
  27. widget,
  28. errorMessage,
  29. loading,
  30. transformedResults,
  31. location,
  32. }: Props) {
  33. const datasetConfig = getDatasetConfig(WidgetType.ISSUE);
  34. if (errorMessage) {
  35. return (
  36. <ErrorPanel>
  37. <IconWarning color="gray500" size="lg" />
  38. </ErrorPanel>
  39. );
  40. }
  41. if (loading) {
  42. // Align height to other charts.
  43. return <LoadingPlaceholder height="200px" />;
  44. }
  45. const query = widget.queries[0];
  46. const queryFields = defined(query.fields)
  47. ? query.fields
  48. : [...query.columns, ...query.aggregates];
  49. const fieldAliases = query.fieldAliases ?? [];
  50. const eventView = eventViewFromWidget(
  51. widget.title,
  52. widget.queries[0],
  53. selection,
  54. widget.displayType
  55. );
  56. return (
  57. <StyledSimpleTableChart
  58. location={location}
  59. title=""
  60. eventView={eventView}
  61. fields={queryFields}
  62. fieldAliases={fieldAliases}
  63. loading={loading}
  64. metadata={ISSUE_FIELDS}
  65. data={transformedResults}
  66. organization={organization}
  67. getCustomFieldRenderer={datasetConfig.getCustomFieldRenderer}
  68. fieldHeaderMap={datasetConfig.fieldHeaderMap}
  69. stickyHeaders
  70. />
  71. );
  72. }
  73. const LoadingPlaceholder = styled(Placeholder)`
  74. background-color: ${p => p.theme.surface200};
  75. `;
  76. const StyledSimpleTableChart = styled(SimpleTableChart)`
  77. margin-top: ${space(1.5)};
  78. border-bottom-left-radius: ${p => p.theme.borderRadius};
  79. border-bottom-right-radius: ${p => p.theme.borderRadius};
  80. font-size: ${p => p.theme.fontSizeMedium};
  81. box-shadow: none;
  82. `;