mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	chore(react/collections/table): reintroduce column context menu
This commit is contained in:
		
							parent
							
								
									2b452a18df
								
							
						
					
					
						commit
						803164791f
					
				@ -1,12 +1,18 @@
 | 
				
			|||||||
 | 
					import { BoardViewData } from ".";
 | 
				
			||||||
import FNote from "../../../entities/fnote";
 | 
					import FNote from "../../../entities/fnote";
 | 
				
			||||||
import attributes from "../../../services/attributes";
 | 
					import attributes from "../../../services/attributes";
 | 
				
			||||||
 | 
					import { executeBulkActions } from "../../../services/bulk_action";
 | 
				
			||||||
import note_create from "../../../services/note_create";
 | 
					import note_create from "../../../services/note_create";
 | 
				
			||||||
 | 
					import { ColumnMap } from "./data";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class BoardApi {
 | 
					export default class BoardApi {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
 | 
					        private byColumn: ColumnMap | undefined,
 | 
				
			||||||
        private parentNote: FNote,
 | 
					        private parentNote: FNote,
 | 
				
			||||||
        private statusAttribute: string
 | 
					        private statusAttribute: string,
 | 
				
			||||||
 | 
					        private viewConfig: BoardViewData,
 | 
				
			||||||
 | 
					        private saveConfig: (newConfig: BoardViewData) => void
 | 
				
			||||||
    ) {};
 | 
					    ) {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async createNewItem(column: string) {
 | 
					    async createNewItem(column: string) {
 | 
				
			||||||
@ -36,5 +42,19 @@ export default class BoardApi {
 | 
				
			|||||||
        await attributes.setLabel(noteId, this.statusAttribute, newColumn);
 | 
					        await attributes.setLabel(noteId, this.statusAttribute, newColumn);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async removeColumn(column: string) {
 | 
				
			||||||
 | 
					        // Remove the value from the notes.
 | 
				
			||||||
 | 
					        const noteIds = this.byColumn?.get(column)?.map(item => item.note.noteId) || [];
 | 
				
			||||||
 | 
					        await executeBulkActions(noteIds, [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                name: "deleteLabel",
 | 
				
			||||||
 | 
					                labelName: this.statusAttribute
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        this.viewConfig.columns = (this.viewConfig.columns ?? []).filter(col => col.value !== column);
 | 
				
			||||||
 | 
					        this.saveConfig(this.viewConfig);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										29
									
								
								apps/client/src/widgets/collections/board/context_menu.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								apps/client/src/widgets/collections/board/context_menu.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					import contextMenu, { ContextMenuEvent } from "../../../menus/context_menu";
 | 
				
			||||||
 | 
					import dialog from "../../../services/dialog";
 | 
				
			||||||
 | 
					import { t } from "../../../services/i18n";
 | 
				
			||||||
 | 
					import Api from "./api";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: string) {
 | 
				
			||||||
 | 
					    event.preventDefault();
 | 
				
			||||||
 | 
					    event.stopPropagation();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    contextMenu.show({
 | 
				
			||||||
 | 
					        x: event.pageX,
 | 
				
			||||||
 | 
					        y: event.pageY,
 | 
				
			||||||
 | 
					        items: [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                title: t("board_view.delete-column"),
 | 
				
			||||||
 | 
					                uiIcon: "bx bx-trash",
 | 
				
			||||||
 | 
					                async handler() {
 | 
				
			||||||
 | 
					                    const confirmed = await dialog.confirm(t("board_view.delete-column-confirmation"));
 | 
				
			||||||
 | 
					                    if (!confirmed) {
 | 
				
			||||||
 | 
					                        return;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    await api.removeColumn(column);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        selectMenuItemHandler() {}
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -10,6 +10,8 @@ import { t } from "../../../services/i18n";
 | 
				
			|||||||
import Api from "./api";
 | 
					import Api from "./api";
 | 
				
			||||||
import FormTextBox from "../../react/FormTextBox";
 | 
					import FormTextBox from "../../react/FormTextBox";
 | 
				
			||||||
import branchService from "../../../services/branches";
 | 
					import branchService from "../../../services/branches";
 | 
				
			||||||
 | 
					import { openColumnContextMenu } from "./context_menu";
 | 
				
			||||||
 | 
					import { ContextMenuEvent } from "../../../menus/context_menu";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface BoardViewData {
 | 
					export interface BoardViewData {
 | 
				
			||||||
    columns?: BoardColumnData[];
 | 
					    columns?: BoardColumnData[];
 | 
				
			||||||
@ -29,7 +31,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
 | 
				
			|||||||
    const [ draggedColumn, setDraggedColumn ] = useState<{ column: string, index: number } | null>(null);
 | 
					    const [ draggedColumn, setDraggedColumn ] = useState<{ column: string, index: number } | null>(null);
 | 
				
			||||||
    const [ columnDropPosition, setColumnDropPosition ] = useState<number | null>(null);
 | 
					    const [ columnDropPosition, setColumnDropPosition ] = useState<number | null>(null);
 | 
				
			||||||
    const api = useMemo(() => {
 | 
					    const api = useMemo(() => {
 | 
				
			||||||
        return new Api(parentNote, statusAttribute);
 | 
					        return new Api(byColumn, parentNote, statusAttribute, viewConfig ?? {}, saveConfig);
 | 
				
			||||||
    }, [ parentNote, statusAttribute ]);
 | 
					    }, [ parentNote, statusAttribute ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function refresh() {
 | 
					    function refresh() {
 | 
				
			||||||
@ -283,12 +285,17 @@ function Column({
 | 
				
			|||||||
        setDraggedCard(null);
 | 
					        setDraggedCard(null);
 | 
				
			||||||
    }, [draggedCard, draggedColumn, dropPosition, columnItems, column, statusAttribute, setDraggedCard, setDropTarget, setDropPosition, onCardDrop]);
 | 
					    }, [draggedCard, draggedColumn, dropPosition, columnItems, column, statusAttribute, setDraggedCard, setDropTarget, setDropPosition, onCardDrop]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const handleContextMenu = useCallback((e: ContextMenuEvent) => {
 | 
				
			||||||
 | 
					        openColumnContextMenu(api, e, column);
 | 
				
			||||||
 | 
					    }, [ api, column ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
        <div
 | 
					        <div
 | 
				
			||||||
            className={`board-column ${dropTarget === column && draggedCard?.fromColumn !== column ? 'drag-over' : ''} ${isDraggingColumn ? 'column-dragging' : ''}`}
 | 
					            className={`board-column ${dropTarget === column && draggedCard?.fromColumn !== column ? 'drag-over' : ''} ${isDraggingColumn ? 'column-dragging' : ''}`}
 | 
				
			||||||
            onDragOver={handleDragOver}
 | 
					            onDragOver={handleDragOver}
 | 
				
			||||||
            onDragLeave={handleDragLeave}
 | 
					            onDragLeave={handleDragLeave}
 | 
				
			||||||
            onDrop={handleDrop}
 | 
					            onDrop={handleDrop}
 | 
				
			||||||
 | 
					            onContextMenu={handleContextMenu}
 | 
				
			||||||
        >
 | 
					        >
 | 
				
			||||||
            <h3
 | 
					            <h3
 | 
				
			||||||
                draggable="true"
 | 
					                draggable="true"
 | 
				
			||||||
 | 
				
			|||||||
@ -77,19 +77,7 @@ export default class BoardApi {
 | 
				
			|||||||
        await this.viewStorage.store(this.persistedData);
 | 
					        await this.viewStorage.store(this.persistedData);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async removeColumn(column: string) {
 | 
					 | 
				
			||||||
        // Remove the value from the notes.
 | 
					 | 
				
			||||||
        const noteIds = this.byColumn.get(column)?.map(item => item.note.noteId) || [];
 | 
					 | 
				
			||||||
        await executeBulkActions(noteIds, [
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                name: "deleteLabel",
 | 
					 | 
				
			||||||
                labelName: this._statusAttribute
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        ]);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.persistedData.columns = (this.persistedData.columns ?? []).filter(col => col.value !== column);
 | 
					 | 
				
			||||||
        this.viewStorage.store(this.persistedData);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async reorderColumns(newColumnOrder: string[]) {
 | 
					    async reorderColumns(newColumnOrder: string[]) {
 | 
				
			||||||
        // Update the column order in persisted data
 | 
					        // Update the column order in persisted data
 | 
				
			||||||
 | 
				
			|||||||
@ -16,32 +16,7 @@ export function setupContextMenu({ $container, api, boardView }: ShowNoteContext
 | 
				
			|||||||
    $container.on("contextmenu", ".board-note", showNoteContextMenu);
 | 
					    $container.on("contextmenu", ".board-note", showNoteContextMenu);
 | 
				
			||||||
    $container.on("contextmenu", ".board-column h3", showColumnContextMenu);
 | 
					    $container.on("contextmenu", ".board-column h3", showColumnContextMenu);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function showColumnContextMenu(event: ContextMenuEvent) {
 | 
					 | 
				
			||||||
        event.preventDefault();
 | 
					 | 
				
			||||||
        event.stopPropagation();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const $el = $(event.currentTarget);
 | 
					 | 
				
			||||||
        const column = $el.closest(".board-column").data("column");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        contextMenu.show({
 | 
					 | 
				
			||||||
            x: event.pageX,
 | 
					 | 
				
			||||||
            y: event.pageY,
 | 
					 | 
				
			||||||
            items: [
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    title: t("board_view.delete-column"),
 | 
					 | 
				
			||||||
                    uiIcon: "bx bx-trash",
 | 
					 | 
				
			||||||
                    async handler() {
 | 
					 | 
				
			||||||
                        const confirmed = await dialog.confirm(t("board_view.delete-column-confirmation"));
 | 
					 | 
				
			||||||
                        if (!confirmed) {
 | 
					 | 
				
			||||||
                            return;
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        await api.removeColumn(column);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            ],
 | 
					 | 
				
			||||||
            selectMenuItemHandler() {}
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function showNoteContextMenu(event: ContextMenuEvent) {
 | 
					    function showNoteContextMenu(event: ContextMenuEvent) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user