Commit 36b2def1 authored by Danjela Shehi's avatar Danjela Shehi
Browse files

refactor(client): make metadata form to save

parent 1b5da588
Pipeline #18620 failed with stage
......@@ -6,7 +6,8 @@ type Book {
divisions: [Division]!
bookComponents: [BookComponent]
parts: [BookComponent]
file: File
fileCover: File
fileAbstract: File
organisation: Organisation
teams: [BookTeam]
title: String!
......@@ -41,6 +42,7 @@ type BookTeamMember {
type MetadataBook {
author: [MetadataBookUser]
editor: [MetadataBookUser]
catalogId: String
language: String
pub_date: DateTime
pub_loc: String
......@@ -48,11 +50,21 @@ type MetadataBook {
copyrightStatement: String
copyrightYear: String
copyrightHolder: String
openAccess: String
openAccess: Boolean
licenceType: String
otherLicenceType: String
licenceStatement: String
nlmId: String
ccLicenseType: String
otherLicenseType: String
licenseStatement: String
publicationType: String
custom: Custom
}
type Custom {
bookSourceType: String
value: String
}
type MetadataBookUser {
......@@ -129,6 +141,8 @@ input CreateBookInput {
input UpdateInput {
title: String
fileCover: Upload
fileAbstract: Upload
subTitle: String
altTitle: String
edition: String
......@@ -136,8 +150,6 @@ input UpdateInput {
abstractTitle: String
metadata: MetadataBookInput
settings: SettingsBookInput
fileId: ID
file: Upload
domain: String
collections: [ID]
}
......@@ -152,11 +164,22 @@ input MetadataBookInput {
copyrightStatement: String
copyrightYear: String
copyrightHolder: String
openAccess: String
catalogId: String
ccLicenseType: String
otherLicenseType: String
licenseStatement: String
publicationType: String
openAccess: Boolean
licenceType: String
otherLicenceType: String
licenceStatement: String
nlmId: String
custom: CustomInput
}
input CustomInput {
bookSourceType: String
value: String
}
input MetadataBookUserInput {
......
......@@ -34,7 +34,7 @@ const getBook = async (_, args, ctx) => {
const book = await (await Book.query().findOne({ id })).getDivisions()
const { file } = await book.getFile()
const { fileCover } = await book.getFile()
let bookComponents = flatten(
book.divisions.map(division => division.bookComponents),
......@@ -51,7 +51,7 @@ const getBook = async (_, args, ctx) => {
bookComponents = bookComponents.slice(start, limit)
return { ...book, bookComponents, file }
return { ...book, bookComponents, fileCover }
}
const updateBook = async (_, { id, input }, ctx) => {
......
......@@ -99,7 +99,7 @@ class Book extends BaseModel {
copyrightStatement: '',
copyrightYear: '',
copyrightHolder: '',
openAccess: '',
openAccess: null,
licenceType: '',
otherLicenceType: '',
licenceStatement: '',
......@@ -192,7 +192,7 @@ class Book extends BaseModel {
type: ['string', 'null'],
},
openAccess: {
type: ['string', 'null'],
type: ['boolean', 'null'],
},
licenceType: {
type: ['string', 'null'],
......
......@@ -193,7 +193,7 @@ const Basic = ({
{errors?.title ? <ErrorText>{errors?.title}</ErrorText> : null}
<br />
<label>Subtitle</label>
{MemorizedWaxField('subtitle', values.subtitle, 'inline')}
{MemorizedWaxField('subTitle', values.subTitle, 'inline')}
{errors?.subtitle ? (
<ErrorText>{errors?.subtitle}</ErrorText>
) : null}
......@@ -228,7 +228,7 @@ const Basic = ({
<Field
component={TextFieldComponent}
label="NLM Catalog ID"
name="catalogId"
name="metadata.catalogId"
readonly={editMode}
required
/>
......
......@@ -5,7 +5,7 @@
import React, { useState, useRef } from 'react'
import { useMutation } from '@apollo/client'
import styled from 'styled-components'
import { Action as ActionButton, ErrorText } from '@pubsweet/ui'
import { Action as ActionButton } from '@pubsweet/ui'
import { th, darken } from '@pubsweet/ui-toolkit'
import { omit, cloneDeep } from 'lodash'
import {
......@@ -42,16 +42,17 @@ export default ({ book }) => {
const fullDataObject = {
title: book.title,
subtitle: book.subtitle,
subTitle: book.subTitle,
altTitle: book.altTitle,
edition: book.edition,
domain: book.domain,
catalogId: book.catalogId,
abstractTitle: book.abstractTitle,
abstract: book.abstract,
fileIdCover: book.fileIdCover,
fileId: book.fileId,
workflow: book.workflow,
metadata: {
catalogId: book.metadata.catalogId,
copyrightStatement: book.metadata.copyrightStatement,
copyrightHolder: book.metadata.copyrightHolder,
copyrightYear: book.metadata.copyrightYear,
......@@ -93,9 +94,6 @@ export default ({ book }) => {
Metadata: <BookTitle>{book.title}</BookTitle>
</ModalHeader>
<ModalBody noPadding>
<ErrorText>
Attention: This form is not functional yet, you can only see the UI
</ErrorText>
<DragAndDrop>
<BookMetadataTabs
book={bookData}
......@@ -110,7 +108,12 @@ export default ({ book }) => {
onClick={async () => {
const formData = await modalRef.current.triggerSave()
const submitData = omit(formData, ['settings'])
const submitData = omit(formData, [
'settings',
'workflow',
'fileIdCover',
'fileIdAbstract',
])
submitData.metadata.editor = formData.metadata.editor.map(item =>
omit(item, ['__typename', 'id']),
......@@ -123,42 +126,12 @@ export default ({ book }) => {
submitData.metadata = omit(submitData.metadata, [
'urlCover',
'urlAbstract',
'fileAbstract',
'fileCover',
])
// eslint-disable-next-line no-console
console.log(submitData)
if (bookData) {
updateBookMetadata({
update: (store, { data: { updateBook } }) => {
// const data = store.readQuery({
// query: query.GET_BOOK_USERS,
// variables: {
// id: updateBook.id,
// input: {
// skip: 0,
// sort: { direction: 'asc', field: ['username'] },
// take: 10,
// },
// },
// })
// data.getBook = Object.assign({}, data.getBook, {
// updateBook,
// })
// // Write our data back to the cache.
// store.writeQuery({
// data,
// query: query.GET_BOOK_USERS,
// variables: {
// id: book.id,
// input: {
// skip: 0,
// sort: { direction: 'asc', field: ['username'] },
// take: 10,
// },
// },
// })
},
variables: { id: book.id, input: submitData },
})
.catch(() => {
......@@ -177,7 +150,7 @@ export default ({ book }) => {
}}
status="primary"
>
{loading ? 'Saving' : 'Save'}{' '}
{loading ? 'Saving...' : 'Save'}
</Button>
<Button
......@@ -186,7 +159,7 @@ export default ({ book }) => {
outlined
status="primary"
>
Cancel
{loading ? 'Close' : 'Cancel'}
</Button>
</ModalFooter>
</Modal>
......
......@@ -200,10 +200,13 @@ const GET_BOOK_USERS = gql`
id
title
abstract
abstractTitle
subTitle
altTitle
edition
workflow
domain
file {
fileCover {
id
name
}
......@@ -382,10 +385,27 @@ const GET_BOOK_USERS = gql`
editor {
${editorAuthor}
}
catalogId
language
pub_date
pub_date
pub_loc
pub_name
copyrightStatement
copyrightYear
copyrightHolder
openAccess
licenceType
otherLicenceType
licenceStatement
nlmId
ccLicenseType
otherLicenseType
licenseStatement
publicationType
custom {
bookSourceType
value
}
}
}
}
......@@ -397,8 +417,9 @@ const UPDATE_BOOK = gql`
id
title
abstract
edition
file {
fileCover {
id
name
}
......
......@@ -63,8 +63,8 @@ const Basic = ({
const MemorizedWaxContent = MemorizedWax({
editorType: 'statement',
setFieldValue,
value: values.settings?.copyrightStatement,
name: 'settings.copyrightStatement',
value: values.metadata?.copyrightStatement,
name: 'metadata.copyrightStatement',
})
return (
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment