-
Notifications
You must be signed in to change notification settings - Fork 0
query more of the text fields in markdown and make figure component #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d7d2e3b
3020193
4f4bcf2
d3f201e
85faacf
d733efa
15ccd2a
e6d8928
3705b6f
bd20be7
ad0b157
fbe727f
18ca6a5
dae1df4
397a360
2cbb8c4
55c3bb1
7107fa3
6b5c910
0d68755
0748fae
cfed495
1c19637
85f9530
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ const DATA_ONLY_PAGES = [ | |
| "resource", | ||
| ]; | ||
|
|
||
| exports.createSchemaCustomization = ({ actions, schema }) => { | ||
| exports.createSchemaCustomization = ({ actions }) => { | ||
| const { createTypes } = actions; | ||
| const typeDefs = [ | ||
| `""" | ||
|
|
@@ -48,6 +48,18 @@ exports.createSchemaCustomization = ({ actions, schema }) => { | |
| link: String | ||
| } | ||
|
|
||
| type PreliminaryFindings { | ||
| summary: String! | ||
| figures: [ImgWithCaption!]! | ||
| } | ||
|
|
||
| type ImgWithCaption @dontInfer { | ||
| type: String! | ||
| url: String | ||
| file: File @fileByRelativePath | ||
| caption: String | ||
| } | ||
|
|
||
| """ | ||
| Software tool reference with optional custom description. | ||
| """ | ||
|
|
@@ -82,6 +94,9 @@ exports.createResolvers = ({ createResolvers }) => { | |
| "No description provided.", | ||
| ), | ||
| }, | ||
| authors: { | ||
| resolve: (source) => resolveToArray(source.authors), | ||
| }, | ||
| title: { | ||
| resolve: (source) => | ||
| stringWithDefault(source.title, "No title provided."), | ||
|
|
@@ -112,6 +127,24 @@ exports.createResolvers = ({ createResolvers }) => { | |
| return current; | ||
| }, | ||
| }, | ||
| nextSteps: { | ||
| resolve: (source) => resolveToArray(source.nextSteps), | ||
| }, | ||
| preliminaryFindings: { | ||
| resolve: (source) => { | ||
| const raw = source.preliminaryFindings; | ||
| if (!raw || typeof raw !== "object") { | ||
| return { | ||
| summary: "", | ||
| figures: [], | ||
| }; | ||
| } | ||
| return { | ||
| summary: stringWithDefault(raw.summary, ""), | ||
| figures: resolveToArray(raw.figures), | ||
| }; | ||
| }, | ||
| }, | ||
|
Comment on lines
+133
to
+147
This comment was marked as resolved.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handled this slightly differently |
||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React from "react"; | ||
|
|
||
| // Custom widget for URL-only image input with preview | ||
| export const UrlImageControl = ({ | ||
| value, | ||
| onChange, | ||
| forID, | ||
| classNameWrapper, | ||
| }) => { | ||
| return React.createElement( | ||
| "div", | ||
| { className: classNameWrapper }, | ||
| React.createElement("input", { | ||
| id: forID, | ||
| type: "text", | ||
| value: value || "", | ||
| onChange: (e) => onChange(e.target.value), | ||
| placeholder: "https://example.com/image.png", | ||
| style: { width: "100%" }, | ||
| }), | ||
| value && | ||
| React.createElement("img", { | ||
| src: value, | ||
| alt: "Preview", | ||
| style: { | ||
| display: "block", | ||
| marginTop: "12px", | ||
| maxWidth: "100%", | ||
| maxHeight: "200px", | ||
| }, | ||
| }), | ||
| ); | ||
| }; | ||
|
|
||
| export const UrlImagePreview = ({ value }) => | ||
| value ? React.createElement("img", { src: value, alt: "Preview" }) : null; | ||
|
Comment on lines
+1
to
+36
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Custom widget and preview for the CMS. Essentially all this is is a "string" widget and a preview so that we can get the functionality of an "image" widget without the button that gives the option to load in a local file. That way when we query by type we know easily which one we are dealing with. The suggested workaround from
Comment on lines
+1
to
+36
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will consider refactoring this to use the pattern in #49 when that gets merged. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import React from "react"; | ||
| import ReactMarkdown from "react-markdown"; | ||
|
|
||
| export const CustomReactMarkdown: React.FC<{ content: string }> = ({ | ||
| content, | ||
| }) => { | ||
| return ( | ||
| <ReactMarkdown | ||
| components={{ | ||
| p: ({ node: _node, ...props }) => ( | ||
| <p style={{ margin: 0 }} {...props} /> | ||
| ), | ||
| }} | ||
| > | ||
| {content} | ||
| </ReactMarkdown> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import React from "react"; | ||
|
|
||
| import { GatsbyImage, getImage } from "gatsby-plugin-image"; | ||
|
|
||
| import { Card } from "antd"; | ||
|
|
||
| import { Figure } from "../types"; | ||
|
|
||
| interface FigureProps { | ||
| figure: Figure; | ||
| } | ||
|
|
||
| const { caption, container, image } = require("../style/figure.module.css"); | ||
|
|
||
| const FigureComponent: React.FC<FigureProps> = ({ figure }) => { | ||
| if (!figure.url && !figure.file) { | ||
| return null; | ||
| } | ||
|
|
||
| if (figure.url) { | ||
| return ( | ||
| <Card className={container}> | ||
| <img | ||
| className={image} | ||
| src={figure.url} | ||
| alt={figure.caption || "Figure"} | ||
| style={{ marginBottom: "1rem" }} | ||
| /> | ||
| <div className={caption}>{figure.caption}</div> | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| const imageForGatsby = getImage(figure.file!.childImageSharp! ?? null); | ||
| if (!imageForGatsby) return null; | ||
| return ( | ||
| <Card className={container}> | ||
| <GatsbyImage | ||
| image={imageForGatsby} | ||
| alt={figure.caption || `Preliminary finding figure`} | ||
| style={{ | ||
| marginBottom: "1rem", | ||
| }} | ||
| /> | ||
|
interim17 marked this conversation as resolved.
|
||
| <div className={caption}>{figure.caption}</div> | ||
| </Card> | ||
| ); | ||
| }; | ||
|
|
||
| export default FigureComponent; | ||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.