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

Fix eslint errors #86

wants to merge 34 commits into from

Conversation

byrond
Copy link
Collaborator

@byrond byrond commented Jan 8, 2021

No description provided.

@byrond byrond added the Work in-Progress Do not merge PR, currently being worked on. label Jan 8, 2021
@byrond byrond self-assigned this Jan 8, 2021
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.

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.

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.

const pagination = query.pageStrategy === 'paginate' ?
<PaginateComponent {...this.props} bootstrapCss={bootstrapCss} onChange={onPageChange} /> :
null;
/* eslint-disable react/jsx-props-no-spreading */
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

props contains a lot of properties, and I wasn't clear what they all are. I believe this is a valid case to disable the rule instead of explicitly listing all of them every time. We can revisit this later, though, if needed.

@@ -124,7 +133,7 @@ class FederatedSolrFacetedSearch extends React.Component {

return (
<SearchComponent
key={i}
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.

I changed the key here (like the others) and didn't notice any issues. Flagging this in case it is incorrect.

facetValues.forEach((v, i) => {
const key = facetValues[i];
facetInputs[key] = facetCounts[i];
});
}

const expanded = !(collapse || false);
const expanded = !collapse;
const height = expanded ? 'auto' : 0;
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 an example of a default value I moved to defaultProps.

terms[type].items.forEach((termObj, j) => termObj.facetCount
&& listFacetHierarchyTermsLis[type].push(
<li className="fs-search-accordion__content-item" key={`${termObj.term}_${termObj.facetValue}_${j}`}>
{/* eslint jsx-a11y/label-has-associated-control: ["error", { assert: "either" } ] */}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By default, the linting rule requires both nesting and id plus for attributes. However, it seemed like generating IDs at this level was discouraged, so I used an override to allow nesting the control under the label to be sufficient.

@@ -178,31 +187,41 @@ class FederatedListFacet extends React.Component {
const listFacetHierarchyLis = [];
// Define array of checkbox Lis which we'll populate with react fragments, per type.
const listFacetHierarchyTermsLis = [];

/* eslint-disable react/no-array-index-key */

// Iterate through types (accordion lis).
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 wasn't sure how to refactor this section to not use loop indexes in keys, so I temporarily disabled the rule. We may want to revisit this section later, so a TODO might be in order here.

@@ -233,6 +257,7 @@ class FederatedListFacet extends React.Component {
return (
<li className="fs-search-accordion__group-item" id={`solr-list-facet-${field}`}>
<div
role="button"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the default in most browsers.

<li className={cx("fs-search-pager__item fs-search-pager__item--first", {"fs-element-invisible": firstPageHidden})} key="start">
<button className={cx("fs-search-pager__item-button fs-search-pager__item-button--first")} tabIndex={firstPageHidden ? "-1" : "0"} onClick={this.onPageChange.bind(this, 0)} onKeyPress={ this.buildHandleEnterKeyPress(this.onPageChange.bind(this, 0)) } title="Go to first page">
<li className={cx('fs-search-pager__item fs-search-pager__item--first', { 'fs-element-invisible': firstPageHidden })} key="start">
<button type="submit" className={cx('fs-search-pager__item-button fs-search-pager__item-button--first')} tabIndex={firstPageHidden ? '-1' : '0'} onClick={this.onPageChange.bind(this, 0)} onKeyPress={this.buildHandleEnterKeyPress(this.onPageChange.bind(this, 0))} title="Go to first page">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Submit is the default type in most browsers.

FederatedSearchFieldContainer.propTypes = {
children: PropTypes.array,
onNewSearch: PropTypes.func,
children: PropTypes.arrayOf(PropTypes.object),
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 used PropTypes.node above, so I may need to change this. Also, I've used a default value here instead of isRequired. Whichever is correct, I'll make these consistent.

@agentrickard
Copy link
Contributor

I started looking at this and still see a lot of console errors: e.g.

index.js:1 Warning: Failed prop type: Invalid prop `options.autocomplete` of type `object` supplied to `FederatedSolrFacetedSearch`, expected `boolean`.
    in FederatedSolrFacetedSearch (at src/index.js:153)

@agentrickard
Copy link
Contributor

The remaining errors all seem to be PropType mismatches, where we are mixing booleans and objects. That needs to be cleaned up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Work in-Progress Do not merge PR, currently being worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants