Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Revert "Merge pull request #368 from elifesciences/312-push-messages" #518

Merged
merged 2 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 25 additions & 36 deletions app/components/pages/SubmissionWizard/steps/Files/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import gql from 'graphql-tag'
import { Mutation, Subscription } from 'react-apollo'
import { Mutation } from 'react-apollo'
import FileUploads from './FileUploads'

const UPLOAD_MUTATION = gql`
mutation UploadFile($id: ID!, $file: Upload!, $fileSize: Int!) {
uploadManuscript(id: $id, file: $file, fileSize: $fileSize) {
mutation UploadFile($id: ID!, $file: Upload!) {
uploadManuscript(id: $id, file: $file) {
id
meta {
title
Expand All @@ -18,12 +18,6 @@ const UPLOAD_MUTATION = gql`
}
`

const ON_UPLOAD_PROGRESS = gql`
subscription {
uploadProgress
}
`

const FileUploadsPage = ({
setFieldValue,
errors,
Expand All @@ -35,33 +29,28 @@ const FileUploadsPage = ({
{(uploadFile, { loading, error: uploadError }) => {
const fieldName = 'files'
return (
<Subscription subscription={ON_UPLOAD_PROGRESS}>
{({ data: uploadData, loading: uploadLoading }) => (
<FileUploads
conversion={{
converting: loading,
// TODO import this constant from somewhere (data model package?)
completed: values[fieldName].some(
file => file.type === 'MANUSCRIPT_SOURCE',
),
progress: uploadLoading ? 0 : uploadData.uploadProgress,
error: uploadError,
}}
formError={errors[fieldName] && touched[fieldName]}
onDrop={([file]) =>
uploadFile({
variables: { file, id: values.id, fileSize: file.size },
}).then(({ data }) => {
setFieldValue('meta.title', data.uploadManuscript.meta.title)
setFieldValue(fieldName, data.uploadManuscript.files)
})
}
previewUrl={`/manuscript/${values.id}`}
setFieldValue={setFieldValue}
{...props}
/>
)}
</Subscription>
<FileUploads
conversion={{
converting: loading,
// TODO import this constant from somewhere (data model package?)
completed: values[fieldName].some(
file => file.type === 'MANUSCRIPT_SOURCE',
),
error: uploadError,
}}
formError={errors[fieldName] && touched[fieldName]}
onDrop={([file]) =>
uploadFile({
variables: { file, id: values.id },
}).then(({ data }) => {
setFieldValue('meta.title', data.uploadManuscript.meta.title)
setFieldValue(fieldName, data.uploadManuscript.files)
})
}
previewUrl={`/manuscript/${values.id}`}
setFieldValue={setFieldValue}
{...props}
/>
)
}}
</Mutation>
Expand Down
5 changes: 2 additions & 3 deletions app/components/ui/molecules/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const DropzoneContent = ({
if (conversion.converting) {
return (
<React.Fragment>
<StyledUploadIcon percentage={conversion.progress} />
<StyledUploadIcon />
<Instruction data-test-id="dropzoneMessage">
Manuscript is uploading {conversion.progress}%
Manuscript is uploading
</Instruction>
</React.Fragment>
)
Expand Down Expand Up @@ -177,7 +177,6 @@ FileUpload.propTypes = {
completed: PropTypes.bool,
error: PropTypes.instanceOf(Error),
converting: PropTypes.bool,
progress: PropTypes.number,
}),
formError: PropTypes.bool,
}
Expand Down
6 changes: 2 additions & 4 deletions app/components/ui/molecules/FileUpload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ it('displays success if conversion.completed is set', () => {
expect(dropzoneContentWrapper.text()).toBe(manuscriptUploadSuccess)
})

// TODO fix this tests to account for upload %
it.skip('displays uploading if conversion.converting is set', () => {
it('displays uploading if conversion.converting is set', () => {
const dropzoneContentWrapper = makeCheerioWrapper({
conversion: { converting: true },
})
expect(dropzoneContentWrapper.text()).toBe(manuscriptUploading)
})

// TODO fix these tests to account for upload %
it.skip('displays uploading even if there are errors', () => {
it('displays uploading even if there are errors', () => {
const dropzoneContentWrapper = makeCheerioWrapper({
conversion: { converting: true, error: new Error('Boo') },
formError: true,
Expand Down
1 change: 0 additions & 1 deletion config/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
baseUrl: deferConfig(
cfg => `http://localhost:${cfg['pubsweet-server'].port}`,
),
hostname: 'localhost',
secret: 'not very secret',
graphiql: true,
logger: winston,
Expand Down
18 changes: 1 addition & 17 deletions server/xpub/entities/manuscript/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const config = require('config')
const User = require('../user')
const {
getPubsub,
asyncIterators,
} = require('pubsweet-server/src/graphql/pubsub')
const mailer = require('@pubsweet/component-send-email')
const logger = require('@pubsweet/logger')
const request = require('request-promise-native')
Expand All @@ -14,8 +10,6 @@ const path = require('path')
const crypto = require('crypto')
const Joi = require('joi')

