refactor(core): refactor search actions and reducer
Convert to TS Proper search action type Replace immutable with immer General cleanup
This commit is contained in:
committed by
GitHub
parent
3211f94f4a
commit
e32ffdf587
@ -90,9 +90,8 @@ export default class RelationControl extends React.Component {
|
||||
forID: PropTypes.string.isRequired,
|
||||
value: PropTypes.node,
|
||||
field: ImmutablePropTypes.map,
|
||||
fetchID: PropTypes.string,
|
||||
query: PropTypes.func.isRequired,
|
||||
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
||||
queryHits: PropTypes.array,
|
||||
classNameWrapper: PropTypes.string.isRequired,
|
||||
setActiveStyle: PropTypes.func.isRequired,
|
||||
setInactiveStyle: PropTypes.func.isRequired,
|
||||
@ -119,7 +118,7 @@ export default class RelationControl extends React.Component {
|
||||
const metadata = {};
|
||||
const searchFieldsArray = getSearchFieldArray(field.get('search_fields'));
|
||||
const { payload } = await query(forID, collection, searchFieldsArray, '', file);
|
||||
const hits = payload.response?.hits || [];
|
||||
const hits = payload.hits || [];
|
||||
const options = this.parseHitOptions(hits);
|
||||
const initialOptions = initialSearchValues
|
||||
.map(v => {
|
||||
@ -221,7 +220,7 @@ export default class RelationControl extends React.Component {
|
||||
const file = field.get('file');
|
||||
|
||||
query(forID, collection, searchFieldsArray, term, file, optionsLength).then(({ payload }) => {
|
||||
const hits = payload.response?.hits || [];
|
||||
const hits = payload.hits || [];
|
||||
const options = this.parseHitOptions(hits);
|
||||
const uniq = uniqOptions(this.state.initialOptions, options);
|
||||
callback(uniq);
|
||||
@ -241,8 +240,7 @@ export default class RelationControl extends React.Component {
|
||||
const isMultiple = this.isMultiple();
|
||||
const isClearable = !field.get('required', true) || isMultiple;
|
||||
|
||||
const hits = queryHits.get(forID, []);
|
||||
const queryOptions = this.parseHitOptions(hits);
|
||||
const queryOptions = this.parseHitOptions(queryHits);
|
||||
const options = uniqOptions(this.state.initialOptions, queryOptions);
|
||||
const selectedValue = getSelectedValue({
|
||||
options,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { fromJS, Map } from 'immutable';
|
||||
import { fromJS } from 'immutable';
|
||||
import { render, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { NetlifyCmsWidgetRelation } from '../';
|
||||
|
||||
@ -137,7 +137,7 @@ const numberFieldsHits = [
|
||||
class RelationController extends React.Component {
|
||||
state = {
|
||||
value: this.props.value,
|
||||
queryHits: Map(),
|
||||
queryHits: [],
|
||||
};
|
||||
|
||||
mounted = false;
|
||||
@ -154,9 +154,8 @@ class RelationController extends React.Component {
|
||||
this.setState({ ...this.state, value });
|
||||
});
|
||||
|
||||
setQueryHits = jest.fn(hits => {
|
||||
setQueryHits = jest.fn(queryHits => {
|
||||
if (this.mounted) {
|
||||
const queryHits = Map().set('relation-field', hits);
|
||||
this.setState({ ...this.state, queryHits });
|
||||
}
|
||||
});
|
||||
@ -186,7 +185,7 @@ class RelationController extends React.Component {
|
||||
|
||||
this.setQueryHits(hits);
|
||||
|
||||
return Promise.resolve({ payload: { response: { hits } } });
|
||||
return Promise.resolve({ payload: { hits } });
|
||||
});
|
||||
|
||||
render() {
|
||||
|
Reference in New Issue
Block a user