diff --git a/webapp/src/components/boardComponent.tsx b/webapp/src/components/boardComponent.tsx index ce6bd33a4..35120a8b9 100644 --- a/webapp/src/components/boardComponent.tsx +++ b/webapp/src/components/boardComponent.tsx @@ -230,12 +230,41 @@ class BoardComponent extends React.Component { const {boardTree, intl} = this.props const {activeView} = boardTree + // TODO: Refactor this as a component if (!group.option.id) { // Empty group + const ref = React.createRef() return (
{ + this.draggedHeaderOption = group.option + }} + onDragEnd={() => { + this.draggedHeaderOption = undefined + }} + + onDragOver={(e) => { + ref.current.classList.add('dragover') + e.preventDefault() + }} + onDragEnter={(e) => { + ref.current.classList.add('dragover') + e.preventDefault() + }} + onDragLeave={(e) => { + ref.current.classList.remove('dragover') + e.preventDefault() + }} + onDrop={(e) => { + ref.current.classList.remove('dragover') + e.preventDefault() + this.onDropToColumn(group.option) + }} >
{ Utils.assertValue(boardTree.groupByProperty) // Move option to new index - const {board} = boardTree - const options = boardTree.groupByProperty.options - const destIndex = option ? options.indexOf(option) : 0 + const visibleOptionIds = boardTree.visibleGroups.map(o => o.option.id) - await mutator.changePropertyOptionOrder(board, boardTree.groupByProperty, draggedHeaderOption, destIndex) + const {activeView} = boardTree + const srcIndex = visibleOptionIds.indexOf(draggedHeaderOption.id) + const destIndex = visibleOptionIds.indexOf(option.id) + + visibleOptionIds.splice(destIndex, 0, visibleOptionIds.splice(srcIndex, 1)[0]) + + await mutator.changeViewVisibleOptionIds(activeView, visibleOptionIds) } } } diff --git a/webapp/src/mutator.ts b/webapp/src/mutator.ts index 7b8c80a47..84dad502a 100644 --- a/webapp/src/mutator.ts +++ b/webapp/src/mutator.ts @@ -371,16 +371,28 @@ class Mutator { await this.updateBlock(newView, view, 'filter') } + async changeViewGroupById(view: BoardView, groupById: string): Promise { + const newView = new MutableBoardView(view) + newView.groupById = groupById + await this.updateBlock(newView, view, 'group by') + } + async changeViewVisibleProperties(view: BoardView, visiblePropertyIds: string[], description = 'show / hide property'): Promise { const newView = new MutableBoardView(view) newView.visiblePropertyIds = visiblePropertyIds await this.updateBlock(newView, view, description) } - async changeViewGroupById(view: BoardView, groupById: string): Promise { + async changeViewVisibleOptionIds(view: BoardView, visibleOptionIds: string[], description = 'reorder'): Promise { const newView = new MutableBoardView(view) - newView.groupById = groupById - await this.updateBlock(newView, view, 'group by') + newView.visibleOptionIds = visibleOptionIds + await this.updateBlock(newView, view, description) + } + + async changeViewHiddenOptionIds(view: BoardView, hiddenOptionIds: string[], description = 'reorder'): Promise { + const newView = new MutableBoardView(view) + newView.hiddenOptionIds = hiddenOptionIds + await this.updateBlock(newView, view, description) } async hideViewColumn(view: BoardView, columnOptionId: string): Promise { @@ -389,6 +401,7 @@ class Mutator { } const newView = new MutableBoardView(view) + newView.visibleOptionIds = newView.visibleOptionIds.filter(o => o !== columnOptionId) newView.hiddenOptionIds.push(columnOptionId) await this.updateBlock(newView, view, 'hide column') } @@ -400,6 +413,9 @@ class Mutator { const newView = new MutableBoardView(view) newView.hiddenOptionIds = newView.hiddenOptionIds.filter((o) => o !== columnOptionId) + // Put the column at the end of the visible list + newView.visibleOptionIds = newView.visibleOptionIds.filter(o => o !== columnOptionId) + newView.visibleOptionIds.push(columnOptionId) await this.updateBlock(newView, view, 'show column') }