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

Adds conditional display on pages #4404

Merged
merged 31 commits into from
Mar 30, 2022
Merged

Conversation

grafitto
Copy link
Contributor

fixes #4231

PR checklist:

  • Update READ.me ?
  • Update API documentation ?

QA checklist:

  • Smoke test the functionality described in the issue
  • Test for side effects
  • UI responsiveness
  • Cross browser testing
  • Code review

@konzz
Copy link
Member

konzz commented Mar 15, 2022

EntitySection component

Sometimes you want to display a section of the entity based on whether a given condition is met.

Examples:

You want to display the name of a person if they are older than 18 years old.
A simple implementation would look like this:

<EntitySection show-if='{"metadata.age": { "$gt": 18 }}'>
  <EntityData label-of="name" />: <EntityData value-of="name" />
</Entitysection>

you want to only show the name of a person if the name exists in the entity metadata

<EntitySection show-if='{"metadata.name": { "$exists": true }}'>
  <EntityData label-of="name" />: <EntityData value-of="name" />
</Entitysection>

You want to show the name of a person if it matches value John in the entity metadata

<EntitySection show-if='{"metadata.name": "John"}'>
  <EntityData label-of="name" />: <EntityData value-of="name" />
</Entitysection>

Inherited properties:

<EntitySection show-if='{"metadata.inherited_text": { "$in": ["something"] }}'>
  <EntityData label-of="name" />: <EntityData value-of="name" />
</Entitysection>

Note: show-if value is a JSON string and the query should follow query string specified by sift

The metadata is unwrapped into a JSON object with keys as the property names and values as the property values.

metadata: {
  name: "John",
  age: 18
}

// Note that if the metadata property name has spaces, they are replaced with underscores and uppercase letters are converted to lowercase letters
// Eg: a metadata property name of "First Name" will be converted to "first_name" therefore:
metadata: {
  "first_name": "John",
  age: 18
}

Some values takes the following format, this includes inherited values and values like multiselect:

metadata: {
    inherited_text: ['text value'], //Can contain more than one values depending on entities inherited from
    inherited_multiselect: ['option 1', 'option 2'],  
    inherited_geolocation: [{ lat: 23, lon: 12}]
}

Note that some values like Date added and Date modified are replaced with creationDate and editDate respectively and also are presented as timestamps. So, to use them, you can do this:

<EntitySection show-if='{"editDate": 12434564323 }'>
  <EntityData label-of="name" />: <EntityData value-of="name" /> // This only shows if the entity
</Entitysection>

@txau
Copy link
Collaborator

txau commented Mar 15, 2022

@konzz the documentation looks neat. I would only add as a reference more complex example, ie. based on the value of an inheritance with multiple inherited values.

@konzz
Copy link
Member

konzz commented Mar 15, 2022

Thanks, it was @grafitto driving, he has the merit here 🥇

@grafitto grafitto force-pushed the 4231-conditional-display-on-pages branch from f3b6dfa to 8c2ee6e Compare March 17, 2022 08:23
@grafitto grafitto marked this pull request as ready for review March 21, 2022 08:28
@grafitto grafitto force-pushed the 4231-conditional-display-on-pages branch from 8c2ee6e to 0cc6d3f Compare March 21, 2022 11:32
@grafitto grafitto marked this pull request as draft March 21, 2022 12:38
@konzz konzz marked this pull request as ready for review March 30, 2022 14:08
@konzz konzz merged commit 660e9cd into development Mar 30, 2022
@konzz konzz deleted the 4231-conditional-display-on-pages branch March 30, 2022 14:23
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.

Be able to condition page templates to a particular value of the entity (8 pts)
3 participants