Skip to content

Commit 686fd8a

Browse files
committed
feat(compass-crud): expand/collapse all COMPASS-8233
1 parent eb4adfd commit 686fd8a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import UpdateMenu from './update-data-menu';
2222
import DeleteMenu from './delete-data-menu';
2323
import { QueryBar } from '@mongodb-js/compass-query-bar';
2424
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
25+
import ExpandControl from './expand-control';
2526

2627
const crudQueryBarStyles = css({
2728
width: '100%',
@@ -107,6 +108,8 @@ export type CrudToolbarProps = {
107108
onResetClicked: () => void;
108109
onUpdateButtonClicked: () => void;
109110
onDeleteButtonClicked: () => void;
111+
onExpandAllClicked: () => void;
112+
onCollapseAllClicked: () => void;
110113
openExportFileDialog: (exportFullCollection?: boolean) => void;
111114
outdated: boolean;
112115
page: number;
@@ -137,6 +140,8 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
137140
onResetClicked,
138141
onUpdateButtonClicked,
139142
onDeleteButtonClicked,
143+
onExpandAllClicked,
144+
onCollapseAllClicked,
140145
openExportFileDialog,
141146
outdated,
142147
page,
@@ -293,6 +298,12 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
293298
<Icon glyph="ChevronRight" />
294299
</IconButton>
295300
</div>
301+
302+
<ExpandControl
303+
onExpandAll={onExpandAllClicked}
304+
onCollapseAll={onCollapseAllClicked}
305+
/>
306+
296307
<ViewSwitcher
297308
activeView={activeDocumentView}
298309
onChange={viewSwitchHandler}

packages/compass-crud/src/components/document-list.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { DocumentTableViewProps } from './table-view/document-table-view';
2222
import DocumentTableView from './table-view/document-table-view';
2323
import type { CrudToolbarProps } from './crud-toolbar';
2424
import { CrudToolbar } from './crud-toolbar';
25-
import type { Document } from 'bson';
25+
import type { Document } from 'hadron-document';
2626
import type { DOCUMENTS_STATUSES } from '../constants/documents-statuses';
2727
import {
2828
DOCUMENTS_STATUS_ERROR,
@@ -512,6 +512,14 @@ const DocumentList: React.FunctionComponent<DocumentListProps> = (props) => {
512512
[view, setCurrentViewInitialScrollTop, scrollRef, viewChanged]
513513
);
514514

515+
const onExpandAllClicked = useCallback(() => {
516+
docs.forEach((doc) => !doc.expanded && doc.expand());
517+
}, [docs]);
518+
519+
const onCollapseAllClicked = useCallback(() => {
520+
docs.forEach((doc) => doc.expanded && doc.collapse());
521+
}, [docs]);
522+
515523
return (
516524
<div className={documentsContainerStyles} data-testid="compass-crud">
517525
<WorkspaceContainer
@@ -533,6 +541,8 @@ const DocumentList: React.FunctionComponent<DocumentListProps> = (props) => {
533541
onResetClicked={onResetClicked}
534542
onUpdateButtonClicked={onUpdateButtonClicked}
535543
onDeleteButtonClicked={onDeleteButtonClicked}
544+
onExpandAllClicked={onExpandAllClicked}
545+
onCollapseAllClicked={onCollapseAllClicked}
536546
openExportFileDialog={openExportFileDialog}
537547
outdated={outdated}
538548
readonly={!isEditable}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Button, Icon, Menu, MenuItem } from '@mongodb-js/compass-components';
2+
import React from 'react';
3+
4+
interface ExpandControlProps {
5+
onExpandAll: () => void;
6+
onCollapseAll: () => void;
7+
}
8+
9+
const ExpandControl: React.FunctionComponent<ExpandControlProps> = ({
10+
onExpandAll,
11+
onCollapseAll,
12+
}) => {
13+
return (
14+
<Menu
15+
trigger={
16+
<Button
17+
size="xsmall"
18+
aria-label="Expand Controls"
19+
title="Expand Controls"
20+
>
21+
<Icon glyph="CaretDown" />
22+
</Button>
23+
}
24+
>
25+
<MenuItem onClick={onExpandAll}>Expand all documents</MenuItem>
26+
<MenuItem onClick={onCollapseAll}>Collapse all documents</MenuItem>
27+
</Menu>
28+
);
29+
};
30+
31+
export default ExpandControl;

0 commit comments

Comments
 (0)