Preview Ideas in CMS (pt. 2/2) - #111
Conversation
… for preview rendering in the idea post template
✅ Deploy Preview for project-idea-board ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| import { ResourceNode } from "../../types"; | ||
| import { fromImmutable } from "./immutable"; | ||
|
|
||
| /** Decap's Immutable metadata side-channel, keyed [field, collection, value]. */ | ||
| export interface FieldsMetaData { | ||
| getIn: (path: string[]) => unknown; | ||
| } | ||
|
|
||
| /** | ||
| * Relation widgets (referenced via dropdowns in the CMS) need their cotent resolved | ||
| * via Decap's metadata side-channel. | ||
| * | ||
| * Relation widgets store only the value_field (a name or slug) in entry data; | ||
| * Decap stashes the full referenced node in `fieldsMetaData` under | ||
| * [field, collection, value]. This is populated asynchronously — on opening an | ||
| * existing entry the relation control hydrates the selected values — so this | ||
| * returns null until the lookup resolves. Each caller supplies the shape its | ||
| * template needs and decides how to handle null (fall back, or filter out). | ||
| */ | ||
| export function resolveRelation( | ||
| fieldsMetaData: FieldsMetaData | undefined, | ||
| field: string, | ||
| collection: string, | ||
| value: string, | ||
| ): Record<string, unknown> | null { | ||
| return fromImmutable<Record<string, unknown>>( | ||
| fieldsMetaData?.getIn([field, collection, value]), | ||
| ); | ||
| } | ||
|
|
There was a problem hiding this comment.
This file is primarily agent written.
We are taking string identifiers like "allenite" for known relation widgets and getting the data out of Decap's fieldsMetaData with the necessary filtering and normalizing.
… for preview rendering in the idea post template
…l/idea-board into idea-preview-post-leave
rugeli
left a comment
There was a problem hiding this comment.
sorry for the delay on the review! I wanted to get into admin and click around the preview page myself, but it looks like I don't have access to the admin site. I actually had this issue since my first review request in this repo. Please lmk if there's anything i need to do on my end, and I may need your guidance getting into admin.
I only left a comment for a typo in this pr, and we can do another pass once this is merged back to the main pr branch, so we can trace the calls and consumers in one complete diff. Overall I think the preview is great, and it's a low-risk feature, so we should just ship it
| } | ||
|
|
||
| /** | ||
| * Relation widgets (referenced via dropdowns in the CMS) need their cotent resolved |
Problem
Closes #87 Closes #55
We have no customized preview for idea pages.
Solution
#112 got the preview rendering, what it left unresolved was getting the data from relational widgets.
Relation widgets
Turns out that when widgets have relations (ideas reference allenites, or allenites reference programs) we can get that data via Decap's
fieldsMetaDatachannel, very cool! Previously I thought that was not possible.But it requires writing resolvers to handle missing data and a do some normalization, which is too bad since we already do all of that in Gatsby. Would be nice if the SSG and the CMS were more integrated.
I had Claude spin up the resolvers in the interest of time and put them in a util folder, since they should be reusable by any other preview down the line that has relational data.
I would say these previews look good enough for now, and are a big improvement over what we had before (nothing). There is not 1:1 visual or functional parity between preview and prod, so I added a little disclaimer at the top.