-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: 3.x
Are you sure you want to change the base?
Changes from all commits
69b42e7
4ea5291
69d27e5
21194ad
932f6f5
2299f74
16d5a75
3908a8a
f44d1e2
08ecbd5
035495d
c71d6d2
dcf6d85
5d66075
05e7b6e
90cb22d
f5a0e74
9e96696
8dc748f
b8bfc9f
b0fe669
87acaa0
9eab0b5
50ebdfe
0d5d167
dd307ee
78a6421
568ace0
d02aa40
e9fa70c
2ab7672
3c6add3
dff2e21
4932e28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
1, { | ||
"extensions": [".js", ".jsx"], | ||
} | ||
] | ||
], | ||
"func-names": "off" | ||
}, | ||
"env": { | ||
"browser": true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}; | ||
|
||
// 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, | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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.