chore: add code formatting and linting (#952)
This commit is contained in:
@ -43,7 +43,7 @@ injectGlobal`
|
||||
.react-autosuggest__suggestion--focused {
|
||||
background-color: #ddd;
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export default class RelationControl extends React.Component {
|
||||
static propTypes = {
|
||||
@ -55,10 +55,7 @@ export default class RelationControl extends React.Component {
|
||||
fetchID: PropTypes.string,
|
||||
query: PropTypes.func.isRequired,
|
||||
clearSearch: PropTypes.func.isRequired,
|
||||
queryHits: PropTypes.oneOfType([
|
||||
PropTypes.array,
|
||||
PropTypes.object,
|
||||
]),
|
||||
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
classNameWrapper: PropTypes.string.isRequired,
|
||||
setActiveStyle: PropTypes.func.isRequired,
|
||||
setInactiveStyle: PropTypes.func.isRequired,
|
||||
@ -88,12 +85,18 @@ export default class RelationControl extends React.Component {
|
||||
* Load extra post data into the store after first query.
|
||||
*/
|
||||
if (this.didInitialSearch) return;
|
||||
if (this.props.queryHits !== prevProps.queryHits && this.props.queryHits.get && this.props.queryHits.get(this.controlID)) {
|
||||
if (
|
||||
this.props.queryHits !== prevProps.queryHits &&
|
||||
this.props.queryHits.get &&
|
||||
this.props.queryHits.get(this.controlID)
|
||||
) {
|
||||
this.didInitialSearch = true;
|
||||
const suggestion = this.props.queryHits.get(this.controlID);
|
||||
if (suggestion && suggestion.length === 1) {
|
||||
const val = this.getSuggestionValue(suggestion[0]);
|
||||
this.props.onChange(val, { [this.props.field.get('collection')]: { [val]: suggestion[0].data } });
|
||||
this.props.onChange(val, {
|
||||
[this.props.field.get('collection')]: { [val]: suggestion[0].data },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -104,7 +107,9 @@ export default class RelationControl extends React.Component {
|
||||
|
||||
onSuggestionSelected = (event, { suggestion }) => {
|
||||
const value = this.getSuggestionValue(suggestion);
|
||||
this.props.onChange(value, { [this.props.field.get('collection')]: { [value]: suggestion.data } });
|
||||
this.props.onChange(value, {
|
||||
[this.props.field.get('collection')]: { [value]: suggestion.data },
|
||||
});
|
||||
};
|
||||
|
||||
onSuggestionsFetchRequested = debounce(({ value }) => {
|
||||
@ -119,19 +124,21 @@ export default class RelationControl extends React.Component {
|
||||
this.props.clearSearch();
|
||||
};
|
||||
|
||||
getSuggestionValue = (suggestion) => {
|
||||
getSuggestionValue = suggestion => {
|
||||
const { field } = this.props;
|
||||
const valueField = field.get('valueField');
|
||||
return suggestion.data[valueField];
|
||||
};
|
||||
|
||||
renderSuggestion = (suggestion) => {
|
||||
renderSuggestion = suggestion => {
|
||||
const { field } = this.props;
|
||||
const valueField = field.get('displayFields') || field.get('valueField');
|
||||
if (List.isList(valueField)) {
|
||||
return (
|
||||
<span>
|
||||
{valueField.toJS().map(key => <span key={key}>{new String(suggestion.data[key])}{' '}</span>)}
|
||||
{valueField.toJS().map(key => (
|
||||
<span key={key}>{new String(suggestion.data[key])} </span>
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@ -147,7 +154,7 @@ export default class RelationControl extends React.Component {
|
||||
queryHits,
|
||||
classNameWrapper,
|
||||
setActiveStyle,
|
||||
setInactiveStyle
|
||||
setInactiveStyle,
|
||||
} = this.props;
|
||||
|
||||
const inputProps = {
|
||||
@ -160,7 +167,7 @@ export default class RelationControl extends React.Component {
|
||||
onBlur: setInactiveStyle,
|
||||
};
|
||||
|
||||
const suggestions = (queryHits.get) ? queryHits.get(this.controlID, []) : [];
|
||||
const suggestions = queryHits.get ? queryHits.get(this.controlID, []) : [];
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
@ -2,9 +2,7 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { WidgetPreviewContainer } from 'netlify-cms-ui-default';
|
||||
|
||||
const RelationPreview = ({ value }) => (
|
||||
<WidgetPreviewContainer>{ value }</WidgetPreviewContainer>
|
||||
)
|
||||
const RelationPreview = ({ value }) => <WidgetPreviewContainer>{value}</WidgetPreviewContainer>;
|
||||
|
||||
RelationPreview.propTypes = {
|
||||
value: PropTypes.node,
|
||||
|
Reference in New Issue
Block a user