issueWidgetCard.tsx 2.4 KB

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