Skip to content
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

[REM] merge: remove useless topLeft attribute from Merge interface #4171

Closed
wants to merge 1 commit into from

Conversation

Rachico
Copy link

@Rachico Rachico commented May 6, 2024

Description:

merge: remove useless topLeft attribute from Merge interface.

Context

The "topLeft" attribute in the Merge interface was used as a shortcut to get the top left position of the merge zone. However, this was creating redundant code.

Task: 3912050

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 May 6, 2024

@Rachico Rachico force-pushed the master-remove-merge-topLeft-attribute-mera branch from ede3e62 to fd378a5 Compare May 6, 2024 13:51
Copy link
Collaborator

@VincentSchippefilt VincentSchippefilt left a comment

Choose a reason for hiding this comment

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

small nit picking, otherwise all good. Thanks

Comment on lines 263 to 264
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
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
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
col: mergeZone!.left,
row: mergeZone!.top,

No need to re-cast into HeaderIndex, you can tell typescript it has to have a value with !

Copy link
Collaborator

Choose a reason for hiding this comment

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

History has shown us that each time we introduce a !, a future bug is also introduce. ! is a way to tell typescript to have truth in you. It could be correct now, but could become incorrect in the future and we will not notice it. The right way to handle this is to check that mergeZone is defined, and you did it correctly. So, simply remove the cast and optional:

col: mergeZone.left,
row: mergeZone.top,

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that ! can be used in tests

Comment on lines 263 to 264
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general rule we should avoid casting unless there is no other choice.

An if(mergeZone) just above instead of the if(this.isInMerge) would fix that.

Note that this wasn't needed because we had an ! before, which is something we should also avoid

Comment on lines 260 to 265
const mergeZone = this.getMerge(position);
return {
sheetId: position.sheetId,
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
};
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
const mergeZone = this.getMerge(position);
return {
sheetId: position.sheetId,
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
};
const mergeZone = this.getMerge(position);
return mergeZone ? {
sheetId: position.sheetId,
col: mergeZone.left,
row: mergeZone.top
} : position;

@Rachico Rachico force-pushed the master-remove-merge-topLeft-attribute-mera branch from fd378a5 to 03ad25f Compare May 6, 2024 14:11
Comment on lines 260 to 262
sheetId: position.sheetId,
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
Copy link
Collaborator

Choose a reason for hiding this comment

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

casting is useless here (and should always be avoided when possible).

Suggested change
sheetId: position.sheetId,
col: mergeZone?.left as HeaderIndex,
row: mergeZone?.top as HeaderIndex,
sheetId: position.sheetId,
col: mergeZone.left,
row: mergeZone.top,

Comment on lines 489 to 490
const mergeZone = getMerges(model)[1];
expect({ col: mergeZone.left, row: mergeZone.top }).toEqual(toCartesian("A2"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check the entire merge and not only the first one

Suggested change
const mergeZone = getMerges(model)[1];
expect({ col: mergeZone.left, row: mergeZone.top }).toEqual(toCartesian("A2"));
expect(getMerges(model)).toEqual([toZone("A2:B2")]);

Copy link
Author

Choose a reason for hiding this comment

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

@LucasLefevre it's not a list, it's an object with the ids of merges as keys
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok,
then you can still check the entire merge

expect(mergeZone).toEqual(toZone("A2:B2"));

@Rachico Rachico force-pushed the master-remove-merge-topLeft-attribute-mera branch 2 times, most recently from 92459af to 525b201 Compare May 7, 2024 08:12
The "topLeft" attribute in the Merge interface was used as a shortcut to get the top left position of the merge zone. However, this was creating redundant code.

Task: 3912050
@Rachico Rachico force-pushed the master-remove-merge-topLeft-attribute-mera branch from 525b201 to 0b2683f Compare May 8, 2024 14:38
@rrahir
Copy link
Collaborator

rrahir commented May 15, 2024

@robodoo r+

robodoo pushed a commit that referenced this pull request May 15, 2024
The "topLeft" attribute in the Merge interface was used as a shortcut to get the top left position of the merge zone. However, this was creating redundant code.

closes #4171

Task: 3912050
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
@robodoo robodoo closed this May 15, 2024
@robodoo robodoo added the 17.3 label May 15, 2024
@fw-bot fw-bot deleted the master-remove-merge-topLeft-attribute-mera branch May 29, 2024 13:46
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.

None yet

7 participants