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

Commit 27be934

Browse files
committed
useEffect loop fixxed
1 parent 80e7462 commit 27be934

File tree

6 files changed

+51
-40
lines changed

6 files changed

+51
-40
lines changed

src/cdm/ComponentsModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type CellComponentProps = {
1818
}
1919

2020
export type EditorCellComponentProps = {
21-
persistChange: (changedValue: string) => void;
21+
persistChange: (changedValue: string) => Promise<void>;
2222
textCell: string;
2323
} & CellComponentProps;
2424

src/components/cellTypes/Editor/RelationEditor.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { recordRowsFromRelation } from "helpers/RelationHelper";
88
import { TableColumn } from "cdm/FolderModel";
99
import { Link } from "obsidian-dataview";
1010
import { OnChangeValue } from "react-select";
11+
import { StyleVariables } from "helpers/Constants";
1112

1213
const RelationEditor = (props: RelationEditorComponentProps) => {
1314
const { defaultCell, persistChange, relationCell } = props;
@@ -22,7 +23,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
2223
? relationCell.map((link: Link) => ({
2324
label: link.fileName(),
2425
value: link.path,
25-
color: "var(--text-normal)",
26+
color: StyleVariables.TEXT_NORMAL,
2627
}))
2728
: []
2829
);
@@ -33,7 +34,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
3334
const arrayTags = newValue.map((tag) => ({
3435
label: tag.value,
3536
value: tag.value,
36-
color: "var(--text-normal)",
37+
color: StyleVariables.TEXT_NORMAL,
3738
}));
3839
setRelationValue(arrayTags);
3940
};
@@ -54,7 +55,7 @@ const RelationEditor = (props: RelationEditorComponentProps) => {
5455
const multiOptions = Object.entries(relationRows).map(([key, value]) => ({
5556
label: value,
5657
value: key,
57-
color: "var(--text-normal)",
58+
color: StyleVariables.TEXT_NORMAL,
5859
}));
5960

6061
setRelationOptions(multiOptions);

src/components/cellTypes/FormulaCell.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,47 @@ const FormulaCell = (mdProps: CellComponentProps) => {
2929

3030
useEffect(() => {
3131
if (formulaRef.current !== null) {
32-
formulaRef.current.innerHTML = "";
32+
const effectCallback = async () => {
33+
formulaRef.current.innerHTML = "";
3334

34-
const formulaResponse = formulaInfo
35-
.runFormula(
36-
tableColumn.config.formula_query,
37-
formulaRow,
38-
configInfo.getLocalSettings()
39-
)
40-
.toString();
41-
42-
renderMarkdown(defaultCell, formulaResponse, formulaRef.current, 5);
35+
const formulaResponse = formulaInfo
36+
.runFormula(
37+
tableColumn.config.formula_query,
38+
formulaRow,
39+
configInfo.getLocalSettings()
40+
)
41+
.toString();
4342

44-
// Save formula response on disk
45-
if (
46-
tableColumn.config.persist_formula &&
47-
formulaCell !== formulaResponse
48-
) {
49-
const newCell = ParseService.parseRowToLiteral(
50-
formulaRow,
51-
tableColumn,
52-
formulaResponse
43+
await renderMarkdown(
44+
defaultCell,
45+
formulaResponse,
46+
formulaRef.current,
47+
5
5348
);
5449

55-
dataActions.updateCell(
56-
row.index,
57-
tableColumn,
58-
newCell,
59-
columnsInfo.getAllColumns(),
60-
configInfo.getLocalSettings()
61-
);
62-
}
50+
// Save formula response on disk
51+
if (
52+
tableColumn.config.persist_formula &&
53+
formulaCell !== formulaResponse
54+
) {
55+
const newCell = ParseService.parseRowToLiteral(
56+
formulaRow,
57+
tableColumn,
58+
formulaResponse
59+
);
60+
61+
await dataActions.updateCell(
62+
row.index,
63+
tableColumn,
64+
newCell,
65+
columnsInfo.getAllColumns(),
66+
configInfo.getLocalSettings()
67+
);
68+
}
69+
};
70+
effectCallback();
6371
}
64-
}, [row]);
72+
}, [formulaRow]);
6573
return (
6674
<span
6775
ref={formulaRef}

src/components/cellTypes/TextCell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const TextCell = (props: CellComponentProps) => {
5454
setDirtyCell(true);
5555
};
5656

57-
const persistChange = (changedValue: string) => {
57+
const persistChange = async (changedValue: string) => {
5858
changedValue = changedValue.trim();
5959
if (changedValue !== undefined && changedValue !== textCell) {
6060
const newCell = ParseService.parseRowToLiteral(
@@ -63,7 +63,7 @@ const TextCell = (props: CellComponentProps) => {
6363
changedValue
6464
);
6565

66-
dataActions.updateCell(
66+
await dataActions.updateCell(
6767
row.index,
6868
tableColumn,
6969
newCell,

src/components/styles/RowTemplateStyles.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { StyleVariables } from "helpers/Constants";
12
import { GroupBase, StylesConfig } from "react-select";
23

34
const CustomTemplateSelectorStyles: StylesConfig<any, true, GroupBase<any>> = {
45
singleValue: (styles) => ({
56
...styles,
6-
color: 'var(--text-normal)',
7+
color: StyleVariables.TEXT_NORMAL,
78
width: "max-content",
89
minWidth: "100%",
910
border: 0
@@ -12,16 +13,16 @@ const CustomTemplateSelectorStyles: StylesConfig<any, true, GroupBase<any>> = {
1213
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
1314
return {
1415
...styles,
15-
color: 'var(--text-normal)',
16-
backgroundColor: 'var(--background-primary)',
16+
color: StyleVariables.TEXT_NORMAL,
17+
backgroundColor: StyleVariables.BACKGROUND_PRIMARY,
1718
textAlign: 'left',
1819
}
1920
},
2021
control: (styles) => {
2122
return {
2223
...styles,
23-
color: 'var(--text-normal)',
24-
backgroundColor: 'var(--background-primary)',
24+
color: StyleVariables.TEXT_NORMAL,
25+
backgroundColor: StyleVariables.BACKGROUND_PRIMARY,
2526
textAlign: 'left',
2627
height: "max-content",
2728
maxHeight: "30px",

src/services/ParseService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class Parse {
111111
const source = generateLiteral(column.nestedKey, newValue);
112112
return deepMerge(source, target);
113113
} catch (e) {
114-
// Just return the original value
114+
LOGGER.error(`Error parsing row to literal: ${e}`);
115+
newValue = "";
115116
}
116117
}
117118
return newValue;

0 commit comments

Comments
 (0)