const { ON_UPLOAD_PROGRESS } = asyncIterators

const parseString = promisify(xml2js.parseString)
const randomBytes = promisify(crypto.randomBytes)
const uploadsPath = config.get('pubsweet-server').uploads
Expand Down Expand Up @@ -116,7 +110,7 @@ const resolvers = {
return manuscript
},

async uploadManuscript(_, { file, id, fileSize }, context) {
async uploadManuscript(_, { file, id }) {
const { stream, filename, mimetype } = await file

const manuscriptContainer = path.join(uploadsPath, id)
Expand All @@ -139,16 +133,6 @@ const resolvers = {
// save source file locally
const saveFileStream = fs.createWriteStream(manuscriptSourcePath)
stream.pipe(saveFileStream)

let uploadedSize = 0
const pubsub = await getPubsub()
stream.on('data', chunk => {
uploadedSize += chunk.length
const uploadProgress = Math.floor(uploadedSize * 100 / fileSize)
pubsub.publish(`${ON_UPLOAD_PROGRESS}.${context.user}`, {
uploadProgress,
})
})
const saveFilePromise = new Promise((resolve, reject) => {
saveFileStream.on('finish', () => resolve(true))
saveFileStream.on('error', reject)
Expand Down
10 changes: 3 additions & 7 deletions server/xpub/entities/manuscript/resolvers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ describe('Submission', () => {
})

describe('uploadManuscript', () => {
// TODO subscribe to uploadProgress before this or mock
it.skip('extracts title from PDF', async () => {
it('extracts title from PDF', async () => {
const { id } = await Manuscript.save(Manuscript.new())
const file = {
filename: 'manuscript.pdf',
Expand All @@ -282,12 +281,9 @@ describe('Submission', () => {
),
encoding: 'utf8',
mimetype: 'application/pdf',
size: 73947,
}
const manuscript = await Mutation.uploadManuscript(
{},
{ id, file, fileSize: file.size },
)

const manuscript = await Mutation.uploadManuscript({}, { id, file })
expect(manuscript).toMatchObject({
id,
meta: {
Expand Down
2 changes: 1 addition & 1 deletion server/xpub/entities/manuscript/typeDefs.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extend type Mutation {
createSubmission: Manuscript!
deleteManuscript(id: ID!): ID!
updateSubmission(data: ManuscriptInput!, isAutoSave: Boolean): Manuscript!
uploadManuscript(id: ID!, file: Upload!, fileSize: Int!): Manuscript!
uploadManuscript(id: ID!, file: Upload!): Manuscript!
finishSubmission(data: ManuscriptInput!): Manuscript!
}

Expand Down
1 change: 0 additions & 1 deletion server/xpub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"apollo-boost": "^0.1.13",
"config": "^2.0.1",
"fs-extra": "^7.0.0",
"graphql-subscriptions": "^0.5.8",
"graphql-tag": "^2.8.0",
"joi": "^13.6.0",
"lodash": "^4.17.5",
Expand Down
Loading