Skip to content

Commit

Permalink
feat(content-explorer): allow not using Portal when rendering modal (#…
Browse files Browse the repository at this point in the history
…3501)

* feat(content-explorer): allow not using Portal when rendering modal

* feat(content-explorer): update test component renderer
  • Loading branch information
dmazaleuskaya committed Jan 31, 2024
1 parent 6e6a6d9 commit b096d38
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class ContentExplorerModalContainer extends Component {
listHeaderRenderer: PropTypes.func,
/** Whether the new folder button should be shown */
showCreateNewFolderButton: PropTypes.bool,
/** Whether the modals should be nested in a Portal or in a div */
shouldNotUsePortal: PropTypes.bool,
/** Props for the search input */
searchInputProps: PropTypes.object,
/** Custom text for the choose button */
Expand Down Expand Up @@ -204,6 +206,7 @@ class ContentExplorerModalContainer extends Component {
isCreatingFolder,
createFolderError,
initialFoldersPath,
shouldNotUsePortal,
...rest
} = this.props;
const { foldersPath, isNewFolderModalOpen } = this.state;
Expand All @@ -219,6 +222,7 @@ class ContentExplorerModalContainer extends Component {
isOpen
onEnterFolder={this.handleEnterFolder}
onCreateNewFolderButtonClick={this.handleCreateNewFolderButtonClick}
shouldNotUsePortal={shouldNotUsePortal}
{...rest}
/>
{isNewFolderModalOpen && (
Expand All @@ -230,6 +234,7 @@ class ContentExplorerModalContainer extends Component {
onCreateFolderInput={onCreateFolderInput}
isCreatingFolder={isCreatingFolder}
createFolderError={createFolderError}
shouldNotUsePortal={shouldNotUsePortal}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import ContentExplorerModalContainer from '../ContentExplorerModalContainer';
describe('features/content-explorer/content-explorer-modal-container/ContentExplorerModalContainer', () => {
const sandbox = sinon.sandbox.create();
const initialSelectedItems = { '123': { id: '123', name: 'folder123' } };
const renderComponent = props =>
shallow(
const renderComponent = (props, renderer = shallow) =>
renderer(
<ContentExplorerModalContainer
onRequestClose={() => {}}
isOpen
Expand Down Expand Up @@ -83,6 +83,20 @@ describe('features/content-explorer/content-explorer-modal-container/ContentExpl
expect(wrapper.find('ContentExplorerModal').prop('onSelectedClick')).toEqual(onSelectedClick);
expect(wrapper.find('ContentExplorerModal').prop('onSelectItem')).toEqual(onSelectItem);
});

test('should render ContentExplorerModal and NewFolderModal in Portal by default', () => {
const wrapper = renderComponent({}, mount);
wrapper.setState({ isNewFolderModalOpen: true });

expect(wrapper.find('Portal').length).toBe(4);
});

test('should not render ContentExplorerModal and NewFolderModal in Portal if shouldNotUsePortal=true', () => {
const wrapper = renderComponent({ shouldNotUsePortal: true }, mount);
wrapper.setState({ isNewFolderModalOpen: true });

expect(wrapper.find('Portal').length).toBe(0);
});
});

describe('onNewFolderModalShown', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Props = {
onSelectedClick?: () => void,
onSelectedItemsUpdate?: Function,
onViewSelectedClick?: Function,
shouldNotUsePortal?: boolean,
title?: string,
};

Expand All @@ -47,6 +48,7 @@ const ContentExplorerModal = ({
onRequestClose,
onSelectedClick,
onSelectItem,
shouldNotUsePortal = false,
...rest
}: Props) => (
<Modal
Expand All @@ -56,6 +58,7 @@ const ContentExplorerModal = ({
})}
isOpen={isOpen}
onRequestClose={onRequestClose}
shouldNotUsePortal={shouldNotUsePortal}
>
{description}
<ContentExplorer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`features/content-explorer/content-explorer-modal/ContentExplorerModal r
<Modal
className="content-explorer-modal"
isOpen={true}
shouldNotUsePortal={false}
style={
{
"backdrop": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class NewFolderModal extends Component {
isCreatingFolder: PropTypes.bool,
/** Message that will be shown when there was an error creating the folder. */
createFolderError: PropTypes.string,
/** Whether the modal should be nested in a Portal or in a div */
shouldNotUsePortal: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -47,6 +49,7 @@ class NewFolderModal extends Component {
parentFolderName: '',
isCreatingFolder: false,
createFolderError: null,
shouldNotUsePortal: false,
};

constructor(props) {
Expand Down Expand Up @@ -82,6 +85,7 @@ class NewFolderModal extends Component {
parentFolderName,
isCreatingFolder,
createFolderError,
shouldNotUsePortal,
} = this.props;
const { folderNameInput } = this.state;

Expand All @@ -93,6 +97,7 @@ class NewFolderModal extends Component {
focusElementSelector=".folder-name-input input"
isOpen={isOpen}
onRequestClose={onRequestClose}
shouldNotUsePortal={shouldNotUsePortal}
title={
<FormattedMessage
{...messages.newFolderModalTitle}
Expand Down

0 comments on commit b096d38

Please sign in to comment.