issueWidgetCard.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/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. 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(widget.title, widget.queries[0], selection);
  51. return (
  52. <StyledSimpleTableChart
  53. location={location}
  54. title=""
  55. eventView={eventView}
  56. fields={queryFields}
  57. fieldAliases={fieldAliases}
  58. loading={loading}
  59. metadata={ISSUE_FIELDS}
  60. data={transformedResults}
  61. organization={organization}
  62. getCustomFieldRenderer={datasetConfig.getCustomFieldRenderer}
  63. fieldHeaderMap={datasetConfig.getFieldHeaderMap?.()}
  64. stickyHeaders
  65. />
  66. );
  67. }
  68. const LoadingPlaceholder = styled(Placeholder)`
  69. background-color: ${p => p.theme.surface300};
  70. `;
  71. const StyledSimpleTableChart = styled(SimpleTableChart)`
  72. margin-top: ${space(1.5)};
  73. border-bottom-left-radius: ${p => p.theme.borderRadius};
  74. border-bottom-right-radius: ${p => p.theme.borderRadius};
  75. font-size: ${p => p.theme.fontSizeMedium};
  76. box-shadow: none;
  77. `;