Skip to content

Commit a4e3a94

Browse files
committed
feat: always show both collapse and expand
1 parent 030b3dc commit a4e3a94

File tree

2 files changed

+14
-33
lines changed

2 files changed

+14
-33
lines changed

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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -560,36 +560,20 @@ describe('CrudToolbar Component', function () {
560560
expect(onExpandAllClicked).to.have.been.calledOnce;
561561
});
562562

563-
it('should show collapse all documents if all documents were previously expanded', function () {
564-
renderCrudToolbar();
563+
it('should call onCollapseAllClicked when "Collapse all documents" is clicked', function () {
564+
const onCollapseAllClicked = sinon.spy();
565+
renderCrudToolbar({ onCollapseAllClicked });
565566

566-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
567-
const toolbar = screen.getByTestId('query-bar').closest('div')!;
568-
userEvent.click(toolbar, { button: 2 });
567+
const toolbar = screen.getByTestId('query-bar').closest('div');
568+
userEvent.click(toolbar!, { button: 2 });
569569

570570
const contextMenu = screen.getByTestId('context-menu');
571-
572-
// No Collapse all documents should be shown
573-
expect(within(contextMenu).queryByText('Collapse all documents')).to.not
574-
.exist;
575-
576-
// Click expand all documents
577-
const expandMenuItem = within(contextMenu).getByText(
578-
'Expand all documents'
579-
);
580-
userEvent.click(expandMenuItem);
581-
582-
// Right click again to open the context menu
583-
userEvent.click(toolbar, { button: 2 });
584-
585-
// Now it should show collapse all documents
586571
const collapseMenuItem = within(contextMenu).getByText(
587572
'Collapse all documents'
588573
);
589574
userEvent.click(collapseMenuItem);
590575

591-
expect(within(contextMenu).getByText('Collapse all documents')).to.be
592-
.visible;
576+
expect(onCollapseAllClicked).to.have.been.called;
593577
});
594578

595579
it('should call insertDataHandler with "import-file" when "Import JSON or CSV file" is clicked', function () {

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,21 +201,19 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
201201
() => querySkip || queryLimit,
202202
[querySkip, queryLimit]
203203
);
204-
const [allDocumentsExpanded, setAllDocumentsExpanded] = useState(false);
205204

206205
const contextMenuRef = useContextMenuItems(
207206
() => [
208207
{
209-
label: allDocumentsExpanded
210-
? 'Collapse all documents'
211-
: 'Expand all documents',
208+
label: 'Expand all documents',
212209
onAction: () => {
213-
if (allDocumentsExpanded) {
214-
onCollapseAllClicked();
215-
} else {
216-
onExpandAllClicked();
217-
}
218-
setAllDocumentsExpanded(!allDocumentsExpanded);
210+
onExpandAllClicked();
211+
},
212+
},
213+
{
214+
label: 'Collapse all documents',
215+
onAction: () => {
216+
onCollapseAllClicked();
219217
},
220218
},
221219
...(isImportExportEnabled
@@ -278,7 +276,6 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
278276
},
279277
],
280278
[
281-
allDocumentsExpanded,
282279
isImportExportEnabled,
283280
readonly,
284281
isWritable,

0 commit comments

Comments
 (0)