Skip to content

Commit

Permalink
context table: no hard reset when file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Jun 24, 2024
1 parent cf76985 commit 1e1d986
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions extension/src-context-table/html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@ export function createSelector(id: string, index: number, options: string[], top
}
}

/**
* Creates a table VNode enclosed by a div element with the 'context table' class.
* @param id The id of the table.
* @returns A table VNode enclosed by a div element.
*/
export function initContextTable(id: string): VNode {
return <div class={{contextTable: true}}>{createTable(id)}</div>;
}

/**
* Creates a table VNode.
* @param id The id of the table.
* @returns A table VNode.
*/
export function createTable(id: string): VNode {
return <div class={{contextTable: true}}><table attrs={{ id: id }}></table></div>;
return <table attrs={{ id: id }}></table>;
}

/**
Expand Down Expand Up @@ -87,7 +96,7 @@ export function createText(text: string): VNode {
* @param colspan The colspan of the header.
* @returns A header element.
*/
export function createHeaderElement(header: string, top: string, rowspan?: number, colspan?: number) {
export function createHeaderElement(header: string, top: string, rowspan?: number, colspan?: number): VNode {
if (rowspan && colspan) {
return <th attrs={{ rowspan: rowspan, colspan: colspan }} style={{ top: top }}>{header}</th>;
} else if (rowspan) {
Expand All @@ -104,7 +113,7 @@ export function createHeaderElement(header: string, top: string, rowspan?: numbe
* @param headers The headers of the header row.
* @returns A header row element.
*/
export function createHeaderRow(headers: VNode[]) {
export function createHeaderRow(headers: VNode[]): VNode {
return <tr>
{...headers}
</tr>;
Expand All @@ -115,7 +124,7 @@ export function createHeaderRow(headers: VNode[]) {
* @param headers The header rows
* @returns A thead element containing the given header rows.
*/
export function createTHead(headers: VNode[]) {
export function createTHead(headers: VNode[]): VNode {
return <thead>{...headers}</thead>;
}

Expand Down
4 changes: 2 additions & 2 deletions extension/src-context-table/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import "./css/table.css";
import { Table } from "@kieler/table-webview/lib/table";
import { SendContextTableDataAction } from "./actions";
import { createHeaderElement, createHeaderRow, createRow, createTable, createTHead, patch } from "./html";
import { createHeaderElement, createHeaderRow, createRow, createTable, createTHead, initContextTable, patch } from "./html";
import {
addSelector,
addText,
Expand Down Expand Up @@ -163,7 +163,7 @@ export class ContextTable extends Table {
// create a table
const placeholderTable = document.createElement("div");
mainDiv.append(placeholderTable);
const table = createTable(this.tableId);
const table = initContextTable(this.tableId);
patch(placeholderTable, table);
}
}
Expand Down

0 comments on commit 1e1d986

Please sign in to comment.