NASA-IMPACT / veda-ui

Frontend for the Dashboard Evolution project
Other
18 stars 4 forks source link

[VEDA2 Refactor] Spike - Replace Parcel Resolver? #896

Closed hanbyul-here closed 1 month ago

hanbyul-here commented 3 months ago

Parcel Resolver has been used to serve the contents of the VEDA from MDX files. The resolver made the metadata of the contents (frontmatter) instantly available through the faux module veda while the contents of each file lazily available through its loader. (So the built assets don't have to hold a large amount of content.)

While the resolver has served its purpose so far, it is explicitly written for Parcel, and we hope VEDA-UI can be agnostic from the bundler.

Documentation about Parcel Resolver & Faux Modules: https://github.com/NASA-IMPACT/veda-ui/blob/main/docs/development/ARCHITECTURE.md#veda-modules

Here are some pointers that helped me get more thoughts on what is going on bts:

Where the mdx data objects are generated ({data : ${FrontMatterData}, content:${FileLoader}}): https://github.com/NASA-IMPACT/veda-ui/blob/main/parcel-resolver-veda/index.js#L66-L81

Where frontmatter gets processed (ex. we have some prefixes that need special handling for frontmatter, such as ::markdown, ::js) : https://github.com/NASA-IMPACT/veda-ui/blob/main/parcel-resolver-veda/stringify-yml-func.js

This ticket is a spike for researching how we can access this problem. The answers that we need to get from this spikes are

danielfdsilva commented 3 months ago

Besides making the different contents available one big task of the veda resolver is to create list of values.

It creates a general list of datasets so then individual ones can be loaded and also of all the existent taxonomies for the filters by looking through all the files. Doing this during build allows you not to have a hardcoded list elsewhere and not needed to load all content during runtime to create this.

These are things that are very basic when you have a database for example, or even when you use a static site generator like gatsby, or something like Next. It becomes much more complicated when you're building an SPA that needs arbitrary data from an arbitrary number of files without using server tech.

oliverroick commented 3 months ago

I feel like I’m missing a lot of detail for how VEDA works internally and how the content is managed so I’m just going to throw out some questions, hoping that it clarifies some questions for me without stirring the pot too much.

hanbyul-here commented 3 months ago

@oliverroick These are all good questions and should be part of Spike. To lay out the contexts that I am aware of...

I hope this gives you more ground to delve into the issue @oliverroick

sandrahoang686 commented 2 months ago

Slack Thread on needing to make a decision wether we want to use a static-page generator like NextJS or stick with what we’re currently using... https://developmentseed.slack.com/archives/C04HM9LQ9UM/p1712011779163419

hanbyul-here commented 1 month ago

Working on the Next test instance, https://github.com/NASA-IMPACT/veda-ui/issues/947 gave me some insights about what is needed to replace Parcel Resovler (To be clear, I am not talking about Parcel as a bundler. I am talking about Faux module 'Veda' that Parcel resolver outputs. These are being used as import { datasets } from 'veda' in the current code base.

  1. Parse the front matter and contents of MDX files: This is being tested as a part of #947 . Thanks to the communities that evolved around MDX; I expect this can be done relatively straightforwardly, Ex. The current progress on parsing the MDX data on Next test instance: https://github.com/developmentseed/next-veda-ui/blob/main/app/blog/utils.ts#L145

  2. Expose types that VEDA depends on: This is also a matter of moving the types to somewhere in the source code.

  3. Expose the datasets/stories that can be globally accessible throughout the applications: This is the element that I am still unclear how to tackle. We moved some components towards the direction that the component will get this data as a prop. (ex. data catalog https://github.com/NASA-IMPACT/veda-ui/blob/main/app/scripts/components/data-catalog/container.tsx#L23) However, this approach is not possible with MDX components. Ex. BlockMap component expects a user to pass dataset-id and layer-id, then gets all other information needed through globally accessible datasets: (https://github.com/NASA-IMPACT/veda-ui/blob/main/app/scripts/components/common/blocks/block-map.tsx#L146. - it is layered but it eventually depends on global datasets, https://github.com/NASA-IMPACT/veda-ui/blob/main/app/scripts/components/common/blocks/block-map.tsx#L186). Some of the ideas (these options are not mutually exclusive to each other.)

I'd like to spend more time on 3, but I wanted to lay out the problem in a more scoped way first.

hanbyul-here commented 1 month ago

To replace what Parcel Resolver does for 3 (Expose the datasets/stories that can be globally accessible throughout the applications), we narrowed down the approaches worth trying. (Thanks @dzole0311 for the insights 🙇 )

Approaches

  1. Use Context. Expose the ProviProviderask Users to fill up this proviProvider wrap the MDX Renderer with this Provider. We should examine how SEO will be affected from this approach. Some resources

  2. Get the datasets on MDX Renderer level and pass them as props. In this approach, rewriting the component so the dataset resolutions can happen on a higher container level will help avoid deep prop drilling.


There was an additional option to expose datasets and stories through an MDX file through using the syntax below.

import datasets from 'somewhere-that-instant-can-get-datasets-list';
<BlockMap dataset-id={...} ... datasets={datasets} />

But this will complicate the editor experience, so this approach won't be worth pursuing.

hanbyul-here commented 1 month ago

As we narrowed down what to do to replace Parcel Resolver, I will close this ticket and open the items with action items. (such as #975)