Skip to content

Commit fead6e4

Browse files
feat(content-explorer): Allow selecting empty selection in ContentExplorer (#3175)
feat: Allow selecting empty selection in ContentExplorer Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent b256b07 commit fead6e4

File tree

7 files changed

+53
-2
lines changed

7 files changed

+53
-2
lines changed

src/features/content-explorer/content-explorer-modal-container/ContentExplorerModalContainer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class ContentExplorerModalContainer extends Component {
1313
* Each column has to be a Column element
1414
*/
1515
additionalColumns: PropTypes.arrayOf(PropTypes.element),
16+
/** Allow users to choose no selections in MULTI_SELECT mode, defaults to false */
17+
isNoSelectionAllowed: PropTypes.bool,
1618
/** Breadcrumb component options */
1719
breadcrumbProps: BreadcrumbPropType,
1820
/** Adds class name. */

src/features/content-explorer/content-explorer-modal/ContentExplorerModal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Props = {
1616
className?: string,
1717
customInput?: React.ComponentType<any>,
1818
description?: string,
19+
isNoSelectionAllowed?: boolean,
1920
isOpen?: boolean,
2021
isResponsive?: boolean,
2122
itemRowHeight?: number,

src/features/content-explorer/content-explorer/ContentExplorer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class ContentExplorer extends Component {
2424
* Each column has to be a Column element
2525
*/
2626
additionalColumns: PropTypes.arrayOf(PropTypes.element),
27+
/** Allow users to choose no selections in MULTI_SELECT mode, defaults to false */
28+
isNoSelectionAllowed: PropTypes.bool,
2729
/** Props for breadcrumbs */
2830
breadcrumbProps: PropTypes.object,
2931
/** Props for the cancel button */
@@ -401,6 +403,7 @@ class ContentExplorer extends Component {
401403
const {
402404
actionButtonsProps,
403405
additionalColumns,
406+
isNoSelectionAllowed = false,
404407
breadcrumbProps,
405408
cancelButtonProps,
406409
chooseButtonProps,
@@ -459,7 +462,7 @@ class ContentExplorer extends Component {
459462
// NOTE: only expecting to have 1 (choose) button so as long as something
460463
// is selected and that item's isActionDisabled is false, we enable the action button
461464
areActionButtonsDisabled =
462-
selectedItemsIds.length === 0 ||
465+
(selectedItemsIds.length === 0 && !isNoSelectionAllowed) ||
463466
(selectedItemsIds.length === 1 && selectedItems[selectedItemsIds[0]].isActionDisabled);
464467
} else if (isViewingSearchResults || contentExplorerMode === ContentExplorerModes.SELECT_FILE) {
465468
// Buttons are only enabled when an item is selected
@@ -552,6 +555,7 @@ class ContentExplorer extends Component {
552555
onSelectedClick={onSelectedClick}
553556
onMoveClick={onMoveItem}
554557
selectedItems={selectedItems}
558+
isNoSelectionAllowed={isNoSelectionAllowed}
555559
/>
556560
</div>
557561
);

src/features/content-explorer/content-explorer/ContentExplorerActionButtons.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const ContentExplorerActionButtons = ({
3838
onMoveClick,
3939
onSelectedClick,
4040
selectedItems,
41+
isNoSelectionAllowed,
4142
}) => {
4243
const handleChooseClick = () => {
4344
let chosenItems = getChosenItemsFromSelectedItems(selectedItems);
@@ -46,7 +47,7 @@ const ContentExplorerActionButtons = ({
4647
chosenItems = [currentFolder];
4748
}
4849

49-
if (onChooseClick && chosenItems.length > 0) {
50+
if (onChooseClick && (chosenItems.length > 0 || isNoSelectionAllowed)) {
5051
onChooseClick(chosenItems);
5152
}
5253
};
@@ -164,6 +165,7 @@ ContentExplorerActionButtons.propTypes = {
164165
onMoveClick: PropTypes.func,
165166
onSelectedClick: PropTypes.func,
166167
selectedItems: ItemsMapPropType.isRequired,
168+
isNoSelectionAllowed: PropTypes.bool,
167169
};
168170

169171
export default ContentExplorerActionButtons;

src/features/content-explorer/content-explorer/__tests__/ContentExplorer.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ describe('features/content-explorer/content-explorer/ContentExplorer', () => {
240240
expect(wrapper.find('ContentExplorerActionButtons').prop('areButtonsDisabled')).toBe(true);
241241
});
242242
});
243+
244+
test('should render with action buttons enabled in MULTI_SELECT mode if there is no selection made when isNoSelectionAllowed is true', () => {
245+
const items = [
246+
{ id: '1', name: 'item1' },
247+
{ id: '2', name: 'item2' },
248+
{ id: '3', name: 'item3' },
249+
];
250+
251+
const wrapper = renderComponent({
252+
contentExplorerMode: ContentExplorerModes.MULTI_SELECT,
253+
items,
254+
isNoSelectionAllowed: true,
255+
});
256+
257+
expect(wrapper.find('ContentExplorerActionButtons').prop('areButtonsDisabled')).toBe(false);
258+
});
243259
});
244260

245261
describe('onEnterFolder', () => {

src/features/content-explorer/content-explorer/__tests__/ContentExplorerActionButtons.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,31 @@ describe('features/content-explorer/content-explorer/ContentExplorerActionButton
230230

231231
expect(onChooseClickSpy.withArgs([currentFolder]).calledOnce).toBe(true);
232232
});
233+
234+
test('should not call onChooseClick in MULTI_SELECT mode if selection is empty', () => {
235+
const onChooseClickSpy = sandbox.spy();
236+
const wrapper = renderComponent({
237+
contentExplorerMode: ContentExplorerModes.MULTI_SELECT,
238+
onChooseClick: onChooseClickSpy,
239+
selectedItems: {},
240+
});
241+
wrapper.find('.content-explorer-choose-button').simulate('click');
242+
243+
expect(onChooseClickSpy.calledOnce).toBe(false);
244+
});
245+
246+
test('should call onChooseClick in MULTI_SELECT mode if selection is empty and isNoSelectionAllowed is true', () => {
247+
const onChooseClickSpy = sandbox.spy();
248+
const wrapper = renderComponent({
249+
contentExplorerMode: ContentExplorerModes.MULTI_SELECT,
250+
onChooseClick: onChooseClickSpy,
251+
selectedItems: {},
252+
isNoSelectionAllowed: true,
253+
});
254+
wrapper.find('.content-explorer-choose-button').simulate('click');
255+
256+
expect(onChooseClickSpy.withArgs([]).calledOnce).toBe(true);
257+
});
233258
});
234259

235260
describe('onMoveClick', () => {

src/features/content-explorer/content-explorer/__tests__/__snapshots__/ContentExplorer.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ exports[`features/content-explorer/content-explorer/ContentExplorer render() cus
5050
"name": "folder",
5151
}
5252
}
53+
isNoSelectionAllowed={false}
5354
isResponsive={false}
5455
selectedItems={Object {}}
5556
/>

0 commit comments

Comments
 (0)