huridocs / uwazi

Uwazi is a web-based, open-source solution for building and sharing document collections
http://www.uwazi.io
MIT License
242 stars 80 forks source link

Entity id inside the url of the Dataset and Library components is inconsistent #6836

Closed meegido closed 5 months ago

meegido commented 5 months ago

Describe the bug The charts and library-embedded cards on an entity page do not always show the data on all entity pages. This happens when the shared is interpolated with special characters (values:!(%27sharedId%27)) and we do it in the Dataset and Library-embed ({list}) components.

To Reproduce Steps to reproduce the behavior:

  1. Create an entity page.
  2. Add a Dataset and a Library-embedded cards component.
  3. Interpolate the entity ID on their URLs: (values:!(${entity.sharedId}))
  4. The error is that the ones with the special characters do not display the relevant information, the charts keep loading, and the cards displayed are from another template for whatever reason.

Expected behavior There is consistency in presenting the information on all entity pages when using the entity id for showing charts.

Screenshots Sometimes this error appears in the browser console.

Screenshot 2024-05-29 at 17 48 17

Device (please select all that apply)

Browser What browser where you using All.

Additional context Add any other context about the problem here.

RafaPolit commented 5 months ago

This is a condition where, when the SharedID starts with a number, the Q encoder puts quotes in front of it to signal it's a string.

Some components may not be taking this into account, the {list} component could be one of them. The way to reproduce this requires values that start with a number which cannot be ensured, so maybe this needs some manual editing of SharedIDs.

The priority reflects not the level of criticality for the bug, but deadlines around a project that is failing due to this problem.

mfacar commented 5 months ago

Given the value is being interpolated, the responsibility of embedding the sharedId is of getPageAssets, which replaces the expression directly with the computed data, after that markdownDatasets tries to decode to fetch the search and the error is produced.

The simpler and fastest solution is to wrap the expression into apostrophes in the URL of the dataset as (values:!('${entity.sharedId}')) in the markdown of the page.

The alternative in code, which I think is not correct, can be to wrap the result of the expression entity.sharedId into apostrophes at the moment of parsing the markdown, for me the first option is safer than the second because we can't anticipate the intended use of that expression in the markdown of a page.

@RafaPolit @meegido

meegido commented 5 months ago

The simpler solution fix works very well 👏 As a side note, it would be great to document it so you don't need to remember each time.

Thank you so much @mfacar!