mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 23:18:59 +01:00
chore(react/collections/table): reintroduce editing of newly added item
This commit is contained in:
parent
3d2a4d8c38
commit
1ce42d1301
@ -3,6 +3,7 @@ import FNote from "../../../entities/fnote";
|
|||||||
import attributes from "../../../services/attributes";
|
import attributes from "../../../services/attributes";
|
||||||
import { executeBulkActions } from "../../../services/bulk_action";
|
import { executeBulkActions } from "../../../services/bulk_action";
|
||||||
import note_create from "../../../services/note_create";
|
import note_create from "../../../services/note_create";
|
||||||
|
import server from "../../../services/server";
|
||||||
import { ColumnMap } from "./data";
|
import { ColumnMap } from "./data";
|
||||||
|
|
||||||
export default class BoardApi {
|
export default class BoardApi {
|
||||||
@ -13,7 +14,8 @@ export default class BoardApi {
|
|||||||
private parentNote: FNote,
|
private parentNote: FNote,
|
||||||
private statusAttribute: string,
|
private statusAttribute: string,
|
||||||
private viewConfig: BoardViewData,
|
private viewConfig: BoardViewData,
|
||||||
private saveConfig: (newConfig: BoardViewData) => void
|
private saveConfig: (newConfig: BoardViewData) => void,
|
||||||
|
private setBranchIdToEdit: (branchId: string | undefined) => void
|
||||||
) {};
|
) {};
|
||||||
|
|
||||||
async createNewItem(column: string) {
|
async createNewItem(column: string) {
|
||||||
@ -22,17 +24,14 @@ export default class BoardApi {
|
|||||||
const parentNotePath = this.parentNote.noteId;
|
const parentNotePath = this.parentNote.noteId;
|
||||||
|
|
||||||
// Create a new note as a child of the parent note
|
// Create a new note as a child of the parent note
|
||||||
const { note: newNote } = await note_create.createNote(parentNotePath, {
|
const { note: newNote, branch: newBranch } = await note_create.createNote(parentNotePath, {
|
||||||
activate: false,
|
activate: false,
|
||||||
title: "New item"
|
title: "New item"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newNote) {
|
if (newNote) {
|
||||||
// Set the status label to place it in the correct column
|
|
||||||
await this.changeColumn(newNote.noteId, column);
|
await this.changeColumn(newNote.noteId, column);
|
||||||
|
this.setBranchIdToEdit(newBranch?.branchId);
|
||||||
// Start inline editing of the newly created card
|
|
||||||
//this.startInlineEditingCard(newNote.noteId);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to create new item:", error);
|
console.error("Failed to create new item:", error);
|
||||||
@ -57,5 +56,13 @@ export default class BoardApi {
|
|||||||
this.saveConfig(this.viewConfig);
|
this.saveConfig(this.viewConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dismissEditingTitle() {
|
||||||
|
this.setBranchIdToEdit(undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
renameCard(noteId: string, newTitle: string) {
|
||||||
|
return server.put(`notes/${noteId}/title`, { title: newTitle.trim() });
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||||
import { ViewModeProps } from "../interface";
|
import { ViewModeProps } from "../interface";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { ColumnMap, getBoardData } from "./data";
|
import { ColumnMap, getBoardData } from "./data";
|
||||||
@ -12,6 +12,7 @@ import FormTextBox from "../../react/FormTextBox";
|
|||||||
import branchService from "../../../services/branches";
|
import branchService from "../../../services/branches";
|
||||||
import { openColumnContextMenu, openNoteContextMenu } from "./context_menu";
|
import { openColumnContextMenu, openNoteContextMenu } from "./context_menu";
|
||||||
import { ContextMenuEvent } from "../../../menus/context_menu";
|
import { ContextMenuEvent } from "../../../menus/context_menu";
|
||||||
|
import { createContext } from "preact";
|
||||||
|
|
||||||
export interface BoardViewData {
|
export interface BoardViewData {
|
||||||
columns?: BoardColumnData[];
|
columns?: BoardColumnData[];
|
||||||
@ -21,6 +22,12 @@ export interface BoardColumnData {
|
|||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BoardViewContextData {
|
||||||
|
branchIdToEdit?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BoardViewContext = createContext<BoardViewContextData>({});
|
||||||
|
|
||||||
export default function BoardView({ note: parentNote, noteIds, viewConfig, saveConfig }: ViewModeProps<BoardViewData>) {
|
export default function BoardView({ note: parentNote, noteIds, viewConfig, saveConfig }: ViewModeProps<BoardViewData>) {
|
||||||
const [ statusAttribute ] = useNoteLabelWithDefault(parentNote, "board:groupBy", "status");
|
const [ statusAttribute ] = useNoteLabelWithDefault(parentNote, "board:groupBy", "status");
|
||||||
const [ byColumn, setByColumn ] = useState<ColumnMap>();
|
const [ byColumn, setByColumn ] = useState<ColumnMap>();
|
||||||
@ -30,9 +37,13 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
|
|||||||
const [ dropPosition, setDropPosition ] = useState<{ column: string, index: number } | null>(null);
|
const [ dropPosition, setDropPosition ] = useState<{ column: string, index: number } | null>(null);
|
||||||
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 [ branchIdToEdit, setBranchIdToEdit ] = useState<string>();
|
||||||
const api = useMemo(() => {
|
const api = useMemo(() => {
|
||||||
return new Api(byColumn, columns ?? [], parentNote, statusAttribute, viewConfig ?? {}, saveConfig);
|
return new Api(byColumn, columns ?? [], parentNote, statusAttribute, viewConfig ?? {}, saveConfig, setBranchIdToEdit );
|
||||||
}, [ byColumn, columns, parentNote, statusAttribute, viewConfig, saveConfig ]);
|
}, [ byColumn, columns, parentNote, statusAttribute, viewConfig, saveConfig, setBranchIdToEdit ]);
|
||||||
|
const boardViewContext = useMemo<BoardViewContextData>(() => ({
|
||||||
|
branchIdToEdit
|
||||||
|
}), [ branchIdToEdit ]);
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
getBoardData(parentNote, statusAttribute, viewConfig ?? {}).then(({ byColumn, newPersistedData }) => {
|
getBoardData(parentNote, statusAttribute, viewConfig ?? {}).then(({ byColumn, newPersistedData }) => {
|
||||||
@ -126,41 +137,43 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="board-view">
|
<div className="board-view">
|
||||||
<div
|
<BoardViewContext.Provider value={boardViewContext}>
|
||||||
className="board-view-container"
|
<div
|
||||||
onDragOver={handleColumnDragOver}
|
className="board-view-container"
|
||||||
onDrop={handleContainerDrop}
|
onDragOver={handleColumnDragOver}
|
||||||
>
|
onDrop={handleContainerDrop}
|
||||||
{byColumn && columns?.map((column, index) => (
|
>
|
||||||
<>
|
{byColumn && columns?.map((column, index) => (
|
||||||
{columnDropPosition === index && draggedColumn?.column !== column && (
|
<>
|
||||||
<div className="column-drop-placeholder show" />
|
{columnDropPosition === index && draggedColumn?.column !== column && (
|
||||||
)}
|
<div className="column-drop-placeholder show" />
|
||||||
<Column
|
)}
|
||||||
api={api}
|
<Column
|
||||||
column={column}
|
api={api}
|
||||||
columnIndex={index}
|
column={column}
|
||||||
columnItems={byColumn.get(column)}
|
columnIndex={index}
|
||||||
statusAttribute={statusAttribute ?? "status"}
|
columnItems={byColumn.get(column)}
|
||||||
draggedCard={draggedCard}
|
statusAttribute={statusAttribute ?? "status"}
|
||||||
setDraggedCard={setDraggedCard}
|
draggedCard={draggedCard}
|
||||||
dropTarget={dropTarget}
|
setDraggedCard={setDraggedCard}
|
||||||
setDropTarget={setDropTarget}
|
dropTarget={dropTarget}
|
||||||
dropPosition={dropPosition}
|
setDropTarget={setDropTarget}
|
||||||
setDropPosition={setDropPosition}
|
dropPosition={dropPosition}
|
||||||
onCardDrop={refresh}
|
setDropPosition={setDropPosition}
|
||||||
draggedColumn={draggedColumn}
|
onCardDrop={refresh}
|
||||||
setDraggedColumn={setDraggedColumn}
|
draggedColumn={draggedColumn}
|
||||||
isDraggingColumn={draggedColumn?.column === column}
|
setDraggedColumn={setDraggedColumn}
|
||||||
/>
|
isDraggingColumn={draggedColumn?.column === column}
|
||||||
</>
|
/>
|
||||||
))}
|
</>
|
||||||
{columnDropPosition === columns?.length && draggedColumn && (
|
))}
|
||||||
<div className="column-drop-placeholder show" />
|
{columnDropPosition === columns?.length && draggedColumn && (
|
||||||
)}
|
<div className="column-drop-placeholder show" />
|
||||||
|
)}
|
||||||
|
|
||||||
<AddNewColumn viewConfig={viewConfig} saveConfig={saveConfig} />
|
<AddNewColumn viewConfig={viewConfig} saveConfig={saveConfig} />
|
||||||
</div>
|
</div>
|
||||||
|
</BoardViewContext.Provider>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -359,6 +372,7 @@ function Card({
|
|||||||
setDraggedCard: (card: { noteId: string, branchId: string, fromColumn: string, index: number } | null) => void,
|
setDraggedCard: (card: { noteId: string, branchId: string, fromColumn: string, index: number } | null) => void,
|
||||||
isDragging: boolean
|
isDragging: boolean
|
||||||
}) {
|
}) {
|
||||||
|
const { branchIdToEdit } = useContext(BoardViewContext);
|
||||||
const colorClass = note.getColorClass() || '';
|
const colorClass = note.getColorClass() || '';
|
||||||
|
|
||||||
const handleDragStart = useCallback((e: DragEvent) => {
|
const handleDragStart = useCallback((e: DragEvent) => {
|
||||||
@ -383,8 +397,26 @@ function Card({
|
|||||||
onDragEnd={handleDragEnd}
|
onDragEnd={handleDragEnd}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={handleContextMenu}
|
||||||
>
|
>
|
||||||
<span class={`icon ${note.getIcon()}`} />
|
{branch.branchId !== branchIdToEdit ? (
|
||||||
{note.title}
|
<>
|
||||||
|
<span class={`icon ${note.getIcon()}`} />
|
||||||
|
{note.title}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<FormTextBox
|
||||||
|
value={note.title}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
api.renameCard(note.noteId, e.currentTarget.value);
|
||||||
|
api.dismissEditingTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
api.dismissEditingTitle();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -447,8 +447,7 @@ export class DifferentialBoardRenderer {
|
|||||||
try {
|
try {
|
||||||
// Update the note title using the board view's server call
|
// Update the note title using the board view's server call
|
||||||
import('../../../services/server').then(async ({ default: server }) => {
|
import('../../../services/server').then(async ({ default: server }) => {
|
||||||
await server.put(`notes/${noteId}/title`, { title: newTitle.trim() });
|
|
||||||
finalTitle = newTitle.trim();
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to update note title:", error);
|
console.error("Failed to update note title:", error);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user