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 3 commits
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 @@ -148,6 +148,7 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
libraryData,
isLoadingLibraryData,
componentPickerMode,
showOnlyPublished,
sidebarBodyComponent,
openInfoSidebar,
} = useLibraryContext();
Expand Down Expand Up @@ -212,6 +213,11 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage
/>
) : undefined;

const extraFilter = [`context_key = "${libraryId}"`];
if (showOnlyPublished) {
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 +236,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, showOnlyPublished } = useLibraryContext();

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

return (
<SearchContextProvider
extraFilter={`context_key = "${libraryId}"`}
overrideSearchSortOrder={SearchSortOption.RECENTLY_MODIFIED}
extraFilter={extraFilter}
overrideSearchSortOrder={
showOnlyPublished
? 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 @@ -107,6 +107,7 @@ const LibraryCollectionPage = () => {
sidebarBodyComponent,
openCollectionInfoSidebar,
componentPickerMode,
showOnlyPublished,
setCollectionId,
} = useLibraryContext();

Expand Down Expand Up @@ -175,6 +176,11 @@ const LibraryCollectionPage = () => {
/>
);

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

return (
<div className="d-flex">
<div className="flex-grow-1">
Expand All @@ -189,7 +195,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
6 changes: 6 additions & 0 deletions src/library-authoring/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface LibraryContextData {
setCollectionId: (collectionId?: string) => void;
// Whether we're in "component picker" mode
componentPickerMode: boolean;
// Only show published components
showOnlyPublished: boolean;
// Sidebar stuff - only one sidebar is active at any given time:
sidebarBodyComponent: SidebarBodyComponentId | null;
closeLibrarySidebar: () => void;
Expand Down Expand Up @@ -69,6 +71,7 @@ interface LibraryProviderProps {
/** The component picker mode is a special mode where the user is selecting a component to add to a Unit (or another
* XBlock) */
componentPickerMode?: boolean;
showOnlyPublished?: boolean;
/** Only used for testing */
initialSidebarComponentUsageKey?: string;
/** Only used for testing */
Expand All @@ -83,6 +86,7 @@ export const LibraryProvider = ({
libraryId,
collectionId: collectionIdProp,
componentPickerMode = false,
showOnlyPublished = false,
initialSidebarComponentUsageKey,
initialSidebarCollectionId,
}: LibraryProviderProps) => {
Expand Down Expand Up @@ -140,6 +144,7 @@ export const LibraryProvider = ({
readOnly,
isLoadingLibraryData,
componentPickerMode,
showOnlyPublished,
sidebarBodyComponent,
closeLibrarySidebar,
openAddContentSidebar,
Expand All @@ -165,6 +170,7 @@ export const LibraryProvider = ({
readOnly,
isLoadingLibraryData,
componentPickerMode,
showOnlyPublished,
sidebarBodyComponent,
closeLibrarySidebar,
openAddContentSidebar,
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 { showOnlyPublished } = 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={showOnlyPublished ? '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
Loading
Loading