17579: Added search input clear after project change
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 2 Dec 2021 21:12:59 +0000 (22:12 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 2 Dec 2021 21:14:17 +0000 (22:14 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/project.spec.js
src/components/collection-panel-files/collection-panel-files.tsx
src/components/collection-panel-files/collection-panel-files2.tsx
src/components/data-explorer/data-explorer.tsx
src/components/search-input/search-input.tsx
src/views/run-process-panel/run-process-first-step.tsx

index 1c1759523ea0243113d0dd41fcbecbcfe636b257..4d77d3a5d1b9d67f61090fdf442f40a3f5c2a1e5 100644 (file)
@@ -194,4 +194,27 @@ describe('Project tests', function() {
             cy.contains(testRootProject.uuid).should('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.createGroup(activeUser.token, {
+            name: `Test root project ${Math.floor(Math.random() * 999999)}`,
+            group_class: 'project',
+        }).as('testProject2');
+
+        cy.getAll('@testProject1', '@testProject2').then(function([testProject1, testProject2]) {
+            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
 });
\ No newline at end of file
index a7001a61ac614e83f5dd6c8eb2e570a9902f55a6..97ec3bf9e1e4a72a9a5d251fbf8e8cd55363613d 100644 (file)
@@ -463,7 +463,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
                         </IconButton>
                     </Tooltip>
                     <div className={path.length > 1 ? classes.searchWrapper : classes.searchWrapperHidden}>
                         </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.dataWrapper}>
                         {
@@ -510,7 +510,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
                 </div>
                 <div className={classes.rightPanel}>
                     <div className={classes.searchWrapper}>
                 </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 &&
                     </div>
                     {
                         isWritable &&
index 4118248283ae7deed8fb2b416a28ed09d764382c..481844d9292eace15d0e373d10bca2ab5ad91313 100644 (file)
@@ -83,6 +83,7 @@ export const CollectionPanelFilesComponent = ({ onItemMenuOpen, onSearchChange,
                 <div className={classes.cardHeaderContent}>
                     <span className={classes.cardHeaderContentTitle}>Files</span>
                     <SearchInput
                 <div className={classes.cardHeaderContent}>
                     <span className={classes.cardHeaderContentTitle}>Files</span>
                     <SearchInput
+                        selfClearProp={''}
                         value={searchValue}
                         label='Search files'
                         onSearch={setSearchValue} />
                         value={searchValue}
                         label='Search files'
                         onSearch={setSearchValue} />
index d272e870bf0caaa46c7918624fe091265fb5c762..5f396bb4d0322eba1a032ce34a87e2f04943acec 100644 (file)
@@ -82,12 +82,19 @@ interface DataExplorerActionProps<T> {
 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules>;
 
 export const DataExplorer = withStyles(styles)(
 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules>;
 
 export const DataExplorer = withStyles(styles)(
-    class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
+    class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>, { currentItemUuid: string }> {
+        constructor(props) {
+            super(props);
+            this.state = {
+                currentItemUuid: props.currentItemUuid
+            };
+        }
         componentDidMount() {
             if (this.props.onSetColumns) {
                 this.props.onSetColumns(this.props.columns);
             }
         }
         componentDidMount() {
             if (this.props.onSetColumns) {
                 this.props.onSetColumns(this.props.columns);
             }
         }
+
         render() {
             const {
                 columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
         render() {
             const {
                 columns, onContextMenu, onFiltersChange, onSortToggle, working, extractKey,
@@ -96,6 +103,7 @@ export const DataExplorer = withStyles(styles)(
                 dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput,
                 paperKey, fetchMode, currentItemUuid, title
             } = this.props;
                 dataTableDefaultView, hideColumnSelector, actions, paperProps, hideSearchInput,
                 paperKey, fetchMode, currentItemUuid, title
             } = this.props;
+
             return <Paper className={classes.root} {...paperProps} key={paperKey}>
                 {title && <div className={classes.title}>{title}</div>}
                 {(!hideColumnSelector || !hideSearchInput) && <Toolbar className={title ? classes.toolbarUnderTitle : classes.toolbar}>
             return <Paper className={classes.root} {...paperProps} key={paperKey}>
                 {title && <div className={classes.title}>{title}</div>}
                 {(!hideColumnSelector || !hideSearchInput) && <Toolbar className={title ? classes.toolbarUnderTitle : classes.toolbar}>
@@ -104,6 +112,7 @@ export const DataExplorer = withStyles(styles)(
                             {!hideSearchInput && <SearchInput
                                 label={searchLabel}
                                 value={searchValue}
                             {!hideSearchInput && <SearchInput
                                 label={searchLabel}
                                 value={searchValue}
+                                selfClearProp={currentItemUuid}
                                 onSearch={onSearch} />}
                         </div>
                         {actions}
                                 onSearch={onSearch} />}
                         </div>
                         {actions}
index 5d5a9a226009c5cea5e7c2893ab5a9a85724f067..955cf5e5296b1a38bf72aa52a6646ec66e92abf8 100644 (file)
@@ -35,6 +35,7 @@ const styles: StyleRulesCallback<CssRules> = theme => {
 interface SearchInputDataProps {
     value: string;
     label?: string;
 interface SearchInputDataProps {
     value: string;
     label?: string;
+    selfClearProp: string;
 }
 
 interface SearchInputActionProps {
 }
 
 interface SearchInputActionProps {
@@ -47,6 +48,7 @@ type SearchInputProps = SearchInputDataProps & SearchInputActionProps & WithStyl
 interface SearchInputState {
     value: string;
     label: string;
 interface SearchInputState {
     value: string;
     label: string;
+    selfClearProp: string;
 }
 
 export const DEFAULT_SEARCH_DEBOUNCE = 1000;
 }
 
 export const DEFAULT_SEARCH_DEBOUNCE = 1000;
@@ -55,7 +57,8 @@ export const SearchInput = withStyles(styles)(
     class extends React.Component<SearchInputProps> {
         state: SearchInputState = {
             value: "",
     class extends React.Component<SearchInputProps> {
         state: SearchInputState = {
             value: "",
-            label: ""
+            label: "",
+            selfClearProp: ""
         };
 
         timeout: number;
         };
 
         timeout: number;
@@ -66,6 +69,7 @@ export const SearchInput = withStyles(styles)(
                     <InputLabel>{this.state.label}</InputLabel>
                     <Input
                         type="text"
                     <InputLabel>{this.state.label}</InputLabel>
                     <Input
                         type="text"
+                        data-cy="search-input"
                         value={this.state.value}
                         onChange={this.handleChange}
                         endAdornment={
                         value={this.state.value}
                         onChange={this.handleChange}
                         endAdornment={
@@ -93,6 +97,10 @@ export const SearchInput = withStyles(styles)(
             if (nextProps.value !== this.props.value) {
                 this.setState({ value: nextProps.value });
             }
             if (nextProps.value !== this.props.value) {
                 this.setState({ value: nextProps.value });
             }
+            if (nextProps.selfClearProp !== this.state.selfClearProp) {
+                this.props.onSearch('');
+                this.setState({ selfClearProp: nextProps.selfClearProp });
+            }
         }
 
         componentWillUnmount() {
         }
 
         componentWillUnmount() {
index 906d3a37b652e06426090c946d5c4d42cc3525e7..ed6d5640ed44c068879222e7d72a5683c6645d14 100644 (file)
@@ -59,7 +59,7 @@ export const RunProcessFirstStep = withStyles(styles)(
         <Grid container spacing={16}>
             <Grid container item xs={6} className={classes.root}>
                 <Grid item xs={12} className={classes.searchGrid}>
         <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}>
                 </Grid>
                 <Grid item xs={12}>
                     <List className={classes.list}>