Sort Result From ID instead of Using Directly from Result

Summary:
As mentioned in [the first comment in the Github issue](https://github.com/facebook/flipper/issues/989#issuecomment-616673590), we were mixing database `id` given from client and `index + 1` on server side. After investigating, most are used correctly; it searches `id` from given database `name`. However, there are a few (if not one) that, in my opinion, was used incorrectly. For example, [`tableOption`](https://fburl.com/diffusion/vlo7xbo1) assumed `id - 1` is the index, which is sometime incorrect.

This diff sorts the database listed from client by `id` before storing in the state.

Changelog: Fixed wrong order assumption on server side

Reviewed By: jknoxville

Differential Revision: D21496345

fbshipit-source-id: 5e15f776356b0357ac14fbde6c2a11efd76cd1e1
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-05-12 04:53:20 -07:00
committed by Facebook GitHub Bot
parent a3e323c4b5
commit ee2369950f

View File

@@ -445,7 +445,7 @@ export default class DatabasesPlugin extends FlipperPlugin<
results: UpdateDatabasesEvent,
): DatabasesPluginState => {
const updates = results.databases;
const databases = updates;
const databases = updates.sort((db1, db2) => db1.id - db2.id);
const selectedDatabase =
state.selectedDatabase ||
(Object.values(databases)[0]