Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic filter that allows user to choose which property is filtered #130

Merged
merged 6 commits into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/client/actions/SearchFilterActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ export function getSearchFilterActions(alt, searchFilterResource, participantRes
loadOptions(property) {
return dispatch => {
dispatch();
participantResource.findAll(`filter[fields][${property}]=true`)
.then(response => this.optionsLoaded(property, processResults(response)),
err => this.optionsLoadingFailed(err));
if (!property) {
this.optionsLoaded('', null); // dispatch empty list
} else {
participantResource.findAll(`filter[fields][${property}]=true`)
.then(response => this.optionsLoaded(property, processResults(response)),
err => this.optionsLoadingFailed(err));
}
};

function processResults(result) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { Input } from 'react-bootstrap';
import { getPropertyFilterContainer } from './PropertyFilterContainer';

export function getGenericPropertyFilterContainer(searchFilterStore, searchFilterActions) {
const PropertyFilterContainer = getPropertyFilterContainer(searchFilterStore, searchFilterActions);

const properties = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Onko joku syy miksei tää oo vain objekti, kun nää on nimi-arvopareja?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Koska sekä nimeä että arvoa käytetään? Voishan ne muuttaa objekteiksi, mutta ei se mun mielestä helpota mitään...

Copy link
Collaborator

@emilvirkki emilvirkki Jul 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se ois ehkä snadisti tyylikkäämpää mun mielestä, nää arrayt joissa on array sisällä on mun mielestä vähemmän dokumentoivia. Tämmönen rakenne on perusteltu sillon kun halutaan tietty järjestys, jos se on tarkoitus niin sitä tää on tosi hyvä näin :)

['childNaps', 'Lapsi nukkuu päiväunet'],
['accommodation', 'Majoittautuminen'],
];

class GenericPropertyFilterContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
property: '',
};
this.onPropertyChange = this.onPropertyChange.bind(this);
this.onValueChange = this.onValueChange.bind(this);
}

onPropertyChange(e) {
this.props.onChange(this.state.property, null);
this.setState({ property: e.target.value });
searchFilterActions.loadOptions.defer(e.target.value);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ylimääräinen tyhjä rivi?

}

onValueChange(e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tän vois poistaa

this.props.onChange();
}

render() {
return (
<div>
<Input type="select" label="Kenttä" value={ this.state.property } onChange={ this.onPropertyChange }>
<option value=""></option>
{ properties.map((property, index) => <option value={ property[0] } key={ index }>{ property[1] }</option>) }
</Input>
<PropertyFilterContainer
onChange={ this.props.onChange }
currentSelection={ this.props.currentSelection }
label=""
property={ this.state.property }
/>
</div>
);
}
}

GenericPropertyFilterContainer.propTypes = {
onChange: React.PropTypes.func.isRequired,
currentSelection: React.PropTypes.object.isRequired,
};

return GenericPropertyFilterContainer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { getPropertyFilterContainer } from './PropertyFilterContainer';
import { getDebouncedTextFieldContainer } from './DebouncedTextFieldContainer';
import { getPresenceFilterContainer } from './PresenceFilterContainer';
import { getSaveSearchButtonContainer } from './SaveSearchButtonContainer';
import { getGenericPropertyFilterContainer } from './GenericPropertyFilterContainer';

export function getQuickFilterContainer(participantStore, participantActions, searchFilterActions, searchFilterStore) {
const DebouncedTextFieldContainer = getDebouncedTextFieldContainer();
const SaveSearchButtonContainer = getSaveSearchButtonContainer(searchFilterActions);
const PropertyFilterContainer = getPropertyFilterContainer(searchFilterStore, searchFilterActions);
const PresenceFilterContainer = getPresenceFilterContainer();
const GenericPropertyFilterContainer = getGenericPropertyFilterContainer(searchFilterStore, searchFilterActions);

function getCurrentSelection(properties, currentFilter) {
const andSelection = currentFilter.and && _.reduce(currentFilter.and, _.merge, {}) || {};
Expand All @@ -25,7 +27,7 @@ export function getQuickFilterContainer(participantStore, participantActions, se
}

function QuickFilterContainer(props, context) {
const currentSelection = getCurrentSelection(['textSearch', 'ageGroup', 'subCamp', 'localGroup', 'campGroup', 'presence'], props.filter);
const currentSelection = getCurrentSelection(['textSearch', 'ageGroup', 'subCamp', 'localGroup', 'campGroup', 'presence', 'childNaps', 'accommodation'], props.filter);

function resetFilters(event) {
event.preventDefault();
Expand Down Expand Up @@ -82,6 +84,10 @@ export function getQuickFilterContainer(participantStore, participantActions, se
onChange={ handleChange }
currentSelection={ currentSelection }
/>
<GenericPropertyFilterContainer
onChange={ handleChange }
currentSelection={ currentSelection }
/>
<SaveSearchButtonContainer location={ props.location } />
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/kuksa-integration/rebuild-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function rebuildParticipantsTable() {
email: participant.email,
internationalGuest: !!participant.localGroup,
diet: participant.diet,
accommodation: participant.accommodation,
accommodation: participant.accommodation || 'Muu',
localGroup: participant.representedParty || _.get(participant, 'localGroup.name') || 'Muu',
campGroup: _.get(participant, 'campGroup.name') || 'Muu',
subCamp: getSubCamp(participant),
Expand Down