Convert network plugin to Sandy

Summary:
converted the network plugin to use DataSource / DataTable. Restructured the storage to contain a single flat normalised object that will be much more efficient for rendering / filtering (as columns currently don't support nested keys yet, and lazy columns are a lot less flexible)

lint errors and further `flipper` package usages will be cleaned up in the next diff to make sure this diff doesn't become too large.

The rest of the plugin is converted in the next diff

Reviewed By: nikoant

Differential Revision: D27938581

fbshipit-source-id: 2e0e2ba75ef13d88304c6566d4519b121daa215b
This commit is contained in:
Michel Weststrate
2021-05-06 04:26:41 -07:00
committed by Facebook GitHub Bot
parent bef1885395
commit 23402dfff6
12 changed files with 608 additions and 763 deletions

View File

@@ -7,20 +7,16 @@
* @format
*/
import type {PartialResponses, Response} from './types';
import {Atom} from 'flipper-plugin';
import type {PartialResponse, ResponseInfo} from './types';
import {Base64} from 'js-base64';
export function assembleChunksIfResponseIsComplete(
partialResponses: Atom<PartialResponses>,
responses: Atom<Record<string, Response>>,
responseId: string,
) {
const partialResponseEntry = partialResponses.get()[responseId];
const numChunks = partialResponseEntry.initialResponse?.totalChunks;
partialResponseEntry: PartialResponse | undefined,
): ResponseInfo | undefined {
const numChunks = partialResponseEntry?.initialResponse?.totalChunks;
if (
!partialResponseEntry.initialResponse ||
!numChunks ||
!partialResponseEntry?.initialResponse ||
Object.keys(partialResponseEntry.followupChunks).length + 1 < numChunks
) {
// Partial response not yet complete, do nothing.
@@ -28,7 +24,7 @@ export function assembleChunksIfResponseIsComplete(
}
// Partial response has all required chunks, convert it to a full Response.
const response: Response = partialResponseEntry.initialResponse;
const response: ResponseInfo = partialResponseEntry.initialResponse;
const allChunks: string[] =
response.data != null
? [
@@ -41,17 +37,11 @@ export function assembleChunksIfResponseIsComplete(
: [];
const data = combineBase64Chunks(allChunks);
responses.update((draft) => {
draft[responseId] = {
...response,
// Currently data is always decoded at render time, so re-encode it to match the single response format.
data,
};
});
partialResponses.update((draft) => {
delete draft[responseId];
});
return {
...response,
// Currently data is always decoded at render time, so re-encode it to match the single response format.
data,
};
}
export function combineBase64Chunks(chunks: string[]): string {