-
Notifications
You must be signed in to change notification settings - Fork 15
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
Agenda quick filters pills #609
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7fde73f
Init
thecalcc eb51b49
Fix breaking of agenda, wire pills dropdown
thecalcc 1a0fccf
Add types
thecalcc c4d1753
Merge branch 'develop' into quick-actions-pills
thecalcc b1c73d6
Move agenda filter pills to quick filter pills
thecalcc 04585ca
Add coment, fix X button not removing agenda filters
thecalcc 3b9ca37
Fix lint
thecalcc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import {gettext, getCreatedSearchParamLabel} from 'utils'; | ||
|
||
import {SearchResultTagList} from './SearchResultTagList'; | ||
import {Tag} from 'components/Tag'; | ||
|
||
import {IProps as IParentProps} from './SearchResultTagsList'; | ||
import {setItemTypeFilter} from 'agenda/actions'; | ||
import {searchFilterSelector} from 'search/selectors'; | ||
import {connect} from 'react-redux'; | ||
import {agendaCoverageStatusFilter, getActiveFilterLabel} from 'agenda/components/AgendaCoverageExistsFilter'; | ||
|
||
const IS_AGENDA = location.pathname.includes('/agenda'); | ||
|
||
type IProps = Pick<IParentProps, | ||
'readonly' | | ||
|
@@ -15,11 +19,86 @@ type IProps = Pick<IParentProps, | |
'toggleFilter' | | ||
'setCreatedFilter' | | ||
'resetFilter' | ||
>; | ||
> & {clearQuickFilter: (filter: string) => void;}; | ||
|
||
type IActiveFilter = { | ||
calendar?: any; | ||
location?: any; | ||
region?: any; | ||
coverage_type?: any; | ||
coverage_status?: any; | ||
}; | ||
|
||
type IActiveFilterUnionType = keyof IActiveFilter; | ||
|
||
interface IReduxStateProps { | ||
itemTypeFilter?: string; | ||
activeFilter?: IActiveFilter; | ||
} | ||
|
||
interface IReduxDispatchProps { | ||
clearItemTypeFilter: () => void; | ||
} | ||
|
||
type IPropsAgendaExtended = IReduxDispatchProps & IReduxStateProps & IProps; | ||
|
||
export function SearchResultsFiltersRow({readonly, searchParams, filterGroups, toggleFilter, setCreatedFilter, resetFilter}: IProps) { | ||
function SearchResultsFiltersRow({ | ||
readonly, | ||
searchParams, | ||
filterGroups, | ||
toggleFilter, | ||
setCreatedFilter, | ||
resetFilter, | ||
itemTypeFilter, | ||
clearItemTypeFilter, | ||
activeFilter, | ||
clearQuickFilter, | ||
}: IPropsAgendaExtended) { | ||
const tags = []; | ||
|
||
/** | ||
* FIXME: This is a bad implementation, but the proper fix would be too time consuming at this moment. | ||
* Ideally we would want to unify the searchParameters so they are stored in the same variable both from | ||
* agenda and wire. Another solution would be to not reuse the same component in wire and agenda filters | ||
* so that wire has its own filter component and agenda has a separate one. The first solution is the better | ||
* one since from a UI stand point the filters component is identical and should be reused ideally. | ||
*/ | ||
if (IS_AGENDA) { | ||
if (itemTypeFilter != null) { | ||
tags.push( | ||
<Tag | ||
key={`tags-filters--from-${itemTypeFilter}`} | ||
testId="tags-filters--agenda-quick-filters" | ||
text={itemTypeFilter === 'events' ? gettext('Events Only') : gettext('Planning Only')} | ||
readOnly={readonly} | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
clearItemTypeFilter(); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
Object.keys(activeFilter ?? {}).filter((filter) => activeFilter?.[filter as IActiveFilterUnionType] != null) | ||
.forEach((filter) => { | ||
tags.push( | ||
<Tag | ||
key={`tags-filters--${filter}`} | ||
testId={`tags-filters--agenda-quick-filters-${filter}`} | ||
text={filter === 'coverage_status' | ||
? getActiveFilterLabel(agendaCoverageStatusFilter, activeFilter) | ||
: activeFilter?.[filter as IActiveFilterUnionType] | ||
} | ||
readOnly={readonly} | ||
onClick={(event) => { | ||
event.preventDefault(); | ||
clearQuickFilter(filter); | ||
}} | ||
/> | ||
); | ||
}); | ||
} | ||
|
||
if (searchParams.created) { | ||
const created = getCreatedSearchParamLabel(searchParams.created); | ||
|
||
|
@@ -81,7 +160,7 @@ export function SearchResultsFiltersRow({readonly, searchParams, filterGroups, t | |
} | ||
} | ||
|
||
if (searchParams.filter != null) { | ||
if (searchParams.filter != null && IS_AGENDA !== true) { | ||
for (const field in searchParams.filter) { | ||
const group = filterGroups[field]; | ||
|
||
|
@@ -129,6 +208,7 @@ export function SearchResultsFiltersRow({readonly, searchParams, filterGroups, t | |
onClick={(event) => { | ||
event.preventDefault(); | ||
resetFilter(); | ||
clearItemTypeFilter?.(); | ||
}} | ||
> | ||
{gettext('Clear filters')} | ||
|
@@ -145,10 +225,19 @@ export function SearchResultsFiltersRow({readonly, searchParams, filterGroups, t | |
); | ||
} | ||
|
||
SearchResultsFiltersRow.propTypes = { | ||
searchParams: PropTypes.object, | ||
filterGroups: PropTypes.object, | ||
toggleFilter: PropTypes.func.isRequired, | ||
setCreatedFilter: PropTypes.func.isRequired, | ||
resetFilter: PropTypes.func.isRequired, | ||
}; | ||
const mapStateToProps = (state: any) => ({ | ||
itemTypeFilter: state.agenda.itemType, | ||
activeFilter: searchFilterSelector(state), | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch: any) => ({ | ||
clearItemTypeFilter: () => dispatch(setItemTypeFilter(null)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this one too |
||
}); | ||
|
||
let component: React.ComponentType<IProps> = SearchResultsFiltersRow as React.ComponentType<IProps>; | ||
|
||
if (IS_AGENDA) { | ||
component = connect<IReduxStateProps, IReduxDispatchProps, IProps>(mapStateToProps, mapDispatchToProps)(SearchResultsFiltersRow); | ||
} | ||
|
||
export default component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've already talked that this is a low quality implementation that we'd normally not approve, but are going with it anyway because of effort that would be required to do a proper one. In such cases it'd be very useful to add a comment describing the situation and guidelines on how should we fix it when we have more time.