Skip to content

use local file or url for protocols#39

Open
interim17 wants to merge 5 commits intomainfrom
feature/protocols
Open

use local file or url for protocols#39
interim17 wants to merge 5 commits intomainfrom
feature/protocols

Conversation

@interim17
Copy link
Contributor

Problem

Advances #7 and #27

Solution

This is to set up the protocols data structure in materials and methods, and to explore on configuration option in decap/gatsby architecture.

I'm assuming for now that protocols are PDFs, and we might have situations where we want a local file upload or an url.

We could take in strings and handle the question of discerning file vs url in the front end, but this approach handles it a bit more cleanly I think, and I like the way it prevents a small bit of clutter in the admin UI.

On the decap side we use the types field to make a variable type widget:
https://decapcms.org/docs/variable-type-widgets/

When a user goes to add a protocol:
Screenshot 2026-02-05 at 9 01 48 PM
They get an option:
Screenshot 2026-02-05 at 9 01 44 PM

On the gatsby side I'm just using a single type with optional fields:

        type Protocol @dontInfer {
            type: String!
            name: String!
            url: String
            file: File @fileByRelativePath
        }

I think we should be able, in theory, to do this in a stricter way with interface and union types in graphql but I think this is good enough for now.
https://graphql.org/learn/schema/#interface-types
Admin site users won't be able to enter conflicting fields, a dev could, but it would silently just prefer one over the other on the front end.

  • New feature (non-breaking change which adds functionality)

@netlify
Copy link

netlify bot commented Feb 6, 2026

Deploy Preview for project-idea-board ready!

Name Link
🔨 Latest commit 41f6a46
🔍 Latest deploy log https://app.netlify.com/projects/project-idea-board/deploys/69862f605437e70008d9a4bd
😎 Deploy Preview https://deploy-preview-39--project-idea-board.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@interim17 interim17 requested a review from Copilot February 6, 2026 18:07
Comment on lines +30 to +35
- type: protocolLink
name: Culture And Freezing Methods
url: https://cell-catalog.allencell.org/pdf/AICS_WTC_cell_culture_protocol.pdf
- type: protocolFile
name: Cell culture protocol
file: /img/cell_culture_protocol.pdf
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type field is created by Decap when you use a variable type widget.

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 support for protocols being either a local uploaded PDF or an external URL, wiring the Decap CMS schema to Gatsby’s GraphQL types and updating frontend rendering accordingly.

Changes:

  • Update Decap CMS config to allow variable-type protocol entries (link vs file).
  • Update Gatsby schema + page query to support Protocol { type, name, url, file }.
  • Update Materials & Methods UI to render protocol links from either url or file.publicURL.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
static/admin/config.yml Adds variable-type list configuration for protocol link/file entries
src/templates/idea-post.tsx Updates GraphQL query for new protocol shape (and adds debug logging)
src/pages/ideas/dev-example.md Updates example frontmatter to new protocol structure
src/components/MaterialsAndMethods.tsx Renders protocol anchor href based on link vs file type
gatsby-node.js Replaces ProtocolItem with Protocol schema including optional url/file

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

title,
materialsAndMethods,
}) => {

Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Remove the debug console.log before merge/release, or gate it behind a development-only check. Leaving this in will spam browser consoles and can leak content in production logs.

Suggested change
if (process.env.NODE_ENV !== "production") {
console.log("protocols:", materialsAndMethods.protocols);
}

Copilot uses AI. Check for mistakes.
Comment on lines 101 to 117
{protocols.map((item, index) => {
const href =
item.type === "protocolLink"
? item.url
: item.file?.publicURL;
return (
<li key={index}>
<a
href={href ?? "#"}
target="_blank"
rel="noreferrer"
>
{item.name}
</a>
</li>
);
})}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

Opening links in a new tab should include rel=\"noopener\" to prevent reverse-tabnabbing (keep noreferrer if desired). Also, falling back to href=\"#\" creates a misleading clickable link; consider conditionally rendering a non-link element (or disabling the anchor) when href is missing instead of using #.

Copilot uses AI. Check for mistakes.
type MaterialsAndMethods {
dataset: MarkdownRemark @link(by: "frontmatter.name")
protocols: [ProtocolItem!]!
protocols: [Protocol!]!
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

In the CMS config, protocols is marked required: false, but the schema declares protocols: [Protocol!]! (non-null). If a markdown entry omits materialsAndMethods.protocols, Gatsby schema/query resolution can fail at build time. Consider making this field nullable (e.g., [Protocol!]) or making the CMS field required so the data always exists.

Suggested change
protocols: [Protocol!]!
protocols: [Protocol!]

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a resolver to handle this case and provide an empty array in that case.

url: https://cell-catalog.allencell.org/pdf/AICS_WTC_cell_culture_protocol.pdf
- type: protocolFile
name: Cell culture protocol
file: /img/cell_culture_protocol.pdf
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The schema uses file: File @fileByRelativePath, which typically expects a relative path like img/cell_culture_protocol.pdf (no leading slash). Using /img/... may prevent Gatsby from resolving the File node, resulting in file being null and the UI falling back to #. Align the stored value with what @fileByRelativePath expects (or adjust the CMS public_folder/value format accordingly).

Suggested change
file: /img/cell_culture_protocol.pdf
file: img/cell_culture_protocol.pdf

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this, it's working as is, and its the same way the img file path for the banner was written.

type: String!
name: String!
url: String
file: File @fileByRelativePath
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 and the query are where I think we could get a little more into the weeds with graphql especially if we had more complex varied types, but this is fine for now IMHO.

interim17 and others added 3 commits February 6, 2026 10:11
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@interim17 interim17 requested a review from meganrm February 6, 2026 18:24
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.

1 participant