Commit 47b35387 authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

fix(applicationparameters): rename config to applicationmanager props everywhere

parent 3cc4f832
......@@ -19,23 +19,23 @@ const getApplicationParameters = async (_, args, ctx) => {
return parameters
}
// const updateApplicationParameter = async (_, args, ctx) => {
// const { context, area, config } = args
const updateApplicationParameters = async (_, { input }, ctx) => {
const { context, area, config } = input
// const parameter = await ApplicationParameter.query().findOne({
// context,
// area,
// })
const parameter = await ApplicationParameter.query().findOne({
context,
area,
})
// const updatedParameter = await parameter.$query().updateAndFetch({ config })
// return updatedParameter
// }
const updatedParameter = await parameter.$query().updateAndFetch({ config })
return updatedParameter
}
module.exports = {
Query: {
getApplicationParameters,
},
// Mutation: {
// updateApplicationParameter,
// },
Mutation: {
updateApplicationParameters,
},
}
......@@ -71,13 +71,14 @@ export class BookBuilder extends React.Component {
render() {
const {
book,
config,
applicationParameter,
history,
addBookComponent,
onMetadataAdd,
addBookComponents,
currentUser,
deleteBookComponent,
updateApplicationParameters,
updateBookComponentPagination,
updateBookComponentOrder,
updateBookComponentWorkflowState,
......@@ -149,7 +150,7 @@ export class BookBuilder extends React.Component {
<Header bookTitle={book.title} actions={headerActions} />
<DivisionsArea
addBookComponent={addBookComponent}
config={config}
applicationParameter={applicationParameter}
onWorkflowUpdate={onWorkflowUpdate}
addBookComponents={addBookComponents}
setState={setState}
......@@ -162,6 +163,7 @@ export class BookBuilder extends React.Component {
onDeleteBookComponent={onDeleteBookComponent}
divisions={divisions}
rules={rules}
updateApplicationParameters={updateApplicationParameters}
updateBookComponentContent={updateBookComponentContent}
updateBookComponentOrder={updateBookComponentOrder}
updateBookComponentPagination={updateBookComponentPagination}
......
......@@ -21,6 +21,7 @@ import {
updateBookComponentUploadingMutation,
unlockBookComponentMutation,
updateBookComponentTypeMutation,
updateApplicationParametersMutation,
exportBookMutation,
orderChangeSubscription,
bookComponentAddedSubscription,
......@@ -52,6 +53,7 @@ const mapper = {
updateBookComponentContentMutation,
updateBookComponentUploadingMutation,
ingestWordFilesMutation,
updateApplicationParametersMutation,
updateBookComponentTypeMutation,
exportBookMutation,
lockChangeSubscription,
......@@ -88,6 +90,8 @@ const mapProps = args => ({
updateBookComponentUploading:
args.updateBookComponentUploadingMutation.updateUploading,
updateComponentType: args.updateBookComponentTypeMutation.updateComponentType,
updateApplicationParameters:
args.updateApplicationParametersMutation.updateApplicationParameter,
updateBookMetadata: args.updateBookMetadataMutation.updateMetadata,
unlockBookComponent: args.unlockBookComponentMutation.unlockBookComponent,
ingestWordFiles: args.ingestWordFilesMutation.ingestWordFiles,
......@@ -257,7 +261,7 @@ const mapProps = args => ({
const Composed = adopt(mapper, mapProps)
const Connected = props => {
const { match, history, currentUser, config } = props
const { match, history, currentUser, applicationParameter } = props
const { id: bookId } = match.params
return (
......@@ -273,6 +277,7 @@ const Connected = props => {
updateBookComponentPagination,
updateBookComponentOrder,
updateComponentType,
updateApplicationParameters,
updateBookComponentWorkflowState,
onError,
onWarning,
......@@ -293,7 +298,7 @@ const Connected = props => {
return (
<BookBuilder
addBookComponent={addBookComponent}
config={config}
applicationParameter={applicationParameter}
state={state}
setState={setState}
addBookComponents={addBookComponents}
......@@ -317,6 +322,7 @@ const Connected = props => {
rules={rules}
updateBookComponentContent={updateBookComponentContent}
updateComponentType={updateComponentType}
updateApplicationParameters={updateApplicationParameters}
updateBookComponentOrder={updateBookComponentOrder}
updateBookComponentPagination={updateBookComponentPagination}
updateBookComponentUploading={updateBookComponentUploading}
......
......@@ -34,6 +34,11 @@ export { default as ingestWordFilesMutation } from './ingestWordFile'
export {
default as updateBookComponentTypeMutation,
} from './updateComponentType'
export {
default as updateApplicationParametersMutation,
} from './updateApplicationParameters'
export {
default as updateBookComponentUploadingMutation,
} from './updateUploading'
......
import React from 'react'
import { Mutation } from 'react-apollo'
import gql from 'graphql-tag'
const UPDATE_APPLICATION_PARAMETERS = gql`
mutation UpdateApplicationParameters($input: updateParametersInput!) {
updateApplicationParameters(input: $input) {
id
}
}
`
const updateApplicationParametersMutation = props => {
const { render } = props
return (
<Mutation mutation={UPDATE_APPLICATION_PARAMETERS}>
{(updateApplicationParameter, updateApplicationParameterResult) =>
render({
updateApplicationParameter,
updateApplicationParameterResult,
})
}
</Mutation>
)
}
export default updateApplicationParametersMutation
......@@ -163,7 +163,7 @@ const BookComponent = ({
onWarning,
connectDragSource,
connectDropTarget,
config,
applicationParameter,
currentUser,
history,
componentType,
......@@ -192,6 +192,7 @@ const BookComponent = ({
updateWorkflowState,
updateBookComponentContent,
updateComponentType,
updateApplicationParameters,
}) => {
const onUpdateComponentType = value => {
updateComponentType({
......@@ -204,6 +205,18 @@ const BookComponent = ({
})
}
const onAddComponentType = value => {
updateApplicationParameters({
variables: {
input: {
context: 'bookBuilder',
area: 'divisions',
config: value,
},
},
})
}
const icon = (
<svg
xmlns="http://www.w3.org/2000/svg"
......@@ -263,8 +276,9 @@ const BookComponent = ({
<ActionsLeft lock={lock}>
<GrabIcon {...provided.dragHandleProps}>{icon}</GrabIcon>
<ComponentTypeMenu
addComponentType={onAddComponentType}
applicationParameter={applicationParameter}
componentType={componentType}
config={config}
divisionType={divisionType}
onChange={onUpdateComponentType}
/>
......@@ -273,9 +287,9 @@ const BookComponent = ({
)} */}
</ActionsLeft>
<BookComponentTitle
applicationParameter={applicationParameter}
bookComponentId={id}
bookId={bookId}
config={config}
title={title}
divisionType={divisionType}
componentType={componentType}
......@@ -305,8 +319,8 @@ const BookComponent = ({
</FirstRow>
<SecondRow
applicationParameter={applicationParameter}
bookComponentId={id}
config={config}
onWorkflowUpdate={onWorkflowUpdate}
onWarning={onWarning}
bookId={bookId}
......
......@@ -58,7 +58,7 @@ const Title = styled.span`
const BookComponentTitle = ({
bookComponentId,
bookId,
config,
applicationParameter,
uploading,
lock,
history,
......@@ -72,7 +72,7 @@ const BookComponentTitle = ({
// history.push(`/books/${bookId}/bookComponents/${bookComponentId}`)
// }
const { config: divisions } = find(config, {
const { config: divisions } = find(applicationParameter, {
context: 'bookBuilder',
area: 'divisions',
})
......
import React from 'react'
import React, { useState } from 'react'
import styled, { css, keyframes } from 'styled-components'
import { find, map, groupBy, forEach } from 'lodash'
import { th } from '@pubsweet/ui-toolkit'
import { Action } from '@pubsweet/ui'
import { DefaultButton } from './Button'
import { Menu as UIMenu } from './Menu'
const AddTypeButton = styled(DefaultButton)`
padding: 10px;
transition: visibility 0.1s ease-in-out 0.1s;
`
const Input = styled.input`
border: 0;
margin: 10px;
/* line-height: 30px; */
font-family: 'Vollkorn';
color: #3f3f3f;
width: 100%;
font-size: ${th('fontSizeHeading4')};
border-bottom: 1px solid #3f3f3f;
line-height: ${th('lineHeightHeading4')};
outline: 0;
&:focus {
border-bottom: 1px solid #0964cc;
}
`
const triangle = css`
background: #3f3f3f;
content: ' ';
......@@ -15,6 +37,7 @@ const triangle = css`
width: 15px;
z-index: 200;
`
const rotate = keyframes`
from { transform: rotate(0deg);}
to { transform: rotate(360deg); }
......@@ -129,14 +152,13 @@ const triangleOption = css`
const Menu = styled(UIMenu)`
display: inline-flex;
div[role='listbox'] {
background: white;
> div:nth-child(2) {
left: 50%;
transform: translate(-50%, 0);
width: 120px;
width: 200px;
z-index: 100;
}
......@@ -148,7 +170,7 @@ const Menu = styled(UIMenu)`
overflow-y: unset;
position: relative;
text-transform: uppercase;
width: 120px;
width: 200px;
&::before {
${triangleUp}
......@@ -211,6 +233,11 @@ const OpenerWrapper = styled.div`
}
`
const AddMenu = styled.div`
display: flex;
flex-direction: row;
`
const Opener = props => {
const { toggleMenu } = props
......@@ -221,22 +248,62 @@ const Opener = props => {
)
}
const Footer = () => {
const Footer = (handleSave, divisions, divisionType) => () => {
const [text, setText] = useState(null)
const createJsonConfig = text => {
divisions.map(division => {
if (division.name === divisionType) {
division.allowedComponentTypes.push({
value: text.replace(/\s+/g, '_').toLowerCase(),
title: text,
predefined: false,
})
}
return division
})
return JSON.stringify(divisions)
}
const disabled = text.replace(/\s/g, '')
return (
<>
<hr />
1111
<AddMenu>
{text === null ? (
<AddTypeButton label="Add a new type" onClick={() => setText('')} />
) : (
<>
<Input
autoFocus
defaultValue={text}
id="addComponentType"
name="addComponentType"
onChange={event => setText(event.target.value)}
/>
<Action
disabled={disabled === ''}
onClick={() => handleSave(createJsonConfig(text))}
>
Save
</Action>
</>
)}
</AddMenu>
</>
)
}
const ComponentTypeMenu = ({
onChange,
addComponentType,
divisionType,
componentType,
config,
applicationParameter,
}) => {
const { config: divisions } = find(config, {
const { config: divisions } = find(applicationParameter, {
context: 'bookBuilder',
area: 'divisions',
})
......@@ -266,7 +333,7 @@ const ComponentTypeMenu = ({
<Menu
onChange={handleChangeComponentType}
options={options}
renderFooter={Footer}
renderFooter={Footer(addComponentType, divisions, divisionType)}
renderOpener={Opener}
value={componentType}
/>
......
......@@ -160,7 +160,7 @@ class Division extends React.Component {
render() {
const {
bookId,
config,
applicationParameter,
currentUser,
updateBookComponentUploading,
updateBookComponentContent,
......@@ -178,6 +178,7 @@ class Division extends React.Component {
update,
reorderingAllowed,
updateComponentType,
updateApplicationParameters,
rules,
} = this.props
......@@ -204,7 +205,7 @@ class Division extends React.Component {
<div ref={provided.innerRef} {...provided.draggableProps}>
<BookComponent
bookId={bookId}
config={config}
applicationParameter={applicationParameter}
onAdminUnlock={onAdminUnlock}
onWorkflowUpdate={onWorkflowUpdate}
currentUser={currentUser}
......@@ -234,6 +235,7 @@ class Division extends React.Component {
title={title}
trackChangesEnabled={trackChangesEnabled}
updateComponentType={updateComponentType}
updateApplicationParameters={updateApplicationParameters}
onWarning={onWarning}
updatePagination={this.onUpdatePagination}
updateWorkflowState={this.onUpdateWorkflowState}
......@@ -248,12 +250,12 @@ class Division extends React.Component {
)
})
const divisionsConfig = find(config, {
const { config: divisionsConfig } = find(applicationParameter, {
context: 'bookBuilder',
area: 'divisions',
})
const componentConfig = find(divisionsConfig.config, ['name', label])
const componentConfig = find(divisionsConfig, ['name', label])
let addButtons = null
......
......@@ -197,7 +197,7 @@ class DivisionsArea extends Component {
render() {
const {
bookId,
config,
applicationParameter,
currentUser,
history,
onWarning,
......@@ -205,6 +205,7 @@ class DivisionsArea extends Component {
addBookComponents,
deleteBookComponent,
onWorkflowUpdate,
updateApplicationParameters,
updateBookComponentPagination,
updateBookComponentOrder,
updateBookComponentWorkflowState,
......@@ -227,7 +228,7 @@ class DivisionsArea extends Component {
<Division
add={addBookComponent}
addBookComponents={addBookComponents}
config={config}
applicationParameter={applicationParameter}
onWorkflowUpdate={onWorkflowUpdate}
onAdminUnlock={onAdminUnlock}
currentUser={currentUser}
......@@ -245,6 +246,7 @@ class DivisionsArea extends Component {
showModal={showModal}
showModalToggle={showModalToggle}
reorderingAllowed={reorderingAllowed}
updateApplicationParameters={updateApplicationParameters}
updateBookComponentContent={updateBookComponentContent}
updateBookComponentOrder={updateBookComponentOrder}
updateBookComponentPagination={updateBookComponentPagination}
......
......@@ -136,7 +136,6 @@ const Options = styled.div`
border: ${th('borderWidth')} ${th('borderStyle')} ${th('colorBorder')};
border-radius: ${th('borderRadius')};
overflow-y: auto;
max-height: ${({ maxHeight }) => `${maxHeight}px`};
z-index: 100;
${override('ui.Menu.Options')};
......
......@@ -25,7 +25,7 @@ class SecondRow extends Component {
// this.toggleModal = this.toggleModal.bind(this)
this.progressValues = [-1, 0, 1]
this.progressOrder = []
const { config: stagesConfig } = find(props.config, {
const { config: stagesConfig } = find(props.applicationParameter, {
context: 'bookBuilder',
area: 'stages',
})
......@@ -37,14 +37,14 @@ class SecondRow extends Component {
updateStateList(title, type, value) {
const {
applicationParameter,
bookComponentId,
workflowStages,
updateWorkflowState,
onWorkflowUpdate,
config,
} = this.props
const { config: instanceConfig } = find(config, {
const { config: instanceConfig } = find(applicationParameter, {
context: 'bookBuilder',
area: 'instance',
})
......@@ -443,7 +443,7 @@ class SecondRow extends Component {
const {
bookId,
bookComponentId,
config,
applicationParameter,
onWarning,
componentType,
uploading,
......@@ -490,11 +490,11 @@ class SecondRow extends Component {
)}
{canViewStateList && (
<WorkflowList
applicationParameter={applicationParameter}
bookComponentStateRules={bookComponentStateRules.find(
stateRule => stateRule.bookComponentId === bookComponentId,
)}
bookId={bookId}
config={config}
currentValues={workflowStages}
update={this.updateStateList}
values={this.progressValues}
......
import React from 'react'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import WorkflowIndicator from './WorkflowIndicator'
import { ButtonWithoutLabel } from './Button'
import Label from './Label'
import Arrow from './Arrow'
......@@ -19,11 +17,11 @@ import Arrow from './Arrow'
// font-size: 13px;
// transition: visibility 0.1s ease-in-out 0.1s;
// `
const LabelArrow = styled.div`
font-size: ${th('fontSizeBase')};
line-height: ${th('lineHeightBase')};
padding-right: 4px;
`
// const LabelArrow = styled.div`
// font-size: ${th('fontSizeBase')};
// line-height: ${th('lineHeightBase')};
// padding-right: 4px;
// `
const FirstRow = styled.div`
display: flex;
position: absolute;
......
......@@ -20,7 +20,7 @@ const Container = styled.div`
`
const WorkflowList = ({
bookId,
config,
applicationParameter,
className,
currentValues,
update,
......@@ -30,7 +30,7 @@ const WorkflowList = ({
if (!bookComponentStateRules) return null
const { stage } = bookComponentStateRules
const { config: stageItems } = find(config, {
const { config: stageItems } = find(applicationParameter, {
context: 'bookBuilder',
area: 'stages',
})
......
......@@ -9,7 +9,10 @@ const mapper = { CurrentUserQuery, ApplicationParameterQuery }
const mapProps = args => ({
currentUser: get(args.CurrentUserQuery, 'data.currentUser'),
config: get(args.ApplicationParameterQuery, 'data.getApplicationParameters'),
applicationParameter: get(
args.ApplicationParameterQuery,
'data.getApplicationParameters',
),
loading: args.CurrentUserQuery.loading,
client: args.CurrentUserQuery.client,
})
......@@ -18,13 +21,13 @@ const Composed = adopt(mapper, mapProps)
const Connected = WrappedComponent => props => (
<Composed>
{({ loading, currentUser, config, client }) => {
{({ loading, currentUser, applicationParameter, client }) => {
if (loading) return 'Loading...'
return (
<WrappedComponent
applicationParameter={applicationParameter}
client={client}
config={config}
currentUser={currentUser}
loading={loading}
{...props}
......
......@@ -6,7 +6,7 @@ import Connected from './ConnectedNavigation'
const PrivateRoute = ({
currentUser,
config,
applicationParameter,
component: Component,
...rest
}) => (
......@@ -14,7 +14,11 @@ const PrivateRoute = ({
render={props => {
if (currentUser) {
return (
<Component {...props} config={config} currentUser={currentUser} />
<Component
{...props}
applicationParameter={applicationParameter}
currentUser={currentUser}
/>
)
}
......
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