diff --git a/src/client/components/boardComponent.tsx b/src/client/components/boardComponent.tsx index 6456d8497..16cbbd2d0 100644 --- a/src/client/components/boardComponent.tsx +++ b/src/client/components/boardComponent.tsx @@ -96,7 +96,7 @@ class BoardComponent extends React.Component { Group by {boardTree.groupByProperty?.name}
{ this.filterClicked(e) }}>Filter
-
{ this.sortClicked(e) }}>Sort
+
{ OctoUtils.showSortMenu(e, mutator, boardTree) }}>Sort
{this.state.isSearching ? { pageController.showFilter(e.target as HTMLElement) } - private async sortClicked(e: React.MouseEvent) { - const { mutator, boardTree } = this.props - const { activeView } = boardTree - const { sortOptions } = activeView - const sortOption = sortOptions.length > 0 ? sortOptions[0] : undefined - - const propertyTemplates = boardTree.board.cardProperties - Menu.shared.options = propertyTemplates.map((o) => { - return { - id: o.id, - name: o.name, - icon: (sortOption.propertyId === o.id) ? sortOption.reversed ? "sortUp" : "sortDown" : undefined - } - }) - Menu.shared.onMenuClicked = async (propertyId: string) => { - let newSortOptions: ISortOption[] = [] - if (sortOption && sortOption.propertyId === propertyId) { - // Already sorting by name, so reverse it - newSortOptions = [ - { propertyId, reversed: !sortOption.reversed } - ] - } else { - newSortOptions = [ - { propertyId, reversed: false } - ] - } - - await mutator.changeViewSortOptions(activeView, newSortOptions) - } - Menu.shared.showAtElement(e.target as HTMLElement) - } - private async optionsClicked(e: React.MouseEvent) { const { boardTree } = this.props diff --git a/src/client/components/tableComponent.tsx b/src/client/components/tableComponent.tsx index 042f1319e..3e1e6c8cc 100644 --- a/src/client/components/tableComponent.tsx +++ b/src/client/components/tableComponent.tsx @@ -90,7 +90,7 @@ class TableComponent extends React.Component {
{ this.propertiesClicked(e) }}>Properties
{ this.filterClicked(e) }}>Filter
-
{ this.sortClicked(e) }}>Sort
+
{ OctoUtils.showSortMenu(e, mutator, boardTree) }}>Sort
{this.state.isSearching ? { pageController.showFilter(e.target as HTMLElement) } - private async sortClicked(e: React.MouseEvent) { - const { mutator, boardTree } = this.props - const { activeView } = boardTree - const { sortOptions } = activeView - const sortOption = sortOptions.length > 0 ? sortOptions[0] : undefined - - const propertyTemplates = boardTree.board.cardProperties - Menu.shared.options = propertyTemplates.map((o) => { - return { - id: o.id, - name: o.name, - icon: (sortOption.propertyId === o.id) ? sortOption.reversed ? "sortUp" : "sortDown" : undefined - } - }) - Menu.shared.onMenuClicked = async (propertyId: string) => { - let newSortOptions: ISortOption[] = [] - if (sortOption && sortOption.propertyId === propertyId) { - // Already sorting by name, so reverse it - newSortOptions = [ - { propertyId, reversed: !sortOption.reversed } - ] - } else { - newSortOptions = [ - { propertyId, reversed: false } - ] - } - - await mutator.changeViewSortOptions(activeView, newSortOptions) - } - Menu.shared.showAtElement(e.target as HTMLElement) - } - private async optionsClicked(e: React.MouseEvent) { const { boardTree } = this.props diff --git a/src/client/octoUtils.tsx b/src/client/octoUtils.tsx index 10b388ada..8ed264a82 100644 --- a/src/client/octoUtils.tsx +++ b/src/client/octoUtils.tsx @@ -1,7 +1,7 @@ import React from "react" import { IPropertyTemplate } from "./board" import { BoardTree } from "./boardTree" -import { BoardView } from "./boardView" +import { BoardView, ISortOption } from "./boardView" import { Editable } from "./components/editable" import { Menu, MenuOption } from "./menu" import { Mutator } from "./mutator" @@ -143,7 +143,7 @@ class OctoUtils { showMenu(e.target as HTMLElement) } } : undefined} - onFocus={mutator ? () => { Menu.shared.hide() } : undefined } + onFocus={mutator ? () => { Menu.shared.hide() } : undefined} > {finalDisplayValue} @@ -176,7 +176,7 @@ class OctoUtils { if (index === 0) { return block.order / 2 } - const previousBlock = blocks[index-1] + const previousBlock = blocks[index - 1] return (block.order + previousBlock.order) / 2 } @@ -185,9 +185,40 @@ class OctoUtils { if (index === blocks.length - 1) { return block.order + 1000 } - const nextBlock = blocks[index+1] + const nextBlock = blocks[index + 1] return (block.order + nextBlock.order) / 2 } + + static showSortMenu(e: React.MouseEvent, mutator: Mutator, boardTree: BoardTree) { + const { activeView } = boardTree + const { sortOptions } = activeView + const sortOption = sortOptions.length > 0 ? sortOptions[0] : undefined + + const propertyTemplates = boardTree.board.cardProperties + Menu.shared.options = propertyTemplates.map((o) => { + return { + id: o.id, + name: o.name, + icon: (sortOption.propertyId === o.id) ? sortOption.reversed ? "sortUp" : "sortDown" : undefined + } + }) + Menu.shared.onMenuClicked = async (propertyId: string) => { + let newSortOptions: ISortOption[] = [] + if (sortOption && sortOption.propertyId === propertyId) { + // Already sorting by name, so reverse it + newSortOptions = [ + { propertyId, reversed: !sortOption.reversed } + ] + } else { + newSortOptions = [ + { propertyId, reversed: false } + ] + } + + await mutator.changeViewSortOptions(activeView, newSortOptions) + } + Menu.shared.showAtElement(e.target as HTMLElement) + } } export { OctoUtils }