Commit 02c84dd2 authored by Giannis Kopanas's avatar Giannis Kopanas Committed by Alexandros Georgantas

feat(applicationmanage): create query

parent 4e4081d1
// TO DO -- review foreign id and foreign type
const Base = require('../editoriaBase')
const { stringNotEmpty, object } = require('../helpers').schema
const BaseModel = require('@pubsweet/base-model')
const { stringNotEmpty } = require('../helpers').schema
class ApplicationParameter extends Base {
class ApplicationParameter extends BaseModel {
constructor(properties) {
super(properties)
this.type = 'applicationParameter'
}
static get tableName() {
return 'application_parameters'
return 'application_parameter'
}
static get schema() {
return {
type: 'object',
required: ['stringNotEmpty'],
properties: {
context: stringNotEmpty,
area: stringNotEmpty,
config: object,
config: {
type: ['object', 'array', 'boolean', 'string'],
},
},
}
}
......
......@@ -6,8 +6,8 @@ create table application_parameter (
updated timestamp with time zone,
--own
context text not null
area text not null
context text not null,
area text not null,
config jsonb
);
......
......@@ -3,11 +3,13 @@ import { get } from 'lodash'
import { adopt } from 'react-adopt'
import CurrentUserQuery from './queries/currentUser'
import ApplicationParameterQuery from './queries/applicationParameter'
const mapper = { CurrentUserQuery }
const mapper = { CurrentUserQuery, ApplicationParameterQuery }
const mapProps = args => ({
currentUser: get(args.CurrentUserQuery, 'data.currentUser'),
config: get(args.ApplicationParameterQuery, 'data.getApplicationParameters'),
loading: args.CurrentUserQuery.loading,
client: args.CurrentUserQuery.client,
})
......@@ -16,11 +18,12 @@ const Composed = adopt(mapper, mapProps)
const Connected = WrappedComponent => props => (
<Composed>
{({ loading, currentUser, client }) => {
{({ loading, currentUser, config, client }) => {
if (loading) return 'Loading...'
return (
<WrappedComponent
client={client}
config={config}
currentUser={currentUser}
loading={loading}
{...props}
......
......@@ -4,11 +4,18 @@ import { Route, Redirect, withRouter } from 'react-router-dom'
import { compose } from 'recompose'
import Connected from './ConnectedNavigation'
const PrivateRoute = ({ currentUser, component: Component, ...rest }) => (
const PrivateRoute = ({
currentUser,
config,
component: Component,
...rest
}) => (
<Route
render={props => {
if (currentUser) {
return <Component {...props} currentUser={currentUser} />
return (
<Component {...props} config={config} currentUser={currentUser} />
)
}
return (
......
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import gql from 'graphql-tag'
const APPLICATION_PARAMETER = gql`
query ApplicationParameter {
getApplicationParameters {
id
context
area
config
}
}
`
const ApplicationParameterQuery = props => {
const { render } = props
return (
<Query fetchPolicy="network-only" query={APPLICATION_PARAMETER}>
{render}
</Query>
)
}
ApplicationParameterQuery.propTypes = {
render: PropTypes.any, // eslint-disable-line
}
export default ApplicationParameterQuery
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