utils.tsx 1.3 KB

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