Skip to content

Commit

Permalink
Merge pull request #1015 from basedosdados/feat/manytomany
Browse files Browse the repository at this point in the history
feat: many to many, keep organization[0] data
  • Loading branch information
rdahis authored Nov 5, 2024
2 parents 8cd8e57 + 1de7464 commit 456e9af
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 59 deletions.
2 changes: 1 addition & 1 deletion next/components/molecules/ThemeCatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function CardThemes ({ responsive, datasetsCards = [], loading, locale }) {
key={i}
name={elm?.name}
themes={elm?.themes}
organization={elm?.organizations?.[0]}
organizations={elm?.organizations}
tags={elm?.tags}
tables={{
id: elm?.first_table_id || elm?.first_closed_table_id,
Expand Down
12 changes: 7 additions & 5 deletions next/components/organisms/DatasetSearchCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Dataset({
name,
spatialCoverage,
temporalCoverageText,
organization,
organizations,
tables,
rawDataSources,
informationRequests,
Expand Down Expand Up @@ -187,8 +187,10 @@ export default function Dataset({
_hover={{ opacity: 0.9 }}
>
<Image
src={organization?.picture.startsWith("https://") ? organization?.picture : `https://basedosdados.org/uploads/group/${organization?.name}`}
alt={organization[`name${capitalize(locale)}`] || organization?.name || t('notProvided')}
src={organizations[0]?.picture?.startsWith("https://")
? organizations[0]?.picture
: `https://basedosdados.org/uploads/group/${organizations[0]?.name}`}
alt={organizations[0]?.[`name${capitalize(locale)}`] || organizations[0]?.name || t('notProvided')}
borderRadius="16px"
minWidth="222px"
minHeight="138px"
Expand Down Expand Up @@ -255,7 +257,7 @@ export default function Dataset({
{t('organization')}:
</Text>
<Link
href={`/search?organization=${organization?.slug}`}
href={`/search?organization=${organizations[0]?.slug}`}
color="#71757A"
fontWeight="400"
_hover={{
Expand All @@ -268,7 +270,7 @@ export default function Dataset({
lineHeight="20px"
textOverflow="ellipsis"
>
{organization[`name${capitalize(locale)}`] || organization?.name}
{organizations[0]?.[`name${capitalize(locale)}`] || organizations[0]?.name}
</Text>
</Link>
</Stack>
Expand Down
6 changes: 3 additions & 3 deletions next/components/organisms/DatasetThemeCatalogCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DatasetCardTag } from "../atoms/DatasetCardTag";
export default function DatasetCard({
name,
themes = [],
organization,
organizations,
tags = [],
tables,
rawDataSources,
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function DatasetCard({
{name}
</Text>
</Link>
<Link href={`/search?organization=${organization.slug}`}>
<Link href={`/search?organization=${organizations?.[0]?.slug}`}>
<Text
noOfLines={2}
lineHeight="16px"
Expand All @@ -147,7 +147,7 @@ export default function DatasetCard({
fontWeight="400"
color="#6F6F6F"
>
{organization[`name${capitalize(locale)}`] || organization.name || organization.slug}
{organizations?.[0]?.[`name${capitalize(locale)}`] || organizations?.[0]?.name || organizations?.[0]?.slug}
</Text>
</Link>

Expand Down
73 changes: 42 additions & 31 deletions next/components/organisms/TablePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,38 +167,49 @@ export default function TablePage({ id }) {
}

const PublishedOrDataCleanedBy = ({ resource }) => {
if (!resource || typeof resource !== 'object' || Object.keys(resource).length === 0) {
return (
<Text
marginRight="4px !important"
fontFamily="Roboto"
fontWeight="400"
fontSize="14px"
lineHeight="20px"
color="#464A51"
>
{t('table.notProvided')}
</Text>
);
}

const people = Object.values(resource);

return (
<HStack spacing="4px">
{resource?.firstName && resource?.lastName ?
<Text
marginRight="4px !important"
fontFamily="Roboto"
fontWeight="400"
fontSize="14px"
lineHeight="20px"
color="#464A51"
>
{`${resource.firstName} ${resource.lastName}`}
</Text>
:
<Text
marginRight="4px !important"
fontFamily="Roboto"
fontWeight="400"
fontSize="14px"
lineHeight="20px"
color="#464A51"
>
{t('table.notProvided')}
</Text>
}
{resource?.email && <EmailIcon {...keyIcons({email : resource.email})}/>}
{resource?.github && <GithubIcon {...keyIcons({github_user : resource.github})}/>}
{resource?.website && <WebIcon {...keyIcons({website : resource.website})}/>}
{resource?.twitter && <TwitterIcon {...keyIcons({twitter_user : resource.twitter_user})}/>}
</HStack>
)
}
<Stack spacing="8px">
{people.map((person, index) => (
<HStack key={index} spacing="4px">
<Text
marginRight="4px !important"
fontFamily="Roboto"
fontWeight="400"
fontSize="14px"
lineHeight="20px"
color="#464A51"
>
{person?.firstName && person?.lastName
? `${person.firstName} ${person.lastName}`
: t('table.notProvided')
}
</Text>
{person?.email && <EmailIcon {...keyIcons({email: person.email})}/>}
{person?.github && <GithubIcon {...keyIcons({github_user: person.github})}/>}
{person?.website && <WebIcon {...keyIcons({website: person.website})}/>}
{person?.twitter && <TwitterIcon {...keyIcons({twitter_user: person.twitter})}/>}
</HStack>
))}
</Stack>
);
};

const StackSkeleton = ({ children, ...props }) => {
return (
Expand Down
18 changes: 11 additions & 7 deletions next/pages/api/datasets/getDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ export default async function getDataset(id, locale = 'pt') {
}
}
}
organization {
_id
slug
name
name${capitalize(locale)}
website
picture
organizations {
edges {
node {
_id
slug
name
name${capitalize(locale)}
website
picture
}
}
}
informationRequests {
edges {
Expand Down
16 changes: 8 additions & 8 deletions next/pages/api/tables/getTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ async function getTable(id, locale='pt') {
dataset {
_id
slug
organization {
_id
slug
name
name${capitalize(locale)}
area {
_id
slug
organizations {
edges {
node {
_id
slug
name
name${capitalize(locale)}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions next/pages/dataset/[dataset].js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) {
borderRadius="16px"
>
<Image
src={dataset?.organization?.picture ? dataset?.organization?.picture : `https://storage.googleapis.com/basedosdados-website/equipe/sem_foto.png`}
src={dataset?.organizations?.edges?.[0]?.node?.picture ? dataset?.organizations?.edges?.[0]?.node?.picture : `https://storage.googleapis.com/basedosdados-website/equipe/sem_foto.png`}
objectFit="contain"
width="300px"
height="182px"
Expand Down Expand Up @@ -253,7 +253,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) {
{t('organization')}
</Text>
<Link
href={`/search?organization=${dataset?.organization?.slug || ""}`}
href={`/search?organization=${dataset?.organizations?.edges?.[0]?.node?.slug || ""}`}
color="#464A51"
fontWeight="400"
>
Expand All @@ -262,7 +262,7 @@ export default function DatasetPage ({ dataset, spatialCoverageNames }) {
fontSize="14px"
lineHeight="20px"
>
{dataset.organization?.[`name${capitalize(locale)}`] || dataset.organization?.name || t('noOrganization')}
{dataset.organizations?.edges?.[0]?.node?.[`name${capitalize(locale)}`] || dataset.organizations?.edges?.[0]?.node?.name || t('noOrganization')}
</Text>
</Link>
</GridItem>
Expand Down
2 changes: 1 addition & 1 deletion next/pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export default function SearchDatasetPage() {
spatialCoverage={(data?.spatial_coverage?.map(coverage => coverage.slug) || [])
.sort((a, b) => a.localeCompare(b))
.join(', ')}
organization={data.organizations[0]}
organizations={data.organizations}
tables={{
id: data?.first_table_id,
number: data?.n_tables
Expand Down

0 comments on commit 456e9af

Please sign in to comment.