Skip to content

Commit

Permalink
Improved accuracy of the admin status filter
Browse files Browse the repository at this point in the history
  • Loading branch information
iambrandonn committed Dec 16, 2015
1 parent ff428f1 commit 6ead42b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ V1.0.3
* Fixed bugs with the next step button not enabling/disabling at the correct times
* Now shows the revised date (and labels it as such) on the admin list view for
revised disclosures. Un-revised disclosures still show the submitted date.
* Improved accuracy of the admin status filter

V1.0.2

Expand Down
80 changes: 39 additions & 41 deletions client/scripts/components/Admin/DisclosureFilterByStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {GreyButton} from '../GreyButton';
import {AdminActions} from '../../actions/AdminActions';
import DisclosureFilter from './DisclosureFilter';
import DoneWithFilterButton from './DoneWithFilterButton';
import {COIConstants} from '../../../../COIConstants';
const APPROVED = COIConstants.DISCLOSURE_STATUS.UP_TO_DATE;
import {merge} from '../../merge';

export class DisclosureFilterByStatus extends DisclosureFilter {
Expand All @@ -40,16 +42,13 @@ export class DisclosureFilterByStatus extends DisclosureFilter {

toggleFilter(evt) {
const code = Number(evt.target.id.replace('statFilt', ''));
const theStatus = this.props.possibleStatuses.find(status => {
return status.code === code;
});
const theStatus = this.props.possibleStatuses
.find(status => status.code === code);
AdminActions.toggleStatusFilter(theStatus);
}

isChecked(value) {
return this.props.activeFilters.find(filter => {
return filter === value;
}) !== undefined;
return this.props.activeFilters.some(filter => filter === value);
}

// render() is implemented in DisclosureFilter, which will call renderFilter
Expand Down Expand Up @@ -86,41 +85,40 @@ export class DisclosureFilterByStatus extends DisclosureFilter {
}
};

const options = this.props.possibleStatuses.filter(status => {
return status.code !== 3;
}).sort((a, b) => {
return a.label.localeCompare(b.label);
}).map((status) => {
const id = `statFilt${status.code}`;
return (
<div style={styles.checkbox} key={status.code}>
<input
id={id}
type="checkbox"
checked={this.isChecked(status.code)}
onChange={this.toggleFilter}
/>
<label htmlFor={id} style={{paddingLeft: 9}}>{status.label}</label>
</div>
);
});

const approved = this.props.possibleStatuses.filter(status => {
return status.code === 3;
}).map(status => {
const id = `statFilt${status.code}`;
return (
<div style={merge(styles.checkbox, {padding: '10px 0'})} key={status.code}>
<input
id={id}
type="checkbox"
checked={this.isChecked(status.code)}
onChange={this.toggleFilter}
/>
<label htmlFor={id} style={{paddingLeft: 9}}>{status.label}</label>
</div>
);
});
const options = this.props.possibleStatuses
.filter(status => status.code !== APPROVED)
.sort((a, b) => a.label.localeCompare(b.label))
.map((status) => {
const id = `statFilt${status.code}`;
return (
<div style={styles.checkbox} key={status.code}>
<input
id={id}
type="checkbox"
checked={this.isChecked(status.code)}
onChange={this.toggleFilter}
/>
<label htmlFor={id} style={{paddingLeft: 9}}>{status.label}</label>
</div>
);
});

const approved = this.props.possibleStatuses
.filter(status => status.code === APPROVED)
.map(status => {
const id = `statFilt${status.code}`;
return (
<div style={merge(styles.checkbox, {padding: '10px 0'})} key={status.code}>
<input
id={id}
type="checkbox"
checked={this.isChecked(status.code)}
onChange={this.toggleFilter}
/>
<label htmlFor={id} style={{paddingLeft: 9}}>{status.label}</label>
</div>
);
});

return (
<div style={styles.container}>
Expand Down
8 changes: 6 additions & 2 deletions client/scripts/stores/AdminStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import ConfigActions from '../actions/ConfigActions';

const PAGE_SIZE = 40;

function defaultStatusFilters() {
return [2, 4, 5, 6];
}

class _AdminStore extends AutoBindingStore {
constructor() {
super(AdminActions);
Expand All @@ -38,7 +42,7 @@ class _AdminStore extends AutoBindingStore {
end: undefined
},
submittedBy: undefined,
status: [2, 4, 5, 6],
status: defaultStatusFilters(),
type: [],
search: ''
},
Expand Down Expand Up @@ -267,7 +271,7 @@ class _AdminStore extends AutoBindingStore {
}

clearStatusFilter() {
this.applicationState.filters.status = [];
this.applicationState.filters.status = defaultStatusFilters();
this.refreshDisclosures();
}

Expand Down
16 changes: 8 additions & 8 deletions server/db/DisclosureDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,12 @@ export const getSummariesForReviewCount = (dbInfo, filters) => {
});
}
}
if (filters.status && filters.status.length > 0) {
if (filters.status) {
query.whereIn('disclosure.status_cd', filters.status);
}
if (filters.type && filters.type.length > 0) {
query.whereIn('disclosure_type.description', filters.type);
}
// if (filters.type) {
// query.whereIn('disclosure_type.description', filters.type);
// }
if (filters.submittedBy) {
query.where('submitted_by', filters.submittedBy);
}
Expand Down Expand Up @@ -788,12 +788,12 @@ export const getSummariesForReview = (dbInfo, sortColumn, sortDirection, start,
});
}
}
if (filters.status && filters.status.length > 0) {
if (filters.status) {
query.whereIn('disclosure.status_cd', filters.status);
}
if (filters.type && filters.type.length > 0) {
query.whereIn('disclosure_type.description', filters.type);
}
// if (filters.type) {
// query.whereIn('disclosure_type.description', filters.type);
// }
if (filters.submittedBy) {
query.where('submitted_by', filters.submittedBy);
}
Expand Down

0 comments on commit 6ead42b

Please sign in to comment.