Skip to content
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: Show published components on content picker #1420

Merged
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
7 changes: 6 additions & 1 deletion src/library-authoring/LibraryAuthoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
/>
) : undefined;

const extraFilter = [`context_key = "${libraryId}"`];
if (componentPickerMode) {
extraFilter.push('last_published IS NOT NULL');
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved
}

return (
<div className="d-flex">
<div className="flex-grow-1">
Expand All @@ -230,7 +235,7 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
)}
<Container className="px-4 mt-4 mb-5 library-authoring-page">
<SearchContextProvider
extraFilter={`context_key = "${libraryId}"`}
extraFilter={extraFilter}
>
<SubHeader
title={<SubHeaderTitle title={libraryData.title} />}
Expand Down
16 changes: 13 additions & 3 deletions src/library-authoring/LibraryRecentlyModified.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,21 @@ const RecentlyModified: React.FC<Record<never, never>> = () => {
};

const LibraryRecentlyModified: React.FC<Record<never, never>> = () => {
const { libraryId } = useLibraryContext();
const { libraryId, componentPickerMode } = useLibraryContext();

const extraFilter = [`context_key = "${libraryId}"`];
if (componentPickerMode) {
extraFilter.push('last_published IS NOT NULL');
}

return (
<SearchContextProvider
extraFilter={`context_key = "${libraryId}"`}
overrideSearchSortOrder={SearchSortOption.RECENTLY_MODIFIED}
extraFilter={extraFilter}
overrideSearchSortOrder={
componentPickerMode
? SearchSortOption.RECENTLY_PUBLISHED
: SearchSortOption.RECENTLY_MODIFIED
}
>
<RecentlyModified />
</SearchContextProvider>
Expand Down
20 changes: 20 additions & 0 deletions src/library-authoring/__mocks__/collection-search.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"key": [
"my-first-collection"
]
},
"published": {
"display_name": "Introduction to Testing",
"description": "Testing"
}
},
{
Expand Down Expand Up @@ -64,6 +68,10 @@
"key": [
"my-first-collection"
]
},
"published": {
"display_name": "Second Text Component",
"description": "Second Testing"
}
},
{
Expand Down Expand Up @@ -97,6 +105,10 @@
"my-first-collection",
"my-second-collection"
]
},
"published": {
"display_name": "Third Text component",
"description": "Third Testing"
}
},
{
Expand Down Expand Up @@ -128,6 +140,10 @@
"key": [
"my-first-collection"
]
},
"published": {
"display_name": "Text 4",
"description": "Testing 4"
}
},
{
Expand Down Expand Up @@ -159,6 +175,10 @@
"key": [
"my-first-collection"
]
},
"published": {
"display_name": "Blank Problem",
"description": "Problem"
}
}
],
Expand Down
60 changes: 50 additions & 10 deletions src/library-authoring/__mocks__/library-search.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Introduction to Testing",
"description": "Testing"
}
},
{
"id": "lbaximtesthtml73a22298-bcd9-4f4c-ae34-0bc2b0612480-46b4a7f2",
Expand All @@ -48,7 +52,11 @@
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Second Text Component",
"description": "Second Testing"
}
},
{
"id": "lbaximtesthtmlbe5b5db9-26ba-4fac-86af-654538c70b5e-73dbaa95",
Expand All @@ -71,7 +79,11 @@
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Third Text component",
"description": "Third Testing"
}
},
{
"id": "lbaximtesthtmle59e8c73-4056-4894-bca4-062781fb3f68-46a404b2",
Expand All @@ -94,7 +106,11 @@
"block_type": "html",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Text 4",
"description": "Testing 4"
}
},
{
"id": "lbaximtestproblemf16116c9-516e-4bb9-b99e-103599f62417-f2798115",
Expand All @@ -117,7 +133,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Blank Problem",
"description": "Problem"
}
},
{
"id": "lbaximtestproblem2ace6b9b-6620-413c-a66f-19c797527f34-3a7973b7",
Expand All @@ -143,7 +163,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Multiple Choice Problem",
"description": "Problem"
}
},
{
"id": "lbaximtestproblem7d7e98ba-3ac9-4aa8-8946-159129b39a28-3a7973b7",
Expand All @@ -169,7 +193,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Single Choice Problem",
"description": "Problem"
}
},
{
"id": "lbaximtestproblem4e1a72f9-ac93-42aa-a61c-ab5f9698c398-3a7973b7",
Expand All @@ -195,7 +223,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Numerical Response Problem",
"description": "Problem"
}
},
{
"id": "lbaximtestproblemad483625-ade2-4712-88d8-c9743abbd291-3a7973b7",
Expand All @@ -221,7 +253,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "Option Response Problem",
"description": "Problem"
}
},
{
"id": "lbaximtestproblemb4c859cb-de70-421a-917b-e6e01ce44bd8-3a7973b7",
Expand All @@ -247,7 +283,11 @@
"block_type": "problem",
"context_key": "lib:Axim:TEST",
"org": "Axim",
"access_id": 15
"access_id": 15,
"published": {
"display_name": "String Response Problem",
"description": "Problem"
}
}
],
"query": "",
Expand Down
4 changes: 4 additions & 0 deletions src/library-authoring/__mocks__/libraryComponentsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default [
id: '1',
usageKey: 'lb:org:lib:html:1',
displayName: 'Text Component 1',
description: 'This is a text: ID=1',
formatted: {
displayName: 'Text Component 1',
content: {
Expand All @@ -18,6 +19,7 @@ export default [
id: '2',
usageKey: 'lb:org:lib:html:2',
displayName: 'Text Component 2',
description: 'This is a text: ID=2',
formatted: {
displayName: 'Text Component 2',
content: {
Expand Down Expand Up @@ -60,6 +62,7 @@ export default [
id: '5',
usageKey: 'lb:org:lib:problem:5',
displayName: 'Problem',
description: 'This is a problem: ID=5',
formatted: {
displayName: 'Problem',
content: {
Expand All @@ -72,6 +75,7 @@ export default [
id: '6',
usageKey: 'lb:org:lib:problem:6',
displayName: 'Problem',
description: 'This is a problem: ID=6',
formatted: {
displayName: 'Problem',
content: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ const LibraryCollectionPage = () => {
/>
);

const extraFilter = [`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`];
if (componentPickerMode) {
extraFilter.push('last_published IS NOT NULL');
}

return (
<div className="d-flex">
<div className="flex-grow-1">
Expand All @@ -189,7 +194,7 @@ const LibraryCollectionPage = () => {
)}
<Container size="xl" className="px-4 mt-4 mb-5 library-authoring-page">
<SearchContextProvider
extraFilter={[`context_key = "${libraryId}"`, `collections.key = "${collectionId}"`]}
extraFilter={extraFilter}
overrideQueries={{ collections: { limit: 0 } }}
>
<SubHeader
Expand Down
16 changes: 13 additions & 3 deletions src/library-authoring/component-info/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ModalComponentPreviewProps {

const ModalComponentPreview = ({ isOpen, close, usageKey }: ModalComponentPreviewProps) => {
const intl = useIntl();
const { componentPickerMode } = useLibraryContext();

return (
<StandardModal
Expand All @@ -24,7 +25,10 @@ const ModalComponentPreview = ({ isOpen, close, usageKey }: ModalComponentPrevie
isOverflowVisible={false}
className="component-preview-modal"
>
<LibraryBlock usageKey={usageKey} />
<LibraryBlock
usageKey={usageKey}
version={componentPickerMode ? 'published' : undefined}
/>
</StandardModal>
);
};
Expand All @@ -33,7 +37,7 @@ const ComponentPreview = () => {
const intl = useIntl();

const [isModalOpen, openModal, closeModal] = useToggle();
const { sidebarComponentUsageKey: usageKey } = useLibraryContext();
const { sidebarComponentUsageKey: usageKey, componentPickerMode } = useLibraryContext();

// istanbul ignore if: this should never happen
if (!usageKey) {
Expand All @@ -57,7 +61,13 @@ const ComponentPreview = () => {
{
// key=modified below is used to auto-refresh the preview when changes are made, e.g. via OLX editor
componentMetadata
? <LibraryBlock usageKey={usageKey} key={componentMetadata.modified} />
? (
<LibraryBlock
usageKey={usageKey}
key={componentMetadata.modified}
version={componentPickerMode ? 'published' : undefined}
/>
)
: null
}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/library-authoring/components/ComponentCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const contentHit: ContentHit = {
org: 'org1',
breadcrumbs: [{ displayName: 'Demo Lib' }],
displayName: 'Text Display Name',
description: 'This is a text: ID=1',
formatted: {
displayName: 'Text Display Formated Name',
content: {
Expand Down
16 changes: 9 additions & 7 deletions src/library-authoring/components/ComponentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => {
formatted,
tags,
usageKey,
description,
published,
} = contentHit;
const description: string = (/* eslint-disable */
blockType === 'html' ? formatted?.content?.htmlContent :
blockType === 'problem' ? formatted?.content?.capaContent :
undefined
) ?? '';/* eslint-enable */
const displayName = formatted?.displayName ?? '';
const componentDescription: string = (
componentPickerMode ? published?.description : description
) ?? '';
const displayName: string = (
componentPickerMode ? published?.displayName : formatted?.displayName
) ?? '';

const handleAddComponentToCourse = () => {
window.parent.postMessage({
Expand All @@ -128,7 +130,7 @@ const ComponentCard = ({ contentHit }: ComponentCardProps) => {
<BaseComponentCard
componentType={blockType}
displayName={displayName}
description={description}
description={componentDescription}
tags={tags}
actions={(
<ActionRow>
Expand Down
11 changes: 11 additions & 0 deletions src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,20 @@ export interface ContentHit extends BaseContentHit {
* - After that is the name and usage key of any parent Section/Subsection/Unit/etc.
*/
breadcrumbs: [{ displayName: string }, ...Array<{ displayName: string, usageKey: string }>];
description?: string;
content?: ContentDetails;
lastPublished: number | null;
collections: { displayName?: string[], key?: string[] },
published?: ContentPublishedData,
}

/**
* Information about the published data of single Xblock returned in search results
* Defined in edx-platform/openedx/core/djangoapps/content/search/documents.py
*/
export interface ContentPublishedData {
description?: string,
displayName?: string,
}

/**
Expand Down