diff --git a/actions/localConfig.js b/actions/localConfig.js index ced9104a9..22bb041d5 100644 --- a/actions/localConfig.js +++ b/actions/localConfig.js @@ -14,6 +14,7 @@ export const LOCAL_CONFIG_LOADED = 'LOCAL_CONFIG_LOADED'; export const SET_STARTUP_PARAMETERS = 'SET_STARTUP_PARAMETERS'; export const SET_COLOR_SCHEME = 'SET_COLOR_SCHEME'; export const SET_USER_INFO_FIELDS = 'SET_USER_INFO_FIELDS'; +export const SET_PERMALINK_PARAMETERS = 'SET_PERMALINK_PARAMETERS'; export function localConfigLoaded(config) { return { @@ -43,3 +44,10 @@ export function setUserInfoFields(fields) { fields }; } + +export function setPermalinkParameters(params) { + return { + type: SET_PERMALINK_PARAMETERS, + params + }; +} diff --git a/plugins/MapFilter.jsx b/plugins/MapFilter.jsx index 9095ad124..b745a63b1 100644 --- a/plugins/MapFilter.jsx +++ b/plugins/MapFilter.jsx @@ -74,6 +74,7 @@ class MapFilter extends React.Component { position: PropTypes.number, setCurrentTask: PropTypes.func, setFilter: PropTypes.func, + setPermalinkParameters: PropTypes.func, /** The side of the application on which to display the sidebar. */ side: PropTypes.string, startupParams: PropTypes.object, @@ -86,7 +87,6 @@ class MapFilter extends React.Component { }; state = { filters: {}, - timeFilter: null, geomFilter: {} }; componentDidUpdate(prevProps, prevState) { @@ -170,6 +170,13 @@ class MapFilter extends React.Component { } }, {}); this.props.setFilter(layerExpressions, this.state.geomFilter.geom); + const permalinkState = Object.entries(this.state.filters).reduce((res, [key, value]) => { + return {...res, [key]: value.values}; + }, {}); + if (this.state.geomFilter.geom) { + permalinkState.__geomfilter = this.state.geomFilter.geom.coordinates; + } + this.props.setPermalinkParameters({f: JSON.stringify(permalinkState)}); } } buildTimeFilter = (layer, filters) => { @@ -408,5 +415,6 @@ export default connect((state) => ({ startupParams: state.localConfig.startupParams }), { setFilter: setFilter, - setCurrentTask: setCurrentTask + setCurrentTask: setCurrentTask, + setPermalinkParameters: setPermalinkParameters })(MapFilter); diff --git a/reducers/localConfig.js b/reducers/localConfig.js index 313cc66b0..d836fa9a5 100644 --- a/reducers/localConfig.js +++ b/reducers/localConfig.js @@ -7,7 +7,7 @@ * LICENSE file in the root directory of this source tree. */ -import {LOCAL_CONFIG_LOADED, SET_STARTUP_PARAMETERS, SET_COLOR_SCHEME, SET_USER_INFO_FIELDS} from '../actions/localConfig'; +import {LOCAL_CONFIG_LOADED, SET_STARTUP_PARAMETERS, SET_COLOR_SCHEME, SET_USER_INFO_FIELDS, SET_PERMALINK_PARAMETERS} from '../actions/localConfig'; import ConfigUtils from '../utils/ConfigUtils'; import {UrlParams} from '../utils/PermaLinkUtils'; @@ -15,6 +15,7 @@ import {UrlParams} from '../utils/PermaLinkUtils'; const defaultState = { ...ConfigUtils.getDefaults(), startupParams: {}, + permalinkParams: {}, colorScheme: 'default' }; @@ -52,6 +53,17 @@ export default function localConfig(state = defaultState, action) { } }; } + case SET_PERMALINK_PARAMETERS: { + return { + ...state, + permalinkParams: Object.entries({...state.permalinkParams, ...action.params}).reduce((res, [key, value]) => { + if (value !== undefined) { + res[key] = value; + } + return res; + }, {}) + }; + } default: return state; } diff --git a/utils/PermaLinkUtils.js b/utils/PermaLinkUtils.js index bc735208d..ca383c657 100644 --- a/utils/PermaLinkUtils.js +++ b/utils/PermaLinkUtils.js @@ -100,6 +100,7 @@ export function generatePermaLink(state, callback, user = false) { .map(entry => ({...entry.layer, pos: entry.pos})); permalinkState.layers = redliningLayers; } + permalinkState.permalinkParams = state.localConfig.permalinkParams; permalinkState.url = fullUrl; const route = user ? "userpermalink" : "createpermalink"; axios.post(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/" + route, permalinkState) @@ -114,7 +115,7 @@ export function resolvePermaLink(initialParams, callback) { axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/resolvepermalink?key=" + key) .then(response => { const data = response.data; - callback({...initialParams, ...(data.query || {})}, data.state || {}, !!data.query); + callback({...initialParams, ...(data.query || {}), ...(data.state.permalinkParams || {})}, data.state || {}, !!data.query); }) .catch(() => { callback(initialParams, {}, false); @@ -123,7 +124,7 @@ export function resolvePermaLink(initialParams, callback) { axios.get(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/bookmarks/" + bkey) .then(response => { const data = response.data; - callback({...initialParams, ...(data.query || {})}, (data.state || {}), !!data.query); + callback({...initialParams, ...(data.query || {}), ...(data.state.permalinkParams || {})}, (data.state || {}), !!data.query); }) .catch(() => { callback(initialParams, {}, false); @@ -170,6 +171,7 @@ export function createBookmark(state, description, callback) { .map(entry => ({...entry.layer, pos: entry.pos})); bookmarkState.layers = redliningLayers; } + bookmarkState.permalinkParams = state.localConfig.permalinkParams; bookmarkState.url = UrlParams.getFullUrl(); axios.post(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/bookmarks/" + "?description=" + description, bookmarkState) @@ -193,6 +195,7 @@ export function updateBookmark(state, bkey, description, callback) { .map(entry => ({...entry.layer, pos: entry.pos})); bookmarkState.layers = redliningLayers; } + bookmarkState.permalinkParams = state.localConfig.permalinkParams; bookmarkState.url = UrlParams.getFullUrl(); axios.put(ConfigUtils.getConfigProp("permalinkServiceUrl").replace(/\/$/, '') + "/bookmarks/" + bkey + "?description=" + description, bookmarkState)