Skip to content

preview component for resources#82

Draft
interim17 wants to merge 8 commits intomigrate-resourcesfrom
resource-preview
Draft

preview component for resources#82
interim17 wants to merge 8 commits intomigrate-resourcesfrom
resource-preview

Conversation

@interim17
Copy link
Contributor

@interim17 interim17 commented Mar 17, 2026

Problem

Advances #55

Provides a basic preview (design pending) for resources, and a pattern for further previews.

We want decently looking preview components in the CMS so that scientist can anticipate how their entries will look.

I was hitting two major road blocks on this:

  • stale or missing data from entry widgets
  • no styles being applied when using our React/gatsby components in previews

Solution

The solution I found to the styling issue was to use vanilla CSS and not use modules.

gatsby-plugin-decap-cms seems like it can handle the styling with minimal/zero configuration if we use vanilla CSS. I tried a number of approaches to get the module scoped CSS into the preview components and had no success.

I think the main risk of plain CSS over modules is namespace collisions. Two mitigations here are
a) we can continue to use modules wherever the components are not needed in previews
b) a reasonably unique out class name and nested CSS rules provides a good degree of modularity

Personally I haven't been taking good advantages of nested CSS to date, it's quite nice. In the following example we have nicely encapsulated selectors, even for generic class names like .card or .description so long as .resource-page is a unique class name in our application:

.resource-page {
    font-family: "Raleway", sans-serif;

    .card {
        background: var(--WHITE);

        .description {
            font-size: 15px;
        }
    }

} 

The other issue, the stale data from some widgets, is solved by using value inside Decap after changes have been made, but normalizing the data from entry which is an Immutable.js Map and not a plain object. We had some related code already in the VariableTypeWidgetControl so I pulled some of it into a util file.

There are a couple other odds and ends in here, like rendering a Markdown widget for resource widget descriptions, and some markdown styling. The styling applied to resources is fairly arbitrary/not final.

Screenshot 2026-03-17 at 9 28 11 AM Screenshot 2026-03-17 at 9 28 30 AM

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a richer “Resource” display and Decap CMS preview support by rendering resource descriptions as Markdown and introducing styling/utilities needed for CMS + frontend parity.

Changes:

  • Update the resource template to use a new CustomReactMarkdown component and new page/card styling.
  • Extend the VariableTypeWidget to support a markdown field type and normalize Decap Immutable values via a shared utility.
  • Register a ResourcePreview for the resource_union widget in Decap CMS.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/templates/resource.tsx Switches resource rendering to a styled card layout and renders description via Markdown
src/style/resource.css Adds styles for the new resource page/card UI
src/style/markdown.css Adds styles for Markdown code blocks/inline code
src/style/index.css Adds an @import for the Raleway font
src/components/CustomReactMarkdown.tsx Adds Markdown rendering helper with code block styling hooks
src/cms/widgets/VariableTypeWidget/types.ts Adds markdown as a supported field type
src/cms/widgets/VariableTypeWidget/VariableTypeWidgetControl.tsx Adds Markdown widget rendering and uses shared Immutable normalization
src/cms/utils/immutable.ts Introduces fromImmutable helper + minimal Immutable-like typing
src/cms/preview-templates/ResourcePreview.tsx Adds preview component that reuses the site’s Resource template
src/cms/cms.js Registers ResourcePreview as the widget preview for resource_union

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1 to +24
.resource-page {
font-family: "Raleway", sans-serif;
line-height: 1.7;
max-width: 680px;
margin: 40px auto;

.resource-card {
background: var(--WHITE);
border: 1.5px solid var(--border-color);
border-radius: 4px;
padding: 28px 32px;

.resource-description {
font-size: 15px;
line-height: 1.7;
color: var(--BLUE_70);
margin-bottom: 20px;
}
}

a {
overflow-wrap: break-word;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of using nested selectors in plain CSS to get a bit of modularity

Comment on lines +1 to +30
.code-block {
background-color: var(--color-bg-secondary, #f6f8fa);
border: 1px solid var(--color-border, #e0e0e0);
border-radius: 4px;
padding: 12px 16px;
overflow-x: auto;
font-family: "Courier New", Courier, monospace;
font-size: 13px;
line-height: 1.6;
white-space: pre;
margin: 8px 0;
code {
background: none;
border: none;
padding: 0;
font-size: inherit;
font-family: inherit;
}
}

/* :global is required because react-markdown renders <code> without a class we can target.
Fenced blocks are excluded via :not(pre > code) since those are handled by .code-block above. */
:global(code:not(pre > code)) {
background-color: var(--color-bg-secondary, #f6f8fa);
border: 1px solid var(--color-border, #e0e0e0);
border-radius: 3px;
padding: 1px 5px;
font-family: "Courier New", Courier, monospace;
font-size: 0.875em;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brought these rules over from the design-pass branch

Comment on lines +17 to +23
<ResourceTemplate
type={v.type}
name={v.name}
description={v.description}
link={v.link}
status={v.status}
/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real benefit of the vanilla CSS vs modules change, getting to use the same template here in the preview as we do in the template.

@interim17 interim17 changed the title Resource preview preview component for resources Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants