Skip to content

[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

Closed
wants to merge 1 commit into from

Conversation

fdamhaut
Copy link
Contributor

@fdamhaut fdamhaut commented Jun 3, 2025

Description:

description of this task, what is implemented and why it is implemented that way.

Task: 3810138

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Jun 3, 2025

Pull request status dashboard

@fdamhaut fdamhaut force-pushed the master-add-origin-to-evaluatedCell-flda branch 5 times, most recently from 970c7cc to deb2f52 Compare June 5, 2025 07:24
@@ -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;
Copy link
Collaborator

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

Suggested change
if (!evaluateCell.origin) evaluateCell.origin = functionResult.origin;
evaluateCell.origin = functionResult.origin;

@@ -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 },
Copy link
Collaborator

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

Comment on lines 334 to 336
// Todo discuss about correctness vs perf
return EMPTY_CELL;
// return { ...EMPTY_CELL, origin: position };
Copy link
Collaborator

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

Comment on lines 512 to 513
if (!evaluatedCell.origin) {
evaluatedCell.origin = position;
Copy link
Collaborator

@LucasLefevre LucasLefevre Jun 17, 2025

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.

@fdamhaut fdamhaut force-pushed the master-add-origin-to-evaluatedCell-flda branch from deb2f52 to af4f07c Compare June 23, 2025 12:23
Comment on lines 67 to 68
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell);
return addOrigin(evaluateCell, functionResult.origin);
Copy link
Collaborator

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

Suggested change
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell);
return addOrigin(evaluateCell, functionResult.origin);
const evaluateCell = _createEvaluatedCell(functionResult, locale, cell);
addOrigin(evaluateCell, functionResult.origin);
return evaluateCell;

@@ -1139,6 +1139,121 @@ describe("evaluateCells", () => {
toCellPosition(sheetId, "A2")
);
});

describe("origin", () => {
let model, sheetId;
Copy link
Collaborator

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

Comment on lines 1154 to 1155
col: 0,
row: 2,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easier to read

Suggested change
col: 0,
row: 2,
...toCartesian("A3")


test("on literal", () => {
setCellContent(model, "A3", "5");
expect(getEvaluatedCell(model, "A3").origin).toMatchObject({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add position to createEvaluatedCell ?

@@ -191,3 +197,13 @@ function errorCell(value: string, message?: string): ErrorCell {
defaultAlign: "center",
};
}

export function addOrigin<T extends FunctionResultObject | EvaluatedCell>(
Copy link
Collaborator

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 ?

@fdamhaut fdamhaut force-pushed the master-add-origin-to-evaluatedCell-flda branch from af4f07c to 3f73e7d Compare June 24, 2025 09:17
@fdamhaut fdamhaut force-pushed the master-add-origin-to-evaluatedCell-flda branch 2 times, most recently from 1c7104c to 7311a46 Compare July 11, 2025 08:29
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
@LucasLefevre LucasLefevre force-pushed the master-add-origin-to-evaluatedCell-flda branch from 7311a46 to 8684e3c Compare July 11, 2025 12:11
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

robodoo r+

robodoo pushed a commit that referenced this pull request Jul 11, 2025
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>
@robodoo robodoo added the 18.5 label Jul 11, 2025
@robodoo robodoo closed this Jul 11, 2025
@fw-bot fw-bot deleted the master-add-origin-to-evaluatedCell-flda branch July 18, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants