Skip to content

Commit

Permalink
components: SearchBar refactor
Browse files Browse the repository at this point in the history
- upgrade react-searchkit 1.0.0-alpha.3
- removed buttonColor, never used, and in case we use it, it has no effect since its overridden by the .ui.input.action.ils-searchbar styles
- subtitle to SearchError as child
- simplified search message when empty results
- Decoupled QueryBuildHelper to a stand alone component connected to RSK state
- fix bug in PatronResultList, when we had empty results, there were displayed two empty results message boxes
- remove RSK override
- configure with props React Search Kit Search bar
- SearchBarILS our simplified not connected to RSK searchbar
- fixed issue with configuration on BucketAggregations
- SearchBarILS replacing individual searchbars
- fixed missing identifiers for all <Identifiers>
- fixed empty results in series literature mobile was disconnected from RSK
- depends on inveniosoftware/react-searchkit#141
- closes inveniosoftware#226
  • Loading branch information
topless committed Oct 13, 2020
1 parent bf2c597 commit 534a666
Show file tree
Hide file tree
Showing 41 changed files with 397 additions and 697 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-scroll": "^1.7.16",
"react-searchkit": "^1.0.0-alpha.4",
"react-searchkit": "^1.0.0-alpha.5",
"react-show-more": "^2.0.0",
"react-tagcloud": "^2.0.0",
"redux": "^4.0.5",
Expand Down Expand Up @@ -95,7 +95,7 @@
"react-router-dom": "^5.1.2",
"react-scripts": "^3.4.1",
"react-scroll": "^1.7.16",
"react-searchkit": "^1.0.0-alpha.4",
"react-searchkit": "^1.0.0-alpha.5",
"react-show-more": "^2.0.0",
"react-tagcloud": "^2.0.0",
"redux": "^4.0.5",
Expand Down
24 changes: 15 additions & 9 deletions src/lib/components/SearchBar/QueryBuildHelper.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { List, Grid } from 'semantic-ui-react';
import { withState } from 'react-searchkit';

export class QueryBuildHelper extends Component {
class _QueryBuildHelper extends Component {
addToQuery = field => {
const { currentQueryString, updateQueryString } = this.props;
const { currentQueryState, updateQueryState } = this.props;
const { queryString } = currentQueryState;

const defaultVal = field.defaultValue ? field.defaultValue : '*';
const newCriteriaString = `${field.field}:${defaultVal}`;
const previousQueryString = currentQueryString;
const previousQueryString = queryString;

if (previousQueryString === '') {
updateQueryString(newCriteriaString);
updateQueryState({ queryString: newCriteriaString });
} else {
updateQueryString(`${previousQueryString} AND ${newCriteriaString}`);
updateQueryState({
queryString: `${previousQueryString} AND ${newCriteriaString}`,
});
}
};

Expand Down Expand Up @@ -46,6 +51,7 @@ export class QueryBuildHelper extends Component {

render() {
const { fields } = this.props;

return (
<Grid>
<Grid.Row columns={1}>
Expand All @@ -58,10 +64,10 @@ export class QueryBuildHelper extends Component {
}
}

QueryBuildHelper.propTypes = {
_QueryBuildHelper.propTypes = {
fields: PropTypes.array.isRequired,
currentQueryString: PropTypes.string.isRequired,
updateQueryString: PropTypes.func.isRequired,
updateQueryState: PropTypes.func.isRequired,
currentQueryState: PropTypes.object.isRequired,
};

QueryBuildHelper.defaultProps = {};
export const QueryBuildHelper = withState(_QueryBuildHelper);
116 changes: 0 additions & 116 deletions src/lib/components/SearchBar/SearchBar.js

This file was deleted.

95 changes: 0 additions & 95 deletions src/lib/components/SearchBar/SearchBar.test.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/lib/components/SearchBar/SearchBarILS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Input } from 'semantic-ui-react';

export class SearchBarILS extends Component {
state = { currentValue: '' };

componentDidMount() {
if (this.focusInput) {
this.focusInput.focus();
}
}

onKeyPressHandler = (event, input) => {
if (event.key === 'Enter') {
const { onSearchHandler } = this.props;
const { currentValue } = this.state;
onSearchHandler(currentValue);
}
};

onPasteHandler = event => {
const { onSearchHandler } = this.props;
const queryString = (event.clipboardData || window.clipboardData).getData(
'text'
);
onSearchHandler(queryString);
};

render() {
const {
className: parentClass,
onKeyPressHandler: parentKeyPressHandler,
onSearchHandler,
onPasteHandler,
placeholder,
...rest
} = this.props;
const { currentValue } = this.state;
return (
<Input
action={{
icon: 'search',
onClick: () => onSearchHandler(currentValue),
}}
onChange={(event, { value }) => {
this.setState({ currentValue: value });
}}
onKeyPress={parentKeyPressHandler || this.onKeyPressHandler}
onPaste={onPasteHandler || this.onPasteHandler}
fluid
size="big"
placeholder={placeholder}
className={`${parentClass} ils-searchbar`}
ref={input => {
this.focusInput = input;
}}
{...rest}
/>
);
}
}

SearchBarILS.propTypes = {
onKeyPressHandler: PropTypes.func,
onPasteHandler: PropTypes.func,
onSearchHandler: PropTypes.func.isRequired,
placeholder: PropTypes.string,
className: PropTypes.string,
};

SearchBarILS.defaultProps = {
onKeyPressHandler: null,
onPasteHandler: null,
placeholder: '',
className: '',
};
Loading

0 comments on commit 534a666

Please sign in to comment.