-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feature/#21 calculate y coordinate on a given table #42
Feature/#21 calculate y coordinate on a given table #42
Conversation
@@ -73,3 +79,75 @@ export const calculateRelationXCoordinate = ( | |||
xOrigin: calculateRelationXCoordinateOrigin(tableOrigin, tableDestination), | |||
xDestination: calculateRelationXCoordinateEnd(tableOrigin, tableDestination), | |||
}); | |||
|
|||
const seekField = ( |
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.
Since SeekResult
is only going to be used inside this function, we can define the interface just before the SeekField
declaration instead of the vm, why this approach? We place in the vms entities that we expect that are going to be used in several files, in this case is rare that this interface could be used outside this file.
+ interface seekResult {
+ found: boolean;
+ parentCollapsed: boolean;
+ YPosition: number;
+ }
const seekField = (
Note you can export in case is needed
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.
It's fixed
src/pods/canvas/canvas.vm.ts
Outdated
yDestination: number; | ||
} | ||
|
||
export interface seekResult { |
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.
We can remove seekResult from this file
one thing to take into account interfaces should be always uppercase
- export interface seekResult {
+ export interface SeekResult {
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.
It's fixed
src/pods/canvas/canvas.vm.ts
Outdated
@@ -47,3 +47,14 @@ export interface XRelationCoords { | |||
xOrigin: number; | |||
xDestination: number; | |||
} | |||
|
|||
export interface YRelationCoords { |
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 we can do the same with this interface as with SeekResult
, but we will need to export this interface
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
) { | ||
const result = seekField(fieldId, newYPosition, field.children); | ||
found = result.found; | ||
newYPosition = parentCollapsed ? newYPosition : result.YPosition; |
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 a comment:
// If the current node was already collapsed, ignore the child YPosition offset (Opa rulez !)
newYPosition = parentCollapsed ? newYPosition : result.YPosition;
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
for (let i = 0; i < fields.length && !found; i++) { | ||
const field = fields[i]; | ||
if (field.id === fieldId) { | ||
found = true; |
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.
Since we are just returning a value we can get rid of
- found = true:
And pass found: true
in the object it self
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
found, | ||
parentCollapsed, | ||
YPosition: newYPosition, | ||
}; |
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.
We could create a helper function
const buildFieldFoundResponse = (parentCollapsed: boolean, YPosition: number) => ({
found: true,
parentCollapsed,
YPosition
});
Then we can replace and simplify:
if (field.id === fieldId) {
- found = true;
-
- return {
- found,
- parentCollapsed,
- YPosition: newYPosition,
- };
+ return buildFieldFoundResponse(parentCollapsed, YNewPosition);
}
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
} else { | ||
if (!parentCollapsed) { | ||
newYPosition += ROW_HEIGHT; | ||
} |
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 reduce the cyclomatic complexity (Hadouken)
Let's create a helped method:
const addFieldRowHeight = (YPosition : number, parentCollapsed : boolean) : number => (!parentColapsed) newYPosition + ROW_HEIGHT : newYPosition;
Then in this code:
} else {
+ newYPosition = addFieldRowHeight(newYPosition, parentCollapsed);
- if (!parentCollapsed) {
- newYPosition += ROW_HEIGHT;
- }
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
|
||
if (!parentCollapsed && field.isCollapsed) { | ||
parentCollapsed = true; | ||
} |
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.
Same thing her we could create a helper
const isParentCollapsedOrCurrentNodeCollapsed = (parentCollapsed : boolean, currentFieldCollapsed : boolean) => (!parentCollapsed && field.isCollapsed) true : parentCollapsed;
+ const parentCollapsed = isParentOrCurrentNodeCollapsed(parentCollapsed, field.isCollapsed);
- if (!parentCollapsed && field.isCollapsed) {
- parentCollapsed = true;
- }
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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
field.type === 'object' && | ||
field.children && | ||
field.children.length > 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.
This if statement is complex, we can wrap it into a helper function, something like:
const doesFieldContainsChildren = (field: Field) => (field.type === 'object' && field.children && field.children.length > 0);
Then the if statement gets simplified and just by reading the name of the function we know what it does:
if (
+ doesFieldContainsChildren(field);
- field.type === 'object' &&
- field.children &&
- field.children.length > 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.
It's fixed
src/pods/canvas/canvas.business.ts
Outdated
found, | ||
parentCollapsed, | ||
YPosition: newYPosition, | ||
}; |
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.
Here we could make use of buildFieldFoundResponse
that we created before
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.
It's fixed
No description provided.