Skip to content

Commit

Permalink
use REST API for repository related content (#438)
Browse files Browse the repository at this point in the history
* use REST API for repository related content

* replace 'depositors' wording with 'creators and contributors'
  • Loading branch information
bklaing2 authored Jan 16, 2025
1 parent b9d040e commit c22c6f3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/app/repositories/[...repoid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export default async function Page({ params }: Props) {

if (!data) notFound()

return (
return <>
<Suspense fallback={<Loading />}>
<Content variables={{ id: repoid }} />
</Suspense>
)
</>
}


78 changes: 78 additions & 0 deletions src/components/RepositoryDetail/RepositoryDashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use client'
import React from 'react'
import Row from 'react-bootstrap/Row'
import Col from 'react-bootstrap/Col'
import Loading from 'src/components/Loading/Loading'
import Error from 'src/components/Error/Error'
import { useRepositoryRelatedContent } from 'src/data/queries/repositoryRelatedContentQuery'
import VerticalBarChart from 'src/components/VerticalBarChart/VerticalBarChart'
import ProductionChart from 'src/components/ProductionChart/ProductionChart'
import HorizontalStackedBarChart from 'src/components/HorizontalStackedBarChart/HorizontalStackedBarChart';
import { resourceTypeDomain, resourceTypeRange, licenseRange, otherDomain, otherRange } from 'src/data/color_palettes';
import { compactNumbers, getTopFive, toBarRecord } from 'src/utils/helpers'
import styles from './RepositoryDetail.module.scss'


function facetToData(facetList) {
return facetList.map((x) => ({
title: x.title,
count: x.count
}))
}


interface Props {
repoId: string
}

export function RepositoryDashboard({ repoId }: Props) {
const { data: repo, loading, error } = useRepositoryRelatedContent(repoId)

if (loading) return <Row><Loading /></Row>

if (error) return (
<Row>
<Col md={{ span: 9, offset: 3 }}>
<Error title="An error occured." message={error.message} />
</Col>
</Row>
)


if (!repo || repo.works.totalCount < 1) {
return <></>
}

const works = getTopFive(repo.works.resourceTypes.map(toBarRecord))
const licenses = getTopFive(repo.works.licenses.map(toBarRecord))

return (
<>
<h3>{compactNumbers(repo.works.totalCount)} Works</h3>

<div className={styles.grid}>
<ProductionChart
title="Publication Year"
data={facetToData(repo.works.published)}
/>
<HorizontalStackedBarChart
chartTitle={'Work Types'}
topCategory={{ title: works.topCategory, percent: works.topPercent }}
data={facetToData(repo.works.resourceTypes)}
domain={resourceTypeDomain}
range={resourceTypeRange}
tooltipText={'The field resourceType from DOI metadata was used to generate this chart.'} />
<HorizontalStackedBarChart
chartTitle='Licenses'
topCategory={{ title: licenses.topCategory, percent: licenses.topPercent }}
data={licenses.data}
domain={[...otherDomain, ...licenses.data.map(l => l.title)]}
range={[...otherRange, ...licenseRange]}
tooltipText={'The field "rights" from DOI metadata was used to generate this chart, showing the % of licenses used across works.'} />
<VerticalBarChart title="Top Creators and Contributors" data={repo.works.creatorsAndContributors || []} />
<VerticalBarChart title="Fields of Science" data={repo.works.fieldsOfScience} />
<VerticalBarChart title="Work Languages" data={repo.works.languages} />
</div>
</>
)
}
54 changes: 2 additions & 52 deletions src/components/RepositoryDetail/RepositoryDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@ import React from 'react'
import Link from 'next/link'
import Button from 'react-bootstrap/Button'
import Badge from 'react-bootstrap/Badge'
import VerticalBarChart from 'src/components/VerticalBarChart/VerticalBarChart'
import ProductionChart from 'src/components/ProductionChart/ProductionChart'
import { faNewspaper } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faSignInAlt } from '@fortawesome/free-solid-svg-icons'

import { compactNumbers, getTopFive, toBarRecord } from 'src/utils/helpers'
import styles from './RepositoryDetail.module.scss'
import { MetricsDisplay } from 'src/components/MetricsDisplay/MetricsDisplay';
import ShareLinks from 'src/components/ShareLinks/ShareLinks';
import { resourceTypeDomain, resourceTypeRange, licenseRange, otherDomain, otherRange } from 'src/data/color_palettes';
import HorizontalStackedBarChart from 'src/components/HorizontalStackedBarChart/HorizontalStackedBarChart';
import { Repository } from 'src/data/types';
import { RepositoryDashboard } from 'src/components/RepositoryDetail/RepositoryDashboard'

type Props = {
repo: Repository
}

function facetToData(facetList) {
return facetList.map((x) => ({
title: x.title,
count: x.count
}))
}


export function RepositorySidebar({ repo }: Props) {
const gotoButtons = () => {
return (
Expand Down Expand Up @@ -97,44 +85,6 @@ export function RepositorySidebar({ repo }: Props) {
export function RepositoryDetail({ repo }: Props) {


const dashboard = () => {
if (repo.works.totalCount < 1) {
return (<></>)
}

const works = getTopFive(repo.works.resourceTypes.map(toBarRecord))
const licenses = getTopFive(repo.works.licenses.map(toBarRecord))

return (
<>
<h3>{compactNumbers(repo.works.totalCount)} Works</h3>

<div className={styles.grid}>
<ProductionChart
title="Publication Year"
data={facetToData(repo.works.published)}
/>
<HorizontalStackedBarChart
chartTitle={'Work Types'}
topCategory={{ title: works.topCategory, percent: works.topPercent }}
data={facetToData(repo.works.resourceTypes)}
domain={resourceTypeDomain}
range={resourceTypeRange}
tooltipText={'The field resourceType from DOI metadata was used to generate this chart.'} />
<HorizontalStackedBarChart
chartTitle='Licenses'
topCategory={{ title: licenses.topCategory, percent: licenses.topPercent }}
data={licenses.data}
domain={[...otherDomain, ...licenses.data.map(l => l.title)]}
range={[...otherRange, ...licenseRange]}
tooltipText={'The field "rights" from DOI metadata was used to generate this chart, showing the % of licenses used across works.'} />
<VerticalBarChart title="Top Depositors" data={repo.works.authors} />
<VerticalBarChart title="Fields of Science" data={repo.works.fieldsOfScience} />
<VerticalBarChart title="Work Languages" data={repo.works.languages} />
</div>
</>
)
}

const tags = () => {
if (repo.re3dataDoi == null) return "";
Expand Down Expand Up @@ -250,7 +200,7 @@ export function RepositoryDetail({ repo }: Props) {
{tags()}
</div>
<div className={styles.dashboard}>
{dashboard()}
<RepositoryDashboard repoId={repo.clientId} />
</div>
<div className={styles.advise}>
{advise()}
Expand Down
6 changes: 6 additions & 0 deletions src/data/queries/repositoryRelatedContentQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useSearchDoiFacetsQuery } from './searchDoiFacetsQuery'

export function useRepositoryRelatedContent(id: string) {
const vars = { clientId: id }
return useSearchDoiFacetsQuery(vars)
}
3 changes: 2 additions & 1 deletion src/data/queries/searchDoiFacetsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function convertToQueryData(json: any): QueryData {
// Missing authors, repositories, and multilevel
return {
works: {
totalCount: meta.total,
published: meta.published,
resourceTypes: meta.resourceTypes.slice(0, 10),
languages: meta.languages.slice(0, 10),
Expand Down Expand Up @@ -89,5 +90,5 @@ export function useSearchDoiFacetsQuery(variables: QueryVar) {


export interface QueryData {
works: Omit<Works, 'nodes' | 'totalCount' | 'pageInfo'>
works: Omit<Works, 'nodes' | 'pageInfo'>
}
2 changes: 2 additions & 0 deletions src/data/queries/searchDoiQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function appendFacets(variables: QueryVar, searchParams: URLSearchParams)
if (variables.published) searchParams.append('published', variables.published)
if (variables.resourceTypeId) searchParams.append('resource-type-id', variables.resourceTypeId)
if (variables.fieldOfScience) searchParams.append('field-of-science', variables.fieldOfScience)
if (variables.clientId) searchParams.append('client-id', variables.clientId)
if (variables.clientType) searchParams.append('client-type', variables.clientType)
}

Expand Down Expand Up @@ -148,6 +149,7 @@ export interface QueryVar {
query?: string
filterQuery?: string
rorId?: string
clientId?: string
cursor?: string
published?: string
resourceTypeId?: string
Expand Down

0 comments on commit c22c6f3

Please sign in to comment.