-
Notifications
You must be signed in to change notification settings - Fork 85
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
feat: allow filtering library by publish status #1570
base: master
Are you sure you want to change the base?
Changes from all commits
fd2c357
7cf5d2e
8889017
6d3db8d
73ef429
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from 'react'; | ||
import { | ||
Badge, | ||
Form, | ||
Menu, | ||
MenuItem, | ||
} from '@openedx/paragon'; | ||
import { FilterList } from '@openedx/paragon/icons'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
import SearchFilterWidget from './SearchFilterWidget'; | ||
import { useSearchContext } from './SearchManager'; | ||
import { PublishStatus } from './data/api'; | ||
|
||
/** | ||
* A button with a dropdown that allows filtering the current search by publish status | ||
*/ | ||
const FilterByPublished: React.FC<Record<never, never>> = () => { | ||
const intl = useIntl(); | ||
const { | ||
publishStatus, | ||
publishStatusFilter, | ||
setPublishStatusFilter, | ||
} = useSearchContext(); | ||
|
||
const clearFilters = React.useCallback(() => { | ||
setPublishStatusFilter([]); | ||
}, []); | ||
|
||
const toggleFilterMode = React.useCallback((mode: PublishStatus) => { | ||
setPublishStatusFilter(oldList => { | ||
if (oldList.includes(mode)) { | ||
return oldList.filter(m => m !== mode); | ||
} | ||
return [...oldList, mode]; | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<SearchFilterWidget | ||
appliedFilters={[]} | ||
label="Publish Status" | ||
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. Please extract "Publish Status" to a message so it can be translated. |
||
clearFilter={clearFilters} | ||
icon={FilterList} | ||
> | ||
<Form.Group className="mb-0"> | ||
<Form.CheckboxSet | ||
name="publish-status-filter" | ||
value={publishStatusFilter} | ||
> | ||
<Menu className="block-type-refinement-menu" style={{ boxShadow: 'none' }}> | ||
<MenuItem | ||
as={Form.Checkbox} | ||
value={PublishStatus.Published} | ||
onChange={() => { toggleFilterMode(PublishStatus.Published); }} | ||
> | ||
<div> | ||
{intl.formatMessage(messages.publishStatusPublished)} | ||
<Badge variant="light" pill>{publishStatus[PublishStatus.Published] ?? 0}</Badge> | ||
</div> | ||
</MenuItem> | ||
<MenuItem | ||
as={Form.Checkbox} | ||
value={PublishStatus.Modified} | ||
onChange={() => { toggleFilterMode(PublishStatus.Modified); }} | ||
> | ||
<div> | ||
{intl.formatMessage(messages.publishStatusModified)} | ||
<Badge variant="light" pill>{publishStatus[PublishStatus.Modified] ?? 0}</Badge> | ||
</div> | ||
</MenuItem> | ||
<MenuItem | ||
as={Form.Checkbox} | ||
value={PublishStatus.NeverPublished} | ||
onChange={() => { toggleFilterMode(PublishStatus.NeverPublished); }} | ||
> | ||
<div> | ||
{intl.formatMessage(messages.publishStatusNeverPublished)} | ||
<Badge variant="light" pill>{publishStatus[PublishStatus.NeverPublished] ?? 0}</Badge> | ||
</div> | ||
</MenuItem> | ||
</Menu> | ||
</Form.CheckboxSet> | ||
</Form.Group> | ||
</SearchFilterWidget> | ||
); | ||
}; | ||
|
||
export default FilterByPublished; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,11 @@ import { MeiliSearch, type Filter } from 'meilisearch'; | |
import { union } from 'lodash'; | ||
|
||
import { | ||
CollectionHit, ContentHit, SearchSortOption, forceArray, | ||
CollectionHit, | ||
ContentHit, | ||
SearchSortOption, | ||
forceArray, | ||
type PublishStatus, | ||
} from './data/api'; | ||
import { useContentSearchConnection, useContentSearchResults } from './data/apiHooks'; | ||
|
||
|
@@ -23,10 +27,13 @@ export interface SearchContextData { | |
setBlockTypesFilter: React.Dispatch<React.SetStateAction<string[]>>; | ||
problemTypesFilter: string[]; | ||
setProblemTypesFilter: React.Dispatch<React.SetStateAction<string[]>>; | ||
publishStatusFilter: PublishStatus[]; | ||
setPublishStatusFilter: React.Dispatch<React.SetStateAction<PublishStatus[]>>; | ||
tagsFilter: string[]; | ||
setTagsFilter: React.Dispatch<React.SetStateAction<string[]>>; | ||
blockTypes: Record<string, number>; | ||
problemTypes: Record<string, number>; | ||
publishStatus: Record<string, number>; | ||
extraFilter?: Filter; | ||
canClearFilters: boolean; | ||
clearFilters: () => void; | ||
|
@@ -99,6 +106,7 @@ export const SearchContextProvider: React.FC<{ | |
const [searchKeywords, setSearchKeywords] = React.useState(''); | ||
const [blockTypesFilter, setBlockTypesFilter] = React.useState<string[]>([]); | ||
const [problemTypesFilter, setProblemTypesFilter] = React.useState<string[]>([]); | ||
const [publishStatusFilter, setPublishStatusFilter] = React.useState<PublishStatus[]>([]); | ||
const [tagsFilter, setTagsFilter] = React.useState<string[]>([]); | ||
const [usageKey, setUsageKey] = useStateWithUrlSearchParam( | ||
'', | ||
|
@@ -140,13 +148,15 @@ export const SearchContextProvider: React.FC<{ | |
blockTypesFilter.length > 0 | ||
|| problemTypesFilter.length > 0 | ||
|| tagsFilter.length > 0 | ||
|| publishStatusFilter.length > 0 | ||
|| !!usageKey | ||
); | ||
const isFiltered = canClearFilters || (searchKeywords !== ''); | ||
const clearFilters = React.useCallback(() => { | ||
setBlockTypesFilter([]); | ||
setTagsFilter([]); | ||
setProblemTypesFilter([]); | ||
setPublishStatusFilter([]); | ||
if (usageKey !== '') { | ||
setUsageKey(''); | ||
} | ||
|
@@ -163,6 +173,7 @@ export const SearchContextProvider: React.FC<{ | |
searchKeywords, | ||
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. Some UI questions, feel free to bounce these off the UX folks if you agree :)
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. @jmakowski1123 @lizc577 @sdaitzman @marcotuts any comments on this? ^ 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. @jmakowski1123 @lizc577 @sdaitzman @marcotuts gentle nudge on this since we're blocked waiting for a decision here. |
||
blockTypesFilter, | ||
problemTypesFilter, | ||
publishStatusFilter, | ||
tagsFilter, | ||
sort, | ||
skipBlockTypeFetch, | ||
|
@@ -178,6 +189,8 @@ export const SearchContextProvider: React.FC<{ | |
setBlockTypesFilter, | ||
problemTypesFilter, | ||
setProblemTypesFilter, | ||
publishStatusFilter, | ||
setPublishStatusFilter, | ||
tagsFilter, | ||
setTagsFilter, | ||
extraFilter, | ||
|
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.
Selecting a Published Status filter doesn't show the "clear filters" link?
Need to modify
canClearFilters
.