-
Notifications
You must be signed in to change notification settings - Fork 60
[IMP] evaluatedCell: add origin #6531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
970c7cc
to
deb2f52
Compare
src/helpers/cells/cell_evaluation.ts
Outdated
@@ -62,7 +64,9 @@ export function createEvaluatedCell( | |||
): EvaluatedCell { | |||
const link = detectLink(functionResult.value); | |||
if (!link) { | |||
return _createEvaluatedCell(functionResult, locale, cell); | |||
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell); | |||
if (!evaluateCell.origin) evaluateCell.origin = functionResult.origin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this if
is useless. What comes out of _createEvaluatedCell
never has an origin
if (!evaluateCell.origin) evaluateCell.origin = functionResult.origin; | |
evaluateCell.origin = functionResult.origin; |
src/helpers/cells/cell_evaluation.ts
Outdated
@@ -148,6 +153,7 @@ const emptyCell = memoize(function emptyCell(format: string | undefined): EmptyC | |||
type: CellValueType.empty, | |||
isAutoSummable: true, | |||
defaultAlign: "left", | |||
origin: { sheetId: "", col: 0, row: 0 }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this since origin
is optional.
It's better to have a missing origin rather than a wrong value
// Todo discuss about correctness vs perf | ||
return EMPTY_CELL; | ||
// return { ...EMPTY_CELL, origin: position }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it without the origin for now
if (!evaluatedCell.origin) { | ||
evaluatedCell.origin = position; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternative approach to all this would be to add the origin when accessing the reference value in refFn
and range
.
It means a cell with a formula which is not returning a reference wouldn't have a .origin
(nor literal cells), but that makes (also/more?) sense.
I would only be 2 places to change instead of the 5 or more here.
deb2f52
to
af4f07c
Compare
src/helpers/cells/cell_evaluation.ts
Outdated
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell); | ||
return addOrigin(evaluateCell, functionResult.origin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if addOrigin
mutates the input, it's better if it doesn't return it. At least it's very clear that it mutates in place
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell); | |
return addOrigin(evaluateCell, functionResult.origin); | |
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell); | |
addOrigin(evaluateCell, functionResult.origin); | |
return evaluateCell; |
tests/evaluation/evaluation.test.ts
Outdated
@@ -1139,6 +1139,121 @@ describe("evaluateCells", () => { | |||
toCellPosition(sheetId, "A2") | |||
); | |||
}); | |||
|
|||
describe("origin", () => { | |||
let model, sheetId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add types. It cannot be inferred and leads to any
tests/evaluation/evaluation.test.ts
Outdated
col: 0, | ||
row: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easier to read
col: 0, | |
row: 2, | |
...toCartesian("A3") |
tests/evaluation/evaluation.test.ts
Outdated
|
||
test("on literal", () => { | ||
setCellContent(model, "A3", "5"); | ||
expect(getEvaluatedCell(model, "A3").origin).toMatchObject({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(getEvaluatedCell(model, "A3").origin).toMatchObject({ | |
expect(getEvaluatedCell(model, "A3").origin).toEqual({ |
@@ -369,7 +371,7 @@ export class Evaluator { | |||
|
|||
if (!isMatrix(formulaReturn)) { | |||
const evaluatedCell = createEvaluatedCell( | |||
nullValueToZeroValue(formulaReturn), | |||
addOrigin(nullValueToZeroValue(formulaReturn), formulaPosition), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add position to createEvaluatedCell ?
src/helpers/cells/cell_evaluation.ts
Outdated
@@ -191,3 +197,13 @@ function errorCell(value: string, message?: string): ErrorCell { | |||
defaultAlign: "center", | |||
}; | |||
} | |||
|
|||
export function addOrigin<T extends FunctionResultObject | EvaluatedCell>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed to be generic anymore ?
af4f07c
to
3f73e7d
Compare
1c7104c
to
7311a46
Compare
With this commit, evaluation result keeps track of the value origin through references. The goal it to reuse the origin value for the "See records" feature in odoo. if A1: =PIVOT.VALUE(...) A2: =A1 with this commit both A1 and A2 will have the "See records" because we can track down that the value in A2 is actually coming from A1 which contains a pivot formula. It also paves the ground if we want to implement dynamic ranges in formula `=IF(..., A1, A2) : VLOOKUP(...)` Task: 3810138
7311a46
to
8684e3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
robodoo r+
With this commit, evaluation result keeps track of the value origin through references. The goal it to reuse the origin value for the "See records" feature in odoo. if A1: =PIVOT.VALUE(...) A2: =A1 with this commit both A1 and A2 will have the "See records" because we can track down that the value in A2 is actually coming from A1 which contains a pivot formula. It also paves the ground if we want to implement dynamic ranges in formula `=IF(..., A1, A2) : VLOOKUP(...)` closes #6531 Task: 3810138 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Description:
description of this task, what is implemented and why it is implemented that way.
Task: 3810138
review checklist