diff --git a/apps/client/src/widgets/view_widgets/table_view.ts b/apps/client/src/widgets/view_widgets/table_view.ts
index 52bd42ea4..f79b92380 100644
--- a/apps/client/src/widgets/view_widgets/table_view.ts
+++ b/apps/client/src/widgets/view_widgets/table_view.ts
@@ -1,7 +1,12 @@
import froca from "../../services/froca.js";
-import renderTable from "./table_view/renderer.js";
import type { StateInfo } from "./table_view/storage.js";
-import ViewMode, { ViewModeArgs } from "./view_mode";
+import ViewMode, { type ViewModeArgs } from "./view_mode.js";
+import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
+import { setLabel } from "../../services/attributes.js";
+import getPromotedAttributeInformation from "./table_view/parser.js";
+import { buildData, TableData } from "./table_view/data.js";
+import applyHeaderCustomization from "./table_view/header-customization.js";
+import server from "../../services/server.js";
const TPL = /*html*/`
@@ -44,6 +49,8 @@ export default class TableView extends ViewMode
{
this.$container = this.$root.find(".table-view-container");
this.args = args;
args.$parent.append(this.$root);
+
+ ModuleRegistry.registerModules([ AllCommunityModule ]);
}
get isFullHeight(): boolean {
@@ -51,12 +58,57 @@ export default class TableView extends ViewMode {
}
async renderList() {
- const { noteIds, parentNote } = this.args;
- const notes = await froca.getNotes(noteIds);
-
this.$container.empty();
- renderTable(this.$container[0], parentNote, notes, this.viewStorage);
+ this.renderTable(this.$container[0]);
return this.$root;
}
+ private async renderTable(el: HTMLElement) {
+ const { noteIds, parentNote } = this.args;
+ const notes = await froca.getNotes(noteIds);
+
+ const info = getPromotedAttributeInformation(parentNote);
+ const viewStorage = await this.viewStorage.restore();
+ const initialState = viewStorage?.gridState;
+
+ createGrid(el, {
+ ...buildData(info, notes),
+ ...setupEditing(),
+ initialState,
+ async onGridReady(event) {
+ applyHeaderCustomization(el, event.api);
+ },
+ onStateUpdated: (event) => this.viewStorage.store({
+ gridState: event.api.getState()
+ })
+ });
+ }
+
+}
+
+function setupEditing(): GridOptions {
+ return {
+ onCellValueChanged(event) {
+ if (event.type !== "cellValueChanged") {
+ return;
+ }
+
+ const noteId = event.data.noteId;
+ const name = event.colDef.field;
+ if (!name) {
+ return;
+ }
+
+ const { newValue } = event;
+ if (name === "title") {
+ // TODO: Deduplicate with note_title.
+ server.put(`notes/${noteId}/title`, { title: newValue });
+ }
+
+ if (name.startsWith("labels.")) {
+ const labelName = name.split(".", 2)[1];
+ setLabel(noteId, labelName, newValue);
+ }
+ }
+ }
}
diff --git a/apps/client/src/widgets/view_widgets/table_view/renderer.ts b/apps/client/src/widgets/view_widgets/table_view/renderer.ts
deleted file mode 100644
index b6ec442c4..000000000
--- a/apps/client/src/widgets/view_widgets/table_view/renderer.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { createGrid, AllCommunityModule, ModuleRegistry, GridOptions } from "ag-grid-community";
-import { buildData, type TableData } from "./data.js";
-import FNote from "../../../entities/fnote.js";
-import getPromotedAttributeInformation from "./parser.js";
-import { setLabel } from "../../../services/attributes.js";
-import applyHeaderCustomization from "./header-customization.js";
-import ViewModeStorage from "../view_mode_storage.js";
-import { type StateInfo } from "./storage.js";
-import server from "../../../services/server.js";
-
-ModuleRegistry.registerModules([ AllCommunityModule ]);
-
-export default async function renderTable(el: HTMLElement, parentNote: FNote, notes: FNote[], storage: ViewModeStorage) {
- const info = getPromotedAttributeInformation(parentNote);
- const viewStorage = await storage.restore();
- const initialState = viewStorage?.gridState;
-
- createGrid(el, {
- ...buildData(info, notes),
- ...setupEditing(),
- initialState,
- async onGridReady(event) {
- applyHeaderCustomization(el, event.api);
- },
- onStateUpdated(event) {
- storage.store({
- gridState: event.api.getState()
- });
- }
- });
-}
-
-function setupEditing(): GridOptions {
- return {
- onCellValueChanged(event) {
- if (event.type !== "cellValueChanged") {
- return;
- }
-
- const noteId = event.data.noteId;
- const name = event.colDef.field;
- if (!name) {
- return;
- }
-
- const { newValue } = event;
- if (name === "title") {
- // TODO: Deduplicate with note_title.
- server.put(`notes/${noteId}/title`, { title: newValue });
- }
-
- if (name.startsWith("labels.")) {
- const labelName = name.split(".", 2)[1];
- setLabel(noteId, labelName, newValue);
- }
- }
- }
-}
-