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 global toggle to find challenge page #2382

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 13 additions & 3 deletions src/components/ChallengePane/ChallengePane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import StartVirtualChallenge from './StartVirtualChallenge/StartVirtualChallenge'
import messages from './Messages'

const ShowArchivedToggleInternal = (props) => {
const ShowChallengeListTogglesInternal = (props) => {
return (
<div className="mr-flex">
<input
Expand All @@ -43,11 +43,20 @@
}}
/>
<div className="mr-text-sm mr-mx-1"><FormattedMessage {...messages.showArchivedLabel} /></div>
<input
type="checkbox"
className="mr-checkbox-toggle mr-mr-1 mr-mb-6 mr-ml-4"
checked={props.showingGlobal}
CollinBeczak marked this conversation as resolved.
Show resolved Hide resolved
onChange={() => {
props.setSearchFilters({ global: !props.showingGlobal })
}}

Check warning on line 52 in src/components/ChallengePane/ChallengePane.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/ChallengePane/ChallengePane.jsx#L51-L52

Added lines #L51 - L52 were not covered by tests
/>
<div className="mr-text-sm mr-mx-1"><FormattedMessage {...messages.showGlobalLabel} /></div>
</div>
)
}

const ShowArchivedToggle = WithChallengeSearch(ShowArchivedToggleInternal);
const ShowChallengeListToggles = WithChallengeSearch(ShowChallengeListTogglesInternal);

// Setup child components with necessary HOCs
const ChallengeResults = WithStatus(ChallengeResultList)
Expand Down Expand Up @@ -118,6 +127,7 @@

render() {
const showingArchived = this.props.history.location.search.includes("archived=true");
const showingGlobal = this.props.history.location.search.includes("global=true")
const challengeStatus = [ChallengeStatus.ready,
ChallengeStatus.partiallyLoaded,
ChallengeStatus.none,
Expand Down Expand Up @@ -156,7 +166,7 @@
<div className="mr-p-6 lg:mr-flex mr-cards-inverse">
<div className="mr-flex-0">
<LocationFilter {...this.props} />
<ShowArchivedToggle showingArchived={showingArchived} {...this.props} />
<ShowChallengeListToggles showingArchived={showingArchived} showingGlobal={showingGlobal} {...this.props} />
<ChallengeResults {...this.props} />
</div>
<div className="mr-flex-1">
Expand Down
5 changes: 5 additions & 0 deletions src/components/ChallengePane/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ export default defineMessages({
showArchivedLabel: {
id: "ChallengePane.controls.showArchived.label",
defaultMessage: "Show Archived"
},

showGlobalLabel: {
id: "ChallengePane.controls.showGlobal.label",
defaultMessage: "Show Global Challenges"
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import { challengePassesLocationFilter }
from '../../../services/Challenge/ChallengeLocation/ChallengeLocation'
import { challengePassesArchivedFilter }
from '../../../services/Challenge/ChallengeArchived/ChallengeArchived'
import { challengePassesGlobalFilter }
from '../../../services/Challenge/ChallengeGlobal/ChallengeGlobal'
import { challengePassesProjectFilter }
from '../../../services/Challenge/ChallengeProject/ChallengeProject'

const allFilters = [
challengePassesArchivedFilter,
challengePassesGlobalFilter,
challengePassesDifficultyFilter,
challengePassesKeywordFilter,
challengePassesCategorizationKeywordsFilter,
Expand Down
3 changes: 2 additions & 1 deletion src/components/HOCs/WithSearchRoute/WithSearchRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const WithSearchRoute = function(WrappedComponent, searchGroup) {
project: param => this.props.setSearchFilters({project: param, searchType: SEARCH_TYPE_PROJECT}),
query: param => this.props.setSearch(param),
challengeSearch: param => this.props.setChallengeSearchMapBounds(toLatLngBounds(param), true),
archived: param => this.props.setSearchFilters({ archived: param === "true" })
archived: param => this.props.setSearchFilters({ archived: param === "true" }),
global: param => this.props.setSearchFilters({ global: param === "true" })
}

state = {
Expand Down
4 changes: 4 additions & 0 deletions src/services/Challenge/Challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@
queryParams.ca = filters.archived;
}

if (filters.global) {
queryParams.cg = filters.global;
}

Check warning on line 449 in src/services/Challenge/Challenge.js

View check run for this annotation

Codecov / codecov/patch

src/services/Challenge/Challenge.js#L446-L449

Added lines #L446 - L449 were not covered by tests
// Keywords/tags can come from both the the query and the filter, so we need to
// combine them into a single keywords array.
const keywords = queryParts.tagTokens.concat(
Expand Down
10 changes: 5 additions & 5 deletions src/services/Challenge/ChallengeArchived/ChallengeArchived.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const challengePassesArchivedFilter = function(filter, challenge) {
if (!filter.archived) {
return challenge.isArchived === false
}

return true
if (!filter.archived) {
return challenge.isArchived === false

Check warning on line 3 in src/services/Challenge/ChallengeArchived/ChallengeArchived.js

View check run for this annotation

Codecov / codecov/patch

src/services/Challenge/ChallengeArchived/ChallengeArchived.js#L2-L3

Added lines #L2 - L3 were not covered by tests
}

return true
}

Check warning on line 7 in src/services/Challenge/ChallengeArchived/ChallengeArchived.js

View check run for this annotation

Codecov / codecov/patch

src/services/Challenge/ChallengeArchived/ChallengeArchived.js#L5-L7

Added lines #L5 - L7 were not covered by tests
7 changes: 7 additions & 0 deletions src/services/Challenge/ChallengeGlobal/ChallengeGlobal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const challengePassesGlobalFilter = function(filter, challenge) {
if (filter.global) {
return challenge.isGlobal === false
}
CollinBeczak marked this conversation as resolved.
Show resolved Hide resolved

return true
}

Check warning on line 7 in src/services/Challenge/ChallengeGlobal/ChallengeGlobal.js

View check run for this annotation

Codecov / codecov/patch

src/services/Challenge/ChallengeGlobal/ChallengeGlobal.js#L2-L7

Added lines #L2 - L7 were not covered by tests
6 changes: 5 additions & 1 deletion src/services/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
difficulty: 'cd',
tags: 'tt',
excludeTasks: 'tExcl',
archived: "ca"
archived: "ca",
global: "cg"
}


Expand Down Expand Up @@ -158,6 +159,9 @@
if (filters.archived) {
searchParameters[PARAMS_MAP.archived] = filters.archived;
}
if (filters.global) {
searchParameters[PARAMS_MAP.global] = filters.global;
}

Check warning on line 164 in src/services/Search/Search.js

View check run for this annotation

Codecov / codecov/patch

src/services/Search/Search.js#L162-L164

Added lines #L162 - L164 were not covered by tests
if (filters.reviewRequestedBy) {
searchParameters[PARAMS_MAP.reviewRequestedBy] = filters.reviewRequestedBy
if (invertFields.reviewRequestedBy) {
Expand Down
Loading