Skip to content

Commit 9020ee0

Browse files
committed
fix(graph): fixed graph + cell parsing
1 parent ed3cfd9 commit 9020ee0

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/components/sidebars/graph.sidebar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const GraphSidebar = () => {
1818

1919
const [graphCellId, setGraphCellId] = useState<CellId>(graph.cells[0]?.id);
2020

21+
useEffect(() => {
22+
setGraphCellId(graph.cells[0]?.id);
23+
}, [graph.cells]);
24+
2125
useEffect(() => {
2226
document.getElementById(GRAPH_RENDERER_ID).innerHTML = "";
2327

src/components/spreadsheet/spreadsheet.utils.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,23 @@ export namespace SpreadsheetUtils {
179179
};
180180

181181
export const tryGetFormulaFromCellValue = (input: string) => {
182-
if (!isNaN(Number(input)) && input.trim() !== "") {
182+
if (input.trim() === "") {
183+
return "";
184+
}
185+
186+
if (input.trim().startsWith("=")) {
187+
return input.trim();
188+
}
189+
190+
if (!isNaN(Number(input))) {
183191
return `= ${input.trim()}`;
184192
}
185193

186-
return input.trim();
194+
if (["TRUE", "FALSE"].includes(input.trim().toUpperCase())) {
195+
return `= ${input.trim().toUpperCase()}`;
196+
}
197+
198+
return `= "${input.trim()}"`;
187199
};
188200

189201
export const getValueText = (value: Value) => {

src/hooks/useGraph.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const GraphProvider = ({ children }: { children: ReactNode }) => {
3535
for (const cellId of spreadsheet.cells.usedCells) {
3636
const value =
3737
spreadsheet.history.history.get(cellId)?.[stepper.step];
38+
3839
if (!value || value.type !== ValueType.Graph) continue;
3940
graphCells.push({
4041
id: cellId,
@@ -43,7 +44,11 @@ export const GraphProvider = ({ children }: { children: ReactNode }) => {
4344
}
4445

4546
setCells(graphCells);
46-
}, [spreadsheet.cells.usedCells]);
47+
}, [
48+
spreadsheet.cells.usedCells,
49+
spreadsheet.history.history,
50+
stepper.step,
51+
]);
4752

4853
const values = {
4954
cells,

0 commit comments

Comments
 (0)