Skip to content

Commit 511be94

Browse files
committed
chore: Fixed ESLint warnings
1 parent 07c624d commit 511be94

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

src/client/entity-editor/common/entity-search-field-option.js

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,24 @@
1717
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
import {Form, InputGroup, OverlayTrigger, Tooltip} from 'react-bootstrap';
21-
import EntitySelect from './entity-select';
20+
import {faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
2221
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
23-
import LinkedEntitySelect from './linked-entity-select';
22+
import _ from 'lodash';
2423
import PropTypes from 'prop-types';
2524
import React from 'react';
26-
import SelectAsync from 'react-select/async';
27-
import ValidationLabel from '../common/validation-label';
28-
import _ from 'lodash';
29-
import {faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
25+
import {Form, InputGroup, OverlayTrigger, Tooltip} from 'react-bootstrap';
3026
import {isValidBBID} from '../../../common/helpers/utils';
27+
import {RecentlyUsed} from '../../unified-form/common/recently-used';
28+
import ValidationLabel from '../common/validation-label';
29+
import EntitySelect from './entity-select';
30+
import LinkedEntitySelect from './linked-entity-select';
3131
import makeImmutable from './make-immutable';
32+
import SelectAsync from 'react-select/async';
3233
import request from 'superagent';
33-
import {RecentlyUsed} from '../../unified-form/common/recently-used';
34-
3534

3635
const ImmutableAsyncSelect = makeImmutable(SelectAsync);
3736

3837
class EntitySearchFieldOption extends React.Component {
39-
static entityTypeMappings = {
40-
//Saving
41-
'Author': 'authors',
42-
'Edition': 'editions',
43-
'EditionGroup': 'edition_groups',
44-
'Publisher': 'publishers',
45-
'Series': 'series',
46-
'Work': 'works',
47-
'Area': 'areas',
48-
//Loading
49-
'authors': 'Author',
50-
'editions': 'Edition',
51-
'edition_groups' : 'EditionGroup',
52-
'publishers': 'Publisher',
53-
'series': 'Series',
54-
'works': 'Work',
55-
'areas': 'Area'
56-
};
57-
5838
constructor(props) {
5939
super(props);
6040
this.selectRef = React.createRef();
@@ -64,6 +44,25 @@ class EntitySearchFieldOption extends React.Component {
6444
this.entityToOption = this.entityToOption.bind(this);
6545
}
6646

47+
static entityTypeMappings = {
48+
// Saving
49+
Area: 'areas',
50+
Author: 'authors',
51+
Edition: 'editions',
52+
EditionGroup: 'editiongroups',
53+
Publisher: 'publishers',
54+
Series: 'series',
55+
Work: 'works',
56+
// Loading
57+
areas: 'Area',
58+
authors: 'Author',
59+
editiongroups: 'EditionGroup',
60+
editions: 'Edition',
61+
publishers: 'Publisher',
62+
series: 'Series',
63+
works: 'Work'
64+
};
65+
6766
/**
6867
* Determines whether an entity provided to the EntitySearch component is an
6968
* Area, using the present attributes.
@@ -106,16 +105,15 @@ class EntitySearchFieldOption extends React.Component {
106105
return entityOption;
107106
}
108107

109-
getRecentlyUsedOptions(){
110-
if(!this.props.recentlyUsedEntityType){
108+
getRecentlyUsedOptions() {
109+
if (!this.props.recentlyUsedEntityType) {
111110
return [];
112111
}
113-
const entityTypes = Array.isArray(this.props.recentlyUsedEntityType)
114-
? this.props.recentlyUsedEntityType : [this.props.recentlyUsedEntityType];
115-
const validEntityTypes = entityTypes.filter(type =>
116-
type && typeof type === 'string' && type.trim().length > 0
117-
);
118-
if(validEntityTypes.length === 0){
112+
const entityTypes = Array.isArray(this.props.recentlyUsedEntityType) ?
113+
this.props.recentlyUsedEntityType : [this.props.recentlyUsedEntityType];
114+
const validEntityTypes = entityTypes.filter(type =>
115+
type && typeof type === 'string' && type.trim().length > 0);
116+
if (validEntityTypes.length === 0) {
119117
return [];
120118
}
121119
const allRecentlyUsedItems = [];
@@ -130,24 +128,24 @@ class EntitySearchFieldOption extends React.Component {
130128
});
131129
}
132130
});
133-
if(allRecentlyUsedItems.length === 0){
131+
if (allRecentlyUsedItems.length === 0) {
134132
return [];
135133
}
136134
const uniqueItems = _.uniqBy(allRecentlyUsedItems, 'id').slice(0, 10);
137135
return uniqueItems.map(item => {
138136
const singularType = EntitySearchFieldOption.entityTypeMappings[item._sourceType] || item._sourceType.replace(/s$/, '');
139137
return {
140138
id: item.id,
141-
text: item.name,
142139
isRecentlyUsed: true,
140+
text: item.name,
143141
type: singularType
144142
};
145143
});
146144
}
147145

148-
getDefaultOptions(){
146+
getDefaultOptions() {
149147
const recentOptions = this.getRecentlyUsedOptions();
150-
if(recentOptions.length === 0){
148+
if (recentOptions.length === 0) {
151149
return true;
152150
}
153151
return [{
@@ -158,12 +156,11 @@ class EntitySearchFieldOption extends React.Component {
158156

159157
async fetchOptions(query) {
160158
const recentOptions = this.getRecentlyUsedOptions();
161-
const uniqueRecentOptions = _.uniqBy(recentOptions, 'id').slice(0, 10);
159+
const uniqueRecentOptions = _.uniqBy(recentOptions, 'id').slice(0, 10);
162160
if (!query) {
163161
if (uniqueRecentOptions.length === 0) {
164162
return [];
165163
}
166-
167164
return [{
168165
label: 'Recently Used',
169166
options: uniqueRecentOptions
@@ -181,9 +178,8 @@ class EntitySearchFieldOption extends React.Component {
181178
if (entity && typeof this.props.onChange === 'function' && (_.snakeCase(entity.type) === this.props.type ||
182179
(_.isArray(this.props.type) && this.props.type.includes(entity.type)))) {
183180
const entityOption = this.entityToOption(entity);
184-
if(entityOption.id && entityOption.text && entityOption.type){
181+
if (entityOption.id && entityOption.text && entityOption.type) {
185182
const storageKey = EntitySearchFieldOption.entityTypeMappings[entityOption.type] || `${entityOption.type.toLowerCase()}s`;
186-
187183
RecentlyUsed.addItem(storageKey, {
188184
id: entityOption.id,
189185
name: entityOption.text
@@ -209,8 +205,8 @@ class EntitySearchFieldOption extends React.Component {
209205
);
210206
const filteredOptions = response.body.filter(combinedFilters);
211207
const searchResults = filteredOptions.map(this.entityToOption);
212-
if(uniqueRecentOptions.length > 0){
213-
return[
208+
if (uniqueRecentOptions.length > 0) {
209+
return [
214210
{
215211
label: 'Recently Used',
216212
options: uniqueRecentOptions
@@ -272,8 +268,8 @@ class EntitySearchFieldOption extends React.Component {
272268
const wrappedSelect = (
273269
<SelectWrapper
274270
{...this.props}
275-
cacheOptions
276271
blurInputOnSelect
272+
cacheOptions
277273
isClearable
278274
className={`Select${this.props.className ? ` ${this.props.className}` : ''}`}
279275
classNamePrefix="react-select"
@@ -319,11 +315,11 @@ EntitySearchFieldOption.propTypes = {
319315
isMulti: PropTypes.bool,
320316
label: PropTypes.string,
321317
languageOptions: PropTypes.array,
318+
onChange: PropTypes.func.isRequired,
322319
recentlyUsedEntityType: PropTypes.oneOfType([
323320
PropTypes.string,
324321
PropTypes.arrayOf(PropTypes.string)
325322
]),
326-
onChange: PropTypes.func.isRequired,
327323
tooltipText: PropTypes.string,
328324
type: PropTypes.oneOfType([
329325
PropTypes.string,

src/client/entity-editor/edition-section/edition-section.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function EditionSection({
241241
}
242242
type="editionGroup"
243243
value={editionGroupValue}
244-
recentlyUsedEntityType="edition_groups"
244+
recentlyUsedEntityType="editiongroups"
245245
onChange={onEditionGroupChange}
246246
{...rest}
247247
/>
@@ -520,7 +520,7 @@ function mapDispatchToProps(dispatch: Dispatch<Action>): DispatchProps {
520520
)),
521521
onEditionGroupChange: (value, action) => {
522522
if(value && value.id && value.text){
523-
RecentlyUsed.addItem('edition_groups', {
523+
RecentlyUsed.addItem('editiongroups', {
524524
id: value.id,
525525
name: value.text
526526
});

0 commit comments

Comments
 (0)