-
Notifications
You must be signed in to change notification settings - Fork 92
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
Changes from 12 commits
fd2c357
7cf5d2e
8889017
6d3db8d
73ef429
3f0f95e
2effa32
09d1284
54913f7
777fe25
f28faaa
fd35ce8
419ac2f
dc3f657
daa98b8
19f9420
a338fe8
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 |
---|---|---|
|
@@ -196,6 +196,8 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => { | |
formatted, | ||
tags, | ||
usageKey, | ||
modified, | ||
lastPublished, | ||
} = contentHit; | ||
const componentDescription: string = ( | ||
showOnlyPublished ? formatted.published?.description : formatted.description | ||
|
@@ -228,6 +230,7 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => { | |
)} | ||
</ActionRow> | ||
)} | ||
hasUnpublishedChanges={modified >= (lastPublished ?? 0)} | ||
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. nit: Why not pull this from the added 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. ohh nice catch |
||
onSelect={openComponent} | ||
/> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
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, SearchSortOption } 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 [onlyPublished, setOnlyPublished] = React.useState(false); | ||
const intl = useIntl(); | ||
const { | ||
publishStatus, | ||
publishStatusFilter, | ||
setPublishStatusFilter, | ||
searchSortOrder, | ||
} = useSearchContext(); | ||
|
||
const clearFilters = React.useCallback(() => { | ||
setPublishStatusFilter([]); | ||
}, []); | ||
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. Selecting a Published Status filter doesn't show the "clear filters" link? Need to modify |
||
|
||
React.useEffect(() => { | ||
if (searchSortOrder === SearchSortOption.RECENTLY_PUBLISHED) { | ||
setPublishStatusFilter([PublishStatus.Published, PublishStatus.Modified]); | ||
setOnlyPublished(true); | ||
} else { | ||
setOnlyPublished(false); | ||
} | ||
}, [searchSortOrder]); | ||
|
||
const toggleFilterMode = React.useCallback((mode: PublishStatus) => { | ||
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. Bug: Selecting one publish_status filter clears all the others? Maybe see 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. it was because I forgot to add the setter to the dependencies. this was somehow breaking the tags filter tests so thank you so much for finding 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. Thank you for working out a simple fix! it's working great now. |
||
setPublishStatusFilter(oldList => { | ||
if (oldList.includes(mode)) { | ||
return oldList.filter(m => m !== mode); | ||
} | ||
return [...oldList, mode]; | ||
}); | ||
}, []); | ||
const modeToLabel = { | ||
published: intl.formatMessage(messages.publishStatusPublished), | ||
modified: intl.formatMessage(messages.publishStatusModified), | ||
never: intl.formatMessage(messages.publishStatusNeverPublished), | ||
}; | ||
const appliedFilters = publishStatusFilter.map(mode => ({ label: modeToLabel[mode] })); | ||
|
||
return ( | ||
<SearchFilterWidget | ||
appliedFilters={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); }} | ||
disabled={onlyPublished} | ||
> | ||
<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 |
---|---|---|
|
@@ -9,7 +9,10 @@ import { MeiliSearch, type Filter } from 'meilisearch'; | |
import { union } from 'lodash'; | ||
|
||
import { | ||
CollectionHit, ContentHit, SearchSortOption, forceArray, | ||
CollectionHit, | ||
ContentHit, | ||
SearchSortOption, | ||
forceArray, PublishStatus, | ||
} from './data/api'; | ||
import { TypesFilterData, useStateOrUrlSearchParam } from './hooks'; | ||
import { useContentSearchConnection, useContentSearchResults } from './data/apiHooks'; | ||
|
@@ -20,12 +23,15 @@ export interface SearchContextData { | |
indexName?: string; | ||
searchKeywords: string; | ||
setSearchKeywords: React.Dispatch<React.SetStateAction<string>>; | ||
publishStatusFilter: PublishStatus[]; | ||
setPublishStatusFilter: React.Dispatch<React.SetStateAction<PublishStatus[]>>; | ||
typesFilter: TypesFilterData; | ||
setTypesFilter: React.Dispatch<React.SetStateAction<TypesFilterData>>; | ||
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; | ||
|
@@ -98,6 +104,14 @@ export const SearchContextProvider: React.FC<{ | |
skipUrlUpdate, | ||
); | ||
|
||
const [publishStatusFilter, setPublishStatusFilter] = useStateOrUrlSearchParam<PublishStatus>( | ||
[], | ||
'published', | ||
(value: string) => Object.values(PublishStatus).find((enumValue) => value === enumValue), | ||
(value: PublishStatus) => value.toString(), | ||
skipUrlUpdate, | ||
); | ||
|
||
// E.g ?usageKey=lb:OpenCraft:libA:problem:5714eb65-7c36-4eee-8ab9-a54ed5a95849 | ||
const sanitizeUsageKey = (value: string): string | undefined => { | ||
try { | ||
|
@@ -144,12 +158,14 @@ export const SearchContextProvider: React.FC<{ | |
const canClearFilters = ( | ||
!typesFilter.isEmpty() | ||
|| tagsFilter.length > 0 | ||
|| publishStatusFilter.length > 0 | ||
|| !!usageKey | ||
); | ||
const isFiltered = canClearFilters || (searchKeywords !== ''); | ||
const clearFilters = React.useCallback(() => { | ||
setTypesFilter((types) => types.clear()); | ||
setTagsFilter([]); | ||
setPublishStatusFilter([]); | ||
if (usageKey !== '') { | ||
setUsageKey(''); | ||
} | ||
|
@@ -164,6 +180,7 @@ export const SearchContextProvider: React.FC<{ | |
indexName, | ||
extraFilter, | ||
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. |
||
publishStatusFilter, | ||
blockTypesFilter: [...typesFilter.blocks], | ||
problemTypesFilter: [...typesFilter.problems], | ||
tagsFilter, | ||
|
@@ -177,6 +194,8 @@ export const SearchContextProvider: React.FC<{ | |
indexName, | ||
searchKeywords, | ||
setSearchKeywords, | ||
publishStatusFilter, | ||
setPublishStatusFilter, | ||
typesFilter, | ||
setTypesFilter, | ||
tagsFilter, | ||
|
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.
Could you please add
<FilterByPublished />
to the LibraryCollectionPage too?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.
will do