import React, { useMemo } from 'react'; import { DraggableFieldState, IAggregator, IDraggableStateKey } from '../../interfaces'; import { observer } from 'mobx-react-lite'; import { useVizStore } from '../../store'; import { DroppableProvided } from 'react-beautiful-dnd'; import { ChevronUpDownIcon, TrashIcon } from '@heroicons/react/24/outline'; import { useTranslation } from 'react-i18next'; import { COUNT_FIELD_ID, MEA_KEY_ID, MEA_VAL_ID } from '../../constants'; import DropdownContext from '../../components/dropdownContext'; import { GLOBAL_CONFIG } from '../../config'; import { Draggable, DroppableStateSnapshot } from '@kanaries/react-beautiful-dnd'; import styled from 'styled-components'; import SelectContext, { type ISelectContextOption } from '../../components/selectContext'; import { refMapper } from '../fieldsContext'; import { getFieldIdentifier } from '@/utils'; const PillActions = styled.div` overflow: visible !important; width: calc(100% - 1.875rem); `; interface SingleEncodeEditorProps { dkey: { id: keyof Omit; }; provided: DroppableProvided; snapshot: DroppableStateSnapshot; } const SingleEncodeEditor: React.FC = (props) => { const { dkey, provided, snapshot } = props; const vizStore = useVizStore(); const { allEncodings, config, allFields } = vizStore; const folds = config.folds ?? []; const channelItem = allEncodings[dkey.id][0]; const { t } = useTranslation(); const aggregationOptions = useMemo(() => { return GLOBAL_CONFIG.AGGREGATOR_LIST.map((op) => ({ value: op, label: t(`constant.aggregator.${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]); return (
{t('actions.drop_field')}
{channelItem && ( {(provided, snapshot) => { return (
{ vizStore.removeField(dkey.id, 0); }} className="grow-0 shrink-0 px-1.5 flex items-center justify-center bg-destructive text-destructive-foreground cursor-pointer" >
{channelItem.fid === MEA_KEY_ID && ( { vizStore.setVisualConfig('folds', keys); }} className="flex-1" > {channelItem.name} )} {channelItem.fid !== MEA_KEY_ID && {channelItem.name}}{' '} {channelItem.analyticType === 'measure' && channelItem.fid !== COUNT_FIELD_ID && config.defaultAggregated && channelItem.aggName !== 'expr' && ( { vizStore.setFieldAggregator(dkey.id, 0, value as IAggregator); }} > {channelItem.aggName || ''} )}
); }}
)}
); }; export default observer(SingleEncodeEditor);