diff --git a/app/components/ConnectedNavigation.js b/app/components/ConnectedNavigation.js deleted file mode 100644 index 02bb463888231bb356c09543307d6316ee3208d9..0000000000000000000000000000000000000000 --- a/app/components/ConnectedNavigation.js +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' -import { get } from 'lodash' -import { adopt } from 'react-adopt' - -import CurrentUserQuery from './queries/currentUser' - -const mapper = { CurrentUserQuery } - -const mapProps = args => ({ - currentUser: get(args.CurrentUserQuery, 'data.currentUser'), - loading: args.CurrentUserQuery.loading, - client: args.CurrentUserQuery.client, -}) - -const Composed = adopt(mapper, mapProps) - -const Connected = WrappedComponent => props => ( - <Composed> - {({ loading, currentUser, client }) => { - if (loading) return 'Loading...' - return ( - <WrappedComponent - client={client} - currentUser={currentUser} - loading={loading} - {...props} - /> - ) - }} - </Composed> -) - -export default Connected diff --git a/app/components/Navigation/Navigation.jsx b/app/components/Navigation/Navigation.jsx deleted file mode 100644 index 32c725d78ecff427d96e37b4661073d1e596c7ed..0000000000000000000000000000000000000000 --- a/app/components/Navigation/Navigation.jsx +++ /dev/null @@ -1,92 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { withRouter } from 'react-router-dom' -import { compose, withProps } from 'recompose' -import { AppBar, Action } from '@pubsweet/ui' - -// TODO -- break into smaller components -class Navigation extends React.Component { - constructor(props) { - super(props) - this.collectionId = '' - this.inEditor = null - this.inPaged = null - } - - componentDidMount() { - this.shouldAddBookLink() - } - - componentWillUpdate() { - this.shouldAddBookLink() - } - - shouldAddBookLink() { - const { history } = this.props - const { location } = history - const { pathname } = location - - this.collectionId = '' - this.inEditor = null - this.inPaged = null - - this.inEditor = pathname.match(/bookComponents/g) - this.inPaged = pathname.match(/pagedPreviewer\/paged/g) - if (this.inEditor || this.inPaged) { - const pathnameSplitted = pathname.split('/') - this.collectionId = pathnameSplitted[2] // eslint-disable-line - } - } - - render() { - const { logoutUser, currentUser, client } = this.props - const links = [<Action to="/books">Books</Action>] - - if (currentUser === null) return null - - if (currentUser && currentUser.admin) { - links.push( - <Action to="/users">Users</Action>, - <Action to="/globalTeams">Global Teams </Action>, - ) - } - - if (this.inEditor || this.inPaged) { - links.push( - <Action to={`/books/${this.collectionId}/book-builder`}> - Back to book - </Action>, - ) - } - - // TODO -- fix object properties underneath - return ( - <div> - <AppBar - brand="Editoria" - navLinkComponents={links} - onLogoutClick={() => logoutUser(client)} - user={currentUser} - /> - </div> - ) - } -} - -Navigation.propTypes = { - client: PropTypes.any, // eslint-disable-line - currentUser: PropTypes.any, // eslint-disable-line - history: PropTypes.any.isRequired, // eslint-disable-line - logoutUser: PropTypes.func.isRequired, -} - -export default compose( - withRouter, - withProps(props => ({ - logoutUser: client => { - client.cache.reset() - localStorage.removeItem('token') - props.history.push('/login') - }, - })), -)(Navigation) diff --git a/app/components/Navigation/Navigation.local.scss b/app/components/Navigation/Navigation.local.scss deleted file mode 100644 index 5f1740754b970f3130f41feed7a6dc8b4ee7186e..0000000000000000000000000000000000000000 --- a/app/components/Navigation/Navigation.local.scss +++ /dev/null @@ -1,3 +0,0 @@ -.root { - font-style: italic; -} \ No newline at end of file diff --git a/app/components/PrivateRoute.jsx b/app/components/PrivateRoute.jsx deleted file mode 100644 index 808b39171c7530fa95337bf97da07c2dc6c7e096..0000000000000000000000000000000000000000 --- a/app/components/PrivateRoute.jsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { Route, Redirect, withRouter } from 'react-router-dom' -import { compose } from 'recompose' -import Connected from './ConnectedNavigation' - -const PrivateRoute = ({ currentUser, component: Component, ...rest }) => ( - <Route - render={props => { - if (currentUser) { - return <Component {...props} /> - } - - return ( - <Redirect - to={{ - pathname: '/login', - state: { from: props.location }, - }} - /> - ) - }} - {...rest} - /> -) - -PrivateRoute.propTypes = { - component: PropTypes.func.isRequired, - location: PropTypes.object.isRequired, // eslint-disable-line -} - -const ConnectedPrivateRoute = Connected(PrivateRoute) -export default compose(withRouter)(ConnectedPrivateRoute) diff --git a/app/components/queries/currentUser.js b/app/components/queries/currentUser.js deleted file mode 100644 index f81808e3e801cf82c23b02141dd789ff3ef07ef7..0000000000000000000000000000000000000000 --- a/app/components/queries/currentUser.js +++ /dev/null @@ -1,30 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' - -import { Query } from 'react-apollo' -import gql from 'graphql-tag' - -const CURRENT_USER = gql` - query CurrentUser { - currentUser { - id - username - admin - } - } -` - -const CurrentUserQuery = props => { - const { render } = props - return ( - <Query fetchPolicy="network-only" query={CURRENT_USER}> - {render} - </Query> - ) -} - -CurrentUserQuery.propTypes = { - render: PropTypes.any, // eslint-disable-line -} - -export default CurrentUserQuery diff --git a/app/routes.jsx b/app/routes.jsx index 5d9d9c777c76281a007f9cd39cdf07a3ec094ce4..bb4dc875a35351993d454206a711c205d9b75884 100644 --- a/app/routes.jsx +++ b/app/routes.jsx @@ -21,11 +21,11 @@ import Dashboard from 'pubsweet-component-editoria-dashboard/src/ConnectedDashbo import PagedStyler from 'pubsweet-component-bookbuilder/src/PagedStyler/PagedStyler' import Manage from 'pubsweet-component-manage/Manage' -import Navigation from './components/Navigation/Navigation' +import Navigation from 'pubsweet-component-editoria-navigation/src/Navigation' // import Navigation from './components/Navigation/Navbar' -import PrivateRoute from './components/PrivateRoute' +import PrivateRoute from 'pubsweet-component-editoria-navigation/src/PrivateRoute' -import Connected from './components/ConnectedNavigation' +import Connected from 'pubsweet-component-editoria-navigation/src/ConnectedNavigation' // Pass configuration to editor const Editor = WithConfig(Wax, { diff --git a/package.json b/package.json index dbe783fbc02434be186207cc941b0f87e8eac035..1e198ab2b8bb216acaff4a073a3cd2efa238de59 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "pubsweet-client": "^9.0.0", "pubsweet-component-bookbuilder": "^1.1.5", "pubsweet-component-editoria-dashboard": "^0.1.4", + "pubsweet-component-editoria-navigation": "^0.1.0", "pubsweet-component-editoria-global-teams": "^0.1.2", "pubsweet-component-epub": "^0.5.2", "pubsweet-component-epub-frontend": "^0.1.3", @@ -58,7 +59,6 @@ "pubsweet-theme-plugin": "^0.0.3", "react-beautiful-dnd":"^10.0.4", "react": "^16.2.0", - "react-adopt": "^0.6.0", "react-bootstrap": "0.32.1", "react-dnd": "2.5.4", "react-dnd-html5-backend": "2.5.4", diff --git a/scripts/seedGlobalTeams.js b/scripts/seedGlobalTeams.js index e94aca935b0272f66810cdd70d2cb17b77ea0a5e..4e41e26925f888d2a63334e98f24f1140d9c2bf1 100644 --- a/scripts/seedGlobalTeams.js +++ b/scripts/seedGlobalTeams.js @@ -7,8 +7,6 @@ const { }, } = require('editoria-data-model') -console.log(Team) - const makeTeam = async type => { const names = { productionEditor: 'Production Editor',