From 247a4d3d80dafd275ed29b7beae10df1f035af4f Mon Sep 17 00:00:00 2001 From: jPalmer Date: Tue, 28 Apr 2020 13:27:56 -0700 Subject: [PATCH] added user preference editor vs json mode --- src/App.css | 4 +++ src/Store.js | 2 ++ src/component/Home/HomeStyles.jsx | 30 ++++++++++++----------- src/component/LayerEdit/LayerEditJson.jsx | 9 +++++++ src/component/LayerEdit/LayerEditView.jsx | 9 +++++++ src/component/LayerEdit/index.jsx | 15 ++++++++++-- src/component/Map/MapMapbox.jsx | 7 +++--- src/component/Page/index.jsx | 2 ++ src/component/Style/StyleLayers.jsx | 4 +-- src/component/Style/StyleSources.jsx | 2 +- src/component/Style/index.jsx | 2 +- src/model/style/reducer.js | 2 +- 12 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/App.css b/src/App.css index 5bfab5a..74dc29c 100644 --- a/src/App.css +++ b/src/App.css @@ -139,6 +139,7 @@ label .badge{position:relative;top:2px;} .field-border-bottom{border-bottom:1px solid #BDBDBD;} .focus .field-border-bottom{border-bottom:1px solid #0687D1;} +.focus-layer-features{font-size:0.65rem;} .flex-2{flex:2;} @@ -293,6 +294,9 @@ label .badge{position:relative;top:2px;} .row-icon-right{position:absolute;right:0.25rem;top:0;} .row-icon-right-second{right:1.3rem;} +.search-option{color:#EDEFF1;padding:2px 2px 1px 2px;cursor:pointer;} +.search-option:hover{color:#FFF;} + .swatch{width:22px;height:22px;cursor:pointer;} .swatch:hover{border:1px solid #AEAEAE;} .swatch-flex{flex:1;height:18px;border:1px solid transparent;} diff --git a/src/Store.js b/src/Store.js index 5788623..497f0c8 100644 --- a/src/Store.js +++ b/src/Store.js @@ -2,12 +2,14 @@ import { applyMiddleware, combineReducers, createStore } from 'redux' import {reducer as app} from './model/app/reducer' import {reducer as map} from './model/map/reducer' +import {reducer as preference} from './model/preference/reducer' import {reducer as source} from './model/source/reducer' import {reducer as style} from './model/style/reducer' export const reducers = combineReducers({ app, map, + preference, source, style, }) diff --git a/src/component/Home/HomeStyles.jsx b/src/component/Home/HomeStyles.jsx index b996c28..dbe8b1e 100644 --- a/src/component/Home/HomeStyles.jsx +++ b/src/component/Home/HomeStyles.jsx @@ -43,26 +43,28 @@ class HomeStyles extends React.Component { const {styles} = this.props, {search, searchShow} = this.state + const handle = { + change: this.handleSearchChange + } + return (
{searchShow ? -
+
- +
-
this.handleSearchShowSet({show:false})}> +
this.handleSearchShowSet({show:false})}>
diff --git a/src/component/LayerEdit/LayerEditJson.jsx b/src/component/LayerEdit/LayerEditJson.jsx index a88d5d5..810777c 100644 --- a/src/component/LayerEdit/LayerEditJson.jsx +++ b/src/component/LayerEdit/LayerEditJson.jsx @@ -6,9 +6,18 @@ import {withRouter} from 'react-router-dom' import Field from '../Field' import modelStyle from '../../model/style' +import modelPreference from '../../model/preference' class LayerEditJson extends React.Component { + componentDidMount (){ + // set user preference to json + modelPreference.actions.setIn({ + path: ['editMode'], + value: 'json', + }) + } + handleChange = async ({value})=>{ const {history, path, layer} = this.props, {pathname} = this.props.location diff --git a/src/component/LayerEdit/LayerEditView.jsx b/src/component/LayerEdit/LayerEditView.jsx index 1be86ad..2bcae60 100644 --- a/src/component/LayerEdit/LayerEditView.jsx +++ b/src/component/LayerEdit/LayerEditView.jsx @@ -2,8 +2,17 @@ import React from 'react' import PropTypes from 'prop-types' import LayerEditGroup from './LayerEditGroup' +import modelPreference from '../../model/preference' class LayerEditView extends React.Component { + + componentDidMount (){ + // set user preference to json + modelPreference.actions.setIn({ + path: ['editMode'], + value: 'editor', + }) + } render (){ const {error, layer, path, style} = this.props diff --git a/src/component/LayerEdit/index.jsx b/src/component/LayerEdit/index.jsx index e04431f..7ffbaa9 100644 --- a/src/component/LayerEdit/index.jsx +++ b/src/component/LayerEdit/index.jsx @@ -11,6 +11,7 @@ import LayerEditJson from './LayerEditJson' import LayerEditView from './LayerEditView' import Tooltip from '../Tooltip' import modelMap from '../../model/map' +import modelPreference from '../../model/preference' import modelStyle from '../../model/style' class LayerEdit extends React.Component { @@ -30,9 +31,17 @@ class LayerEdit extends React.Component { } renderSection (){ - const {focusFeatures, error, match, layer, path, style} = this.props + const {editMode, focusFeatures, error, match, layer, path, style} = this.props + + let redirect + if (focusFeatures.length > 0){ + redirect = `${match.url}/features` + } else if (editMode === 'json'){ + redirect = `${match.url}/json` + } else { + redirect = `${match.url}/editor` + } - const redirect = (focusFeatures.length > 0)? `${match.url}/features` :`${match.url}/editor` return ( { const {layerId} = props return { + editMode: modelPreference.selectors.getIn(state, {path:['editMode']}), focusFeatures: modelMap.selectors.focusFeaturesByLayerId(state, {layerId}), layer: modelStyle.selectors.getIn(state, {path: props.path}), } diff --git a/src/component/Map/MapMapbox.jsx b/src/component/Map/MapMapbox.jsx index 7ba49a4..ec00acb 100644 --- a/src/component/Map/MapMapbox.jsx +++ b/src/component/Map/MapMapbox.jsx @@ -76,6 +76,7 @@ class MapMapbox extends React.Component { buildMap (){ const {accessTokens, style} = this.props + if (!style) return
if (this.map){ // tear down map @@ -386,10 +387,10 @@ MapMapbox.propTypes = { const mapStoreToProps = (store, props)=>{ const {style} = props return { - accessTokens: modelStyle.selectors.accessTokens(store, {styleId: style.get('id')}), + accessTokens: modelStyle.selectors.accessTokens(store, {styleId: style && style.get('id')}), accessTokenDeploy: modelMap.selectors.accessTokenDeploy(store), - domainHeaders: modelStyle.selectors.domainHeaders(store, {styleId: style.get('id')}), - featureStates: modelStyle.selectors.featureStates(store, {styleId: style.get('id')}), + domainHeaders: modelStyle.selectors.domainHeaders(store, {styleId: style && style.get('id')}), + featureStates: modelStyle.selectors.featureStates(store, {styleId: style && style.get('id')}), featureStateDeploy: modelMap.selectors.featureStateDeploy(store), } } diff --git a/src/component/Page/index.jsx b/src/component/Page/index.jsx index 9294d38..aa977c4 100644 --- a/src/component/Page/index.jsx +++ b/src/component/Page/index.jsx @@ -9,6 +9,7 @@ import Nav from './Nav' import Route from './Route' import modelApp from '../../model/app' +import modelPreference from '../../model/preference' import modelSource from '../../model/source' import modelStyle from '../../model/style' @@ -17,6 +18,7 @@ class Page extends React.Component { async componentDidMount(){ try{ await modelApp.actions.setLoading(true) + await modelPreference.actions.init() await modelStyle.actions.init() await modelSource.actions.init() await modelApp.actions.setLoading(false) diff --git a/src/component/Style/StyleLayers.jsx b/src/component/Style/StyleLayers.jsx index e672c92..e537449 100644 --- a/src/component/Style/StyleLayers.jsx +++ b/src/component/Style/StyleLayers.jsx @@ -96,7 +96,7 @@ class StyleLayers extends React.Component { value={search} />
-
this.handleSearchShowSet({show:false})}> +
this.handleSearchShowSet({show:false})}>
@@ -200,7 +200,7 @@ class StyleLayers extends React.Component { return (
- {focusLayers[layerId]} + {focusLayers[layerId]}
) } diff --git a/src/component/Style/StyleSources.jsx b/src/component/Style/StyleSources.jsx index b9203e5..0aa1bf6 100644 --- a/src/component/Style/StyleSources.jsx +++ b/src/component/Style/StyleSources.jsx @@ -61,7 +61,7 @@ class StyleSources extends React.Component { value={search} />
-
this.handleSearchShowSet({show:false})}> +
this.handleSearchShowSet({show:false})}>
diff --git a/src/component/Style/index.jsx b/src/component/Style/index.jsx index 649e33d..0250478 100644 --- a/src/component/Style/index.jsx +++ b/src/component/Style/index.jsx @@ -115,7 +115,7 @@ class Style extends React.Component { - {focusLayers && focusLayers.length > 0 && ( + {focusLayers && Object.keys(focusLayers).length > 0 && ( )} diff --git a/src/model/style/reducer.js b/src/model/style/reducer.js index bb693ce..6a2ff30 100644 --- a/src/model/style/reducer.js +++ b/src/model/style/reducer.js @@ -115,7 +115,7 @@ export const reducer = (st = state, action)=>{ }) } case 'STYLE_REMOVEIN':{ - const {path, value} = action.payload + const {path} = action.payload const styles = st.styles.removeIn(path) if (path.length < 3){ // changed whole style, no updated needed