Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add expand-collapse button #42

Merged
merged 6 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/icon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { LabIcon } from '@jupyterlab/ui-components';

import wholeWord from '../style/icons/whole-word.svg';
import expandAll from '../style/icons/expand-all.svg';

export const wholeWordIcon = new LabIcon({
name: 'search-replace:wholeWord',
svgstr: wholeWord
});

export const expandAllIcon = new LabIcon({
name: 'search-replace:expandAll',
svgstr: expandAll
});
19 changes: 18 additions & 1 deletion src/searchReplace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Debouncer } from '@lumino/polling';
import { CommandRegistry } from '@lumino/commands';
import { requestAPI } from './handler';
import { VDomModel, VDomRenderer } from '@jupyterlab/apputils';
import { wholeWordIcon } from './icon';
import { wholeWordIcon, expandAllIcon } from './icon';
import {
Search,
TreeView,
Expand Down Expand Up @@ -294,6 +294,23 @@ const SearchReplaceElement = (props: IProps) => {
>
<refreshIcon.react></refreshIcon.react>
</Button>
<Button
madhur-tandon marked this conversation as resolved.
Show resolved Hide resolved
title="button to expand and collapse all results"
onClick={() => {
const elements =
document.getElementsByClassName('search-tree-files');
for (let i = 0; i < elements.length; i++) {
const treeItem = elements[i];
if (treeItem.hasAttribute('expanded')) {
treeItem.removeAttribute('expanded');
} else {
treeItem.setAttribute('expanded', '');
}
}
}}
madhur-tandon marked this conversation as resolved.
Show resolved Hide resolved
>
<expandAllIcon.react></expandAllIcon.react>
madhur-tandon marked this conversation as resolved.
Show resolved Hide resolved
</Button>
</div>
<div className="search-bar-with-options">
<Search
Expand Down
5 changes: 5 additions & 0 deletions style/icons/expand-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ui-tests/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,26 @@ test('should make a new request on refresh', async ({ page }) => {
page.locator('[title="button to refresh and reload results"]').click()
]);
});


test('should expand and collapse tree view on clicking expand-collapse button', async ({ page }) => {
// Click #tab-key-0 .lm-TabBar-tabIcon svg >> nth=0
await page.locator('[title="Search and replace"]').click();
// Fill input[type="search"]
await page.locator('input[type="search"]').fill('strange');

await Promise.all([
page.waitForResponse(
response =>
/.*search\/\?query=strange/.test(response.url()) &&
response.request().method() === 'GET'
),
page.locator('input[type="search"]').press('Enter'),
page.locator('[title="button to expand and collapse all results"]').click()
]);

madhur-tandon marked this conversation as resolved.
Show resolved Hide resolved
expect(await page.locator('.search-tree-matches').count()).toEqual(0);

await page.locator('[title="button to expand and collapse all results"]').click();
expect(await page.locator('.search-tree-matches').count()).toEqual(5);
});