import React, { useEffect, useMemo } from 'react'; import { ToolbarBaseProps, ToolbarCollection } from '../ToolbarCollection'; import { observer } from 'mobx-react-lite'; import { FiltersMap } from '@wix/bex-core'; import { KanbanBaseProps } from './KanbanProps'; import { StageComponent } from './Stage'; import { Box, Divider } from '@wix/design-system'; import { CollectionCard } from '../CollectionCard'; import { KanbanCardDragAndDrop } from '../KanbanDragAndDropDndKit/KanbanCardDragAndDrop'; import { StagesSkeleton } from './StagesSkeleton'; import { useKanbanCollectionSyncProps } from './useKanbanCollectionSyncProps'; export interface KanbanProps extends ToolbarBaseProps, KanbanBaseProps {} function _Kanban(props: KanbanProps) { const { state, dataHook } = props; const { toolbar, events } = state; const scrollToStage = ({ stageKey }: { stageKey: string }) => { const stageElement = document.querySelector( `[data-hook="kanban-stage-container-${stageKey}"]`, ); if (stageElement) { stageElement.scrollIntoView?.({ behavior: 'smooth', block: 'nearest', inline: 'center', }); } }; useKanbanCollectionSyncProps(props); useEffect(() => { events.on('scrollToStage', scrollToStage); return () => { events.off('scrollToStage', scrollToStage); }; }, [events]); const stages = useMemo(() => { return props.state.stages; }, [props.state.stages]); // Calculate active stage key from activeId const activeId = state.dragAndDropState.activeId; const activeStageKey = activeId ? activeId.substring(0, activeId.indexOf('-##-')) || null : null; // Wrap with global drag and drop context - always enabled for Kanban const { KanbanDragAndDropContext, DragOverlay } = KanbanCardDragAndDrop; // Find the index of the first DONE stage const firstDoneIndex = stages.findIndex( (stage: S) => props.state?.stageType?.(stage) === 'DONE', ); const stagesContent = ( {stages.map((stage: S, index: number) => ( <> {index === firstDoneIndex && firstDoneIndex !== -1 && ( )} ))} ); return ( {/* hack for showing manage tags action in more actions menu */} {props.tags && props.tags} {props.state.isLoadingStages ? : stagesContent} ); } export const Kanban = observer(_Kanban);