Skip to content

Commit 203c1ec

Browse files
committed
feat(DatasetFiles): complete FileInfoCell with all the file info
1 parent ab9cb03 commit 203c1ec

31 files changed

Lines changed: 605 additions & 47 deletions

File tree

packages/design-system/src/lib/components/tooltip/overlay-trigger/OverlayTrigger.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface OverlayTriggerProps {
77
message: string
88
children: ReactElement
99
}
10+
1011
export function OverlayTrigger({ placement, message, children }: OverlayTriggerProps) {
1112
return (
1213
<OverlayTriggerBS

packages/design-system/src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export { Modal } from './components/modal/Modal'
1818
export { Table } from './components/table/Table'
1919
export { Tooltip } from './components/tooltip/Tooltip'
2020
export { Icon } from './components/Icon.enum'
21+
export { OverlayTrigger } from './components/tooltip/overlay-trigger/OverlayTrigger'

public/locales/en/files.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"metadataReleased": "Metadata Released",
3+
"published": "Published",
4+
"deposited": "Deposited",
5+
"embargoedWillBeUntil": "Draft: will be embargoed until",
6+
"embargoedUntil" : "Embargoed until",
7+
"embargoedWasThrough": "Was embargoed until"
8+
}

src/files/domain/models/File.ts

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
export enum FileSizeUnit {
2+
BYTES = 'B',
3+
KILOBYTES = 'KB',
4+
MEGABYTES = 'MB',
5+
GIGABYTES = 'GB',
6+
TERABYTES = 'TB',
7+
PETABYTES = 'PB'
8+
}
9+
110
export class FileSize {
2-
constructor(readonly value: number, readonly unit: string) {}
11+
constructor(readonly value: number, readonly unit: FileSizeUnit) {}
312

413
toString(): string {
514
return `${this.value} ${this.unit}`
@@ -11,14 +20,54 @@ export interface FileAccess {
1120
canDownload: boolean
1221
}
1322

23+
export enum FileStatus {
24+
DRAFT = 'draft',
25+
RELEASED = 'released'
26+
}
27+
1428
export class FileVersion {
15-
constructor(public readonly majorNumber: number, public readonly minorNumber: number) {}
29+
constructor(
30+
public readonly majorNumber: number,
31+
public readonly minorNumber: number,
32+
public readonly status: FileStatus
33+
) {}
1634

1735
toString(): string {
1836
return `${this.majorNumber}.${this.minorNumber}`
1937
}
2038
}
2139

40+
export enum FileDateType {
41+
METADATA_RELEASED = 'metadataReleased',
42+
PUBLISHED = 'published',
43+
DEPOSITED = 'deposited'
44+
}
45+
46+
export interface FileDate {
47+
type: FileDateType
48+
date: string
49+
}
50+
51+
export interface FileEmbargo {
52+
active: boolean
53+
date: string
54+
}
55+
56+
export interface FileTabularData {
57+
variablesCount: number
58+
observationsCount: number
59+
unf: string
60+
}
61+
62+
export enum FileLabelType {
63+
CATEGORY = 'category',
64+
TAG = 'tag'
65+
}
66+
export interface FileLabel {
67+
type: FileLabelType
68+
value: string
69+
}
70+
2271
export class File {
2372
constructor(
2473
readonly id: string,
@@ -27,10 +76,15 @@ export class File {
2776
readonly access: FileAccess,
2877
readonly type: string,
2978
readonly size: FileSize,
30-
readonly publicationDate: string,
79+
readonly date: FileDate,
3180
readonly downloads: number,
32-
readonly checksum: string,
33-
readonly thumbnail?: string
81+
readonly labels: FileLabel[],
82+
readonly checksum?: string,
83+
readonly thumbnail?: string,
84+
readonly directory?: string,
85+
readonly embargo?: FileEmbargo,
86+
readonly tabularData?: FileTabularData,
87+
readonly description?: string
3488
) {}
3589

3690
getLink(): string {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import styles from './FileInfoCell.module.scss'
2+
import { CopyToClipboardButton } from './copy-to-clipboard-button/CopyToClipboardButton'
3+
4+
export function FileChecksum({ checksum }: { checksum: string | undefined }) {
5+
if (!checksum) {
6+
return <></>
7+
}
8+
9+
return (
10+
<div className={styles['checksum-container']}>
11+
{checksum}
12+
<CopyToClipboardButton text={checksum} />
13+
</div>
14+
)
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FileDate as FileDateModel } from '../../../../../files/domain/models/File'
2+
import { useTranslation } from 'react-i18next'
3+
4+
export function FileDate({ date }: { date: FileDateModel }) {
5+
const { t } = useTranslation('files')
6+
return (
7+
<div>
8+
<span>
9+
{t(date.type)} {date.date}
10+
</span>
11+
</div>
12+
)
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styles from './FileInfoCell.module.scss'
2+
3+
export function FileDescription({ description }: { description: string | undefined }) {
4+
if (!description) {
5+
return <></>
6+
}
7+
return <div className={styles['description-container']}>{description}</div>
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export function FileDirectory({ directory }: { directory: string | undefined }) {
2+
if (!directory) {
3+
return <></>
4+
}
5+
return (
6+
<div className="directory-container">
7+
<span>{directory}</span>
8+
</div>
9+
)
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { FileStatus } from '../../../../../files/domain/models/File'
2+
3+
interface FileDownloadsProps {
4+
downloads: number
5+
status: FileStatus
6+
}
7+
export function FileDownloads({ downloads, status }: FileDownloadsProps) {
8+
if (status !== FileStatus.RELEASED) {
9+
return <></>
10+
}
11+
12+
return (
13+
<div>
14+
<span>{downloads} Downloads</span>
15+
</div>
16+
)
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { FileEmbargo, FileStatus } from '../../../../../files/domain/models/File'
2+
import { useTranslation } from 'react-i18next'
3+
4+
interface FileEmbargoDateProps {
5+
embargo: FileEmbargo | undefined
6+
status: FileStatus
7+
}
8+
9+
export function FileEmbargoDate({ embargo, status }: FileEmbargoDateProps) {
10+
const { t } = useTranslation('files')
11+
12+
if (!embargo) {
13+
return <></>
14+
}
15+
16+
return (
17+
<div>
18+
<span>
19+
{t(embargoTypeOfDate(embargo.active, status))} {embargo.date}
20+
</span>
21+
</div>
22+
)
23+
}
24+
25+
const embargoTypeOfDate = (embargoIsActive: boolean, status: FileStatus) => {
26+
if (status === FileStatus.RELEASED) {
27+
return embargoIsActive ? 'embargoedUntil' : 'embargoedWasThrough'
28+
}
29+
30+
return 'embargoedWillBeUntil'
31+
}

0 commit comments

Comments
 (0)