Skip to content

Commit c91c817

Browse files
Merge pull request #5250 from nqviet/filter-update-fix-issue-5068
filter update: fix issue #5068
2 parents 67575a8 + ade0526 commit c91c817

File tree

14 files changed

+72
-63
lines changed

14 files changed

+72
-63
lines changed

__tests__/shared/components/challenge-listing/__snapshots__/index.jsx.snap

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ exports[`Matches shallow shapshot 1 shapshot 1 1`] = `
4848
loadMoreActive={null}
4949
loadMoreAll={null}
5050
loadMoreMy={null}
51+
loadMoreMyPast={null}
5152
loadMoreOnGoing={null}
5253
loadMoreOpenForRegistration={null}
5354
loadMorePast={null}
@@ -115,6 +116,7 @@ exports[`Matches shallow shapshot 2 shapshot 2 1`] = `
115116
loadMoreActive={null}
116117
loadMoreAll={null}
117118
loadMoreMy={null}
119+
loadMoreMyPast={null}
118120
loadMoreOnGoing={null}
119121
loadMoreOpenForRegistration={null}
120122
loadMorePast={null}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"supertest": "^3.1.0",
144144
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3",
145145
"tc-ui": "^1.0.12",
146-
"topcoder-react-lib": "1000.26.0",
146+
"topcoder-react-lib": "1000.26.1",
147147
"topcoder-react-ui-kit": "2.0.1",
148148
"topcoder-react-utils": "0.7.8",
149149
"turndown": "^4.0.2",

