Skip to content

Commit

Permalink
Store filter configuration in compact permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Feb 26, 2024
1 parent f19e886 commit cc725f5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
8 changes: 8 additions & 0 deletions actions/localConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -43,3 +44,10 @@ export function setUserInfoFields(fields) {
fields
};
}

export function setPermalinkParameters(params) {
return {
type: SET_PERMALINK_PARAMETERS,
params
};
}
12 changes: 10 additions & 2 deletions plugins/MapFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -86,7 +87,6 @@ class MapFilter extends React.Component {
};
state = {
filters: {},
timeFilter: null,
geomFilter: {}
};
componentDidUpdate(prevProps, prevState) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -408,5 +415,6 @@ export default connect((state) => ({
startupParams: state.localConfig.startupParams
}), {
setFilter: setFilter,
setCurrentTask: setCurrentTask
setCurrentTask: setCurrentTask,
setPermalinkParameters: setPermalinkParameters
})(MapFilter);
14 changes: 13 additions & 1 deletion reducers/localConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
* 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';

const defaultState = {
...ConfigUtils.getDefaults(),
startupParams: {},
permalinkParams: {},
colorScheme: 'default'
};

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions utils/PermaLinkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit cc725f5

Please sign in to comment.