issueWidgetCard.tsx 2.4 KB

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