-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds support for jsonata based references in static.json (#47)
### Problem After creating a few example search portals, it's become obvious that some of the data is not in ideal structures for programmatic output and/or it is relying on application-specific code to render reliably. When obtaining property values based on fields in a `static.json` file, this generator (and most others) use JSONPath. This works for well-structured data that has been made with the generator's usage in mind, but starts to encounter issues in existing (complex) data structures. As an example, [the Convergance Graph in this result](https://from-static-labs.github.io/aps-rpl/results?subject=globus%3A%2F%2Fbb8d048a-2cad-4029-a9c7-671ec5d1f84d%2Fportal%2Freports%2Fhome%2Frpl%2Fexperiments%2FColorPicker_26_155_177_2023-04-20%2Fresults) does not render based on [application-specific logic that replaces the hostname on files](https://github.com/globus-gladier/rpl-portal/blob/136f846fd53ac21e85a7089f6aae3620c9f3ca4f/rpl_portal/fields.py#L28-L35) ([current portal for comparison](https://acdc.alcf.anl.gov/rpl/detail/globus%253A%252F%252Fbb8d048a-2cad-4029-a9c7-671ec5d1f84d%252Fportal%252Freports%252Fhome%252Frpl%252Fexperiments%252FColorPicker_26_155_177_2023-04-20%252Fresults/)). In addition to the incorrect host, I was using a very naive lookup for the Convergence Graph based on what the data seemed to imply: ```json { "label": "Convergence Graph", "property": "entries[0].content.files[2].url", "type": "image" } ``` The third result appeared to always be the correct reference, but in reality, there are no guarantees. ### Solution - JSONata > JSON query and transformation language https://jsonata.org/ By allowing `static.json` authors to express attribute references as JSONata it allows for more advanced property selection and transformation. The above example can be expressed as: ```json { "label": "Convergence Graph", "property": "$replace(entries[0].content.files[filename='convergence_graph.png'].url, 'https://bb8d048a-2cad-4029-a9c7-671ec5d1f84d.e.globus.org/', 'https://g-cd34a.fd635.8443.data.globus.org/')", "type": "image" } ``` This is improved on the initial implementation by: - Replacing the host with the actual host needed to render the asset. - Querying for the file that has the `convergence_graph.png` filename. Another example is value is the representation of array objects. <img width="1680" alt="Screenshot 2024-04-22 at 10 18 20 AM" src="https://github.com/globus/static-search-portal/assets/694253/e8384ed0-90ac-45f0-a7d7-df284a962036"> Here, `gmeta[0].entries[0].content.datacite.creators` is an array of objects: ``` "creators": [ { "family_name": "Example", "given_name": "Vandana", "creator_name": "Vandana Example" } ], ``` Our default rendering scheme here is just to dump the object (this will likely be improved, but can only go so far). Using JSONata a user can alter the `static.json` file to something like: ```json { "label": "Creator", "property": "$join(entries[0].content.datacite.creators.creator_name, ', ')" } ``` <img width="1334" alt="Screenshot 2024-04-22 at 10 25 57 AM" src="https://github.com/globus/static-search-portal/assets/694253/66ed96ba-1f62-45ee-bb01-df2c166e0131">
- Loading branch information
1 parent
31b22ed
commit 6232a8b
Showing
7 changed files
with
125 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters