-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from datacite/fair-vis-feature-2
Fair vis feature 2
- Loading branch information
Showing
6 changed files
with
257 additions
and
1 deletion.
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
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,72 @@ | ||
import React from 'react' | ||
import { Row, Col } from 'react-bootstrap' | ||
import HelpIcon from '../HelpIcon/HelpIcon' | ||
|
||
type Props = { | ||
url: string | ||
title?: string | ||
variables: { | ||
id: string, | ||
gridId: string, | ||
crossrefFunderId: string, | ||
cursor: string, | ||
filterQuery: string, | ||
published: string, | ||
resourceTypeId: string, | ||
fieldOfScience: string, | ||
language: string, | ||
license: string, | ||
registrationAgency: string | ||
} | ||
} | ||
|
||
const DownloadReports: React.FunctionComponent<Props> = ({ variables}) => { | ||
|
||
const filteredVariables = Object.fromEntries(Object.entries(variables).filter(([, value]) => value)) | ||
const params = new URLSearchParams(filteredVariables).toString() | ||
|
||
const apiurlBase = '/api/download-reports' | ||
|
||
|
||
const downloadReports = () => { | ||
return ( | ||
<div className="panel panel-transparent download-reports"> | ||
<div className="panel-body"> | ||
<Row> | ||
<Col className="download-list" id="full-metadata" xs={12}> | ||
<div id="download-related-works"> | ||
<a | ||
rel="noreferrer" | ||
href={`${apiurlBase}/related-works?${params}`} | ||
download | ||
> | ||
Related Works (CSV) | ||
</a> | ||
<HelpIcon text='Includes descriptions and formatted citations in APA style for up to 200 DOIs associated with this organization.' size={20} position='inline' /> | ||
</div> | ||
<div id="download-funders" className="download"> | ||
<a | ||
rel="noreferrer" | ||
href={`${apiurlBase}/funders?${params}`} | ||
download | ||
> | ||
Funders (CSV) | ||
</a> | ||
<HelpIcon text='Includes up to 200 funders associated with related works.' size={20} position='inline' /> | ||
</div> | ||
</Col> | ||
</Row> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<h3 className="member-results">Download Reports</h3> | ||
{downloadReports()} | ||
</> | ||
) | ||
} | ||
|
||
export default DownloadReports |
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,74 @@ | ||
import { NextApiRequest, NextApiResponse } from "next" | ||
import { gql } from '@apollo/client'; | ||
import apolloClient from '../../../utils/apolloClient' | ||
import { stringify } from 'csv-stringify/sync' | ||
|
||
const QUERY = gql` | ||
query getOrganizationQuery( | ||
$id: ID | ||
$gridId: ID | ||
$crossrefFunderId: ID | ||
$cursor: String | ||
$filterQuery: String | ||
$published: String | ||
$resourceTypeId: String | ||
$fieldOfScience: String | ||
$language: String | ||
$license: String | ||
$registrationAgency: String | ||
) { | ||
organization( | ||
id: $id | ||
gridId: $gridId | ||
crossrefFunderId: $crossrefFunderId | ||
) { | ||
works( | ||
first: 0 | ||
after: $cursor | ||
query: $filterQuery | ||
published: $published | ||
resourceTypeId: $resourceTypeId | ||
fieldOfScience: $fieldOfScience | ||
language: $language | ||
license: $license | ||
registrationAgency: $registrationAgency | ||
facetCount: 200 | ||
) { | ||
funders { | ||
id | ||
title | ||
count | ||
} | ||
} | ||
} | ||
} | ||
` | ||
|
||
|
||
export default async function downloadReportsHandler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const variables = req.query | ||
|
||
const { data } = await apolloClient.query({ | ||
query: QUERY, | ||
variables: variables | ||
}) | ||
|
||
|
||
const csv = stringify(data.organization.works.funders, { | ||
header: true, | ||
columns: [ { key: 'id', header: 'Funder ID' }, { key: 'title', header: 'Title' }, { key: 'count', header: 'Work Count' } ] | ||
}) | ||
|
||
|
||
try { | ||
res.status(200) | ||
res.setHeader('Content-Type', 'text/csv') | ||
res.setHeader('Content-Disposition', `attachment; filename="funders_${variables.id}.csv"`) | ||
res.send(csv) | ||
} catch (error) { | ||
res.status(400).json({ error }) | ||
} | ||
} |
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,90 @@ | ||
import { NextApiRequest, NextApiResponse } from "next" | ||
import { gql } from '@apollo/client'; | ||
import apolloClient from '../../../utils/apolloClient' | ||
import { stringify } from 'csv-stringify/sync' | ||
|
||
const QUERY = gql` | ||
query getOrganizationQuery( | ||
$id: ID | ||
$gridId: ID | ||
$crossrefFunderId: ID | ||
$cursor: String | ||
$filterQuery: String | ||
$published: String | ||
$resourceTypeId: String | ||
$fieldOfScience: String | ||
$language: String | ||
$license: String | ||
$registrationAgency: String | ||
) { | ||
organization( | ||
id: $id | ||
gridId: $gridId | ||
crossrefFunderId: $crossrefFunderId | ||
) { | ||
works( | ||
first: 200 | ||
after: $cursor | ||
query: $filterQuery | ||
published: $published | ||
resourceTypeId: $resourceTypeId | ||
fieldOfScience: $fieldOfScience | ||
language: $language | ||
license: $license | ||
registrationAgency: $registrationAgency | ||
) { | ||
nodes { | ||
...WorkFragment | ||
} | ||
} | ||
} | ||
} | ||
fragment WorkFragment on Work { | ||
titles { | ||
title | ||
} | ||
descriptions { | ||
description | ||
descriptionType | ||
} | ||
doi | ||
formattedCitation(style: "apa", locale: "en-US", format: text) | ||
publicationYear | ||
} | ||
` | ||
|
||
|
||
export default async function downloadReportsHandler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
const variables = req.query | ||
|
||
const { data } = await apolloClient.query({ | ||
query: QUERY, | ||
variables: variables | ||
}) | ||
|
||
const sortedData = [...data.organization.works.nodes].sort((a, b) => b.publicationYear - a.publicationYear) | ||
|
||
const csv = stringify(sortedData, { | ||
header: true, | ||
columns: [ | ||
{ key: 'titles[0].title', header: 'Title' }, | ||
{ key: 'publicationYear', header: 'Publication Year' }, | ||
{ key: 'doi', header: 'DOI' }, | ||
{ key: 'descriptions[0].description', header: 'Description' }, | ||
{ key: 'formattedCitation', header: 'Formatted Citation' } | ||
] | ||
}) | ||
|
||
try { | ||
res.status(200) | ||
res.setHeader('Content-Type', 'text/csv') | ||
res.setHeader('Content-Disposition', `attachment; filename="related-works_${variables.id}.csv"`) | ||
res.send(csv) | ||
} catch (error) { | ||
res.status(400).json({ error }) | ||
} | ||
|
||
} |
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