-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IIIF #78 - Adding attachment info the Resource edit page
- Loading branch information
1 parent
df0f24b
commit dcde885
Showing
10 changed files
with
249 additions
and
7 deletions.
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,80 @@ | ||
// @flow | ||
|
||
import cx from 'classnames'; | ||
import React, { type ComponentType } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Icon, Image, List } from 'semantic-ui-react'; | ||
import FileUtils from '../utils/File'; | ||
import styles from './AttachmentDetails.module.css'; | ||
|
||
type Props = { | ||
attachment?: { | ||
byte_size: number, | ||
content_type: string, | ||
key: string, | ||
} | ||
}; | ||
|
||
const AttachmentDetails: ComponentType<any> = (props: Props) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div | ||
className={styles.attachmentDetails} | ||
> | ||
{ !props.attachment && ( | ||
<span> | ||
{ t('AttachmentDetails.messages.noContent') } | ||
</span> | ||
)} | ||
{ props.attachment && ( | ||
<List | ||
className={cx(styles.ui, styles.list, styles.horizontal)} | ||
horizontal | ||
> | ||
<List.Item | ||
content={props.attachment?.key} | ||
header={t('AttachmentDetails.labels.key')} | ||
image={( | ||
<Image> | ||
<Icon | ||
circular | ||
name='aws' | ||
size='large' | ||
/> | ||
</Image> | ||
)} | ||
/> | ||
<List.Item | ||
content={FileUtils.getFileSize(props.attachment?.byte_size)} | ||
header={t('AttachmentDetails.labels.fileSize')} | ||
image={( | ||
<Image> | ||
<Icon | ||
circular | ||
name='file alternate' | ||
size='large' | ||
/> | ||
</Image> | ||
)} | ||
/> | ||
<List.Item | ||
content={props.attachment?.content_type} | ||
header={t('AttachmentDetails.labels.type')} | ||
image={( | ||
<Image> | ||
<Icon | ||
circular | ||
name='th large' | ||
size='large' | ||
/> | ||
</Image> | ||
)} | ||
/> | ||
</List> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default AttachmentDetails; |
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,9 @@ | ||
.attachmentDetails { | ||
margin-top: 1.5em; | ||
} | ||
|
||
.attachmentDetails > .ui.list.horizontal { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
} |
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,31 @@ | ||
// @flow | ||
|
||
import React, { type ComponentType } from 'react'; | ||
import { Icon } from 'semantic-ui-react'; | ||
|
||
type Props = { | ||
className?: string, | ||
value: boolean | ||
}; | ||
|
||
const AttachmentStatus: ComponentType<any> = (props: Props) => { | ||
if (props.value) { | ||
return ( | ||
<Icon | ||
className={props.className} | ||
color='green' | ||
name='check circle' | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Icon | ||
className={props.className} | ||
color='red' | ||
name='times circle' | ||
/> | ||
); | ||
}; | ||
|
||
export default AttachmentStatus; |
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
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,3 @@ | ||
.resource .ui.menu i.icon.attachmentStatus { | ||
margin-left: 0.5em; | ||
} |
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,19 @@ | ||
const FILE_SIZE_UNITS = ['B', 'kB', 'MB', 'GB', 'TB']; | ||
|
||
/** | ||
* Returns the human-readable file size for the passed bytes. | ||
* | ||
* @param size | ||
* | ||
* @returns {`${number} ${string}`} | ||
*/ | ||
const getFileSize = (size: number) => { | ||
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024)); | ||
const fileSize = ((size / 1024 ** i).toFixed(2)) * 1; | ||
|
||
return `${fileSize} ${FILE_SIZE_UNITS[i]}`; | ||
}; | ||
|
||
export default { | ||
getFileSize | ||
}; |