feat: allow filtering library by publish status (#1570)
* Adds a filter widget for Publish status. * Adds "Unpublished changes" badge.
This commit is contained in:
committed by
GitHub
parent
31f39cb015
commit
05dddce920
@@ -25,6 +25,12 @@ export enum SearchSortOption {
|
||||
RECENTLY_MODIFIED = 'modified:desc',
|
||||
}
|
||||
|
||||
export enum PublishStatus {
|
||||
Published = 'published',
|
||||
Modified = 'modified',
|
||||
NeverPublished = 'never',
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content search configuration from the CMS.
|
||||
*/
|
||||
@@ -133,6 +139,7 @@ export interface ContentHit extends BaseContentHit {
|
||||
lastPublished: number | null;
|
||||
collections: { displayName?: string[], key?: string[] };
|
||||
published?: ContentPublishedData;
|
||||
publishStatus: PublishStatus;
|
||||
formatted: BaseContentHit['formatted'] & { published?: ContentPublishedData, };
|
||||
}
|
||||
|
||||
@@ -179,6 +186,7 @@ interface FetchSearchParams {
|
||||
searchKeywords: string,
|
||||
blockTypesFilter?: string[],
|
||||
problemTypesFilter?: string[],
|
||||
publishStatusFilter?: PublishStatus[],
|
||||
/** The full path of tags that each result MUST have, e.g. ["Difficulty > Hard", "Subject > Math"] */
|
||||
tagsFilter?: string[],
|
||||
extraFilter?: Filter,
|
||||
@@ -194,6 +202,7 @@ export async function fetchSearchResults({
|
||||
searchKeywords,
|
||||
blockTypesFilter,
|
||||
problemTypesFilter,
|
||||
publishStatusFilter,
|
||||
tagsFilter,
|
||||
extraFilter,
|
||||
sort,
|
||||
@@ -205,6 +214,7 @@ export async function fetchSearchResults({
|
||||
totalHits: number,
|
||||
blockTypes: Record<string, number>,
|
||||
problemTypes: Record<string, number>,
|
||||
publishStatus: Record<string, number>,
|
||||
}> {
|
||||
const queries: MultiSearchQuery[] = [];
|
||||
|
||||
@@ -215,6 +225,8 @@ export async function fetchSearchResults({
|
||||
|
||||
const problemTypesFilterFormatted = problemTypesFilter?.length ? [problemTypesFilter.map(pt => `content.problem_types = ${pt}`)] : [];
|
||||
|
||||
const publishStatusFilterFormatted = publishStatusFilter?.length ? [publishStatusFilter.map(ps => `publish_status = ${ps}`)] : [];
|
||||
|
||||
const tagsFilterFormatted = formatTagsFilter(tagsFilter);
|
||||
|
||||
const limit = 20; // How many results to retrieve per page.
|
||||
@@ -235,6 +247,7 @@ export async function fetchSearchResults({
|
||||
...typeFilters,
|
||||
...extraFilterFormatted,
|
||||
...tagsFilterFormatted,
|
||||
...publishStatusFilterFormatted,
|
||||
],
|
||||
attributesToHighlight: ['display_name', 'description', 'published'],
|
||||
highlightPreTag: HIGHLIGHT_PRE_TAG,
|
||||
@@ -249,7 +262,7 @@ export async function fetchSearchResults({
|
||||
if (!skipBlockTypeFetch) {
|
||||
queries.push({
|
||||
indexUid: indexName,
|
||||
facets: ['block_type', 'content.problem_types'],
|
||||
facets: ['block_type', 'content.problem_types', 'publish_status'],
|
||||
filter: [
|
||||
...extraFilterFormatted,
|
||||
// We exclude the block type filter here so we get all the other available options for it.
|
||||
@@ -266,6 +279,7 @@ export async function fetchSearchResults({
|
||||
totalHits: results[0].totalHits ?? results[0].estimatedTotalHits ?? hitLength,
|
||||
blockTypes: results[1]?.facetDistribution?.block_type ?? {},
|
||||
problemTypes: results[1]?.facetDistribution?.['content.problem_types'] ?? {},
|
||||
publishStatus: results[1]?.facetDistribution?.publish_status ?? {},
|
||||
nextOffset: hitLength === limit ? offset + limit : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
fetchTagsThatMatchKeyword,
|
||||
getContentSearchConfig,
|
||||
fetchBlockTypes,
|
||||
type PublishStatus,
|
||||
} from './api';
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,7 @@ export const useContentSearchResults = ({
|
||||
searchKeywords,
|
||||
blockTypesFilter = [],
|
||||
problemTypesFilter = [],
|
||||
publishStatusFilter = [],
|
||||
tagsFilter = [],
|
||||
sort = [],
|
||||
skipBlockTypeFetch = false,
|
||||
@@ -69,6 +71,7 @@ export const useContentSearchResults = ({
|
||||
blockTypesFilter?: string[];
|
||||
/** Only search for these problem types (e.g. `["choiceresponse", "multiplechoiceresponse"]`) */
|
||||
problemTypesFilter?: string[];
|
||||
publishStatusFilter?: PublishStatus[];
|
||||
/** Required tags (all must match), e.g. `["Difficulty > Hard", "Subject > Math"]` */
|
||||
tagsFilter?: string[];
|
||||
/** Sort search results using these options */
|
||||
@@ -88,6 +91,7 @@ export const useContentSearchResults = ({
|
||||
searchKeywords,
|
||||
blockTypesFilter,
|
||||
problemTypesFilter,
|
||||
publishStatusFilter,
|
||||
tagsFilter,
|
||||
sort,
|
||||
],
|
||||
@@ -103,6 +107,7 @@ export const useContentSearchResults = ({
|
||||
searchKeywords,
|
||||
blockTypesFilter,
|
||||
problemTypesFilter,
|
||||
publishStatusFilter,
|
||||
tagsFilter,
|
||||
sort,
|
||||
// For infinite pagination of results, we can retrieve additional pages if requested.
|
||||
@@ -128,6 +133,7 @@ export const useContentSearchResults = ({
|
||||
// The distribution of block type filter options
|
||||
blockTypes: pages?.[0]?.blockTypes ?? {},
|
||||
problemTypes: pages?.[0]?.problemTypes ?? {},
|
||||
publishStatus: pages?.[0]?.publishStatus ?? {},
|
||||
status: query.status,
|
||||
isLoading: query.isLoading,
|
||||
isError: query.isError,
|
||||
|
||||
Reference in New Issue
Block a user