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

Fix eslint errors #86

Open
wants to merge 34 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
69b42e7
fix eslint errors in curent-query component
byrond Jan 8, 2021
4ea5291
code cleanup in current-query component
byrond Jan 8, 2021
69d27e5
current-query: use field as key instead of index
byrond Jan 8, 2021
21194ad
fix eslint errors in federated-solr-faceted-search component
byrond Jan 13, 2021
932f6f5
fix eslint errors in FederatedSolrComponentPack
byrond Jan 14, 2021
2299f74
fix eslint errors in chevron icon
byrond Jan 14, 2021
16d5a75
fix eslint errors in search icon
byrond Jan 14, 2021
3908a8a
fix eslint errors in FederatedListFacet component
byrond Jan 15, 2021
f44d1e2
fix eslint errors in FederatedRangeFacet component
byrond Jan 20, 2021
08ecbd5
fix eslint errors in FederatedCountLabel component
byrond Jan 20, 2021
035495d
fix date picker in FederatedRangeFacet component
byrond Jan 23, 2021
c71d6d2
fix eslint errors in FederatedResultList component
byrond Jan 23, 2021
dcf6d85
fix eslint errors in FederatedPagination component
byrond Jan 25, 2021
5d66075
fix eslint errors in FederatedResult component
byrond Jan 26, 2021
05e7b6e
fix result count text spacing
byrond Jan 26, 2021
90cb22d
fix eslint errors in FederatedSearchFieldContainer component
byrond Jan 26, 2021
f5a0e74
fix eslint errors in FederatedSortMenu component
byrond Jan 29, 2021
9e96696
fix eslint errors in FederatedTextSearch component
byrond Jan 29, 2021
8dc748f
fix eslint errors in FederatedTextSearchNoAutocomplete component
byrond Jan 29, 2021
b8bfc9f
fix eslint errors in FederatedTextSearchAsYouType component
byrond Jan 29, 2021
b0fe669
fix eslint errors in helpers
byrond Jan 29, 2021
87acaa0
fix eslint errors in index.js
byrond Jan 29, 2021
9eab0b5
fix autocomplete
byrond Jan 29, 2021
50ebdfe
Fixes spacing of elements in autocomplete instructions.
agentrickard Feb 1, 2021
0d5d167
Ignore anonymous functions in eslint.
agentrickard Mar 2, 2021
dd307ee
Disable warnings for logging of console errors.
agentrickard Mar 2, 2021
78a6421
Remove dangerouslySetHtmlInner calls for straight vars.
agentrickard Mar 2, 2021
568ace0
Revert "Remove dangerouslySetHtmlInner calls for straight vars."
agentrickard Mar 2, 2021
d02aa40
Restores innerHTML call and supresses the eslint error.
agentrickard Mar 2, 2021
e9fa70c
Resolve proptype mismatch.
agentrickard Mar 3, 2021
2ab7672
FIx siteList prop.
agentrickard Mar 3, 2021
3c6add3
Fix bad autocomplete prop.
agentrickard Mar 3, 2021
dff2e21
Fix prop type for query on search-as-you-type.
agentrickard Mar 3, 2021
4932e28
Cleans up array prop mismatches.
agentrickard Mar 3, 2021
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
1, {
"extensions": [".js", ".jsx"],
}
]
],
"func-names": "off"
},
"env": {
"browser": true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"postinstall": "patch-package"
},
"dependencies": {
"classnames": "^2.2.5",
"he": "1.2.0",
"intl": "^1.2.5",
"patch-package": "^6.2.0",
Expand Down
247 changes: 133 additions & 114 deletions src/components/current-query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import moment from 'moment';
import { LiveMessenger } from 'react-aria-live';
import helpers from '../../helpers';


// Create dumb component which can be configured by props.
const FacetType = props => (
<button className="fs-applied-filters__filter" key={props.id} onClick={props.onClick}>
const FacetType = ({ id, onClick, children }) => (
<button className="fs-applied-filters__filter" key={id} onClick={onClick} type="submit">
<span className="fs-element-invisible">
Remove filter
</span>
{props.children}
{children}
</button>
);
FacetType.propTypes = {
id: PropTypes.string.isRequired,
onClick: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably remove isRequired and provide a default of [] instead. I think I did that in at least one other place.

};

// Configure and render the FacetType component to render as list facet type.
class ListFacetType extends React.Component {
removeListFacetValue(field, values, value) {
this.props.announcePolite(`Removed ${field.value} filter.`);
const ListFacetType = function ({ searchField, announcePolite, onChange }) {
function removeListFacetValue(field, values, value) {
announcePolite(`Removed ${field.value} filter.`);

const {
foundIdx,
Expand Down Expand Up @@ -47,64 +51,74 @@ class ListFacetType extends React.Component {
}

// Send query based on new state.
this.props.onChange(field, values.filter((v, i) => i !== foundIdx));
onChange(field, values.filter((v, i) => i !== foundIdx));
}
}

render() {
const { searchField } = this.props;
return (searchField.value.map((val, i) => (
<FacetType
key={i}
id={i}
onClick={() => this.removeListFacetValue(searchField.field, searchField.value, val)}
>
{/* Add spacing to hierarchical facet values: Type>Term = Type > Term. */}
{val.replace('>', ' > ')}
</FacetType>
)));
}
}
return (searchField.value.map((val) => (
<FacetType
key={searchField.field}
id={searchField.field}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to resolve a "don't use an index in the id" linting error. I don't think it changed/broke any behavior, but it's worth a look.

onClick={() => removeListFacetValue(searchField.field, searchField.value, val)}
>
{/* Add spacing to hierarchical facet values: Type>Term = Type > Term. */}
{val.replace('>', ' > ')}
</FacetType>
)));
};
ListFacetType.propTypes = {
announcePolite: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
searchField: PropTypes.shape({
field: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
}).isRequired,
};

// Configure and render the FacetType component to render as range facet type.
class RangeFacetType extends React.Component {
removeRangeFacetValue(field) {
this.props.announcePolite(`Removed ${field.value} filter.`);
this.props.onChange(field, []);
const RangeFacetType = function ({ searchField, announcePolite, onChange }) {
function removeRangeFacetValue(field) {
announcePolite(`Removed ${field.value} filter.`);
onChange(field, []);
}

render() {
const { searchField } = this.props;
// Create a moment from the search start date.
const start = moment(searchField.value[0]);
// Use UTC.
start.utc();
// Create a formatted string from start date.
const startFormatted = start.format('MM/DD/YYYY');
// Create a moment from search end date.
const end = moment(searchField.value[1]);
// Use utc.
end.utc();
// Create a formatted string from end date.
const endFormatted = end.format('MM/DD/YYYY');
// Determine if we chose the same or different start / end dates.
const diff = start.diff(end, 'days');
// Only show the start date if the same date were chosen, otherwise: start - end.
const filterValue = diff ? `${startFormatted} - ${endFormatted}` : startFormatted;
return (
<FacetType onClick={() => this.removeRangeFacetValue(searchField.field)}>
{filterValue}
</FacetType>
);
}
}
// Create a moment from the search start date.
const start = moment(searchField.value[0]);
// Use UTC.
start.utc();
// Create a formatted string from start date.
const startFormatted = start.format('MM/DD/YYYY');
// Create a moment from search end date.
const end = moment(searchField.value[1]);
// Use utc.
end.utc();
// Create a formatted string from end date.
const endFormatted = end.format('MM/DD/YYYY');
// Determine if we chose the same or different start / end dates.
const diff = start.diff(end, 'days');
// Only show the start date if the same date were chosen, otherwise: start - end.
const filterValue = diff ? `${startFormatted} - ${endFormatted}` : startFormatted;
return (
<FacetType onClick={() => removeRangeFacetValue(searchField.field)}>
{filterValue}
</FacetType>
);
};
RangeFacetType.propTypes = {
announcePolite: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
searchField: PropTypes.shape({
value: PropTypes.arrayOf(PropTypes.string).isRequired,
field: PropTypes.string.isRequired,
}).isRequired,
};

// Configure and render the FacetType component to render as text facet type.
class TextFacetType extends React.Component {
removeTextValue(field) {
this.props.announcePolite(`Removed search term ${field.value}.`);
const TextFacetType = function ({ searchField, announcePolite, onChange }) {
function removeTextValue(field) {
announcePolite(`Removed search term ${field.value}.`);
// Setting this to '' or "" throws a fatal error.
this.props.onChange(field, null);
onChange(field, null);
// Get current querystring params.
const parsed = queryString.parse(window.location.search);
// Remove the search term param, if it exists.
Expand All @@ -127,67 +141,72 @@ class TextFacetType extends React.Component {
}
}

render() {
const { searchField } = this.props;
return (
<FacetType onClick={() => this.removeTextValue(searchField.field)}>
{searchField.value}
</FacetType>
);
}
}

class FederatedCurrentQuery extends React.Component {
render() {
const { query } = this.props;

const fields = query.searchFields.filter(searchField => searchField.value
&& searchField.value.length > 0);

// Create a map of known facet type child components which can be rendered dynamically.
const facetTypes = {
'list-facet': ListFacetType,
'range-facet': RangeFacetType,
text: TextFacetType,
};

return (
<LiveMessenger>
{({ announcePolite }) => (
<React.Fragment>
{fields.length > 0 && // Only render this if there are filters applied.
<div className="fs-applied-filters">
<h2 className="fs-element-invisible">
Currently Applied Search Filters.
</h2>
<p className="fs-element-invisible">
Click a filter to remove it from your search query.
</p>
{/* Only render the values for visible facets / filters */}
{fields.filter(searchField => !searchField.isHidden).map((searchField, i) => {
// Determine which child component to render.
const MyFacetType = facetTypes[searchField.type];
return (
<MyFacetType
{...this.props}
key={i}
searchField={searchField}
announcePolite={announcePolite}
/>
);
})}
</div>
}
</React.Fragment>
)}
</LiveMessenger>
);
}
}
return (
<FacetType onClick={() => removeTextValue(searchField.field)}>
{searchField.value}
</FacetType>
);
};
TextFacetType.propTypes = {
announcePolite: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
searchField: PropTypes.shape({
field: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
}).isRequired,
};

const FederatedCurrentQuery = (props) => {
const { onChange, query } = props;

const fields = query.searchFields.filter((searchField) => searchField.value
&& searchField.value.length > 0);

// Create a map of known facet type child components which can be rendered dynamically.
const facetTypes = {
'list-facet': ListFacetType,
'range-facet': RangeFacetType,
text: TextFacetType,
};

return (
<LiveMessenger>
{({ announcePolite }) => (
<>
{fields.length > 0 // Only render this if there are filters applied.
&& (
<div className="fs-applied-filters">
<h2 className="fs-element-invisible">
Currently Applied Search Filters.
</h2>
<p className="fs-element-invisible">
Click a filter to remove it from your search query.
</p>
{/* Only render the values for visible facets / filters */}
{fields.filter((searchField) => !searchField.isHidden).map((searchField) => {
// Determine which child component to render.
const MyFacetType = facetTypes[searchField.type];
return (
<MyFacetType
key={searchField.field}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another instance of changing the key, so we don't use a loop index value.

searchField={searchField}
announcePolite={announcePolite}
onChange={onChange}
/>
);
})}
</div>
)}
</>
)}
</LiveMessenger>
);
};
FederatedCurrentQuery.propTypes = {
onChange: PropTypes.func,
query: PropTypes.object,
onChange: PropTypes.func.isRequired,
query: PropTypes.shape({
searchFields: PropTypes.arrayOf(PropTypes.object),
}).isRequired,
};

export default FederatedCurrentQuery;
Loading