From dbd59b770fcb3cdca67fa4acd52440c18bca6520 Mon Sep 17 00:00:00 2001 From: BALURAM1226 Date: Sun, 11 Feb 2024 14:27:27 +0530 Subject: [PATCH 1/6] Issue #338 : Added getEvaluatedData prop for expose the result of the formula --- src/Spreadsheet.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index 6fa224df..effdcd42 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -119,6 +119,8 @@ export type Props = { nextCell: null | CellType, coords: null | Point.Point ) => void; + /** Callback called when the Spreadsheet's data changes and get realtime evaluated data. */ + getEvaluatedData : (data: Matrix.Matrix) => void; }; /** @@ -146,6 +148,7 @@ const Spreadsheet = ( onActivate = () => {}, onBlur = () => {}, onCellCommit = () => {}, + getEvaluatedData = () => {}, } = props; type State = Types.StoreState; @@ -242,6 +245,17 @@ const Spreadsheet = ( prevDataRef.current = state.model.data; }, [state.model.data, onChange, props.data]); + const prevEvaluatedDataRef = React.useRef>( + state.model.evaluatedData + ); + + React.useEffect(() => { + if (state?.model?.evaluatedData !== prevEvaluatedDataRef?.current) { + getEvaluatedData(state?.model?.evaluatedData); + } + prevEvaluatedDataRef.current = state.model.evaluatedData; + }, [state?.model?.evaluatedData, getEvaluatedData]); + // Listen to selection changes const prevSelectedRef = React.useRef(state.selected); React.useEffect(() => { From d6a97dbfbcceadae6ce6e6734ad2969553bc596d Mon Sep 17 00:00:00 2001 From: Kumavat Baluram <72209634+BALURAM1226@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:11:37 +0530 Subject: [PATCH 2/6] Update src/Spreadsheet.tsx Co-authored-by: Iddan Aaronsohn --- src/Spreadsheet.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index effdcd42..36d16299 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -119,8 +119,8 @@ export type Props = { nextCell: null | CellType, coords: null | Point.Point ) => void; - /** Callback called when the Spreadsheet's data changes and get realtime evaluated data. */ - getEvaluatedData : (data: Matrix.Matrix) => void; + /** Callback called when the Spreadsheet's evaluated data changes. */ + onEvaluatedDataChange : (data: Matrix.Matrix) => void; }; /** From 7741d38c12c4dd633b42429b9962827e665d6db1 Mon Sep 17 00:00:00 2001 From: Kumavat Baluram <72209634+BALURAM1226@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:16:41 +0530 Subject: [PATCH 3/6] Update Spreadsheet.tsx Rename prop function name getEvaluatedData to onEvaluatedDataChange --- src/Spreadsheet.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index 36d16299..7ce3a581 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -148,7 +148,7 @@ const Spreadsheet = ( onActivate = () => {}, onBlur = () => {}, onCellCommit = () => {}, - getEvaluatedData = () => {}, + onEvaluatedDataChange = () => {}, } = props; type State = Types.StoreState; @@ -251,10 +251,10 @@ const Spreadsheet = ( React.useEffect(() => { if (state?.model?.evaluatedData !== prevEvaluatedDataRef?.current) { - getEvaluatedData(state?.model?.evaluatedData); + onEvaluatedDataChange(state?.model?.evaluatedData); } prevEvaluatedDataRef.current = state.model.evaluatedData; - }, [state?.model?.evaluatedData, getEvaluatedData]); + }, [state?.model?.evaluatedData, onEvaluatedDataChange]); // Listen to selection changes const prevSelectedRef = React.useRef(state.selected); From 14d6a8f52a31c3446d0cb446cc6436b324bc7fc2 Mon Sep 17 00:00:00 2001 From: Kumavat Baluram <72209634+BALURAM1226@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:43:40 +0530 Subject: [PATCH 4/6] Update Spreadsheet.tsx Adjust space of new changed code --- src/Spreadsheet.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index 7ce3a581..dd7c3dd4 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -120,7 +120,7 @@ export type Props = { coords: null | Point.Point ) => void; /** Callback called when the Spreadsheet's evaluated data changes. */ - onEvaluatedDataChange : (data: Matrix.Matrix) => void; + onEvaluatedDataChange: (data: Matrix.Matrix) => void; }; /** @@ -245,16 +245,15 @@ const Spreadsheet = ( prevDataRef.current = state.model.data; }, [state.model.data, onChange, props.data]); - const prevEvaluatedDataRef = React.useRef>( - state.model.evaluatedData - ); + const prevEvaluatedDataRef = React.useRef>(state.model.evaluatedData); + React.useEffect(() => { + if (state?.model?.evaluatedData !== prevEvaluatedDataRef?.current) { + onEvaluatedDataChange(state?.model?.evaluatedData); + } - React.useEffect(() => { - if (state?.model?.evaluatedData !== prevEvaluatedDataRef?.current) { - onEvaluatedDataChange(state?.model?.evaluatedData); - } + prevEvaluatedDataRef.current = state.model.evaluatedData; - }, [state?.model?.evaluatedData, onEvaluatedDataChange]); + }, [state?.model?.evaluatedData, onEvaluatedDataChange]); // Listen to selection changes const prevSelectedRef = React.useRef(state.selected); From 79a5ea787034028a6d4dfb3fff3e5186c8c7186a Mon Sep 17 00:00:00 2001 From: BALURAM1226 Date: Thu, 22 Feb 2024 20:58:05 +0530 Subject: [PATCH 5/6] bugfix : code style issue --- src/Spreadsheet.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index dd7c3dd4..d42430b5 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -120,7 +120,7 @@ export type Props = { coords: null | Point.Point ) => void; /** Callback called when the Spreadsheet's evaluated data changes. */ - onEvaluatedDataChange: (data: Matrix.Matrix) => void; + onEvaluatedDataChange: (data: Matrix.Matrix) => void; }; /** @@ -245,13 +245,14 @@ const Spreadsheet = ( prevDataRef.current = state.model.data; }, [state.model.data, onChange, props.data]); - const prevEvaluatedDataRef = React.useRef>(state.model.evaluatedData); + const prevEvaluatedDataRef = React.useRef>( + state.model.evaluatedData + ); React.useEffect(() => { if (state?.model?.evaluatedData !== prevEvaluatedDataRef?.current) { onEvaluatedDataChange(state?.model?.evaluatedData); } - prevEvaluatedDataRef.current = state.model.evaluatedData; }, [state?.model?.evaluatedData, onEvaluatedDataChange]); From 45f17b0fbf42b13978e92ef0f2cc259245b33550 Mon Sep 17 00:00:00 2001 From: BALURAM1226 Date: Wed, 6 Mar 2024 09:06:48 +0530 Subject: [PATCH 6/6] bugfix : add missing type in Spreadsheet.test.tsx --- src/Spreadsheet.test.tsx | 1 + src/Spreadsheet.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Spreadsheet.test.tsx b/src/Spreadsheet.test.tsx index 9ba5c98f..42051f73 100644 --- a/src/Spreadsheet.test.tsx +++ b/src/Spreadsheet.test.tsx @@ -97,6 +97,7 @@ const EXAMPLE_DATA = createEmptyMatrix(ROWS, COLUMNS); const EXAMPLE_PROPS: Props = { data: EXAMPLE_DATA, onChange: jest.fn(), + onEvaluatedDataChange: jest.fn(), }; const EXAMPLE_VALUE: Value = "EXAMPLE_VALUE"; const EXAMPLE_CELL: CellType = { value: EXAMPLE_VALUE }; diff --git a/src/Spreadsheet.tsx b/src/Spreadsheet.tsx index d42430b5..70d0b3a9 100644 --- a/src/Spreadsheet.tsx +++ b/src/Spreadsheet.tsx @@ -120,7 +120,7 @@ export type Props = { coords: null | Point.Point ) => void; /** Callback called when the Spreadsheet's evaluated data changes. */ - onEvaluatedDataChange: (data: Matrix.Matrix) => void; + onEvaluatedDataChange?: (data: Matrix.Matrix) => void; }; /**