columnFields.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import styled from '@emotion/styled';
  2. import Field from 'sentry/components/forms/field';
  3. import space from 'sentry/styles/space';
  4. import {Organization} from 'sentry/types';
  5. import {QueryFieldValue} from 'sentry/utils/discover/fields';
  6. import {DisplayType, WidgetType} from 'sentry/views/dashboardsV2/types';
  7. import ColumnEditCollection from 'sentry/views/eventsV2/table/columnEditCollection';
  8. import {FieldValueOption} from 'sentry/views/eventsV2/table/queryField';
  9. import {generateFieldOptions} from 'sentry/views/eventsV2/utils';
  10. interface Props {
  11. displayType: DisplayType;
  12. fieldOptions: ReturnType<typeof generateFieldOptions>;
  13. fields: QueryFieldValue[];
  14. onChange: (newColumns: QueryFieldValue[]) => void;
  15. organization: Organization;
  16. widgetType: WidgetType;
  17. errors?: Record<string, string>[];
  18. filterAggregateParameters?: (option: FieldValueOption) => boolean;
  19. filterPrimaryOptions?: (option: FieldValueOption) => boolean;
  20. noFieldsMessage?: string;
  21. }
  22. export function ColumnFields({
  23. displayType,
  24. fieldOptions,
  25. widgetType,
  26. fields,
  27. organization,
  28. errors,
  29. onChange,
  30. filterAggregateParameters,
  31. filterPrimaryOptions,
  32. noFieldsMessage,
  33. }: Props) {
  34. return (
  35. <Field
  36. inline={false}
  37. error={errors?.find(error => error?.fields)?.fields}
  38. flexibleControlStateSize
  39. stacked
  40. >
  41. {displayType === DisplayType.TABLE ? (
  42. <ColumnCollectionEdit
  43. columns={fields}
  44. onChange={onChange}
  45. fieldOptions={fieldOptions}
  46. organization={organization}
  47. source={widgetType}
  48. showAliasField={organization.features.includes(
  49. 'new-widget-builder-experience-design'
  50. )}
  51. filterAggregateParameters={filterAggregateParameters}
  52. filterPrimaryOptions={filterPrimaryOptions}
  53. noFieldsMessage={noFieldsMessage}
  54. />
  55. ) : (
  56. // The only other display type this component
  57. // renders for is TOP_N, where the n - 1 fields
  58. // are columns and the nth field is the y-axis
  59. <ColumnCollectionEdit
  60. columns={fields.slice(0, fields.length - 1)}
  61. onChange={newColumns => {
  62. onChange([...newColumns, fields[fields.length - 1]]);
  63. }}
  64. fieldOptions={fieldOptions}
  65. organization={organization}
  66. source={widgetType}
  67. filterPrimaryOptions={filterPrimaryOptions}
  68. noFieldsMessage={noFieldsMessage}
  69. />
  70. )}
  71. </Field>
  72. );
  73. }
  74. const ColumnCollectionEdit = styled(ColumnEditCollection)`
  75. margin-top: ${space(1)};
  76. `;