Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SearchKeywordsField,
SearchSortWidget,
TypesFilterData,
PublishStatus,
} from '../search-manager';
import LibraryContent from './LibraryContent';
import { LibrarySidebar } from './library-sidebar';
Expand Down Expand Up @@ -259,6 +260,11 @@ const LibraryAuthoringPage = ({
<Tab key={contentType} eventKey={contentType} title={tabTitles[contentType]} />
));

const publishedFilters = [PublishStatus.Published, PublishStatus.Modified];
if (!showOnlyPublished) {
publishedFilters.push(PublishStatus.NeverPublished);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Check for showOnlyPublished flag inside FilterByPublished instead of passing filters via props. This should take care of all the places that this component is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FilterByPublished component is outside the context of libraries, so it could be used on other screens. In f768f29 I created LibraryFilterByPublished to reuse it and I fixed the collections bug

return (
<div className="d-flex">
<div className="flex-grow-1">
Expand Down Expand Up @@ -299,7 +305,7 @@ const LibraryAuthoringPage = ({
<SearchKeywordsField className="mr-3" />
<FilterByTags />
{!(insideCollections || insideUnits) && <FilterByBlockType />}
<FilterByPublished />
<FilterByPublished visibleFilters={publishedFilters} />
<ClearFiltersButton />
<ActionRow.Spacer />
<SearchSortWidget />
Expand Down
16 changes: 16 additions & 0 deletions src/library-authoring/component-picker/ComponentPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,20 @@ describe('<ComponentPicker />', () => {
expect(screen.queryByRole('tab', { name: /collections/i })).not.toBeInTheDocument();
expect(screen.queryByRole('tab', { name: /components/i })).not.toBeInTheDocument();
});

it('should not display never published filter', async () => {
render(<ComponentPicker />);

expect(await screen.findByText('Test Library 1')).toBeInTheDocument();
fireEvent.click(screen.getByDisplayValue(/lib:sampletaxonomyorg1:tl1/i));

// Wait for the content library to load
const filterButton = await screen.findByRole('button', { name: /publish status/i });
fireEvent.click(filterButton);

// Verify the filters. Note: It's hard to verify the `published` filter,
// because there are many components with that text on the screen, but that's not the important thing.
expect(screen.getByText(/modified since publish/i)).toBeInTheDocument();
expect(screen.queryByText(/never published/i)).not.toBeInTheDocument();
});
});
60 changes: 28 additions & 32 deletions src/search-manager/FilterByPublished.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import messages from './messages';
import SearchFilterWidget from './SearchFilterWidget';
import { useSearchContext } from './SearchManager';
import { PublishStatus } from './data/api';
import { allPublishFilters, PublishStatus } from './data/api';

interface FilterByPublishedProps {
visibleFilters?: PublishStatus[],
}

/**
* A button with a dropdown that allows filtering the current search by publish status
*/
const FilterByPublished: React.FC<Record<never, never>> = () => {
const FilterByPublished = ({
visibleFilters = allPublishFilters,
}: FilterByPublishedProps) => {
const intl = useIntl();
const {
publishStatus,
Expand All @@ -42,6 +48,25 @@ const FilterByPublished: React.FC<Record<never, never>> = () => {
};
const appliedFilters = publishStatusFilter.map(mode => ({ label: modeToLabel[mode] }));

const filterLabels = {
[PublishStatus.Published]: intl.formatMessage(messages.publishStatusPublished),
[PublishStatus.Modified]: intl.formatMessage(messages.publishStatusModified),
[PublishStatus.NeverPublished]: intl.formatMessage(messages.publishStatusNeverPublished),
};

const visibleFiltersToRender = visibleFilters.map((filter) => (
<MenuItem
as={Form.Checkbox}
value={filter}
onChange={() => { toggleFilterMode(filter); }}
Comment thread
ChrisChV marked this conversation as resolved.
Resolved
>
<div>
{filterLabels[filter]}
<Badge variant="light" pill>{publishStatus[filter] ?? 0}</Badge>
</div>
</MenuItem>
));

return (
<SearchFilterWidget
appliedFilters={appliedFilters}
Expand All @@ -55,36 +80,7 @@ const FilterByPublished: React.FC<Record<never, never>> = () => {
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>
{visibleFiltersToRender}
</Menu>
</Form.CheckboxSet>
</Form.Group>
Expand Down
2 changes: 2 additions & 0 deletions src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum PublishStatus {
NeverPublished = 'never',
}

export const allPublishFilters: PublishStatus[] = Object.values(PublishStatus);

/**
* Get the content search configuration from the CMS.
*/
Expand Down