import { BarsArrowDownIcon, BarsArrowUpIcon, ChevronUpDownIcon } from '@heroicons/react/24/outline'; import { observer } from 'mobx-react-lite'; import React, { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { DraggableProvided } from '@kanaries/react-beautiful-dnd'; import { COUNT_FIELD_ID, MEA_KEY_ID, MEA_VAL_ID } from '../../constants'; import { IAggregator, IDraggableViewStateKey } from '../../interfaces'; import { useVizStore } from '../../store'; import { Pill } from '../components'; import { GLOBAL_CONFIG } from '../../config'; import DropdownContext from '../../components/dropdownContext'; import SelectContext, { type ISelectContextOption } from '../../components/selectContext'; import { refMapper } from '../fieldsContext'; interface PillProps { provided: DraggableProvided; fIndex: number; dkey: IDraggableViewStateKey; } const OBPill: React.FC = (props) => { const { provided, dkey, fIndex } = props; const vizStore = useVizStore(); const { config, allFields } = vizStore; const field = vizStore.allEncodings[dkey.id][fIndex]; const { t } = useTranslation('translation', { keyPrefix: 'constant.aggregator' }); const aggregationOptions = useMemo(() => { return GLOBAL_CONFIG.AGGREGATOR_LIST.map((op) => ({ value: op, label: t(op), })); }, []); const foldOptions = useMemo(() => { const validFoldBy = allFields.filter((f) => f.analyticType === 'measure' && f.fid !== MEA_VAL_ID); return validFoldBy.map((f) => ({ key: f.fid, label: f.name, })); }, [allFields]); const folds = field.fid === MEA_KEY_ID ? config.folds ?? [] : null; return ( {folds && ( { vizStore.setVisualConfig('folds', keys); }} > {field.name} )} {!folds && {field.name}}   {field.analyticType === 'measure' && field.fid !== COUNT_FIELD_ID && config.defaultAggregated && field.aggName !== 'expr' && ( { vizStore.setFieldAggregator(dkey.id, fIndex, value as IAggregator); }} > {field.aggName || ''} )} {field.analyticType === 'dimension' && field.sort === 'ascending' && ( )} {field.analyticType === 'dimension' && field.sort === 'descending' && ( )} ); }; export default observer(OBPill);