Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering to the Network profiler #2340

Merged
merged 10 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
modify text and support multiple substrings
  • Loading branch information
kenzieschmoll committed Sep 15, 2020
commit cb9d6b65e7d2d8ca59a94d6a8aacb7986a2754ea
40 changes: 27 additions & 13 deletions packages/devtools_app/lib/src/network/network_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,32 @@ class NetworkController with SearchControllerMixin<NetworkRequest> {
r.method.toLowerCase() != filter.method.toLowerCase()) {
return false;
}
if (filter.uriSubstring != null &&
!r.uri.toLowerCase().contains(filter.uriSubstring.toLowerCase())) {
return false;
}
if (filter.status != null &&
r.status.toLowerCase() != filter.status.toLowerCase()) {
r.status?.toLowerCase() != filter.status.toLowerCase()) {
return false;
}
if (filter.type != null &&
r.type.toLowerCase() != filter.type.toLowerCase()) {
return false;
}
if (filter.substrings.isNotEmpty) {
for (final substring in filter.substrings) {
final caseInsensitiveSubstring = substring.toLowerCase();
final matchesUri =
r.uri.toLowerCase().contains(caseInsensitiveSubstring);
final matchesMethod =
r.method.toLowerCase().contains(caseInsensitiveSubstring);
final matchesStatus =
r.status?.toLowerCase()?.contains(caseInsensitiveSubstring) ??
false;
final matchesType =
r.type.toLowerCase().contains(caseInsensitiveSubstring);
if (matchesUri || matchesMethod || matchesStatus || matchesType) {
return true;
}
}
return false;
}
return true;
}).toList();
_activeFilter.value = filter;
Expand All @@ -325,15 +339,15 @@ class NetworkController with SearchControllerMixin<NetworkRequest> {
class NetworkFilter {
NetworkFilter({
this.method,
this.uriSubstring,
this.substrings = const [],
this.status,
this.type,
});

factory NetworkFilter.from(NetworkFilter filter) {
return NetworkFilter(
method: filter.method,
uriSubstring: filter.uriSubstring,
substrings: filter.substrings,
status: filter.status,
type: filter.type,
);
Expand All @@ -342,7 +356,7 @@ class NetworkFilter {
factory NetworkFilter.fromQuery(String query) {
final partsBySpace = query.split(' ');

String uriSubstring;
List<String> substrings = [];
String method;
String status;
String type;
Expand All @@ -360,31 +374,31 @@ class NetworkFilter {
}
}
} else {
uriSubstring = part;
substrings.add(part);
}
}
return NetworkFilter(
method: method,
uriSubstring: uriSubstring,
substrings: substrings,
status: status,
type: type,
);
}

String method;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these all be final?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no because they need to be modified when adjusting the filter in the dialog. We could make a copyWith method. Leaving as is for now since I'll likely tweak all this code in a follow up to use a query.


String uriSubstring;
List<String> substrings;

String status;

String type;

String get query {
final _uriSubstring = uriSubstring ?? '';
final _substrings = substrings.join(' ');
final _method = method != null ? 'method:$method' : '';
final _status = status != null ? 'status:$status' : '';
final _type = type != null ? 'type:$type' : '';
return '$_uriSubstring $_method $_status $_type'.trim();
return '$_substrings $_method $_status $_type'.trim();
}

static bool isValidFilter({@required List<String> keys, String query}) {
Expand Down
4 changes: 3 additions & 1 deletion packages/devtools_app/lib/src/network/network_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class _NetworkFilterDialogState extends State<NetworkFilterDialog> {
static const queryInstructions = '''
Type a filter query to show specific requests.

Any free text that is not part of an available filter below will be queried as a substring of the request URI.
Any text that is not paired with an available filter key below will be queried against all categories (method, uri, status, type).

Available filters:
'method', 'm' (e.g. 'm:get', 'm:put')
Expand All @@ -435,6 +435,8 @@ Available filters:
Example queries:
'my-endpoint method:put status:404 type:json'
'example.com m:get s:200 t:htm'
'http s:404'
'POST'
''';

TextEditingController queryTextFieldController;
Expand Down