Skip to content

f2f filterfix #5077

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

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function ChallengeTags(props) {
setImmediate(() => setChallengeListingFilter({ types: [challengeType.abbreviation] }))
)
}
to={`${challengesUrl}?filter[types][0]=${encodeURIComponent(challengeType.abbreviation)}`}
to={`${challengesUrl}?types[]=${encodeURIComponent(challengeType.abbreviation)}`}
>
{challengeType.name}
</TrackTag>
Expand All @@ -90,7 +90,7 @@ export default function ChallengeTags(props) {
key={tag}
onClick={() => setImmediate(() => setChallengeListingFilter({ tags: [tag] }))
}
to={`${challengesUrl}?filter[tags][0]=${
to={`${challengesUrl}?tags[]=${
encodeURIComponent(tag)}`}
>
{tag}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import PT from 'prop-types';
import SwitchWithLabel from 'components/SwitchWithLabel';
// import { challenge as challengeUtils } from 'topcoder-react-lib';
import { challenge as challengeUtils } from 'topcoder-react-lib';
// import { COMPETITION_TRACKS as TRACKS } from 'utils/tc';
import _ from 'lodash';

Expand All @@ -17,7 +17,7 @@ import FiltersSwitch from './FiltersSwitch';

import './ChallengeFilters.scss';

// const Filter = challengeUtils.filter;
const Filter = challengeUtils.filter;

export default function ChallengeFilters({
communityFilters,
Expand Down Expand Up @@ -56,9 +56,9 @@ export default function ChallengeFilters({
const isTrackOn = track => filterState.tracks && filterState.tracks[track];

const switchTrack = (track, on) => {
const newFilter = _.cloneDeep(filterState);
newFilter.tracks[track] = on;
setFilterState({ ...newFilter });
const act = on ? Filter.addTrack : Filter.removeTrack;
const filterObj = act(filterState, track);
setFilterState({ ...filterObj });
};

const clearSearch = () => {
Expand Down
17 changes: 9 additions & 8 deletions src/shared/containers/challenge-listing/FilterPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import React from 'react';
import { isReviewOpportunitiesBucket } from 'utils/challenge-listing/buckets';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
// import qs from 'qs';
import qs from 'qs';
import _ from 'lodash';

/* The default name for user-saved challenge filters. An integer
* number will be appended to it, when necessary, to keep filter
Expand Down Expand Up @@ -47,8 +48,8 @@ export class Container extends React.Component {
getTypes,
loadingKeywords,
loadingTypes,
// setFilterState,
// filterState,
setFilterState,
filterState,
communityList,
getCommunityList,
auth,
Expand All @@ -62,10 +63,10 @@ export class Container extends React.Component {
if (!loadingKeywords) getKeywords();


// const query = qs.parse(window.location.search.slice(1));
// if (query.filter && !filterState.track) {
// setFilterState(query.filter);
// } else {
const query = qs.parse(window.location.search.slice(1));
if (!_.isEmpty(query) && !filterState.track) {
setFilterState(query);
}
// const trackStatus = localStorage.getItem('trackStatus');
// const filterObj = trackStatus ? JSON.parse(trackStatus) : null;
// if (filterObj) {
Expand Down Expand Up @@ -189,7 +190,7 @@ function mapDispatchToProps(dispatch) {
// },
// selectBucket: bucket => dispatch(sa.selectBucket(bucket)),
selectCommunity: id => dispatch(cla.selectCommunity(id)),
// setFilterState: s => dispatch(cla.setFilter(s)),
setFilterState: s => dispatch(cla.setFilter(s)),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/shared/reducers/challenge-listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ function onSetFilter(state, { payload }) {
* do it very carefuly (many params are not validated). */
const filter = _.pickBy(_.pick(
payload,
['tags', 'types', 'name', 'startDateEnd', 'endDateStart', 'groups'],
['tags', 'types', 'name', 'startDateEnd', 'endDateStart', 'groups', 'tracks'],
), value => (!_.isArray(value) && value && value !== '') || (_.isArray(value) && value.length > 0));
// if (_.isPlainObject(filter.tags)) {
// filter.tags = _.values(filter.tags);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/reducers/challenge-listing/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function onSelectBucket(state, { payload }) {
switch (payload.bucket) {
case BUCKETS.ALL:
// case BUCKETS.SAVED_FILTER:
updateQuery({ bucket: undefined });
updateQuery({ bucket: payload.bucket });
break;
default:
updateQuery({ bucket: payload.expanding ? undefined : payload.bucket });
Expand Down
29 changes: 25 additions & 4 deletions src/shared/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import _ from 'lodash';
import qs from 'qs';
import { isomorphy } from 'topcoder-react-utils';

import { BUCKETS } from 'utils/challenge-listing/buckets';
/**
* Get current URL hash parameters as object
*/
Expand Down Expand Up @@ -37,19 +37,40 @@ export function getQuery() {
export function updateQuery(update) {
if (isomorphy.isServerSide()) return;

// let query = qs.parse(window.location.search.slice(1));
let filterObj = {};
// check if bucket is selected
if (update.bucket) {
// fetching everything else from url except bucket
filterObj = {
...qs.parse(window.location.search.slice(1)),
...update,
};
if (update.bucket === BUCKETS.ALL) {
delete filterObj.bucket; // delete bucket field for all challenges
}
} else {
// fetch only bucket from url
const query = qs.parse(window.location.search.slice(1));
filterObj = {
...(query.bucket && { bucket: query.bucket }), // fetch only bucket from url
...update,
};
}
let query = '?';
const { hash } = window.location;
const filterArray = [];

/* _.merge won't work here, because it just ignores the fields explicitely
* set as undefined in the objects to be merged, rather than deleting such
* fields in the target object. */
_.forIn(update, (value, key) => {
_.forIn(filterObj, (value, key) => {
if (_.isArray(value) && value.length > 0) filterArray.push(value.map(item => `${key}[]=${item}`).join('&'));
// eslint-disable-next-line max-len
else if (_.isUndefined(value) || _.isEmpty(value) || (_.isArray(value) && value.length === 0)) delete query[key];
else {
else if (typeof value === 'object') {
const separator = query === '?' ? '' : '&';
query += `${separator}${qs.stringify({ tracks: value }, { encodeValuesOnly: true })}`;
} else {
const separator = query === '?' ? '' : '&';
query += `${separator}${key}=${value}`;
}
Expand Down