-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
ede3e62
to
fd378a5
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.
small nit picking, otherwise all good. Thanks
src/plugins/core/merge.ts
Outdated
col: mergeZone?.left as HeaderIndex, | ||
row: mergeZone?.top as HeaderIndex, |
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.
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 !
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.
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,
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.
Note that !
can be used in tests
src/plugins/core/merge.ts
Outdated
col: mergeZone?.left as HeaderIndex, | ||
row: mergeZone?.top as HeaderIndex, |
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.
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
src/plugins/core/merge.ts
Outdated
const mergeZone = this.getMerge(position); | ||
return { | ||
sheetId: position.sheetId, | ||
col: mergeZone?.left as HeaderIndex, | ||
row: mergeZone?.top as HeaderIndex, | ||
}; |
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.
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; |
fd378a5
to
03ad25f
Compare
src/plugins/core/merge.ts
Outdated
sheetId: position.sheetId, | ||
col: mergeZone?.left as HeaderIndex, | ||
row: mergeZone?.top as HeaderIndex, |
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.
casting is useless here (and should always be avoided when possible).
sheetId: position.sheetId, | |
col: mergeZone?.left as HeaderIndex, | |
row: mergeZone?.top as HeaderIndex, | |
sheetId: position.sheetId, | |
col: mergeZone.left, | |
row: mergeZone.top, |
const mergeZone = getMerges(model)[1]; | ||
expect({ col: mergeZone.left, row: mergeZone.top }).toEqual(toCartesian("A2")); |
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.
Check the entire merge and not only the first one
const mergeZone = getMerges(model)[1]; | |
expect({ col: mergeZone.left, row: mergeZone.top }).toEqual(toCartesian("A2")); | |
expect(getMerges(model)).toEqual([toZone("A2:B2")]); |
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.
@LucasLefevre it's not a list, it's an object with the ids of merges as keys
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.
Ah ok,
then you can still check the entire merge
expect(mergeZone).toEqual(toZone("A2:B2"));
92459af
to
525b201
Compare
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
525b201
to
0b2683f
Compare
@robodoo r+ |
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>
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