cy.get('[data-cy=form-submit-btn]').click();
- cy.get('button[aria-label=Remove]').click({ multiple: true });
+ cy.get('button[aria-label=Remove]').should('exist');
+ cy.get('button[aria-label=Remove]').click({ multiple: true, force: true });
cy.get('[data-cy=form-submit-btn]').should('not.exist');
});
cy.contains(testRootProject.uuid).should('exist');
});
});
+
+ it('clears search input when changing project', () => {
+ cy.createGroup(activeUser.token, {
+ name: `Test root project ${Math.floor(Math.random() * 999999)}`,
+ group_class: 'project',
+ }).as('testProject1');
+
+ cy.getAll('@testProject1').then(function([testProject1]) {
+ cy.loginAs(activeUser);
+
+ cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
+
+ cy.get('[data-cy=search-input] input').type('test123');
+
+ cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
+
+ cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
+ });
+ });
});
\ No newline at end of file
</IconButton>
</Tooltip>
<div className={path.length > 1 ? classes.searchWrapper : classes.searchWrapperHidden}>
- <SearchInput label="Search" value={leftSearch} onSearch={setLeftSearch} />
+ <SearchInput selfClearProp={leftKey} label="Search" value={leftSearch} onSearch={setLeftSearch} />
</div>
<div className={classes.dataWrapper}>
{
</div>
<div className={classes.rightPanel}>
<div className={classes.searchWrapper}>
- <SearchInput label="Search" value={rightSearch} onSearch={setRightSearch} />
+ <SearchInput selfClearProp={rightKey} label="Search" value={rightSearch} onSearch={setRightSearch} />
</div>
{
isWritable &&
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import React from "react";
-import { configure, shallow, mount } from "enzyme";
-import { WithStyles } from "@material-ui/core";
-import Adapter from "enzyme-adapter-react-16";
-import { TreeItem, TreeItemStatus } from '../tree/tree';
-import { FileTreeData } from '../file-tree/file-tree-data';
-import { CollectionFileType } from "../../models/collection-file";
-import { CollectionPanelFilesComponent, CollectionPanelFilesProps, CssRules } from './collection-panel-files2';
-import { SearchInput } from '../search-input/search-input';
-
-configure({ adapter: new Adapter() });
-
-jest.mock('components/file-tree/file-tree', () => ({
- FileTree: () => 'FileTree',
-}));
-
-describe('<CollectionPanelFiles />', () => {
- let props: CollectionPanelFilesProps & WithStyles<CssRules>;
-
- beforeEach(() => {
- props = {
- classes: {} as Record<CssRules, string>,
- items: [],
- isWritable: true,
- isLoading: false,
- tooManyFiles: false,
- onUploadDataClick: jest.fn(),
- onSearchChange: jest.fn(),
- onItemMenuOpen: jest.fn(),
- onOptionsMenuOpen: jest.fn(),
- onSelectionToggle: jest.fn(),
- onCollapseToggle: jest.fn(),
- onFileClick: jest.fn(),
- loadFilesFunc: jest.fn(),
- currentItemUuid: '',
- };
- });
-
- it('renders properly', () => {
- // when
- const wrapper = shallow(<CollectionPanelFilesComponent {...props} />);
-
- // then
- expect(wrapper).not.toBeUndefined();
- });
-
- it('filters out files', () => {
- // given
- const searchPhrase = 'test';
- const items: Array<TreeItem<FileTreeData>> = [
- {
- data: {
- url: '',
- type: CollectionFileType.DIRECTORY,
- name: 'test',
- },
- id: '1',
- open: true,
- active: true,
- status: TreeItemStatus.LOADED,
- },
- {
- data: {
- url: '',
- type: CollectionFileType.FILE,
- name: 'test123',
- },
- id: '2',
- open: true,
- active: true,
- status: TreeItemStatus.LOADED,
- },
- {
- data: {
- url: '',
- type: CollectionFileType.FILE,
- name: 'another-file',
- },
- id: '3',
- open: true,
- active: true,
- status: TreeItemStatus.LOADED,
- }
- ];
-
- // setup
- props.items = items;
- const wrapper = mount(<CollectionPanelFilesComponent {...props} />);
- wrapper.find(SearchInput).simulate('change', { target: { value: searchPhrase } });
-
- // when
- setTimeout(() => { // we have to use set timeout because of the debounce
- expect(wrapper.find('FileTree').prop('items'))
- .toEqual([
- {
- data: { url: '', type: 'directory', name: 'test' },
- id: '1',
- open: true,
- active: true,
- status: 'loaded'
- },
- {
- data: { url: '', type: 'file', name: 'test123' },
- id: '2',
- open: true,
- active: true,
- status: 'loaded'
- }
- ]);
- }, 0);
- });
-});
\ No newline at end of file
+++ /dev/null
-// Copyright (C) The Arvados Authors. All rights reserved.
-//
-// SPDX-License-Identifier: AGPL-3.0
-
-import React from 'react';
-import { TreeItem, TreeItemStatus } from 'components/tree/tree';
-import { FileTreeData } from 'components/file-tree/file-tree-data';
-import { FileTree } from 'components/file-tree/file-tree';
-import { IconButton, Grid, Typography, StyleRulesCallback, withStyles, WithStyles, CardHeader, Card, Button, Tooltip, CircularProgress } from '@material-ui/core';
-import { CustomizeTableIcon } from 'components/icon/icon';
-import { DownloadIcon } from 'components/icon/icon';
-import { SearchInput } from '../search-input/search-input';
-
-export interface CollectionPanelFilesProps {
- items: Array<TreeItem<FileTreeData>>;
- isWritable: boolean;
- isLoading: boolean;
- tooManyFiles: boolean;
- onUploadDataClick: () => void;
- onSearchChange: (searchValue: string) => void;
- onItemMenuOpen: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>, isWritable: boolean) => void;
- onOptionsMenuOpen: (event: React.MouseEvent<HTMLElement>, isWritable: boolean) => void;
- onSelectionToggle: (event: React.MouseEvent<HTMLElement>, item: TreeItem<FileTreeData>) => void;
- onCollapseToggle: (id: string, status: TreeItemStatus) => void;
- onFileClick: (id: string) => void;
- loadFilesFunc: () => void;
- currentItemUuid?: string;
-}
-
-export type CssRules = 'root' | 'cardSubheader' | 'nameHeader' | 'fileSizeHeader' | 'uploadIcon' | 'button' | 'centeredLabel' | 'cardHeaderContent' | 'cardHeaderContentTitle';
-
-const styles: StyleRulesCallback<CssRules> = theme => ({
- root: {
- paddingBottom: theme.spacing.unit,
- height: '100%'
- },
- cardSubheader: {
- paddingTop: 0,
- paddingBottom: 0,
- minHeight: 8 * theme.spacing.unit,
- },
- cardHeaderContent: {
- display: 'flex',
- paddingRight: 2 * theme.spacing.unit,
- justifyContent: 'space-between',
- },
- cardHeaderContentTitle: {
- paddingLeft: theme.spacing.unit,
- paddingTop: 2 * theme.spacing.unit,
- paddingRight: 2 * theme.spacing.unit,
- },
- nameHeader: {
- marginLeft: '75px'
- },
- fileSizeHeader: {
- marginRight: '65px'
- },
- uploadIcon: {
- transform: 'rotate(180deg)'
- },
- button: {
- marginRight: -theme.spacing.unit,
- marginTop: '8px'
- },
- centeredLabel: {
- fontSize: '0.875rem',
- textAlign: 'center'
- },
-});
-
-export const CollectionPanelFilesComponent = ({ onItemMenuOpen, onSearchChange, onOptionsMenuOpen, onUploadDataClick, classes,
- isWritable, isLoading, tooManyFiles, loadFilesFunc, ...treeProps }: CollectionPanelFilesProps & WithStyles<CssRules>) => {
- const { useState, useEffect } = React;
- const [searchValue, setSearchValue] = useState('');
-
- useEffect(() => {
- onSearchChange(searchValue);
- }, [onSearchChange, searchValue]);
-
- return (<Card data-cy='collection-files-panel' className={classes.root}>
- <CardHeader
- title={
- <div className={classes.cardHeaderContent}>
- <span className={classes.cardHeaderContentTitle}>Files</span>
- <SearchInput
- value={searchValue}
- label='Search files'
- onSearch={setSearchValue} />
- </div>
- }
- className={classes.cardSubheader}
- classes={{ action: classes.button }}
- action={<>
- {isWritable &&
- <Button
- data-cy='upload-button'
- onClick={onUploadDataClick}
- variant='contained'
- color='primary'
- size='small'>
- <DownloadIcon className={classes.uploadIcon} />
- Upload data
- </Button>}
- {!tooManyFiles &&
- <Tooltip title="More options" disableFocusListener>
- <IconButton
- data-cy='collection-files-panel-options-btn'
- onClick={(ev) => onOptionsMenuOpen(ev, isWritable)}>
- <CustomizeTableIcon />
- </IconButton>
- </Tooltip>}
- </>
- } />
- {tooManyFiles
- ? <div className={classes.centeredLabel}>
- File listing may take some time, please click to browse: <Button onClick={loadFilesFunc}><DownloadIcon />Show files</Button>
- </div>
- : <>
- <Grid container justify="space-between">
- <Typography variant="caption" className={classes.nameHeader}>
- Name
- </Typography>
- <Typography variant="caption" className={classes.fileSizeHeader}>
- File size
- </Typography>
- </Grid>
- {isLoading
- ? <div className={classes.centeredLabel}><CircularProgress /></div>
- : <div style={{ height: 'calc(100% - 60px)' }}>
- <FileTree
- onMenuOpen={(ev, item) => onItemMenuOpen(ev, item, isWritable)}
- {...treeProps} /></div>}
- </>
- }
- </Card>);
-};
-
-export const CollectionPanelFiles = withStyles(styles)(CollectionPanelFilesComponent);
export const DataExplorer = withStyles(styles)(
class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
+
componentDidMount() {
if (this.props.onSetColumns) {
this.props.onSetColumns(this.props.columns);
}
}
+
render() {
const {
columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
paperKey, fetchMode, currentItemUuid, title,
doHidePanel, doMaximizePanel, panelName, panelMaximized
} = this.props;
+
return <Paper className={classes.root} {...paperProps} key={paperKey}>
<Grid container direction="column" wrap="nowrap" className={classes.container}>
{title && <Grid item xs className={classes.title}>{title}</Grid>}
{!hideSearchInput && <SearchInput
label={searchLabel}
value={searchValue}
+ selfClearProp={currentItemUuid}
onSearch={onSearch} />}
</div>
{actions}
describe("on submit", () => {
it("calls onSearch with initial value passed via props", () => {
- const searchInput = mount(<SearchInput value="initial value" onSearch={onSearch} />);
+ const searchInput = mount(<SearchInput selfClearProp="" value="initial value" onSearch={onSearch} />);
searchInput.find("form").simulate("submit");
expect(onSearch).toBeCalledWith("initial value");
});
it("calls onSearch with current value", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} />);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} />);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
searchInput.find("form").simulate("submit");
expect(onSearch).toBeCalledWith("current value");
});
it("calls onSearch with new value passed via props", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} />);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} />);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
searchInput.setProps({value: "new value"});
searchInput.find("form").simulate("submit");
});
it("cancels timeout set on input value change", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} debounce={1000} />);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000} />);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
searchInput.find("form").simulate("submit");
jest.runTimersToTime(1000);
describe("on input value change", () => {
it("calls onSearch after default timeout", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} />);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} />);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
expect(onSearch).not.toBeCalled();
jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
});
it("calls onSearch after the time specified in props has passed", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} debounce={2000}/>);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={2000}/>);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(1000);
expect(onSearch).not.toBeCalled();
});
it("calls onSearch only once after no change happened during the specified time", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} debounce={1000}/>);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(500);
searchInput.find("input").simulate("change", { target: { value: "changed value" } });
});
it("calls onSearch again after the specified time has passed since previous call", () => {
- const searchInput = mount(<SearchInput value="" onSearch={onSearch} debounce={1000}/>);
+ const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
searchInput.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(500);
searchInput.find("input").simulate("change", { target: { value: "intermediate value" } });
});
+ describe("on input target change", () => {
+ it("clears the input value on selfClearProp change", () => {
+ const searchInput = mount(<SearchInput selfClearProp="abc" value="123" onSearch={onSearch} debounce={1000}/>);
+ searchInput.setProps({ selfClearProp: 'aaa' });
+ jest.runTimersToTime(1000);
+ expect(onSearch).toBeCalledWith("");
+ expect(onSearch).toHaveBeenCalledTimes(1);
+ });
+ });
+
});
interface SearchInputDataProps {
value: string;
label?: string;
+ selfClearProp: string;
}
interface SearchInputActionProps {
interface SearchInputState {
value: string;
label: string;
+ selfClearProp: string;
}
export const DEFAULT_SEARCH_DEBOUNCE = 1000;
class extends React.Component<SearchInputProps> {
state: SearchInputState = {
value: "",
- label: ""
+ label: "",
+ selfClearProp: ""
};
timeout: number;
<InputLabel>{this.state.label}</InputLabel>
<Input
type="text"
+ data-cy="search-input"
value={this.state.value}
onChange={this.handleChange}
endAdornment={
if (nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value });
}
+ if (this.state.value !== '' && nextProps.selfClearProp && nextProps.selfClearProp !== this.state.selfClearProp) {
+ this.props.onSearch('');
+ this.setState({ selfClearProp: nextProps.selfClearProp });
+ }
}
componentWillUnmount() {
<Grid container spacing={16}>
<Grid container item xs={6} className={classes.root}>
<Grid item xs={12} className={classes.searchGrid}>
- <SearchInput value='' onSearch={onSearch} />
+ <SearchInput selfClearProp={JSON.stringify(selectedWorkflow)} value='' onSearch={onSearch} />
</Grid>
<Grid item xs={12}>
<List className={classes.list}>