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

Docgen conditions inside tables #414

Merged
merged 5 commits into from Feb 17, 2023
Merged

Conversation

Dheeraj3reddy
Copy link
Contributor

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Collaborator

@cfjedimaster cfjedimaster left a comment

Choose a reason for hiding this comment

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

Why do we not support expr(company.supportsX="TRUE")? The back end would be able to know the context from the root of expression, company.

Copy link
Member

@piyuverma piyuverma left a comment

Choose a reason for hiding this comment

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

Added comments.

src/pages/overview/document-generation-api/templatetags.md Outdated Show resolved Hide resolved
@@ -245,6 +245,32 @@ Default extension is vertical. If cell-extension construct is not provided, then

![Table gets horizontally extended as table columns are repeated](../images/horizontal-extension1.png)

### Add index based conditions
Conditionals can also be added inside tables. Condition evaluation is similar to that outside table, but we provide an additional construct
Copy link
Member

Choose a reason for hiding this comment

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

Conditional Sections are now supported inside Table and List. Use of 'expr-context' construct is mandatory to define conditionals inside tables and lists. 'expr-context'
Below is the example showing the usage of 'expr-context' and conditionals inside tables and lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use of expr-context is not mandatory for conditions inside tables as one can also use normal conditions based on fields present outside the array of objects.

Copy link
Member

Choose a reason for hiding this comment

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

got it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I raised a comment on this before, but do we need to use the expr-context expression? I don't understand why that is necessary when inside a table, I can already refer to a value that's in the array. So why do we need to provide additional context for a condition?

Copy link
Member

Choose a reason for hiding this comment

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

@Dheeraj3reddy Can you add in your thought here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider the expression expr(company.supportsX=”TRUE”). This is a condition which needs to be evaluated separately for each company i.e., each row in the final output has a different output based on its supportsX field. As per jsonata, the expression company.supportsX=”TRUE” cannot be evaluated directly as left-hand side of equation is an array of objects [“TRUE”,”FALSE”,”TRUE”] and right-hand side is a normal string. This is different from normal text tags being used inside table (like company.name as in those we don’t need any comparison as such, we just get an array result from jsonata [“ABC”,”DEF”,”XYZ”] and populate the table based on that. The key reason for conditions requiring extra context is that jsonata does not support comparison (operators like =, !=, >, <, …) between an array of objects and normal string.

src/pages/overview/document-generation-api/templatetags.md Outdated Show resolved Hide resolved
src/pages/overview/document-generation-api/templatetags.md Outdated Show resolved Hide resolved
@Dheeraj3reddy
Copy link
Contributor Author

Why do we not support expr(company.supportsX="TRUE")? The back end would be able to know the context from the root of expression, company.

Knowing context from the expression can become complicated. For that we need to parse the expressions using jsonata library. This might look simple in this case, but since jsonata supports complicated expressions also, parsing the expression to know context becomes difficult in such cases.

@Dheeraj3reddy Dheeraj3reddy merged commit 3fb612d into develop Feb 17, 2023
1 check passed
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.

None yet

5 participants