123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import {Fragment, type ReactNode} from 'react';
- import type {DraggableSyntheticListeners, UseDraggableArguments} from '@dnd-kit/core';
- import styled from '@emotion/styled';
- import {Button} from 'sentry/components/button';
- import {IconDelete, IconGrabbable} from 'sentry/icons';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import type {QueryFieldValue} from 'sentry/utils/discover/fields';
- import {QueryField as TableQueryField} from 'sentry/views/discover/table/queryField';
- import {FieldValueKind} from 'sentry/views/discover/table/types';
- export interface QueryFieldProps {
- fieldOptions: React.ComponentProps<typeof TableQueryField>['fieldOptions'];
- onChange: (newValue: QueryFieldValue) => void;
- value: QueryFieldValue;
- attributes?: UseDraggableArguments['attributes'];
- canDelete?: boolean;
- canDrag?: boolean;
- fieldValidationError?: ReactNode;
- forwardRef?: React.Ref<HTMLDivElement>;
- isDragging?: boolean;
- listeners?: DraggableSyntheticListeners;
- onDelete?: () => void;
- style?: React.CSSProperties;
- }
- export function QueryField({
- onDelete,
- onChange,
- fieldOptions,
- value,
- forwardRef,
- listeners,
- attributes,
- canDelete,
- canDrag,
- style,
- fieldValidationError,
- isDragging,
- }: QueryFieldProps) {
- return (
- <QueryFieldWrapper ref={forwardRef} style={style}>
- {isDragging ? null : (
- <Fragment>
- {canDrag && (
- <DragAndReorderButton
- {...listeners}
- {...attributes}
- aria-label={t('Drag to reorder')}
- icon={<IconGrabbable size="xs" />}
- size="zero"
- borderless
- />
- )}
- <TableQueryField
- placeholder={t('Select group')}
- fieldValue={value}
- fieldOptions={fieldOptions}
- onChange={onChange}
- filterPrimaryOptions={option => option.value.kind !== FieldValueKind.FUNCTION}
- />
- {fieldValidationError ? fieldValidationError : null}
- {canDelete && (
- <Button
- size="zero"
- borderless
- onClick={onDelete}
- icon={<IconDelete />}
- title={t('Remove group')}
- aria-label={t('Remove group')}
- />
- )}
- </Fragment>
- )}
- </QueryFieldWrapper>
- );
- }
- const DragAndReorderButton = styled(Button)`
- height: ${p => p.theme.form.md.height}px;
- `;
- const QueryFieldWrapper = styled('div')`
- display: flex;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- > * + * {
- margin-left: ${space(1)};
- }
- `;
|