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

FeatureInfo: Render Markdown into React components, add support for conditional rendering #669

Closed
jacobwod opened this issue Feb 11, 2021 · 2 comments
Assignees
Labels
module:client/core Core functionality (not a plugin) new feature Request for adding/changing functionality optimization
Milestone

Comments

@jacobwod
Copy link
Member

jacobwod commented Feb 11, 2021

Problem

The current implementation has two major flaws:

  1. The markdown can not contain any [tags]. This is due to the shortcode feature in FeatureInfo that basically sees everything between [ and ] as a tag. This conflicts with Markdown's Links and Images syntax.
  2. The resulting HTML is plain HTML, whereas we'd like to use MUI components on some ocassions. For example, a table should not parse into <table> but rather the MUI Table Component, to ensure correct rendering, dark mode support etc.

Suggestions

  1. I will initially remove the shortcode functionality. We could look into making something similar, but it must not conflict with Markdown syntax.
  2. I'll see if our Markdown parser can be extended to render MUI Components. A quick search gave this promising result. Update: using react-markdown makes this possible.
  3. Implement some kind of conditional rendering. It could be used e.g not to render empty fields.

Currently implemented

  • Fixed problem 1: Markdown can use all []-tags.
  • Fixed problem 2: We return React components
  • Added support for suggestion 3, see below.

Example of conditional rendering

<if {foo}>Will show if 'foo' is truthy</if>

<if {foo}=bar>Will show if 'foo' evaluates to 'bar'</if>
@jacobwod jacobwod added optimization module:client/core Core functionality (not a plugin) new feature Request for adding/changing functionality labels Feb 11, 2021
@jacobwod jacobwod self-assigned this Feb 11, 2021
@jacobwod
Copy link
Member Author

jacobwod added a commit that referenced this issue Feb 16, 2021
…hinfo Markdown, part of #669:

- I ended up with the HTML-like tags. The reason is that {} are already used by our properties, while [] are part of Markdown syntax.
- Currently <if> is the only supported condition.
- You can use it like <if {foo}>Will show if 'foo' is truthy</if>, or <if {foo}=bar>Will show if 'foo' evaluates to 'bar'</if>.
@jacobwod jacobwod changed the title Make Markdown create MUI components when parsed in FeatureInfo FeatureInfo: Render Markdown into React components, add support for conditional rendering Feb 16, 2021
@jacobwod
Copy link
Member Author

This is almost done, though it's been a while since I looked into this last time. AFAIR, everything works as expected, except the new DocumentHandler links, which need to be sent as Components.

For the purpose of documentation, can @sweco-seqtob show me an example of code for Infoclick box (in admin) that is needed in order to render a DocumentHandler link? (I finally got DocumentHandler running this week so I can set it up accordingly now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:client/core Core functionality (not a plugin) new feature Request for adding/changing functionality optimization
Projects
None yet
Development

No branches or pull requests

2 participants