fix(relation): fix relation widget selection bug (#1572)

This commit is contained in:
jimmycleveland-clearlink 2018-08-07 09:51:47 -06:00 committed by Shawn Erquhart
parent b2debb05a1
commit 77fbc041bb
3 changed files with 8 additions and 3 deletions

View File

@ -41,7 +41,7 @@ export default class Widget extends Component {
getAsset: PropTypes.func.isRequired,
resolveWidget: PropTypes.func.isRequired,
getEditorComponents: PropTypes.func.isRequired,
isFetching: PropTypes.node,
isFetching: PropTypes.bool,
query: PropTypes.func.isRequired,
clearSearch: PropTypes.func.isRequired,
queryHits: PropTypes.oneOfType([

View File

@ -36,6 +36,7 @@ const entries = (state = defaultState, action) => {
return state.withMutations((map) => {
const entryIds = List(loadedEntries.map(entry => ({ collection: entry.collection, slug: entry.slug })));
map.set('isFetching', false);
map.set('fetchID', null);
map.set('page', page);
map.set('term', searchTerm);
map.set('entryIds', (!page || isNaN(page) || page === 0) ? entryIds : map.get('entryIds', List()).concat(entryIds));
@ -45,6 +46,7 @@ const entries = (state = defaultState, action) => {
if (action.payload.searchTerm !== state.get('term')) {
return state.withMutations((map) => {
map.set('isFetching', action.payload.namespace ? true : false);
map.set('fetchID', action.payload.namespace)
map.set('term', action.payload.searchTerm);
});
}
@ -55,6 +57,7 @@ const entries = (state = defaultState, action) => {
response = action.payload.response;
return state.withMutations((map) => {
map.set('isFetching', false);
map.set('fetchID', null);
map.set('term', searchTerm);
map.mergeIn(['queryHits'], Map({ [action.payload.namespace]: response.hits }));
});

View File

@ -51,7 +51,8 @@ export default class RelationControl extends React.Component {
forID: PropTypes.string.isRequired,
value: PropTypes.node,
field: PropTypes.node,
isFetching: PropTypes.node,
isFetching: PropTypes.bool,
fetchID: PropTypes.string,
query: PropTypes.func.isRequired,
clearSearch: PropTypes.func.isRequired,
queryHits: PropTypes.oneOfType([
@ -141,6 +142,7 @@ export default class RelationControl extends React.Component {
const {
value,
isFetching,
fetchID,
forID,
queryHits,
classNameWrapper,
@ -172,7 +174,7 @@ export default class RelationControl extends React.Component {
inputProps={inputProps}
focusInputOnSuggestionClick={false}
/>
<Loader active={isFetching === this.controlID} />
<Loader active={isFetching && this.controlID === fetchID} />
</div>
);
}