-
Notifications
You must be signed in to change notification settings - Fork 1
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
Dataset Catalog #225
base: main
Are you sure you want to change the base?
Dataset Catalog #225
Changes from 24 commits
9244020
e95ddd7
0020bba
fbb12c6
cdb4d94
8996824
c0d92c8
92743c0
b0956bc
8a78b97
245f838
fea86ba
ca679b1
e295d17
16a034b
8129977
a2f567e
39303dd
89057f3
a13a864
657c8fa
8fbf828
ae0a94e
8521f32
3380b3c
0f67654
4f49046
a00cecc
341e8e1
1869850
2be97db
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Space } from 'antd'; | ||
import CatalogueCard from './CatalogueCard'; | ||
import { useMetadata } from '@/features/metadata/hooks'; | ||
|
||
const Catalogue = () => { | ||
const { projects } = useMetadata(); | ||
return ( | ||
<Space align="center" direction="vertical" size="large" style={{ width: '100%' }}> | ||
{projects.map((project) => ( | ||
<CatalogueCard project={project} key={project.identifier} /> | ||
))} | ||
</Space> | ||
); | ||
}; | ||
|
||
export default Catalogue; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { useMemo } from 'react'; | ||
import i18n from '@/i18n'; | ||
import { Card, Carousel, Descriptions, Flex, Space, Tag, Tooltip, Typography } from 'antd'; | ||
import type { Project } from '@/types/metadata'; | ||
import { isoDateToString } from '@/utils/strings'; | ||
import { useTranslationFn } from '@/hooks'; | ||
import { BOX_SHADOW } from '@/constants/overviewConstants'; | ||
import Dataset from '@/components/Provenance/Catalogue/Dataset'; | ||
|
||
const { Paragraph, Text, Title } = Typography; | ||
|
||
const MAX_KEYWORD_CHARACTERS = 50; | ||
|
||
const CatalogueCard = ({ project }: { project: Project }) => { | ||
const lang = i18n.language; | ||
const t = useTranslationFn(); | ||
|
||
const { selectedKeywords, extraKeywords, extraKeywordCount } = useMemo(() => { | ||
const keywords = project.datasets.flatMap((d) => d.dats_file.keywords ?? []).map((k) => t(k.value as string)); | ||
|
||
let totalCharacters = 0; | ||
const selectedKeywords: string[] = []; | ||
const extraKeywords: string[] = []; | ||
|
||
for (const keyword of keywords) { | ||
if (totalCharacters + keyword.length > MAX_KEYWORD_CHARACTERS) { | ||
extraKeywords.push(keyword); | ||
} else { | ||
selectedKeywords.push(keyword); | ||
totalCharacters += keyword.length; | ||
} | ||
} | ||
|
||
return { | ||
selectedKeywords, | ||
extraKeywords, | ||
extraKeywordCount: extraKeywords.length, | ||
}; | ||
}, [project.datasets, t]); | ||
|
||
const projectCreated = isoDateToString(project.created, lang); | ||
const projectUpdated = isoDateToString(project.updated, lang); | ||
|
||
const projectInfo = [ | ||
{ | ||
key: '1', | ||
label: t('Created'), | ||
children: ( | ||
<Paragraph | ||
ellipsis={{ | ||
rows: 1, | ||
tooltip: { title: projectCreated }, | ||
}} | ||
> | ||
{projectCreated} | ||
</Paragraph> | ||
), | ||
span: 1.5, | ||
}, | ||
{ | ||
key: '2', | ||
label: t('Updated'), | ||
children: <Paragraph ellipsis={{ rows: 1, tooltip: { title: projectUpdated } }}>{projectUpdated}</Paragraph>, | ||
span: 1.5, | ||
}, | ||
]; | ||
|
||
return ( | ||
<Card key={project.identifier} style={{ height: '260px', maxWidth: '1300px', ...BOX_SHADOW }}> | ||
SanjeevLakhwani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Flex justify="space-between"> | ||
<div style={{ flex: 1, paddingRight: '10px' }}> | ||
<Space direction="vertical"> | ||
<Title level={4} style={{ marginTop: 0 }}> | ||
{t(project.title)} | ||
</Title> | ||
<Paragraph | ||
SanjeevLakhwani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ellipsis={{ | ||
rows: 3, | ||
tooltip: { title: t(project.description) }, | ||
}} | ||
> | ||
{t(project.description)} | ||
</Paragraph> | ||
<div> | ||
{selectedKeywords.map((kw) => ( | ||
<Tag key={kw} color="blue"> | ||
{kw} | ||
</Tag> | ||
))} | ||
{extraKeywordCount !== 0 && ( | ||
<Tooltip title={extraKeywords.join(', ')}> | ||
<Text>+{extraKeywordCount} more</Text> | ||
</Tooltip> | ||
)} | ||
</div> | ||
<Descriptions items={projectInfo} /> | ||
</Space> | ||
</div> | ||
<div style={{ flex: 1, maxWidth: '600px' }}> | ||
<Title level={5} style={{ marginTop: 0 }}> | ||
{t('Datasets')} | ||
</Title> | ||
<Carousel | ||
arrows={project.datasets.length > 1} | ||
style={{ border: '1px solid lightgray', borderRadius: '7px', height: '170px', padding: '16px' }} | ||
> | ||
{project.datasets.map((d) => ( | ||
<Dataset parentProjectID={project.identifier} key={d.identifier} dataset={d} format="carousel" /> | ||
))} | ||
</Carousel> | ||
</div> | ||
</Flex> | ||
</Card> | ||
); | ||
}; | ||
export default CatalogueCard; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { DOI_PATTERN, URL_PATTERN } from '@/constants/patterns'; | ||
// import i18n from '@/i18n'; | ||
|
||
export const stringToBoolean = (s: string | undefined) => | ||
['true', 't', '1', 'yes'].includes((s || '').toLocaleLowerCase()); | ||
|
||
export const stringIsDOI = (s: string) => !!s.match(DOI_PATTERN); | ||
export const stringIsURL = (s: string) => !!s.match(URL_PATTERN); | ||
|
||
export const isoDateToString = (d: string, lang?: string) => { | ||
const dateLang = lang === 'fr' ? 'fr-CA' : 'en-US'; | ||
return new Date(d).toLocaleString(dateLang, { | ||
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. why not use i18n.language (or in this case the lang argument) directly here? 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. I gets accessed before i18n is initialized causing issues. 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. but can it be passed into the function elsewhere, thus mitigating the "if french else assume english" extra logic? 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. I can create a utility function for it to separate logic., but I think such logic also exists on the initial render of the website (except there is an extra log statement for saying unsupported language). |
||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
}); | ||
}; |
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.
I think for consistency this should be called Project. we can then later split it into multiple view modes, like with Dataset.
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.
I would rather change, Dataset to CatalogDataset as Dataset/Project by itself can mean multiple things in public context by conflicting with overview. I do understand that it is in a folder but the naming does reduce the readability.
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.
catalogdataset to me doesn't make sense, as the dataset isn't just used in the catalog
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.
I mean it in the form that a "Dataset" could mean multiple things while at least prefixing catalog tells the purpose. If you think otherwise still, lmk, I shall change it.