utils.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(): SelectValue<string>[] {
  32. const sortOptions = [...ISSUE_WIDGET_SORT_OPTIONS];
  33. return sortOptions.map(sortOption => ({
  34. label: getSortLabel(sortOption),
  35. value: sortOption,
  36. }));
  37. }