mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 22:35:50 +01:00
chore(react/collections/table): bring back footer
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { useContext, useEffect, useRef, useState } from "preact/hooks";
|
import { useContext, useEffect, useRef, useState } from "preact/hooks";
|
||||||
import { ViewModeProps } from "../interface";
|
import { ViewModeProps } from "../interface";
|
||||||
import "./index.css";
|
|
||||||
import { buildColumnDefinitions } from "./columns";
|
import { buildColumnDefinitions } from "./columns";
|
||||||
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
import getAttributeDefinitionInformation, { buildRowDefinitions, TableData } from "./rows";
|
||||||
import { useNoteLabelInt } from "../../react/hooks";
|
import { useNoteLabelInt } from "../../react/hooks";
|
||||||
@@ -9,6 +8,11 @@ import Tabulator from "./tabulator";
|
|||||||
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule} from 'tabulator-tables';
|
import { Tabulator as VanillaTabulator, SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, ColumnDefinition, DataTreeModule} from 'tabulator-tables';
|
||||||
import { useContextMenu } from "./context_menu";
|
import { useContextMenu } from "./context_menu";
|
||||||
import { ParentComponent } from "../../react/react_utils";
|
import { ParentComponent } from "../../react/react_utils";
|
||||||
|
import FNote from "../../../entities/fnote";
|
||||||
|
import { t } from "../../../services/i18n";
|
||||||
|
import Button from "../../react/Button";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
interface TableConfig {
|
interface TableConfig {
|
||||||
tableData?: {
|
tableData?: {
|
||||||
columns?: ColumnDefinition[];
|
columns?: ColumnDefinition[];
|
||||||
@@ -42,15 +46,31 @@ export default function TableView({ note, viewConfig }: ViewModeProps<TableConfi
|
|||||||
return (
|
return (
|
||||||
<div className="table-view">
|
<div className="table-view">
|
||||||
{columnDefs && (
|
{columnDefs && (
|
||||||
|
<>
|
||||||
<Tabulator
|
<Tabulator
|
||||||
tabulatorRef={tabulatorRef}
|
tabulatorRef={tabulatorRef}
|
||||||
className="table-view-container"
|
className="table-view-container"
|
||||||
columns={columnDefs}
|
columns={columnDefs}
|
||||||
data={rowData}
|
data={rowData}
|
||||||
modules={[ SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, DataTreeModule ]}
|
modules={[ SortModule, FormatModule, InteractionModule, EditModule, ResizeColumnsModule, FrozenColumnsModule, PersistenceModule, MoveColumnsModule, MoveRowsModule, DataTreeModule ]}
|
||||||
|
footerElement={<TableFooter note={note} />}
|
||||||
{...contextMenuEvents}
|
{...contextMenuEvents}
|
||||||
/>
|
/>
|
||||||
|
<TableFooter note={note} />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TableFooter({ note }: { note: FNote }) {
|
||||||
|
return (note.type !== "search" &&
|
||||||
|
<div className="tabulator-footer">
|
||||||
|
<div className="tabulator-footer-contents">
|
||||||
|
<Button triggerCommand="addNewRow" icon="bx bx-plus" text={t("table_view.new-row")} />
|
||||||
|
{" "}
|
||||||
|
<Button triggerCommand="addNewTableColumn" icon="bx bx-carousel" text={t("table_view.new-column")} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
import { useContext, useEffect, useLayoutEffect, useRef } from "preact/hooks";
|
||||||
import { ColumnDefinition, EventCallBackMethods, Module, Tabulator as VanillaTabulator } from "tabulator-tables";
|
import { ColumnDefinition, EventCallBackMethods, Module, Tabulator as VanillaTabulator } 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 { RefObject } from "preact";
|
import { ComponentChildren, RefObject } from "preact";
|
||||||
|
import { ParentComponent, renderReactWidget } from "../../react/react_utils";
|
||||||
|
|
||||||
interface TableProps<T> extends Partial<EventCallBackMethods> {
|
interface TableProps<T> extends Partial<EventCallBackMethods> {
|
||||||
tabulatorRef: RefObject<VanillaTabulator>;
|
tabulatorRef: RefObject<VanillaTabulator>;
|
||||||
@@ -10,9 +11,11 @@ interface TableProps<T> extends Partial<EventCallBackMethods> {
|
|||||||
columns: ColumnDefinition[];
|
columns: ColumnDefinition[];
|
||||||
data?: T[];
|
data?: T[];
|
||||||
modules?: (new (table: VanillaTabulator) => Module)[];
|
modules?: (new (table: VanillaTabulator) => Module)[];
|
||||||
|
footerElement?: ComponentChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, ...events }: TableProps<T>) {
|
export default function Tabulator<T>({ className, columns, data, modules, tabulatorRef: externalTabulatorRef, footerElement, ...events }: TableProps<T>) {
|
||||||
|
const parentComponent = useContext(ParentComponent);
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const tabulatorRef = useRef<VanillaTabulator>(null);
|
const tabulatorRef = useRef<VanillaTabulator>(null);
|
||||||
|
|
||||||
@@ -28,7 +31,8 @@ export default function Tabulator<T>({ className, columns, data, modules, tabula
|
|||||||
|
|
||||||
const tabulator = new VanillaTabulator(containerRef.current, {
|
const tabulator = new VanillaTabulator(containerRef.current, {
|
||||||
columns,
|
columns,
|
||||||
data
|
data,
|
||||||
|
footerElement: (parentComponent && footerElement ? renderReactWidget(parentComponent, footerElement)[0] : undefined)
|
||||||
});
|
});
|
||||||
|
|
||||||
tabulatorRef.current = tabulator;
|
tabulatorRef.current = tabulator;
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import FNote from "../../../entities/fnote.js";
|
|
||||||
import { t } from "../../../services/i18n.js";
|
|
||||||
|
|
||||||
function shouldDisplayFooter(parentNote: FNote) {
|
|
||||||
return (parentNote.type !== "search");
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function buildFooter(parentNote: FNote) {
|
|
||||||
if (!shouldDisplayFooter(parentNote)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return /*html*/`\
|
|
||||||
<button class="btn btn-sm" data-trigger-command="addNewRow">
|
|
||||||
<span class="bx bx-plus"></span> ${t("table_view.new-row")}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<button class="btn btn-sm" data-trigger-command="addNewTableColumn">
|
|
||||||
<span class="bx bx-carousel"></span> ${t("table_view.new-column")}
|
|
||||||
</button>
|
|
||||||
`.trimStart();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user