Skip to content

Commit

Permalink
refactor: remove ComponentPickerModal component
Browse files Browse the repository at this point in the history
Replace with standard modal and component picker components.
  • Loading branch information
navinkarkera committed Nov 13, 2024
1 parent 68361f6 commit 6c489d1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 75 deletions.
8 changes: 4 additions & 4 deletions src/library-authoring/LibraryLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LibraryProvider } from './common/context';
import { CreateCollectionModal } from './create-collection';
import { LibraryTeamModal } from './library-team';
import LibraryCollectionPage from './collections/LibraryCollectionPage';
import { ComponentPickerModal } from './component-picker';
import { ComponentPicker} from './component-picker';

Check failure on line 13 in src/library-authoring/LibraryLayout.tsx

View workflow job for this annotation

GitHub Actions / tests

A space is required before '}'
import { ComponentEditorModal } from './components/ComponentEditorModal';

const LibraryLayout = () => {
Expand All @@ -32,9 +32,9 @@ const LibraryLayout = () => {
collectionId={collectionId}
/** The component picker modal to use. We need to pass it as a reference instead of
* directly importing it to avoid the import cycle:
* ComponentPickerModal > ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPickerModal */
componentPickerModal={ComponentPickerModal}
* ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPicker */
componentPicker={ComponentPicker}
>
<Routes>
<Route
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/add-content/AddContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const AddContentContainer = () => {
collectionId,
openCreateCollectionModal,
openComponentEditor,
componentPickerModal,
componentPicker,
} = useLibraryContext();
const createBlockMutation = useCreateLibraryBlock();
const updateComponentsMutation = useAddComponentsToCollection(libraryId, collectionId);
Expand Down Expand Up @@ -239,7 +239,7 @@ const AddContentContainer = () => {
return (
<Stack direction="vertical">
{collectionId ? (
componentPickerModal && (
componentPicker && (
<>
<AddContentButton contentType={libraryContentButtonData} onCreateContent={onCreateContent} />
<PickLibraryContentModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { studioHomeMock } from '../../studio-home/__mocks__';
import { getStudioHomeApiUrl } from '../../studio-home/data/api';
import mockResult from '../__mocks__/library-search.json';
import { LibraryProvider } from '../common/context';
import { ComponentPickerModal } from '../component-picker';
import { ComponentPicker } from '../component-picker';
import * as api from '../data/api';
import {
mockContentLibrary,
Expand Down Expand Up @@ -40,7 +40,7 @@ const render = () => baseRender(<PickLibraryContentModal isOpen onClose={onClose
<LibraryProvider
libraryId={libraryId}
collectionId="collectionId"
componentPickerModal={ComponentPickerModal}
componentPicker={ComponentPicker}
>
{children}
</LibraryProvider>
Expand Down
27 changes: 17 additions & 10 deletions src/library-authoring/add-content/PickLibraryContentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useContext, useState } from 'react';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import { ActionRow, Button } from '@openedx/paragon';
import { ActionRow, Button, StandardModal } from '@openedx/paragon';

import { ToastContext } from '../../generic/toast-context';
import { type SelectedComponent, useLibraryContext } from '../common/context';
Expand Down Expand Up @@ -41,14 +41,14 @@ export const PickLibraryContentModal: React.FC<PickLibraryContentModalProps> = (
libraryId,
collectionId,
/** We need to get it as a reference instead of directly importing it to avoid the import cycle:
* ComponentPickerModal > ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPickerModal */
componentPickerModal: ComponentPickerModal,
* ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPicker */
componentPicker: ComponentPicker,
} = useLibraryContext();

// istanbul ignore if: this should never happen
if (!collectionId || !ComponentPickerModal) {
throw new Error('libraryId and componentPickerModal are required');
if (!collectionId || !ComponentPicker) {
throw new Error('libraryId and componentPicker are required');
}

const updateComponentsMutation = useAddComponentsToCollection(libraryId, collectionId);
Expand All @@ -70,12 +70,19 @@ export const PickLibraryContentModal: React.FC<PickLibraryContentModalProps> = (
}, [selectedComponents]);

return (
<ComponentPickerModal
libraryId={libraryId}
<StandardModal
title="Select components"
isOverflowVisible={false}
size="xl"
isOpen={isOpen}
onClose={onClose}
onChangeComponentSelection={setSelectedComponents}
footerNode={<PickLibraryContentModalFooter onSubmit={onSubmit} selectedComponents={selectedComponents} />}
/>
>
<ComponentPicker
libraryId={libraryId}
componentPickerMode="multiple"
onChangeComponentSelection={setSelectedComponents}
/>
</StandardModal>
);
};
26 changes: 13 additions & 13 deletions src/library-authoring/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
useState,
} from 'react';

import type { ComponentPickerModal } from '../component-picker';
import type { ComponentPicker } from '../component-picker';
import type { ContentLibrary } from '../data/api';
import { useContentLibrary } from '../data/apiHooks';

Expand All @@ -27,9 +27,9 @@ type NoComponentPickerType = {
restrictToLibrary?: never;
/** The component picker modal to use. We need to pass it as a reference instead of
* directly importing it to avoid the import cycle:
* ComponentPickerModal > ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPickerModal */
componentPickerModal?: typeof ComponentPickerModal;
* ComponentPicker > LibraryAuthoringPage/LibraryCollectionPage >
* Sidebar > AddContentContainer > ComponentPicker */
componentPicker?: typeof ComponentPicker;
};

type ComponentPickerSingleType = {
Expand All @@ -39,7 +39,7 @@ type ComponentPickerSingleType = {
addComponentToSelectedComponents?: never;
removeComponentFromSelectedComponents?: never;
restrictToLibrary: boolean;
componentPickerModal?: never;
componentPicker?: never;
};

type ComponentPickerMultipleType = {
Expand All @@ -49,7 +49,7 @@ type ComponentPickerMultipleType = {
addComponentToSelectedComponents: ComponentSelectedEvent;
removeComponentFromSelectedComponents: ComponentSelectedEvent;
restrictToLibrary: boolean;
componentPickerModal?: never;
componentPicker?: never;
};

type ComponentPickerType = NoComponentPickerType | ComponentPickerSingleType | ComponentPickerMultipleType;
Expand Down Expand Up @@ -121,23 +121,23 @@ type NoComponentPickerProps = {
onComponentSelected?: never;
onChangeComponentSelection?: never;
restrictToLibrary?: never;
componentPickerModal?: typeof ComponentPickerModal;
componentPicker?: typeof ComponentPicker;
};

export type ComponentPickerSingleProps = {
componentPickerMode: 'single';
onComponentSelected: ComponentSelectedEvent;
onChangeComponentSelection?: never;
restrictToLibrary?: boolean;
componentPickerModal?: never;
componentPicker?: never;
};

export type ComponentPickerMultipleProps = {
componentPickerMode: 'multiple';
onComponentSelected?: never;
onChangeComponentSelection?: ComponentSelectionChangedEvent;
restrictToLibrary?: boolean;
componentPickerModal?: never;
componentPicker?: never;
};

type ComponentPickerProps = NoComponentPickerProps | ComponentPickerSingleProps | ComponentPickerMultipleProps;
Expand All @@ -150,7 +150,7 @@ type LibraryProviderProps = {
showOnlyPublished?: boolean;
/** Only used for testing */
initialSidebarComponentInfo?: SidebarComponentInfo;
componentPickerModal?: typeof ComponentPickerModal;
componentPicker?: typeof ComponentPicker;
} & ComponentPickerProps;

/**
Expand All @@ -166,7 +166,7 @@ export const LibraryProvider = ({
onChangeComponentSelection,
showOnlyPublished = false,
initialSidebarComponentInfo,
componentPickerModal,
componentPicker,
}: LibraryProviderProps) => {
const [collectionId, setCollectionId] = useState(collectionIdProp);
const [sidebarComponentInfo, setSidebarComponentInfo] = useState<SidebarComponentInfo | undefined>(
Expand Down Expand Up @@ -276,7 +276,7 @@ export const LibraryProvider = ({
if (!componentPickerMode) {
return {
...contextValue,
componentPickerModal,
componentPicker,
};
}
if (componentPickerMode === 'single') {
Expand Down Expand Up @@ -329,7 +329,7 @@ export const LibraryProvider = ({
openComponentEditor,
closeComponentEditor,
resetSidebarAdditionalActions,
componentPickerModal,
componentPicker,
]);

return (
Expand Down
43 changes: 0 additions & 43 deletions src/library-authoring/component-picker/ComponentPickerModal.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/library-authoring/component-picker/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { ComponentPicker } from './ComponentPicker';

Check failure on line 1 in src/library-authoring/component-picker/index.ts

View workflow job for this annotation

GitHub Actions / tests

Prefer default export on a file with single export
export { ComponentPickerModal } from './ComponentPickerModal';

0 comments on commit 6c489d1

Please sign in to comment.