mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	feat(views/table): focus if creating child note
This commit is contained in:
		
							parent
							
								
									c13969217c
								
							
						
					
					
						commit
						84479a2c2a
					
				| @ -123,16 +123,19 @@ export function showRowContextMenu(_e: UIEvent, row: RowComponent, parentNote: F | |||||||
|                 title: t("table_view.row-insert-child"), |                 title: t("table_view.row-insert-child"), | ||||||
|                 uiIcon: "bx bx-empty", |                 uiIcon: "bx bx-empty", | ||||||
|                 handler: async () => { |                 handler: async () => { | ||||||
|                     const branchId = row.getData().branchId; |  | ||||||
|                     const note = await froca.getBranch(branchId)?.getNote(); |  | ||||||
|                     const bestNotePath = note?.getBestNotePath(parentNote.noteId); |  | ||||||
|                     const target = e.target; |                     const target = e.target; | ||||||
|                     if (!target) { |                     if (!target) { | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|  |                     const branchId = row.getData().branchId; | ||||||
|  |                     const note = await froca.getBranch(branchId)?.getNote(); | ||||||
|                     const component = $(target).closest(".component").prop("component"); |                     const component = $(target).closest(".component").prop("component"); | ||||||
|                     component.triggerCommand("addNewRow", { |                     component.triggerCommand("addNewRow", { | ||||||
|                         parentNotePath: bestNotePath?.join("/") |                         parentNotePath: note?.noteId, | ||||||
|  |                         customOpts: { | ||||||
|  |                             target: "after", | ||||||
|  |                             targetBranchId: branchId, | ||||||
|  |                         } | ||||||
|                     }); |                     }); | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import SpacedUpdate from "../../../services/spaced_update.js"; | |||||||
| import type { CommandListenerData, EventData } from "../../../components/app_context.js"; | import type { CommandListenerData, EventData } from "../../../components/app_context.js"; | ||||||
| import type { Attribute } from "../../../services/attribute_parser.js"; | import type { Attribute } from "../../../services/attribute_parser.js"; | ||||||
| import note_create, { CreateNoteOpts } from "../../../services/note_create.js"; | import note_create, { CreateNoteOpts } from "../../../services/note_create.js"; | ||||||
| import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options} from 'tabulator-tables'; | import {Tabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule, Options, RowComponent} from 'tabulator-tables'; | ||||||
| import "tabulator-tables/dist/css/tabulator.css"; | import "tabulator-tables/dist/css/tabulator.css"; | ||||||
| import "../../../../src/stylesheets/table.css"; | import "../../../../src/stylesheets/table.css"; | ||||||
| import { canReorderRows, configureReorderingRows } from "./dragging.js"; | import { canReorderRows, configureReorderingRows } from "./dragging.js"; | ||||||
| @ -107,7 +107,7 @@ export default class TableView extends ViewMode<StateInfo> { | |||||||
|     private newAttribute?: Attribute; |     private newAttribute?: Attribute; | ||||||
|     private persistentData: StateInfo["tableData"]; |     private persistentData: StateInfo["tableData"]; | ||||||
|     /** If set to a note ID, whenever the rows will be updated, the title of the note will be automatically focused for editing. */ |     /** If set to a note ID, whenever the rows will be updated, the title of the note will be automatically focused for editing. */ | ||||||
|     private noteIdToEdit?: string; |     private branchIdToEdit?: string; | ||||||
| 
 | 
 | ||||||
|     constructor(args: ViewModeArgs) { |     constructor(args: ViewModeArgs) { | ||||||
|         super(args, "table"); |         super(args, "table"); | ||||||
| @ -145,7 +145,7 @@ export default class TableView extends ViewMode<StateInfo> { | |||||||
|         const columnDefs = buildColumnDefinitions(info, movableRows); |         const columnDefs = buildColumnDefinitions(info, movableRows); | ||||||
|         let opts: Options = { |         let opts: Options = { | ||||||
|             layout: "fitDataFill", |             layout: "fitDataFill", | ||||||
|             index: "noteId", |             index: "branchId", | ||||||
|             columns: columnDefs, |             columns: columnDefs, | ||||||
|             data: rowData, |             data: rowData, | ||||||
|             persistence: true, |             persistence: true, | ||||||
| @ -237,11 +237,12 @@ export default class TableView extends ViewMode<StateInfo> { | |||||||
|                 ...customOpts |                 ...customOpts | ||||||
|             } |             } | ||||||
|             console.log("Create with ", opts); |             console.log("Create with ", opts); | ||||||
|             note_create.createNote(parentNotePath, opts).then(({ note }) => { |             note_create.createNote(parentNotePath, opts).then(({ branch }) => { | ||||||
|                 if (!note) { |                 if (branch) { | ||||||
|                     return; |                     setTimeout(() => { | ||||||
|  |                         this.focusOnBranch(branch?.branchId); | ||||||
|  |                     }); | ||||||
|                 } |                 } | ||||||
|                 this.noteIdToEdit = note.noteId; |  | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -285,16 +286,43 @@ export default class TableView extends ViewMode<StateInfo> { | |||||||
| 
 | 
 | ||||||
|         const info = getAttributeDefinitionInformation(this.parentNote); |         const info = getAttributeDefinitionInformation(this.parentNote); | ||||||
|         const { definitions } = await buildRowDefinitions(this.parentNote, info); |         const { definitions } = await buildRowDefinitions(this.parentNote, info); | ||||||
|         this.api.replaceData(definitions); |         await this.api.replaceData(definitions); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     focusOnBranch(branchId: string) { | ||||||
|  |         if (!this.api) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         const row = findRowDataById(this.api.getRows(), branchId); | ||||||
|  |         if (!row) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Expand the parent tree if any.
 | ||||||
|  |         if (this.api.options.dataTree) { | ||||||
|  |             const parent = row.getTreeParent(); | ||||||
|  |             if (parent) { | ||||||
|  |                 parent.treeExpand(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         if (this.noteIdToEdit) { |  | ||||||
|             const row = this.api?.getRows().find(r => r.getData().noteId === this.noteIdToEdit); |  | ||||||
|             if (row) { |  | ||||||
|         row.getCell("title").edit(); |         row.getCell("title").edit(); | ||||||
|     } |     } | ||||||
|             this.noteIdToEdit = undefined; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | function findRowDataById(rows: RowComponent[], branchId: string): RowComponent | null { | ||||||
|  |     for (let row of rows) { | ||||||
|  |         const item = row.getIndex() as string; | ||||||
|  | 
 | ||||||
|  |         if (item === branchId) { | ||||||
|  |             return row; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         let found = findRowDataById(row.getTreeChildren(), branchId); | ||||||
|  |         if (found) return found; | ||||||
|  |     } | ||||||
|  |     return null; | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran