Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/notion): import select columns as single-valued labels

Elian Doran7d1964c45ec1
diff --git a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts b/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
index 37ae2fbda6..e41a70df4e 100644
--- a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
+++ b/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
@@ -411,6 +411,24 @@ describe("Notion importer — integration", () => {
expect(empty?.getLabelValue("label:Multi_select")).toBe("promoted,multi,text,alias=Multi-select");
});
+ it("imports a select column as a single-valued text label", async () => {
+ const dbId = "388c5eca1b8b8078a20fd18330d81306";
+ const rowId = "388c5eca1b8b80929a78da7c68154bd7";
+ // Notion renders a single-select value as one <span class="selected-value"> in the cell.
+ const props = `<table class="properties"><tbody><tr class="property-row property-row-select"><th><span class="icon property-icon"><img src="x.svg"/></span>Select column</th><td><span class="selected-value select-value-color-gray">First</span></td></tr></tbody></table>`;
+ const importRoot = await importNotion({
+ "DB 388c5eca1b8b8078a20fd18330d81306.html":
+ `<html><head><title>DB</title></head><body><div id="${dbId}"><div class="page-body"></div></div></body></html>`,
+ "DB/Row 388c5eca1b8b80929a78da7c68154bd7.html":
+ `<html><head><title>Row</title></head><body><div id="${rowId}">${props}<div class="page-body"><p>x</p></div></div></body></html>`
+ });
+
+ const db = importRoot.getChildNotes().find((n) => n.title === "DB");
+ expect(db?.getOwnedLabel("label:Select_column")?.value).toBe("promoted,single,text,alias=Select column");
+ const row = db?.getChildNotes().find((n) => n.title === "Row");
+ expect(row?.getOwnedLabelValue("Select_column")).toBe("First");
+ });
+
it("neutralizes commas in a column name so the alias can't corrupt the definition", async () => {
const dbId = "388c5eca1b8b8078a20fd18330d81306";
const rowId = "388c5eca1b8b80929a78da7c68154bd7";
diff --git a/packages/trilium-core/src/services/import/notion/importer.ts b/packages/trilium-core/src/services/import/notion/importer.ts
index 5bdc8aba3a..9606fd0a15 100644
--- a/packages/trilium-core/src/services/import/notion/importer.ts
+++ b/packages/trilium-core/src/services/import/notion/importer.ts
@@ -482,7 +482,7 @@ export function firstChildNotionId(body: HTMLElement | null): string | undefined
* Reads a page's database properties from its Notion properties table. Each column is a
* `<tr class="property-row property-row-<type>">` whose `<th>` holds the column name (after an icon span,
* which carries no text) and `<td>` the value. Handled so far:
- * - `text`: the cell's text → one single-valued property;
+ * - `text` / `select`: the cell's text → one single-valued property;
* - `multi_select`: each `<span class="selected-value">` option → one entry of a multi-valued property.
* The importer turns each `{ name, value }` into a Trilium label; blank names/values are skipped (Notion
* sometimes emits an empty cell, e.g. an unset multi-select, which should contribute no label). Other types
@@ -498,7 +498,9 @@ function extractProperties(root: HTMLElement): NotionProperty[] {
}
const type = row.getAttribute("class")?.match(/property-row-(\w+)/)?.[1];
- if (type === "text") {
+ if (type === "text" || type === "select") {
+ // `select` is a single chosen option (one `<span class="selected-value">`); its cell text is the
+ // whole value, so it takes the same single-valued path as a free-text column.
const value = cell.textContent?.trim();
if (value) {
properties.push({ name, value, labelType: "text", multiplicity: "single" });