-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Data pages: extract shared component for sources #2840
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
122 changes: 122 additions & 0 deletions
122
packages/@ourworldindata/components/src/IndicatorSources/IndicatorSources.tsx
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,122 @@ | ||
import React from "react" | ||
import { ExpandableToggle } from "../ExpandableToggle/ExpandableToggle.js" | ||
import { OwidOrigin } from "@ourworldindata/utils" | ||
import { SimpleMarkdownText } from "../SimpleMarkdownText.js" | ||
import { CodeSnippet } from "../CodeSnippet/CodeSnippet.js" | ||
import { REUSE_THIS_WORK_SECTION_ID } from "../SharedDataPageConstants.js" | ||
|
||
export type OriginSubset = Pick< | ||
OwidOrigin, | ||
| "producer" | ||
| "descriptionSnapshot" | ||
| "dateAccessed" | ||
| "urlMain" | ||
| "description" | ||
| "citationFull" | ||
> | ||
|
||
export interface IndicatorSourcesProps { | ||
origins: OriginSubset[] | ||
} | ||
|
||
export const IndicatorSources = (props: IndicatorSourcesProps) => { | ||
const citationFullBlockFn = (source: OriginSubset) => { | ||
source.citationFull && ( | ||
<div | ||
className="key-data" | ||
style={{ | ||
gridColumn: "span 2", | ||
}} | ||
> | ||
<div className="key-data__title--dark">Citation</div> | ||
This is the citation of the original data obtained from the | ||
source, prior to any processing or adaptation by Our World in | ||
Data. To cite data downloaded from this page, please use the | ||
suggested citation given in{" "} | ||
<a href={"#" + REUSE_THIS_WORK_SECTION_ID}> | ||
Reuse This Work | ||
</a>{" "} | ||
below. | ||
<CodeSnippet code={source.citationFull} theme="light" /> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div className="data-sources grid span-cols-12"> | ||
<h3 className="data-sources__heading span-cols-2 span-lg-cols-3 col-md-start-2 span-md-cols-10 col-sm-start-1 span-sm-cols-12"> | ||
This data is based on the following sources | ||
</h3> | ||
<div className="col-start-4 span-cols-6 col-lg-start-5 span-lg-cols-7 col-md-start-2 span-md-cols-10 col-sm-start-1 span-sm-cols-12"> | ||
{props.origins.map((source, idx: number, sources) => { | ||
return ( | ||
<div className="data-sources__source-item" key={idx}> | ||
<ExpandableToggle | ||
label={ | ||
source.producer ?? | ||
source.descriptionSnapshot ?? | ||
source.description ?? | ||
"" | ||
} | ||
isStacked={idx !== sources.length - 1} | ||
hasTeaser | ||
content={ | ||
<> | ||
{source.description && ( | ||
<p className="article-block__text"> | ||
<SimpleMarkdownText | ||
text={source.description} | ||
/> | ||
</p> | ||
)} | ||
{(source.dateAccessed || | ||
source.urlMain) && ( | ||
<div | ||
className="grid source__key-data" | ||
style={{ | ||
gridTemplateColumns: | ||
"minmax(0,1fr) minmax(0,2fr)", | ||
}} | ||
> | ||
{source.dateAccessed && ( | ||
<div className="key-data"> | ||
<div className="key-data__title--dark"> | ||
Retrieved on | ||
</div> | ||
<div> | ||
{ | ||
source.dateAccessed | ||
} | ||
</div> | ||
</div> | ||
)} | ||
{source.urlMain && ( | ||
<div className="key-data key-data--hide-overflow"> | ||
<div className="key-data__title--dark"> | ||
Retrieved from | ||
</div> | ||
<div> | ||
<a | ||
href={ | ||
source.urlMain | ||
} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{source.urlMain} | ||
</a> | ||
</div> | ||
</div> | ||
)} | ||
{citationFullBlockFn(source)} | ||
</div> | ||
)} | ||
</> | ||
} | ||
/> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
</div> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
...rworldindata/utils/src/SharedConstants.ts → ...components/src/SharedDataPageConstants.ts
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export const DATAPAGE_SOURCES_AND_PROCESSING_SECTION_ID = | ||
"sources-and-processing" as const | ||
export const REUSE_THIS_WORK_SECTION_ID = "reuse-this-work" | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for renaming the file! it really bugged me that I had given it such a generic name...