Migrate to power search
Reviewed By: LukeDefeo Differential Revision: D51027189 fbshipit-source-id: 4fb3699a278db280237e5182d41d3c746e44a2bb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a8f5fecc2b
commit
4bb0f59ab8
@@ -180,7 +180,7 @@ test('Reducer correctly combines initial response and followup chunk', () => {
|
|||||||
responseHeaders: [{key: 'Content-Type', value: 'text/plain'}],
|
responseHeaders: [{key: 'Content-Type', value: 'text/plain'}],
|
||||||
responseIsMock: false,
|
responseIsMock: false,
|
||||||
responseLength: 5,
|
responseLength: 5,
|
||||||
status: 200,
|
status: '200',
|
||||||
url: 'http://test.com',
|
url: 'http://test.com',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ test('Can handle custom headers', async () => {
|
|||||||
responseIsMock: false,
|
responseIsMock: false,
|
||||||
responseLength: 0,
|
responseLength: 0,
|
||||||
'response_header_second-test-header': 'dolphins',
|
'response_header_second-test-header': 'dolphins',
|
||||||
status: 200,
|
status: '200',
|
||||||
url: 'http://www.fbflipper.com',
|
url: 'http://www.fbflipper.com',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ test('binary data gets serialized correctly', async () => {
|
|||||||
],
|
],
|
||||||
responseIsMock: false,
|
responseIsMock: false,
|
||||||
responseLength: 24838,
|
responseLength: 24838,
|
||||||
status: 200,
|
status: '200',
|
||||||
url: 'http://www.fbflipper.com',
|
url: 'http://www.fbflipper.com',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -265,7 +265,7 @@ test('binary data gets serialized correctly', async () => {
|
|||||||
],
|
],
|
||||||
responseIsMock: false,
|
responseIsMock: false,
|
||||||
responseLength: 24838,
|
responseLength: 24838,
|
||||||
status: 200,
|
status: '200',
|
||||||
url: 'http://www.fbflipper.com',
|
url: 'http://www.fbflipper.com',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ import {
|
|||||||
usePlugin,
|
usePlugin,
|
||||||
useValue,
|
useValue,
|
||||||
createDataSource,
|
createDataSource,
|
||||||
DataTableLegacy as DataTable,
|
_DataTableWithPowerSearch as DataTable,
|
||||||
DataTableColumnLegacy as DataTableColumn,
|
_DataTableColumnWithPowerSearch as DataTableColumn,
|
||||||
DataTableManagerLegacy as DataTableManager,
|
_DataTableWithPowerSearchManager as DataTableManager,
|
||||||
theme,
|
theme,
|
||||||
renderReactRoot,
|
renderReactRoot,
|
||||||
batch,
|
batch,
|
||||||
|
dataTablePowerSearchOperators,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {
|
import {
|
||||||
Request,
|
Request,
|
||||||
@@ -50,7 +51,6 @@ import {
|
|||||||
getHeaderValue,
|
getHeaderValue,
|
||||||
getResponseLength,
|
getResponseLength,
|
||||||
getRequestLength,
|
getRequestLength,
|
||||||
formatStatus,
|
|
||||||
formatBytes,
|
formatBytes,
|
||||||
formatDuration,
|
formatDuration,
|
||||||
requestsToText,
|
requestsToText,
|
||||||
@@ -118,6 +118,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
|||||||
);
|
);
|
||||||
const requests = createDataSource<Request, 'id'>([], {
|
const requests = createDataSource<Request, 'id'>([], {
|
||||||
key: 'id',
|
key: 'id',
|
||||||
|
indices: [['method'], ['status']],
|
||||||
});
|
});
|
||||||
const selectedId = createState<string | undefined>(undefined);
|
const selectedId = createState<string | undefined>(undefined);
|
||||||
const tableManagerRef = createRef<undefined | DataTableManager<Request>>();
|
const tableManagerRef = createRef<undefined | DataTableManager<Request>>();
|
||||||
@@ -136,11 +137,16 @@ export function plugin(client: PluginClient<Events, Methods>) {
|
|||||||
return;
|
return;
|
||||||
} else if (payload.startsWith(searchTermDelim)) {
|
} else if (payload.startsWith(searchTermDelim)) {
|
||||||
tableManagerRef.current?.clearSelection();
|
tableManagerRef.current?.clearSelection();
|
||||||
tableManagerRef.current?.setSearchValue(
|
tableManagerRef.current?.setSearchExpression([
|
||||||
payload.slice(searchTermDelim.length),
|
{
|
||||||
);
|
field: {label: 'Row', key: 'entireRow', useWholeRow: true},
|
||||||
|
operator:
|
||||||
|
dataTablePowerSearchOperators.searializable_object_contains(),
|
||||||
|
searchValue: payload.slice(searchTermDelim.length),
|
||||||
|
},
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
tableManagerRef.current?.setSearchValue('');
|
tableManagerRef.current?.setSearchExpression([]);
|
||||||
tableManagerRef.current?.selectItemById(payload);
|
tableManagerRef.current?.selectItemById(payload);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -537,6 +543,7 @@ function createRequestFromRequestInfo(
|
|||||||
domain,
|
domain,
|
||||||
requestHeaders: data.headers,
|
requestHeaders: data.headers,
|
||||||
requestData: decodeBody(data.headers, data.data),
|
requestData: decodeBody(data.headers, data.data),
|
||||||
|
status: '...',
|
||||||
};
|
};
|
||||||
customColumns
|
customColumns
|
||||||
.filter((c) => c.type === 'request')
|
.filter((c) => c.type === 'request')
|
||||||
@@ -557,7 +564,7 @@ function updateRequestWithResponseInfo(
|
|||||||
const res = {
|
const res = {
|
||||||
...request,
|
...request,
|
||||||
responseTime: new Date(response.timestamp),
|
responseTime: new Date(response.timestamp),
|
||||||
status: response.status,
|
status: response.status.toString(),
|
||||||
reason: response.reason,
|
reason: response.reason,
|
||||||
responseHeaders: response.headers,
|
responseHeaders: response.headers,
|
||||||
responseData: decodeBody(response.headers, response.data),
|
responseData: decodeBody(response.headers, response.data),
|
||||||
@@ -659,12 +666,20 @@ const baseColumns: DataTableColumn<Request>[] = [
|
|||||||
key: 'requestTime',
|
key: 'requestTime',
|
||||||
title: 'Request Time',
|
title: 'Request Time',
|
||||||
width: 120,
|
width: 120,
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.older_than_absolute_date(),
|
||||||
|
dataTablePowerSearchOperators.newer_than_absolute_date(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'responseTime',
|
key: 'responseTime',
|
||||||
title: 'Response Time',
|
title: 'Response Time',
|
||||||
width: 120,
|
width: 120,
|
||||||
visible: false,
|
visible: false,
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.older_than_absolute_date(),
|
||||||
|
dataTablePowerSearchOperators.newer_than_absolute_date(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'requestData',
|
key: 'requestData',
|
||||||
@@ -672,26 +687,55 @@ const baseColumns: DataTableColumn<Request>[] = [
|
|||||||
width: 120,
|
width: 120,
|
||||||
visible: false,
|
visible: false,
|
||||||
formatters: formatOperationName,
|
formatters: formatOperationName,
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.searializable_object_contains(),
|
||||||
|
dataTablePowerSearchOperators.searializable_object_not_contains(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'domain',
|
key: 'domain',
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.string_contains(),
|
||||||
|
dataTablePowerSearchOperators.string_not_contains(),
|
||||||
|
dataTablePowerSearchOperators.string_matches_exactly(),
|
||||||
|
dataTablePowerSearchOperators.string_not_matches_exactly(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'url',
|
key: 'url',
|
||||||
title: 'Full URL',
|
title: 'Full URL',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.string_contains(),
|
||||||
|
dataTablePowerSearchOperators.string_not_contains(),
|
||||||
|
dataTablePowerSearchOperators.string_matches_exactly(),
|
||||||
|
dataTablePowerSearchOperators.string_not_matches_exactly(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'method',
|
key: 'method',
|
||||||
title: 'Method',
|
title: 'Method',
|
||||||
width: 70,
|
width: 70,
|
||||||
|
powerSearchConfig: {
|
||||||
|
operators: [
|
||||||
|
dataTablePowerSearchOperators.enum_set_is_any_of({}),
|
||||||
|
dataTablePowerSearchOperators.enum_set_is_none_of({}),
|
||||||
|
],
|
||||||
|
inferEnumOptionsFromData: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'status',
|
key: 'status',
|
||||||
title: 'Status',
|
title: 'Status',
|
||||||
width: 70,
|
width: 70,
|
||||||
formatters: formatStatus,
|
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
powerSearchConfig: {
|
||||||
|
operators: [
|
||||||
|
dataTablePowerSearchOperators.enum_set_is_any_of({}),
|
||||||
|
dataTablePowerSearchOperators.enum_set_is_none_of({}),
|
||||||
|
],
|
||||||
|
inferEnumOptionsFromData: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'requestLength',
|
key: 'requestLength',
|
||||||
@@ -699,6 +743,13 @@ const baseColumns: DataTableColumn<Request>[] = [
|
|||||||
width: 100,
|
width: 100,
|
||||||
formatters: formatBytes,
|
formatters: formatBytes,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.float_equals(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_than(),
|
||||||
|
dataTablePowerSearchOperators.float_less_than(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_or_equal(),
|
||||||
|
dataTablePowerSearchOperators.float_less_or_equal(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'responseLength',
|
key: 'responseLength',
|
||||||
@@ -706,6 +757,13 @@ const baseColumns: DataTableColumn<Request>[] = [
|
|||||||
width: 100,
|
width: 100,
|
||||||
formatters: formatBytes,
|
formatters: formatBytes,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.float_equals(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_than(),
|
||||||
|
dataTablePowerSearchOperators.float_less_than(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_or_equal(),
|
||||||
|
dataTablePowerSearchOperators.float_less_or_equal(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'duration',
|
key: 'duration',
|
||||||
@@ -713,6 +771,13 @@ const baseColumns: DataTableColumn<Request>[] = [
|
|||||||
width: 100,
|
width: 100,
|
||||||
formatters: formatDuration,
|
formatters: formatDuration,
|
||||||
align: 'right',
|
align: 'right',
|
||||||
|
powerSearchConfig: [
|
||||||
|
dataTablePowerSearchOperators.float_equals(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_than(),
|
||||||
|
dataTablePowerSearchOperators.float_less_than(),
|
||||||
|
dataTablePowerSearchOperators.float_greater_or_equal(),
|
||||||
|
dataTablePowerSearchOperators.float_less_or_equal(),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -727,7 +792,10 @@ const errorStyle = {
|
|||||||
function getRowStyle(row: Request) {
|
function getRowStyle(row: Request) {
|
||||||
return row.responseIsMock
|
return row.responseIsMock
|
||||||
? mockingStyle
|
? mockingStyle
|
||||||
: row.status && row.status >= 400 && row.status < 600
|
: row.status &&
|
||||||
|
row.status !== '...' &&
|
||||||
|
parseInt(row.status, 10) >= 400 &&
|
||||||
|
parseInt(row.status, 10) < 600
|
||||||
? errorStyle
|
? errorStyle
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Atom,
|
Atom,
|
||||||
DataTableManagerLegacy as DataTableManager,
|
_DataTableWithPowerSearchManager as DataTableManager,
|
||||||
getFlipperLib,
|
getFlipperLib,
|
||||||
} from 'flipper-plugin';
|
} from 'flipper-plugin';
|
||||||
import {createContext} from 'react';
|
import {createContext} from 'react';
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export interface Request {
|
|||||||
requestData: string | Uint8Array | undefined;
|
requestData: string | Uint8Array | undefined;
|
||||||
// response
|
// response
|
||||||
responseTime?: Date;
|
responseTime?: Date;
|
||||||
status?: number;
|
status: string;
|
||||||
reason?: string;
|
reason?: string;
|
||||||
responseHeaders?: Array<Header>;
|
responseHeaders?: Array<Header>;
|
||||||
responseData?: string | Uint8Array | undefined;
|
responseData?: string | Uint8Array | undefined;
|
||||||
|
|||||||
@@ -268,10 +268,6 @@ export function formatBytes(count: number | undefined): string {
|
|||||||
return count + ' B';
|
return count + ' B';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatStatus(status: number | undefined) {
|
|
||||||
return status ? '' + status : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatOperationName(requestData: string): string {
|
export function formatOperationName(requestData: string): string {
|
||||||
try {
|
try {
|
||||||
const parsedData = JSON.parse(requestData);
|
const parsedData = JSON.parse(requestData);
|
||||||
|
|||||||
Reference in New Issue
Block a user