Skip to content

feat(markdown-docx): add optional transformer - #397#441

Merged
algomaster99 merged 5 commits intoalgoo-ooxmlfrom
k-kumar-01/i397/optional-transformer
Aug 17, 2021
Merged

feat(markdown-docx): add optional transformer - #397#441
algomaster99 merged 5 commits intoalgoo-ooxmlfrom
k-kumar-01/i397/optional-transformer

Conversation

@K-Kumar-01
Copy link
Copy Markdown
Collaborator

Signed-off-by: k-kumar-01 kushalkumargupta4@gmail.com

Add the logic to transform Optional nodes from CiceroMark<->OOXML.

Changes

  • transformation logic:OOXML<->CiceroMark
  • tests for optional
  • update tests for other(xml changes in variable and clause)

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to master from fork:branchname

transformation logic:OOXML<->CiceroMark
tests for optional
update tests for other(xml changes in variable and clause)

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01 K-Kumar-01 added this to the Implement optional milestone Aug 10, 2021
Copy link
Copy Markdown
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

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

I'm finding the code hard to follow, as you add more special cases. In general terms I would structure the code as a transformation from treeA -> treeB with a switch statement to handle different nodes in treeA, converting them to nodes in treeB. In particular I found the part where you compare lengths of arrays to hard coded values confusing.

</w:rPr>
<w:alias w:val="Shipper1 | org.accordproject.organization.Organization"/>
<w:tag w:val="shipper"/>
<w:tag w:val="org.accordproject.ciceromark.Variable----shipper"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What are tag and alias used for? Could we make them consistent. E.g.
org.acme.Thing/name ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

w:alias: the name which is displayed by word on hovering on content control.
w:tag: Bind the office JS API handles for elements with similar tags.

Could we make them consistent. E.g.org.acme.Thing/name ?

I do not understand what exactly you mean here. I have introduced the first thing to distinguish the type of content control as we discussed in the meeting.

@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

K-Kumar-01 commented Aug 10, 2021

In general terms I would structure the code as a transformation from treeA -> treeB with a switch statement to handle different nodes in treeA, converting them to nodes in treeB.

Actually, this is what I am doing but I was handling it with if statements.

In particular I found the part where you compare lengths of arrays to hard coded values confusing.

I agree here but this is done to insert the sibling children of a node under the same parent.

EDIT:
Screenshot from 2021-08-10 21-17-55
Screenshot from 2021-08-10 21-19-00

@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@algomaster99
Requesting your reviews also.

@K-Kumar-01 K-Kumar-01 requested a review from dselman August 10, 2021 18:21
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@dselman @algomaster99
I have completed the transformation for the formula in another branch. Since the branch is extension of this one, we can merge that once this PR gets merged.

Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

First iteration of review done. Look at the comments.

Also, add a test case when hasSome is false. You will need to see how nodes behave in that case. Currently, you have made nodes = whenSome.

Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
transform both whenSome and whenNone nodes
add tests for hasSome:false
update the xml

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

K-Kumar-01 commented Aug 12, 2021

@algomaster99
I have incorporated the changes to transform hasSome:false condition in optional.
Let me know if there are any other changes required.

EDIT: The conditions may seem to be a bit terrifying 😅 but it was the only implementation I can think of.

Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Dropped some comments which I think you really need to look into. Please try to incorporate them. I will try to take out some time and refactor your code a bit over the weekend.

Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/constants.js
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/rules.js
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
…iables, add generic method for nesting

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@algomaster99
Made the desired changes.

@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@algomaster99 @dselman
Requesting your reviews.

Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Left some comments. There are some things I don't understand so I might give more reviews on this PR in future.

Comment thread packages/markdown-docx/src/ToOOXMLVisitor/rules.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment on lines +55 to +58
// Contains the tags for optional or conditional nodes.
// Optional/conditional themselves can act contain multiple inline nodes.
// However, they are not block elements and are present inside
// paragraph or clause nodes so an extra array is needed to store their info.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@K-Kumar-01 You forgot to remove this array.

Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js Outdated
Comment thread packages/markdown-docx/src/ToOOXMLVisitor/index.js
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
Comment thread packages/markdown-docx/src/ToCiceroMarkVisitor.js Outdated
Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@algomaster99
Made the changes. Let me know if there are any other changes required.


/**
* Inserts Baskerville Old Face font family OOXML tag.
* Inserts Baskerville Old Face font family OOXML tag to distinguish nodes of whenNone/whenFalse
Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 Aug 17, 2021

Choose a reason for hiding this comment

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

Try to put yourself in a person's shoe who is not that familiar with this code.

They try to interpret this function and they found out that it has something to do with optional or condition nodes. They look at the CiceroMark properties and see that in fact, whenSome and whenNone exist. However, they would definitely question "what are whenTrue and whenFalse for?" Given then context, they would deduce that whenTrue and whenFalse are also attributes in the CiceroMark which is false!

In fact this is true wherever you have metioned the above terms so you need to rectify that. Probably a better wording would be:

Inserts a different fontface so that the hidden contents can be distinguished. There can be two types of hidden content -
1) when `hasSome` is true, the content inside `whenNone` is hidden.
2) when `hasSome` is false, the content inside `whenSome` is hidden.

I know this takes time and it may not be commensurate for the time you spend thinking over it. But I can promise you that you only will forget the same code you have written 4 months later given you don't work on this project for that long.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99 Actually, this is not quite the right description. the font family is for else condition always. It does not matter whether they are hidden or visible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If they are visible, then we do not want to change the font.

Copy link
Copy Markdown
Collaborator Author

@K-Kumar-01 K-Kumar-01 Aug 17, 2021

Choose a reason for hiding this comment

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

@algomaster99
Does this sound right?

 Inserts a different font family so that the conditional/optional content(else condition) can be distinguished. They can be of following types:-
 1) `whenNone` nodes for optional(to be distinguished from `whenSome`)
 2) `whenFalse` nodes for conditional(to be distinguished from `whenTrue`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay, so the font face has been introduced to handle conditional as well? I thought you would make a separate PR for that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
It will automatically deal with that when I make the PR for conditional. Optional and Conditional are identically same. Just some node keys changing.

Copy link
Copy Markdown
Collaborator Author

@K-Kumar-01 K-Kumar-01 Aug 17, 2021

Choose a reason for hiding this comment

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

@algomaster99
I will update the JSDOC for conditional in that PR. Currently, I will only make it only for optional. Does it sound fine?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good. You could have applied the same logic for the variables too but that's okay. We can merge this one.

Anyway, just try to focus on one feature at a time. It causes confusion otherwise.

@algomaster99
Copy link
Copy Markdown
Contributor

@K-Kumar-01 Shall I proceed for merge if all tests are passing?

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@algomaster99 Sure
was pushing the updated JSDOC comment for optional for now.
WIll later change it for both conditional and optional as mentioned.

@algomaster99 algomaster99 merged commit de694a2 into algoo-ooxml Aug 17, 2021
@algomaster99 algomaster99 deleted the k-kumar-01/i397/optional-transformer branch August 17, 2021 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants