forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Content Search Modal: Filters [FC-0040] (openedx#918)
Implementation of openedx/modular-learning#201 Implements a modal for searching course content with filters for searching in current or all courses, filtering by content type, content tags and text.
- Loading branch information
1 parent
aaf4989
commit fc3e38f
Showing
24 changed files
with
1,129 additions
and
109 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable react/prop-types */ | ||
// @ts-check | ||
import React from 'react'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
|
||
/** | ||
* Displays a friendly, localized text name for the given XBlock/component type | ||
* e.g. `vertical` becomes `"Unit"` | ||
* @type {React.FC<{type: string}>} | ||
*/ | ||
const BlockTypeLabel = ({ type }) => { | ||
// TODO: Load the localized list of Component names from Studio REST API? | ||
const msg = messages[`blockType.${type}`]; | ||
|
||
if (msg) { | ||
return <FormattedMessage {...msg} />; | ||
} | ||
// Replace underscores and hypens with spaces, then let the browser capitalize this | ||
// in a locale-aware way to get a reasonable display value. | ||
// e.g. 'drag-and-drop-v2' -> "Drag And Drop V2" | ||
return <span style={{ textTransform: 'capitalize' }}>{type.replace(/[_-]/g, ' ')}</span>; | ||
}; | ||
|
||
export default BlockTypeLabel; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable react/prop-types */ | ||
// @ts-check | ||
import React from 'react'; | ||
import { useClearRefinements } from 'react-instantsearch'; | ||
import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { Button } from '@openedx/paragon'; | ||
import messages from './messages'; | ||
|
||
/** | ||
* A button that appears when at least one filter is active, and will clear the filters when clicked. | ||
* @type {React.FC<Record<never, never>>} | ||
*/ | ||
const ClearFiltersButton = () => { | ||
const { refine, canRefine } = useClearRefinements(); | ||
if (canRefine) { | ||
return ( | ||
<Button variant="link" size="sm" onClick={refine}> | ||
<FormattedMessage {...messages.clearFilters} /> | ||
</Button> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default ClearFiltersButton; |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable react/prop-types */ | ||
// @ts-check | ||
import React from 'react'; | ||
import { useStats, useClearRefinements } from 'react-instantsearch'; | ||
|
||
/** | ||
* If the user hasn't put any keywords/filters yet, display an "empty state". | ||
* Likewise, if the results are empty (0 results), display a special message. | ||
* Otherwise, display the results, which are assumed to be the children prop. | ||
* @type {React.FC<{children: React.ReactElement}>} | ||
*/ | ||
const EmptyStates = ({ children }) => { | ||
const { nbHits, query } = useStats(); | ||
const { canRefine: hasFiltersApplied } = useClearRefinements(); | ||
const hasQuery = !!query; | ||
|
||
if (!hasQuery && !hasFiltersApplied) { | ||
// We haven't started the search yet. Display the "start your search" empty state | ||
// Note this isn't localized because it's going to be replaced in a fast-follow PR. | ||
return <p className="text-muted text-center mt-6">Enter a keyword or select a filter to begin searching.</p>; | ||
} | ||
if (nbHits === 0) { | ||
// Note this isn't localized because it's going to be replaced in a fast-follow PR. | ||
return <p className="text-muted text-center mt-6">No results found. Change your search and try again.</p>; | ||
} | ||
|
||
return children; | ||
}; | ||
|
||
export default EmptyStates; |
Oops, something went wrong.