src/shared/actions/challenge-listing/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,14 @@ function getAllChallengesDone(uuid, page, backendFilter, tokenV3, frontFilter =
284284
backendFilter,
285285
frontFilter: {
286286
...frontFilter,
287+
status: 'Active',
287288
perPage: PAGE_SIZE,
288289
page: page + 1,
289290
sortBy: sorts[BUCKETS.ALL],
290291
sortOrder: SORT[sorts[BUCKETS.ALL]].order,
291292
},
292293
};
293294
delete filter.frontFilter.sorts;
294-
// if (status === 'All') {
295-
// delete filter.frontFilter.status;
296-
// }
297295
const service = getService(tokenV3);
298296
return service.getChallenges(filter).then(ch => ({
299297
uuid,

src/shared/components/challenge-listing/Filters/ChallengeSearchBar/style.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $challenge-radius-4: $corner-radius * 2;
1414
padding: 0 $base-unit * 3;
1515

1616
@media (max-width: #{$screen-lg - 1px}) {
17-
display: none;
17+
padding: 0 $base-unit * 2;
1818
}
1919
}
2020

src/shared/components/challenge-listing/Filters/FiltersPanel/index.jsx

+11-14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default function FiltersPanel({
5858
selectCommunity,
5959
// selectedCommunityId,
6060
setFilterState,
61+
setSearchText,
6162
// validKeywords,
6263
validTypes,
6364
// isSavingFilter,
@@ -340,19 +341,13 @@ export default function FiltersPanel({
340341
styleName="input-control"
341342
name="past-period"
342343
id={range.label}
343-
defaultChecked={range.isCustom
344-
? (
345-
_.every(staticRanges, r => !r.isSelected({
346-
startDate: filterState.endDateStart,
347-
endDate: filterState.startDateEnd,
348-
}))
349-
&& (!!filterState.endDateStart || !!filterState.startDateEnd)
350-
) : (
351-
range.isSelected({
352-
startDate: filterState.endDateStart,
353-
endDate: filterState.startDateEnd,
354-
})
355-
)
344+
value={range.label}
345+
checked={range.isCustom
346+
? filterState.customDate
347+
: !filterState.customDate && range.isSelected({
348+
startDate: filterState.endDateStart,
349+
endDate: filterState.startDateEnd,
350+
})
356351
}
357352
onChange={() => {
358353
if (range.isCustom) {
@@ -561,9 +556,10 @@ export default function FiltersPanel({
561556
endDateStart: null,
562557
startDateEnd: null,
563558
reviewOpportunityTypes: _.keys(REVIEW_OPPORTUNITY_TYPES),
564-
customDate: true,
559+
customDate: false,
565560
});
566561
selectCommunity(defaultCommunityId);
562+
setSearchText('');
567563
// localStorage.setItem('trackStatus', JSON.stringify({}));
568564
}}
569565
size="sm"
@@ -605,6 +601,7 @@ FiltersPanel.propTypes = {
605601
selectCommunity: PT.func.isRequired,
606602
// selectedCommunityId: PT.string.isRequired,
607603
setFilterState: PT.func.isRequired,
604+
setSearchText: PT.func.isRequired,
608605
// validKeywords: PT.arrayOf(PT.string).isRequired,
609606
validTypes: PT.arrayOf(PT.shape()).isRequired,
610607
onClose: PT.func,

src/shared/components/challenge-listing/Filters/FiltersPanel/style.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
position: relative;
285285
display: inline-block;
286286
line-height: 30px;
287-
width: 33%;
287+
flex: 1 1 33%;
288288

289289
.checkbox-label {
290290
display: inline-block;

src/shared/components/challenge-listing/Listing/index.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Listing({
2525
allMyChallengesLoaded,
2626
allMyPastChallengesLoaded,
2727
allChallengesLoaded,
28+
allPastChallengesLoaded,
2829
allOpenForRegistrationChallengesLoaded,
2930
challenges,
3031
openForRegistrationChallenges,
@@ -94,7 +95,7 @@ function Listing({
9495
case BUCKETS.ALL_PAST:
9596
bucketChallenges = [].concat(pastChallenges);
9697
loading = loadingPastChallenges;
97-
loadMore = loadMorePast;
98+
loadMore = allPastChallengesLoaded ? null : loadMorePast;
9899
newExpanded = newExpanded || (+meta.pastChallengesCount === bucketChallenges.length);
99100
break;
100101
// case BUCKETS.PAST:
@@ -302,6 +303,7 @@ Listing.propTypes = {
302303
allMyChallengesLoaded: PT.bool.isRequired,
303304
allMyPastChallengesLoaded: PT.bool.isRequired,
304305
allChallengesLoaded: PT.bool.isRequired,
306+
allPastChallengesLoaded: PT.bool.isRequired,
305307
allOpenForRegistrationChallengesLoaded: PT.bool.isRequired,
306308
challenges: PT.arrayOf(PT.shape()),
307309
openForRegistrationChallenges: PT.arrayOf(PT.shape()),
@@ -356,6 +358,7 @@ const mapStateToProps = (state) => {
356358
allMyChallengesLoaded: cl.allMyChallengesLoaded,
357359
allMyPastChallengesLoaded: cl.allMyPastChallengesLoaded,
358360
allChallengesLoaded: cl.allChallengesLoaded,
361+
allPastChallengesLoaded: cl.allPastChallengesLoaded,
359362
allOpenForRegistrationChallengesLoaded: cl.allOpenForRegistrationChallengesLoaded,
360363
// pastSearchTimestamp: cl.pastSearchTimestamp,
361364
challengeTypes: cl.challengeTypes,

src/shared/components/challenge-listing/Sidebar/index.jsx

+5-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import React from 'react';
1919
import PT from 'prop-types';
20-
import _ from 'lodash';
20+
// import _ from 'lodash';
2121
import { BUCKETS } from 'utils/challenge-listing/buckets';
2222
import BucketSelector from './BucketSelector';
2323
// import FiltersEditor from './FiltersEditor';
@@ -39,7 +39,7 @@ export default function SideBarFilters({
3939
// dragState,
4040
// editSavedFiltersMode,
4141
// extraBucket,
42-
filterState,
42+
// filterState,
4343
// hideTcLinksInFooter,
4444
isAuth,
4545
// resetFilterName,
@@ -49,7 +49,7 @@ export default function SideBarFilters({
4949
// setEditSavedFiltersMode,
5050
// updateAllSavedFilters,
5151
// updateSavedFilter,
52-
setFilter,
52+
// setFilter,
5353
past,
5454
setPast,
5555
previousBucketOfActiveTab,
@@ -62,13 +62,6 @@ export default function SideBarFilters({
6262
return;
6363
}
6464
setPreviousBucketOfPastChallengesTab(activeBucket);
65-
setFilter({
66-
..._.omit(filterState, 'status'),
67-
endDateStart: null,
68-
startDateEnd: null,
69-
previousStartDate: filterState.endDateStart,
70-
previousEndDate: filterState.startDateEnd,
71-
});
7265
setPast(false);
7366
if (previousBucketOfActiveTab) {
7467
selectBucket(previousBucketOfActiveTab);
@@ -82,12 +75,6 @@ export default function SideBarFilters({
8275
return;
8376
}
8477
setPreviousBucketOfActiveTab(activeBucket);
85-
setFilter({
86-
..._.omit(filterState, 'previousStartDate', 'previousEndDate'),
87-
status: 'Completed',
88-
endDateStart: filterState.previousStartDate,
89-
startDateEnd: filterState.previousEndDate,
90-
});
9178
setPast(true);
9279
if (previousBucketOfPastChallengesTab) {
9380
selectBucket(previousBucketOfPastChallengesTab);
@@ -195,7 +182,7 @@ SideBarFilters.propTypes = {
195182
// dragSavedFilterStart: PT.func.isRequired,
196183
// editSavedFiltersMode: PT.bool.isRequired,
197184
// extraBucket: PT.string,
198-
filterState: PT.shape().isRequired,
185+
// filterState: PT.shape().isRequired,
199186
// hideTcLinksInFooter: PT.bool,
200187
isAuth: PT.bool,
201188
// resetFilterName: PT.func.isRequired,
@@ -205,7 +192,7 @@ SideBarFilters.propTypes = {
205192
// setEditSavedFiltersMode: PT.func.isRequired,
206193
// updateAllSavedFilters: PT.func.isRequired,
207194
// updateSavedFilter: PT.func.isRequired,
208-
setFilter: PT.func.isRequired,
195+
// setFilter: PT.func.isRequired,
209196
past: PT.bool.isRequired,
210197
setPast: PT.func.isRequired,
211198
previousBucketOfActiveTab: PT.string,

src/shared/components/challenge-listing/index.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default function ChallengeListing(props) {
120120
loadingOnGoingChallenges={props.loadingOnGoingChallenges}
121121
loadingReviewOpportunities={props.loadingReviewOpportunities}
122122
loadMoreMy={props.loadMoreMy}
123+
loadMoreMyPast={props.loadMoreMyPast}
123124
loadMoreAll={props.loadMoreAll}
124125
loadMoreOpenForRegistration={props.loadMoreOpenForRegistration}
125126
loadMoreOnGoing={props.loadMoreOnGoing}
@@ -197,6 +198,7 @@ ChallengeListing.defaultProps = {
197198
// extraBucket: null,
198199
// hideTcLinksInFooter: false,
199200
loadMoreMy: null,
201+
loadMoreMyPast: null,
200202
loadMoreAll: null,
201203
loadMoreOpenForRegistration: null,
202204
loadMoreOnGoing: null,
@@ -245,6 +247,7 @@ ChallengeListing.propTypes = {
245247
loadingPastChallenges: PT.bool.isRequired,
246248
loadingReviewOpportunities: PT.bool.isRequired,
247249
loadMoreMy: PT.func,
250+
loadMoreMyPast: PT.func,
248251
loadMoreAll: PT.func,
249252
loadMoreOpenForRegistration: PT.func,
250253
loadMoreOnGoing: PT.func,

src/shared/containers/challenge-listing/FilterPanel.jsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ export class Container extends React.Component {
5959
if (query.bucket) {
6060
if (query.bucket === BUCKETS.ALL_PAST || query.bucket === BUCKETS.MY_PAST) {
6161
setPast(true);
62-
query.status = 'Completed';
6362
}
6463

65-
if (query.bucket === BUCKETS.REVIEW_OPPORTUNITIES) {
66-
this.initialDefaultChallengeTypes = true;
67-
}
68-
69-
if (!(query.bucket === BUCKETS.ALL_PAST || query.bucket === BUCKETS.MY_PAST)) {
64+
if (query.bucket !== BUCKETS.ALL_PAST && query.bucket !== BUCKETS.MY_PAST) {
7065
delete query.endDateStart;
7166
delete query.startDateEnd;
7267
}
@@ -91,8 +86,8 @@ export class Container extends React.Component {
9186
this.initialDefaultChallengeTypes = true;
9287
}
9388

94-
if (query.name) {
95-
setSearchText(query.name);
89+
if (query.search) {
90+
setSearchText(query.search);
9691
}
9792

9893
if (!_.isEmpty(query)) {
@@ -108,11 +103,11 @@ export class Container extends React.Component {
108103
} = this.props;
109104

110105
if (validTypes.length && !this.initialDefaultChallengeTypes) {
111-
this.initialDefaultChallengeTypes = true;
112106
setFilterState({
113107
..._.clone(filterState),
114108
types: validTypes.map(item => item.abbreviation),
115109
});
110+
this.initialDefaultChallengeTypes = true;
116111
}
117112
}
118113

src/shared/containers/challenge-listing/Listing/index.jsx

+31-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ const { mapToBackend } = challengeUtils.filter;
3737
let mounted = false;
3838

3939
export class ListingContainer extends React.Component {
40+
constructor(props) {
41+
super(props);
42+
this.firstReload = false;
43+
}
44+
4045
componentDidMount() {
4146
const {
4247
activeBucket,
@@ -113,6 +118,7 @@ export class ListingContainer extends React.Component {
113118
dropOpenForRegistrationChallenges,
114119
dropPastChallenges,
115120
getPastChallenges,
121+
past,
116122
} = this.props;
117123
const oldUserId = _.get(prevProps, 'auth.user.userId');
118124
const userId = _.get(this.props, 'auth.user.userId');
@@ -136,15 +142,19 @@ export class ListingContainer extends React.Component {
136142
// }
137143
const bucket = sortChangedBucket(sorts, prevProps.sorts);
138144
const f = this.getBackendFilter();
145+
const fA = {
146+
back: { ..._.clone(f.back), startDateEnd: null, endDateStart: null },
147+
front: { ..._.clone(f.front), startDateEnd: null, endDateStart: null },
148+
};
139149
if (bucket) {
140150
switch (bucket) {
141151
case BUCKETS.MY: {
142152
dropMyChallenges();
143153
getMyChallenges(
144154
0,
145-
f.back,
155+
fA.back,
146156
auth.tokenV3,
147-
f.front,
157+
fA.front,
148158
);
149159
break;
150160
}
@@ -162,19 +172,19 @@ export class ListingContainer extends React.Component {
162172
dropOpenForRegistrationChallenges();
163173
getOpenForRegistrationChallenges(
164174
0,
165-
f.back,
175+
fA.back,
166176
auth.tokenV3,
167-
f.front,
177+
fA.front,
168178
);
169179
break;
170180
}
171181
case BUCKETS.ONGOING: {
172182
dropActiveChallenges();
173183
getActiveChallenges(
174184
0,
175-
f.back,
185+
fA.back,
176186
auth.tokenV3,
177-
f.front,
187+
fA.front,
178188
);
179189
break;
180190
}
@@ -214,7 +224,19 @@ export class ListingContainer extends React.Component {
214224
}
215225
return;
216226
}
217-
if (filterChanged(filter, prevProps.filter)) {
227+
let reload;
228+
if (!this.firstReload) {
229+
reload = true;
230+
this.firstReload = true;
231+
} else if (prevProps.past === past) {
232+
reload = past
233+
? filterChanged(filter, prevProps.filter)
234+
: filterChanged(
235+
_.omit(filter, 'startDateEnd', 'endDateStart'),
236+
_.omit(prevProps.filter, 'startDateEnd', 'endDateStart'),
237+
);
238+
}
239+
if (reload) {
218240
this.reloadChallenges();
219241
}
220242
setTimeout(() => {
@@ -738,6 +760,7 @@ ListingContainer.propTypes = {
738760
getTotalChallengesCount: PT.func.isRequired,
739761
// userChallenges: PT.arrayOf(PT.string),
740762
// getUserChallenges: PT.func.isRequired,
763+
past: PT.bool.isRequired,
741764
};
742765

743766
const mapStateToProps = (state, ownProps) => {
@@ -797,6 +820,7 @@ const mapStateToProps = (state, ownProps) => {
797820
expandedTags: cl.expandedTags,
798821
meta: cl.meta,
799822
// userChallenges: cl.userChallenges,
823+
past: cl.sidebar.past,
800824
};
801825
};
802826

@@ -877,7 +901,6 @@ function mapDispatchToProps(dispatch) {
877901
// dispatch(a.getUserChallengesInit(uuid));
878902
// dispatch(a.getUserChallengesDone(userId, tokenV3));
879903
// },
880-
setPast: isPast => dispatch(sa.setPast(isPast)),
881904
};
882905
}
883906

0 commit comments

Comments
 (0)