diff --git a/packages/component-faraday-ui/src/AuthorCard.js b/packages/component-faraday-ui/src/AuthorCard.js index a1e6fad9f49b97aeab9b3e551f3be3bca608327b..8f627001d6beef0cfc09ad8d80b0bc2a57362d25 100644 --- a/packages/component-faraday-ui/src/AuthorCard.js +++ b/packages/component-faraday-ui/src/AuthorCard.js @@ -100,7 +100,7 @@ const AuthorEdit = ({ <Row> <Field component={Empty} name="id" /> <Field component={Empty} name="isSubmitting" /> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label required>Email</Label> <ValidatedField component={TextField} @@ -108,7 +108,7 @@ const AuthorEdit = ({ validate={[required, validators.emailValidator]} /> </Item> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label required>First name</Label> <ValidatedField component={TextField} @@ -116,7 +116,7 @@ const AuthorEdit = ({ validate={[required]} /> </Item> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label required>Last name</Label> <ValidatedField component={TextField} diff --git a/packages/component-faraday-ui/src/DateParser.js b/packages/component-faraday-ui/src/DateParser.js deleted file mode 100644 index cd35989c68f1947f7593e0176d9104dd4fa6ca5f..0000000000000000000000000000000000000000 --- a/packages/component-faraday-ui/src/DateParser.js +++ /dev/null @@ -1,12 +0,0 @@ -import React, { Fragment } from 'react' -import moment from 'moment' -import { Text } from 'pubsweet-component-faraday-ui' - -const DateParser = ({ label, date, format = 'DD.MM.YYYY' }) => ( - <Fragment> - {label && <Text>{label} </Text>} - {date && <Text mr={1}>{moment(date).format(format)}</Text>} - </Fragment> -) - -export default DateParser diff --git a/packages/component-faraday-ui/src/DateParser.md b/packages/component-faraday-ui/src/DateParser.md deleted file mode 100644 index a734dede59a3f900b073d89a555f6373e3c11ab9..0000000000000000000000000000000000000000 --- a/packages/component-faraday-ui/src/DateParser.md +++ /dev/null @@ -1,21 +0,0 @@ -Date parser without label - -```js -const date = 1534942072364 -;<DateParser date={date} /> -``` - -Date parser with label - -```js -const date = 1534942072364; -<DateParser date={date} label='Updated on: '/> -``` - -Date parser with format - -```js -const date = 1534942072364 -const format = 'DD.MM.YY' -;<DateParser date={date} format={format} /> -``` diff --git a/packages/component-faraday-ui/src/DownloadZipFiles.js b/packages/component-faraday-ui/src/DownloadZipFiles.js index 459f44b422ffc4a6a80e17089166f932bdd12a3e..3244bb90c623ccfecf7441f86da5a76a1733214d 100644 --- a/packages/component-faraday-ui/src/DownloadZipFiles.js +++ b/packages/component-faraday-ui/src/DownloadZipFiles.js @@ -1,107 +1,31 @@ -import React, { Fragment } from 'react' -import qs from 'querystring' -import PropTypes from 'prop-types' +import React from 'react' import { connect } from 'react-redux' import { Spinner } from '@pubsweet/ui' -import { compose, withHandlers, withState } from 'recompose' +import { compose, withState } from 'recompose' import { getUserToken, currentUserIsReviewer, } from 'pubsweet-component-faraday-selectors' +import { Item } from 'pubsweet-component-faraday-ui' -const ZipFiles = ({ disabled, fetching, children, downloadFiles }) => ( - <Fragment onClick={!disabled ? downloadFiles : null}> +import { withZipDownload } from './helpers' + +const DownloadZipFiles = ({ disabled, fetching, children, downloadFiles }) => ( + <Item + flex={0} + justify="flex-end" + mr={1} + onClick={!disabled ? downloadFiles : null} + > {fetching ? <Spinner /> : children} - </Fragment> + </Item> ) -const cache = {} - -const reviewerFiles = ['manuscripts', 'supplementary'] -const defaultFiles = [...reviewerFiles, 'coverLetter'] - -const DownloadZipFiles = compose( +export default compose( connect((state, { collectionId }) => ({ token: getUserToken(state), isReviewer: currentUserIsReviewer(state, collectionId), })), withState('fetching', 'setFetching', false), - withHandlers({ - createAnchorElement: () => (file, filename) => { - const url = URL.createObjectURL(file) - const a = document.createElement('a') - - a.href = url - a.download = filename - document.body.appendChild(a) - - return { - a, - url, - } - }, - removeAnchorElement: () => (a, url) => { - document.body.removeChild(a) - URL.revokeObjectURL(url) - }, - }), - withHandlers({ - downloadFiles: ({ - token, - isReviewer, - fragmentId, - setFetching, - archiveName, - createAnchorElement, - removeAnchorElement, - }) => () => { - const getUrl = `${ - window.location.origin - }/api/files/${fragmentId}?${qs.stringify({ - fileTypes: isReviewer ? reviewerFiles : defaultFiles, - })}` - if (cache[fragmentId]) { - const fileName = archiveName || `${fragmentId}-archive.zip` - - const { a, url } = createAnchorElement(cache[fragmentId], fileName) - a.click() - removeAnchorElement(a, url) - } else { - setFetching(fetching => true) - const xhr = new XMLHttpRequest() - xhr.onreadystatechange = function onXhrStateChange() { - if (this.readyState === 4) { - setFetching(fetching => false) - if (this.status >= 200 && this.status < 300) { - const fileName = archiveName || `${fragmentId}-archive.zip` - const f = new File([this.response], fileName, { - type: 'application/zip', - }) - cache[fragmentId] = f - - const { a, url } = createAnchorElement(f, fileName) - a.click() - removeAnchorElement(a, url) - } - } - } - xhr.open('GET', getUrl) - xhr.responseType = 'blob' - xhr.setRequestHeader('Authorization', `Bearer ${token}`) - xhr.send() - } - }, - }), -)(ZipFiles) - -DownloadZipFiles.propTypes = { - disabled: PropTypes.bool, - archiveName: PropTypes.string, - fragmentId: PropTypes.string.isRequired, -} - -DownloadZipFiles.defaultProps = { - disabled: false, -} - -export default DownloadZipFiles + withZipDownload, +)(DownloadZipFiles) diff --git a/packages/component-faraday-ui/src/ManuscriptCard.js b/packages/component-faraday-ui/src/ManuscriptCard.js index 69060affa4868d517fb19e379c03817650e3bb4f..4fbaf55e081576ed335a99d45fe22e0627f81242 100644 --- a/packages/component-faraday-ui/src/ManuscriptCard.js +++ b/packages/component-faraday-ui/src/ManuscriptCard.js @@ -1,7 +1,6 @@ import React from 'react' -import moment from 'moment' import { get } from 'lodash' -import { H3, H4 } from '@pubsweet/ui' +import { H3, H4, DateParser } from '@pubsweet/ui' import styled from 'styled-components' import { th } from '@pubsweet/ui-toolkit' import { withJournal } from 'xpub-journal' @@ -21,7 +20,6 @@ import { import { OpenModal } from './modals' const ManuscriptCard = ({ - submitDate, onCardClick, onDelete, canDelete, @@ -47,9 +45,16 @@ const ManuscriptCard = ({ )} <Row alignItems="center" justify="flex-start" mb={1}> <Text customId mr={1}>{`ID ${customId}`}</Text> - <Text mr={3} secondary> - {submitDate} - </Text> + <DateParser + durationThreshold={0} + timestamp={fragment.submitted || ''} + > + {timestamp => ( + <Text mr={3} secondary> + Submitted on {timestamp} + </Text> + )} + </DateParser> <H4>{manuscriptType.label || type}</H4> <Text ml={1} secondary> {journal} @@ -97,13 +102,10 @@ export default compose( }), withProps( ({ - fragment: { submitted, metadata }, + fragment: { metadata }, journal = {}, collection: { status = 'draft' }, }) => ({ - submitDate: submitted - ? `Submitted on ${moment(submitted).format('DD.MM.YYYY')}` - : '', manuscriptType: get(journal, 'manuscriptTypes', []).find( t => t.value === get(metadata, 'type', ''), ), diff --git a/packages/component-faraday-ui/src/ManuscriptDetailsTop.js b/packages/component-faraday-ui/src/ManuscriptDetailsTop.js index 2ddbca724b9f74267e28eb4efc4d8cd99d308c6e..b8409fd1d38455ba1a356e5d715d3d002c8666e7 100644 --- a/packages/component-faraday-ui/src/ManuscriptDetailsTop.js +++ b/packages/component-faraday-ui/src/ManuscriptDetailsTop.js @@ -1,21 +1,23 @@ import React from 'react' import { Row, + Item, ActionLink, - DateParser, IconButton, DownloadZipFiles, ManuscriptVersion, + Text, } from 'pubsweet-component-faraday-ui' +import { DateParser } from '@pubsweet/ui' const ManuscriptDetailsTop = ({ history, collection = {}, fragment = {} }) => ( <Row alignItems="center" mb={1}> - <Row alignItems="center" justify="flex-start"> + <Item alignItems="center" justify="flex-start"> <ActionLink icon="arrow-left" onClick={() => history.push('/')}> Dashboard </ActionLink> - </Row> - <Row alignItems="center" justify="flex-end"> + </Item> + <Item alignItems="center" justify="flex-end"> <DownloadZipFiles archiveName={`ID-${collection.customId}`} collectionId={collection.id} @@ -23,9 +25,11 @@ const ManuscriptDetailsTop = ({ history, collection = {}, fragment = {} }) => ( > <IconButton icon="download" /> </DownloadZipFiles> - <DateParser date={fragment.submitted} label="Updated on" /> + <DateParser durationThreshold={0} timestamp={fragment.submitted || ''}> + {timestamp => <Text mr={1}>Updated on {timestamp}</Text>} + </DateParser> <ManuscriptVersion collection={collection} fragment={fragment} /> - </Row> + </Item> </Row> ) diff --git a/packages/component-faraday-ui/src/PersonInfo.js b/packages/component-faraday-ui/src/PersonInfo.js index c3fb7835d565d63f6904d329f5b1f5c26e840e7c..fbf87496c6675126ec17a2ae3fe221dfd0977601 100644 --- a/packages/component-faraday-ui/src/PersonInfo.js +++ b/packages/component-faraday-ui/src/PersonInfo.js @@ -17,15 +17,15 @@ const PersonInfo = ({ person: { email, firstName, lastName, affiliation } = defaultPerson, }) => ( <Row> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label>Email</Label> <Text>{email}</Text> </Item> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label>First name</Label> <Text>{firstName}</Text> </Item> - <Item vertical withRightMargin> + <Item mr={1} vertical> <Label>Last name</Label> <Text>{lastName}</Text> </Item> diff --git a/packages/component-faraday-ui/src/gridItems/Item.js b/packages/component-faraday-ui/src/gridItems/Item.js index 780a1125f49da355bb7f0b988be7a0d8c04046c3..ff1e97565e920f624c7891ee064867cf61cc7425 100644 --- a/packages/component-faraday-ui/src/gridItems/Item.js +++ b/packages/component-faraday-ui/src/gridItems/Item.js @@ -1,6 +1,7 @@ import { isNumber } from 'lodash' import styled from 'styled-components' -import { th } from '@pubsweet/ui-toolkit' + +import { marginHelper } from 'pubsweet-component-faraday-ui' /** @component */ export default styled.div.attrs({ @@ -10,6 +11,6 @@ export default styled.div.attrs({ flex: ${({ flex }) => (isNumber(flex) ? flex : 1)}; flex-direction: ${({ vertical }) => (vertical ? 'column' : 'row')}; justify-content: ${({ justify }) => justify || 'initial'}; - margin-right: ${({ withRightMargin }) => - withRightMargin ? th('gridUnit') : 0}; + align-items: ${({ alignItems }) => alignItems || 'flex-start'}; + ${marginHelper}; ` diff --git a/packages/component-faraday-ui/src/helpers/index.js b/packages/component-faraday-ui/src/helpers/index.js index fdb100ed3c6ae307c079422034d3a5d61a359863..63fc161e32f2d37c749fec068c92dd09189b96a0 100644 --- a/packages/component-faraday-ui/src/helpers/index.js +++ b/packages/component-faraday-ui/src/helpers/index.js @@ -1,7 +1,7 @@ import * as validators from './formValidators' export { default as withFilePreview } from './withFilePreview' -export { default as withFileDownload } from './withFileDownload' +export * from './withFileDownload' export { default as withNativeFileDrop } from './withNativeFileDrop' export { default as withFileSectionDrop } from './withFileSectionDrop' diff --git a/packages/component-faraday-ui/src/helpers/withFileDownload.js b/packages/component-faraday-ui/src/helpers/withFileDownload.js index 132ad70c96698851eef1ab8f1836d926a9835d11..8ed0e5fac29b49e451b257208f9a20ab446a8747 100644 --- a/packages/component-faraday-ui/src/helpers/withFileDownload.js +++ b/packages/component-faraday-ui/src/helpers/withFileDownload.js @@ -1,6 +1,10 @@ import qs from 'querystring' import { withHandlers } from 'recompose' +const cache = {} +const reviewerFiles = ['manuscripts', 'supplementary'] +const defaultFiles = [...reviewerFiles, 'coverLetter'] + const createAnchorElement = (file, filename) => { const url = URL.createObjectURL(file) const a = document.createElement('a') @@ -20,7 +24,7 @@ const removeAnchorElement = (a, url) => { URL.revokeObjectURL(url) } -export default withHandlers({ +export const withFileDownload = withHandlers({ downloadFile: () => ({ fileId, token, fileName = 'file' }) => { if (!token) return @@ -48,3 +52,49 @@ export default withHandlers({ xhr.send() }, }) + +export const withZipDownload = withHandlers({ + downloadFiles: ({ + token, + isReviewer, + fragmentId, + setFetching, + archiveName, + }) => () => { + const getUrl = `${ + window.location.origin + }/api/files/${fragmentId}?${qs.stringify({ + fileTypes: isReviewer ? reviewerFiles : defaultFiles, + })}` + if (cache[fragmentId]) { + const fileName = archiveName || `${fragmentId}-archive.zip` + + const { a, url } = createAnchorElement(cache[fragmentId], fileName) + a.click() + removeAnchorElement(a, url) + } else { + setFetching(fetching => true) + const xhr = new XMLHttpRequest() + xhr.onreadystatechange = function onXhrStateChange() { + if (this.readyState === 4) { + setFetching(fetching => false) + if (this.status >= 200 && this.status < 300) { + const fileName = archiveName || `${fragmentId}-archive.zip` + const f = new File([this.response], fileName, { + type: 'application/zip', + }) + cache[fragmentId] = f + + const { a, url } = createAnchorElement(f, fileName) + a.click() + removeAnchorElement(a, url) + } + } + } + xhr.open('GET', getUrl) + xhr.responseType = 'blob' + xhr.setRequestHeader('Authorization', `Bearer ${token}`) + xhr.send() + } + }, +}) diff --git a/packages/component-faraday-ui/src/index.js b/packages/component-faraday-ui/src/index.js index 5265ed1692701c22ca6862324403566bf11ebf1b..118583283e1f10934ff3fb596c01f9e3d60837c3 100644 --- a/packages/component-faraday-ui/src/index.js +++ b/packages/component-faraday-ui/src/index.js @@ -21,7 +21,6 @@ export { default as Tag } from './Tag' export { default as Text } from './Text' export { default as WizardAuthors } from './WizardAuthors' export { default as WizardFiles } from './WizardFiles' -export { default as DateParser } from './DateParser' export { default as DownloadZipFiles } from './DownloadZipFiles' // Manuscript Details diff --git a/packages/component-wizard/src/components/StepTwo.js b/packages/component-wizard/src/components/StepTwo.js index cf9e7586195ebc70b29cc3da8fa1e7d7b5dc8beb..71c6ad520c544f057a16df405c5ae03696d6da27 100644 --- a/packages/component-wizard/src/components/StepTwo.js +++ b/packages/component-wizard/src/components/StepTwo.js @@ -37,7 +37,7 @@ const StepTwo = ({ </Row> <Row mb={1}> - <Item data-test-id="submission-title" flex={3} vertical withRightMargin> + <Item data-test-id="submission-title" flex={3} mr={1} vertical> <Label required>MANUSCRIPT TITLE</Label> <ValidatedField component={TextField} diff --git a/packages/components-faraday/src/components/Dashboard/DashboardFilters.js b/packages/components-faraday/src/components/Dashboard/DashboardFilters.js index aea159fd763b3196a879c27a6a9b279b3569ec5b..e6270636c733b30f9096973d68a63f7a354385eb 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardFilters.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardFilters.js @@ -12,7 +12,7 @@ const DashboardFilters = ({ <Text mr={1} pb={1} secondary> Filters </Text> - <Item flex={0} vertical withRightMargin> + <Item flex={0} mr={1} vertical> <Label>Priority</Label> <Menu inline diff --git a/packages/components-faraday/src/components/Dashboard/DashboardItems.js b/packages/components-faraday/src/components/Dashboard/DashboardItems.js index 28a48894ab6b556655ba7feb34bec25fbaf5b6dd..7ff466590403b75f9299f30296a5fd3bf3edd322 100644 --- a/packages/components-faraday/src/components/Dashboard/DashboardItems.js +++ b/packages/components-faraday/src/components/Dashboard/DashboardItems.js @@ -14,7 +14,7 @@ const DashboardItems = ({ onClick, list, deleteProject }) => ( <Root> {!list.length ? ( <Row justify="center" mt={4}> - <H3>Nothing to do at the moment. Please upload a manuscript.</H3> + <H3>Manuscripts will appear here!</H3> </Row> ) : ( list.map(collection => (