-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a derived atom for dataset hydration from Next.js, expose it i…
…n the veda lib
- Loading branch information
Showing
5 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { atom } from 'jotai'; | ||
import { DatasetLayer } from '$types/veda'; | ||
|
||
/** | ||
* This is the primary storage atom for external datasets (e.g. passed from Next.js). | ||
*/ | ||
export const externalDatasetsAtom = atom<any[]>([]); | ||
|
||
/** | ||
* Derived atom that transforms the provided datasets into layers. | ||
* It is used by the timelineDatasetsAtom to rebuild state from URL parameters | ||
* while it preserves the parent dataset metadata for each layer that comes | ||
* from the MDX configuration. | ||
*/ | ||
export const datasetLayersAtom = atom<DatasetLayer[]>((get) => { | ||
const datasets = get(externalDatasetsAtom); | ||
|
||
return datasets.flatMap((dataset) => { | ||
return (dataset.layers || []).map((l: any) => ({ | ||
...l, | ||
parentDataset: { | ||
id: dataset.id, | ||
name: dataset.name | ||
} | ||
})); | ||
}); | ||
}); |
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