mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(views/table): allow creating relations
This commit is contained in:
parent
897cdc26ae
commit
0d347f8823
@ -287,6 +287,7 @@ export type CommandMappings = {
|
||||
columnToEdit?: ColumnComponent;
|
||||
referenceColumn?: ColumnComponent;
|
||||
direction?: "before" | "after";
|
||||
type?: "label" | "relation";
|
||||
};
|
||||
deleteTableColumn: CommandData & {
|
||||
columnToDelete?: ColumnComponent;
|
||||
|
@ -30,7 +30,7 @@ export default class TableColumnEditing extends Component {
|
||||
this.parentNote = parentNote;
|
||||
}
|
||||
|
||||
addNewTableColumnCommand({ referenceColumn, columnToEdit, direction }: EventData<"addNewTableColumn">) {
|
||||
addNewTableColumnCommand({ referenceColumn, columnToEdit, direction, type }: EventData<"addNewTableColumn">) {
|
||||
let attr: Attribute | undefined;
|
||||
|
||||
this.existingAttributeToEdit = undefined;
|
||||
@ -44,7 +44,7 @@ export default class TableColumnEditing extends Component {
|
||||
if (!attr) {
|
||||
attr = {
|
||||
type: "label",
|
||||
name: "label:myLabel",
|
||||
name: `${type ?? "label"}:myLabel`,
|
||||
value: "promoted,single,text"
|
||||
};
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, parentNote:
|
||||
title: t("table_view.add-column-to-the-left"),
|
||||
uiIcon: "bx bx-horizontal-left",
|
||||
enabled: !column.getDefinition().frozen,
|
||||
items: buildInsertSubmenu(e, column, "before"),
|
||||
handler: () => getParentComponent(e)?.triggerCommand("addNewTableColumn", {
|
||||
referenceColumn: column
|
||||
})
|
||||
@ -93,6 +94,7 @@ function showColumnContextMenu(_e: UIEvent, column: ColumnComponent, parentNote:
|
||||
{
|
||||
title: t("table_view.add-column-to-the-right"),
|
||||
uiIcon: "bx bx-horizontal-right",
|
||||
items: buildInsertSubmenu(e, column, "after"),
|
||||
handler: () => getParentComponent(e)?.triggerCommand("addNewTableColumn", {
|
||||
referenceColumn: column,
|
||||
direction: "after"
|
||||
@ -243,3 +245,26 @@ function buildColumnItems(tabulator: Tabulator) {
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
function buildInsertSubmenu(e: MouseEvent, referenceColumn: ColumnComponent, direction: "before" | "after"): MenuItem<unknown>[] {
|
||||
return [
|
||||
{
|
||||
title: "Label",
|
||||
handler: () => {
|
||||
getParentComponent(e)?.triggerCommand("addNewTableColumn", {
|
||||
referenceColumn,
|
||||
type: "label"
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Relation",
|
||||
handler: () => {
|
||||
getParentComponent(e)?.triggerCommand("addNewTableColumn", {
|
||||
referenceColumn,
|
||||
type: "relation"
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user