Skip to content

Commit

Permalink
feat: allow filtering library by publish status
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Oct 19, 2024
1 parent a94df2f commit a1b1a47
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
ClearFiltersButton,
FilterByBlockType,
FilterByTags,
FilterByPublished,
SearchContextProvider,
SearchKeywordsField,
SearchSortWidget,
Expand Down Expand Up @@ -242,6 +243,7 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
<div className="d-flex mt-3 align-items-center">
<FilterByTags />
<FilterByBlockType />
<FilterByPublished />
<ClearFiltersButton />
<div className="flex-grow-1" />
<SearchSortWidget />
Expand Down
19 changes: 12 additions & 7 deletions src/library-authoring/components/BaseComponentCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useMemo } from 'react';
import {
Badge,
Card,
Container,
Icon,
Expand All @@ -11,12 +12,14 @@ import TagCount from '../../generic/tag-count';
import { BlockTypeLabel, type ContentHitTags, Highlight } from '../../search-manager';

type BaseComponentCardProps = {
componentType: string,
displayName: string, description: string,
numChildren?: number,
tags: ContentHitTags,
actions: React.ReactNode,
openInfoSidebar: () => void
componentType: string;
displayName: string;
description: string;
numChildren?: number;
tags: ContentHitTags;
actions: React.ReactNode;
openInfoSidebar: () => void;
hasUnpublishedChanges?: boolean;
};

const BaseComponentCard = ({
Expand All @@ -27,6 +30,7 @@ const BaseComponentCard = ({
tags,
actions,
openInfoSidebar,
...props
} : BaseComponentCardProps) => {
const tagCount = useMemo(() => {
if (!tags) {
Expand Down Expand Up @@ -75,7 +79,8 @@ const BaseComponentCard = ({
<div className="text-truncate h3 mt-2">
<Highlight text={displayName} />
</div>
<Highlight text={description} />
<Highlight text={description} /><br />
{props.hasUnpublishedChanges ? <Badge variant="warning">Unpublished changes</Badge> : null}
</Card.Section>
</Card.Body>
</Card>
Expand Down
3 changes: 3 additions & 0 deletions src/library-authoring/components/ComponentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => {
formatted,
tags,
usageKey,
modified,
lastPublished,
} = contentHit;
const description: string = (/* eslint-disable */
blockType === 'html' ? formatted?.content?.htmlContent :
Expand Down Expand Up @@ -150,6 +152,7 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => {
</ActionRow>
)}
openInfoSidebar={() => openComponentInfoSidebar(usageKey)}
hasUnpublishedChanges={modified >= (lastPublished ?? 0)}
/>
);
};
Expand Down
77 changes: 77 additions & 0 deletions src/search-manager/FilterByPublished.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';
import { FormattedMessage } from '@edx/frontend-platform/i18n';

Check failure on line 2 in src/search-manager/FilterByPublished.tsx

View workflow job for this annotation

GitHub Actions / tests (18)

'FormattedMessage' is defined but never used

Check failure on line 2 in src/search-manager/FilterByPublished.tsx

View workflow job for this annotation

GitHub Actions / tests (20)

'FormattedMessage' is defined but never used
import {
Badge,
Form,
Menu,
MenuItem,
} from '@openedx/paragon';
import { FilterList } from '@openedx/paragon/icons';
import SearchFilterWidget from './SearchFilterWidget';
import messages from './messages';

Check failure on line 11 in src/search-manager/FilterByPublished.tsx

View workflow job for this annotation

GitHub Actions / tests (18)

'messages' is defined but never used

Check failure on line 11 in src/search-manager/FilterByPublished.tsx

View workflow job for this annotation

GitHub Actions / tests (20)

'messages' is defined but never used
// import { useSearchContext } from './SearchManager';

/**
* A button with a dropdown that allows filtering the current search by publish status
*/
const FilterByPublished: React.FC<Record<never, never>> = () => {
// const {
// publishedFilter,
// setPublishedFilter,
// } = useSearchContext();

const clearFilters = React.useCallback(() => {
// setPublishedFilter(undefined);
}, []);

return (
<SearchFilterWidget
appliedFilters={[]}
label="Publish Status"
clearFilter={clearFilters}
icon={FilterList}
>
<Form.Group className="mb-0">
<Form.CheckboxSet
name="block-type-filter"
value={[]}
>
<Menu className="block-type-refinement-menu" style={{ boxShadow: 'none' }}>
<MenuItem
as={Form.Checkbox}
value={1}
onChange={() => {}}
>
<div>
Published
<Badge variant="light" pill>15</Badge>
</div>
</MenuItem>
<MenuItem
as={Form.Checkbox}
value={2}
onChange={() => {}}
>
<div>
Modified since publish
<Badge variant="light" pill>5</Badge>
</div>
</MenuItem>
<MenuItem
as={Form.Checkbox}
value={3}
onChange={() => {}}
>
<div>
Never published
<Badge variant="light" pill>2</Badge>
</div>
</MenuItem>
</Menu>
</Form.CheckboxSet>
</Form.Group>
</SearchFilterWidget>
);
};

export default FilterByPublished;
1 change: 1 addition & 0 deletions src/search-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { default as BlockTypeLabel } from './BlockTypeLabel';
export { default as ClearFiltersButton } from './ClearFiltersButton';
export { default as FilterByBlockType } from './FilterByBlockType';
export { default as FilterByTags } from './FilterByTags';
export { default as FilterByPublished } from './FilterByPublished';
export { default as Highlight } from './Highlight';
export { default as SearchKeywordsField } from './SearchKeywordsField';
export { default as SearchSortWidget } from './SearchSortWidget';
Expand Down

0 comments on commit a1b1a47

Please sign in to comment.