Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 14e9228

Browse files
committed
persisting entire objects
1 parent 7c70e3e commit 14e9228

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
"dependencies": {
5252
"@emotion/styled": "11.10.4",
5353
"@mui/icons-material": "5.10.6",
54-
"@mui/material": "5.10.6",
54+
"@mui/material": "5.10.8",
5555
"@popperjs/core": "2.11.6",
56-
"@tanstack/match-sorter-utils": "8.1.1",
57-
"@tanstack/react-table": "8.5.13",
56+
"@tanstack/match-sorter-utils": "8.5.14",
57+
"@tanstack/react-table": "8.5.15",
5858
"eventemitter3": "4.0.7",
5959
"fuse.js": "6.6.2",
6060
"luxon": "3.0.4",

src/components/cellTypes/TextCell.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { renderMarkdown } from "components/obsidianArq/MarkdownRenderer";
33
import React, { MouseEventHandler, useEffect, useRef } from "react";
44
import { useState } from "react";
55
import EditorCell from "components/cellTypes/EditorCell";
6-
import { TableColumn } from "cdm/FolderModel";
6+
import { RowDataType, TableColumn } from "cdm/FolderModel";
77
import { c, getAlignmentClassname } from "helpers/StylesHelper";
8+
import { Literal } from "obsidian-dataview";
89

910
const TextCell = (props: CellComponentProps) => {
1011
const { defaultCell } = props;
@@ -25,7 +26,7 @@ const TextCell = (props: CellComponentProps) => {
2526
(state) => state.actions
2627
);
2728

28-
const textCell = textRow[column.id]?.toString();
29+
const textCell = parseTextRowToString(textRow, column.id);
2930
/** Ref to cell container */
3031
const containerCellRef = useRef<HTMLDivElement>();
3132
const [dirtyCell, setDirtyCell] = useState(false);
@@ -51,10 +52,11 @@ const TextCell = (props: CellComponentProps) => {
5152

5253
const persistChange = (changedValue: string) => {
5354
if (changedValue !== undefined && changedValue !== textCell) {
55+
const newCell = parseStringToTextRow(textRow, column.id, changedValue);
5456
dataActions.updateCell(
5557
row.index,
5658
tableColumn,
57-
changedValue.trim(),
59+
newCell,
5860
columnsInfo.getAllColumns(),
5961
configInfo.getLocalSettings()
6062
);
@@ -80,4 +82,29 @@ const TextCell = (props: CellComponentProps) => {
8082
);
8183
};
8284

85+
function parseTextRowToString(row: RowDataType, columnId: string) {
86+
const cellRoot = row[columnId];
87+
let textCell = "";
88+
if (typeof cellRoot === "object") {
89+
textCell = JSON.stringify(cellRoot);
90+
} else {
91+
textCell = cellRoot?.toString();
92+
}
93+
return textCell;
94+
}
95+
96+
function parseStringToTextRow(
97+
row: RowDataType,
98+
columnId: string,
99+
newValue: string
100+
): Literal {
101+
const cellRoot = row[columnId];
102+
if (typeof cellRoot === "object") {
103+
// TODO control anidated values in function of columnId spliting by "."
104+
return JSON.parse(newValue);
105+
} else {
106+
return newValue.trim();
107+
}
108+
}
109+
83110
export default TextCell;

src/services/ParseService.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InputType, MarkdownBreakerRules } from "helpers/Constants";
2-
import { Literal, WrappedLiteral } from "obsidian-dataview/lib/data-model/value";
2+
import { DataObject, Literal, WrappedLiteral } from "obsidian-dataview/lib/data-model/value";
33
import { DateTime } from "luxon";
44
import { LOGGER } from "services/Logger";
55
import { DataviewService } from "services/DataviewService";
@@ -27,9 +27,6 @@ class Parse {
2727
.type} to ${dataTypeDst}`);
2828
// Check empty or undefined literals
2929
switch (dataTypeDst) {
30-
case InputType.TEXT:
31-
parsedLiteral = this.parseToString(wrapped);
32-
break;
3330
case InputType.MARKDOWN:
3431
parsedLiteral = this.parseToMarkdown(wrapped, localSettings, isInline);
3532
break;
@@ -56,7 +53,7 @@ class Parse {
5653
// Do nothing
5754
break;
5855
default:
59-
parsedLiteral = parsedLiteral = this.parseToString(wrapped);
56+
parsedLiteral = this.parseToText(wrapped, localSettings);
6057

6158
}
6259
LOGGER.debug(`<=parseLiteral`);
@@ -96,13 +93,18 @@ class Parse {
9693
}
9794
}
9895

99-
private parseToString(wrapped: WrappedLiteral): string {
100-
if (DateTime.isDateTime(wrapped.value)) {
101-
LOGGER.debug("adapting DateTime to string...");
102-
// Values of dataview parse to md friendly strings
103-
return wrapped.value.toFormat("yyyy-MM-dd");
104-
} else {
105-
return DataviewService.getDataviewAPI().value.toString(wrapped.value);
96+
private parseToText(wrapped: WrappedLiteral, localSettings: LocalSettings): string | DataObject {
97+
switch (wrapped.type) {
98+
case 'object':
99+
if (DateTime.isDateTime(wrapped.value)) {
100+
return wrapped.value.toFormat(localSettings.datetime_format);
101+
} else {
102+
// nested metadata exposed as DataObject
103+
return wrapped.value;
104+
}
105+
// Else go to default
106+
default:
107+
return DataviewService.getDataviewAPI().value.toString(wrapped.value);
106108
}
107109
}
108110

@@ -129,9 +131,9 @@ class Parse {
129131
switch (wrapped.type) {
130132
case 'boolean':
131133
case 'number':
132-
// Do nothing
133134
auxMarkdown = wrapped.value.toString();
134135
break;
136+
135137
case 'array':
136138
auxMarkdown = wrapped.value
137139
.map(v => this.parseToMarkdown(DataviewService.getDataviewAPI().value.wrapValue(v), localSettings, isInline))
@@ -145,7 +147,6 @@ class Parse {
145147
} else {
146148
// Parse datetime
147149
auxMarkdown = wrapped.value.toFormat(localSettings.datetime_format);
148-
auxMarkdown = this.handleMarkdownBreaker(auxMarkdown, localSettings, isInline);
149150
}
150151
break;
151152
case 'object':
@@ -154,11 +155,10 @@ class Parse {
154155
}
155156
// Else go to default
156157
default:
157-
auxMarkdown = this.parseToString(wrapped) as string;
158-
// Check possible markdown breakers
159-
auxMarkdown = this.handleMarkdownBreaker(auxMarkdown, localSettings, isInline);
158+
auxMarkdown = DataviewService.getDataviewAPI().value.toString(wrapped.value);
160159
}
161-
return auxMarkdown;
160+
// Check possible markdown breakers
161+
return this.handleYamlBreaker(auxMarkdown, localSettings, isInline);;
162162
}
163163

164164
private parseToOptionsArray(wrapped: WrappedLiteral): Literal {
@@ -168,7 +168,7 @@ class Parse {
168168
return wrapped.value;
169169
}
170170

171-
private handleMarkdownBreaker(value: string, localSettings: LocalSettings, isInline?: boolean): string {
171+
private handleYamlBreaker(value: string, localSettings: LocalSettings, isInline?: boolean): string {
172172
// Do nothing if is inline
173173
if (isInline) {
174174
return value;
@@ -191,6 +191,7 @@ class Parse {
191191

192192
return value;
193193
}
194+
194195
/**
195196
* Singleton instance
196197
* @returns {VaultManager}

0 commit comments

Comments
 (0)