Skip to content

Commit

Permalink
Sort returned list of objects (elastic#56356)
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jan 30, 2020
1 parent 44545eb commit 2a2ef3b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ export const useDataInit = () => {
});
dispatch({ type: 'setCurrentTextObject', payload: newObject });
} else {
// For now, we always take the first text object returned.
dispatch({ type: 'setCurrentTextObject', payload: results[0] });
dispatch({
type: 'setCurrentTextObject',
// For backwards compatibility, we sort here according to date created to
// always take the first item created.
payload: results.sort((a, b) => a.createdAt - b.createdAt)[0],
});
}
} catch (e) {
setError(e);
Expand Down

0 comments on commit 2a2ef3b

Please sign in to comment.