Skip to content

Commit

Permalink
Implemented usage of props for SearchBar in MapsSearch and user searc…
Browse files Browse the repository at this point in the history
…h plugins
  • Loading branch information
mbarto committed Oct 21, 2016
1 parent e2ef856 commit d07ce83
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
12 changes: 11 additions & 1 deletion web/client/actions/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SAVE_MAP = 'SAVE_MAP';
const PERMISSIONS_LIST_LOADING = 'PERMISSIONS_LIST_LOADING';
const PERMISSIONS_LIST_LOADED = 'PERMISSIONS_LIST_LOADED';
const RESET_CURRENT_MAP = 'RESET_CURRENT_MAP';
const MAPS_SEARCH_TEXT_CHANGED = 'MAPS_SEARCH_TEXT_CHANGED';

function resetCurrentMap() {
return {
Expand All @@ -48,6 +49,13 @@ function mapsLoading(searchText, params) {
};
}

function mapsSearchTextChanged(text) {
return {
type: MAPS_SEARCH_TEXT_CHANGED,
text
};
}

function mapsLoaded(maps, params, searchText) {
return {
type: MAPS_LIST_LOADED,
Expand Down Expand Up @@ -409,6 +417,7 @@ module.exports = {
RESET_UPDATING,
MAP_ERROR,
RESET_CURRENT_MAP,
MAPS_SEARCH_TEXT_CHANGED,
loadMaps,
updateMap,
updateMapMetadata,
Expand All @@ -430,5 +439,6 @@ module.exports = {
onDisplayMetadataEdit,
resetUpdating,
resetCurrentMap,
mapError
mapError,
mapsSearchTextChanged
};
11 changes: 10 additions & 1 deletion web/client/actions/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const USERMANAGER_EDIT_USER_DATA = 'USERMANAGER_EDIT_USER_DATA';
const USERMANAGER_UPDATE_USER = 'USERMANAGER_UPDATE_USER';
const USERMANAGER_DELETE_USER = 'USERMANAGER_DELETE_USER';
const USERMANAGER_GETGROUPS = 'USERMANAGER_GETGROUPS';
const USERS_SEARCH_TEXT_CHANGED = 'USERS_SEARCH_TEXT_CHANGED';

const API = require('../api/GeoStoreDAO');
const {get, assign} = require('lodash');
function getUsersloading(text, start, limit) {
Expand Down Expand Up @@ -317,12 +319,19 @@ function deleteUser(id, status = "confirm") {
}
}

function usersSearchTextChanged(text) {
return {
type: USERS_SEARCH_TEXT_CHANGED,
text
};
}

module.exports = {
getUsers, USERMANAGER_GETUSERS,
editUser, USERMANAGER_EDIT_USER,
changeUserMetadata, USERMANAGER_EDIT_USER_DATA,
saveUser, USERMANAGER_UPDATE_USER,
deleteUser, USERMANAGER_DELETE_USER,
getGroups, USERMANAGER_GETGROUPS
getGroups, USERMANAGER_GETGROUPS,
usersSearchTextChanged, USERS_SEARCH_TEXT_CHANGED
};
9 changes: 6 additions & 3 deletions web/client/plugins/MapSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const {connect} = require('react-redux');


const {loadMaps} = require('../actions/maps');
const {loadMaps, mapsSearchTextChanged} = require('../actions/maps');
const ConfigUtils = require('../utils/ConfigUtils');

const SearchBar = connect((state) => ({
Expand All @@ -17,8 +17,10 @@ const SearchBar = connect((state) => ({
placeholderMsgId: "maps.search",
typeAhead: false,
start: state && state.maps && state.maps.start,
limit: state && state.maps && state.maps.limit
limit: state && state.maps && state.maps.limit,
searchText: (state.maps && state.maps.searchText !== '*' && state.maps.searchText) || ""
}), {
onSearchTextChange: mapsSearchTextChanged,
onSearch: (text, options) => {
let searchText = (text && text !== "") ? (text) : ConfigUtils.getDefaults().initialMapFilter || "*";
return loadMaps(ConfigUtils.getDefaults().geoStoreUrl, searchText, options);
Expand All @@ -34,7 +36,8 @@ const SearchBar = connect((state) => ({
},
onSearchReset: () => {
dispatchProps.onSearchReset({start: 0, limit: stateProps.limit});
}
},
onSearchTextChange: dispatchProps.onSearchTextChange
};
})(require("../components/mapcontrols/search/SearchBar"));

Expand Down
11 changes: 8 additions & 3 deletions web/client/plugins/manager/users/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
const {connect} = require('react-redux');


const {getUsers} = require('../../../actions/users');
const {getUsers, usersSearchTextChanged} = require('../../../actions/users');

const {trim} = require('lodash');

const SearchBar = connect((state) => ({
className: "user-search",
hideOnBlur: false,
placeholderMsgId: "users.searchUsers",
typeAhead: false,
start: state && state.users && state.users.start,
limit: state && state.users && state.users.limit
limit: state && state.users && state.users.limit,
searchText: (state.users && state.users.searchText && trim(state.users.searchText, '*')) || ""
}), {
onSearchTextChange: usersSearchTextChanged,
onSearch: (text, options) => {
let searchText = (text && text !== "") ? ("*" + text + "*") : "*";
return getUsers(searchText, options);
Expand All @@ -32,7 +36,8 @@ const SearchBar = connect((state) => ({
},
onSearchReset: () => {
dispatchProps.onSearchReset({params: {start: 0, limit: stateProps.limit}});
}
},
onSearchTextChange: dispatchProps.onSearchTextChange
};
})(require("../../../components/mapcontrols/search/SearchBar"));

Expand Down
11 changes: 9 additions & 2 deletions web/client/reducers/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@
const {
MAPS_LIST_LOADED, MAPS_LIST_LOADING, MAPS_LIST_LOAD_ERROR, MAP_CREATED, MAP_UPDATING,
MAP_METADATA_UPDATED, MAP_DELETING, MAP_DELETED, ATTRIBUTE_UPDATED, PERMISSIONS_LIST_LOADING,
PERMISSIONS_LIST_LOADED, SAVE_MAP, PERMISSIONS_UPDATED, THUMBNAIL_ERROR, RESET_UPDATING} = require('../actions/maps');
PERMISSIONS_LIST_LOADED, SAVE_MAP, PERMISSIONS_UPDATED, THUMBNAIL_ERROR, RESET_UPDATING,
MAPS_SEARCH_TEXT_CHANGED} = require('../actions/maps');
const MAP_TYPE_CHANGED = "MAP_TYPE_CHANGED"; // NOTE: this is from home action in product. move to maps actions when finished;
const assign = require('object-assign');
const _ = require('lodash');

function maps(state = {
mapType: "openlayers",
enabled: false,
errors: [] }, action) {
errors: [],
searchText: ""}, action) {
switch (action.type) {
case MAP_TYPE_CHANGED: {
return assign({}, state, {
mapType: action.mapType
});
}
case MAPS_SEARCH_TEXT_CHANGED: {
return assign({}, state, {
searchText: action.text
});
}
case MAPS_LIST_LOADING:
return assign({}, state, {
loading: true,
Expand Down
7 changes: 6 additions & 1 deletion web/client/reducers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const {
USERMANAGER_GETUSERS, USERMANAGER_EDIT_USER, USERMANAGER_EDIT_USER_DATA, USERMANAGER_UPDATE_USER, USERMANAGER_DELETE_USER,
USERMANAGER_GETGROUPS
USERMANAGER_GETGROUPS, USERS_SEARCH_TEXT_CHANGED
} = require('../actions/users');
const assign = require('object-assign');
function users(state = {
Expand All @@ -25,6 +25,11 @@ function users(state = {
limit: action.limit,
totalCount: action.status === "loading" ? state.totalCount : action.totalCount
});
case USERS_SEARCH_TEXT_CHANGED: {
return assign({}, state, {
searchText: action.text
});
}
case USERMANAGER_EDIT_USER: {
let newUser = action.status ? {
status: action.status,
Expand Down

0 comments on commit d07ce83

Please sign in to comment.