utils.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type {SelectValue} from 'sentry/types';
  2. import type {FieldValue} from 'sentry/views/discover/table/types';
  3. import {FieldValueKind} from 'sentry/views/discover/table/types';
  4. import {getSortLabel, IssueSortOptions} from 'sentry/views/issueList/utils';
  5. import type {ColumnType} from './fields';
  6. import {ISSUE_FIELDS} from './fields';
  7. export function generateIssueWidgetFieldOptions(
  8. issueFields: Record<string, ColumnType> = ISSUE_FIELDS
  9. ) {
  10. const fieldKeys = Object.keys(issueFields).sort();
  11. const fieldOptions: Record<string, SelectValue<FieldValue>> = {};
  12. fieldKeys.forEach(field => {
  13. fieldOptions[`field:${field}`] = {
  14. label: field,
  15. value: {
  16. kind: FieldValueKind.FIELD,
  17. meta: {
  18. name: field,
  19. dataType: issueFields[field],
  20. },
  21. },
  22. };
  23. });
  24. return fieldOptions;
  25. }
  26. export const ISSUE_WIDGET_SORT_OPTIONS = [
  27. IssueSortOptions.DATE,
  28. IssueSortOptions.NEW,
  29. IssueSortOptions.FREQ,
  30. IssueSortOptions.TRENDS,
  31. IssueSortOptions.USER,
  32. ];
  33. export function generateIssueWidgetOrderOptions(): SelectValue<string>[] {
  34. const sortOptions = [...ISSUE_WIDGET_SORT_OPTIONS];
  35. return sortOptions.map(sortOption => ({
  36. label: getSortLabel(sortOption),
  37. value: sortOption,
  38. }));
  39. }