Skip to content

Commit f47e85d

Browse files
committed
feat(search): search obj values from display cmd
1 parent ba5859a commit f47e85d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

lib/reactotron-core-ui/src/utils/filterCommands/filterCommands.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
import filterCommands, { filterSearch, filterHidden } from "./index"
22
import { CommandType } from "reactotron-core-contract"
33

4+
const EXAMPLE_VALUE_OBJECT = {
5+
id: 1,
6+
lastUpdateAt: "13:44",
7+
queries: [],
8+
mutations: [],
9+
cache: {
10+
"Launch:5eb87cd9ffd86e000604b32aSEARCHCACHE": {
11+
__typename: "Launch",
12+
id: "5eb87cd9ffd86e000604b32a",
13+
mission_name: "FalconSat",
14+
launch_date_unix: 1143239400,
15+
launch_success: null,
16+
upcoming: false,
17+
},
18+
"Launch:5eb87cdaffd86e000604b32b": {
19+
__typename: "Launch",
20+
id: "5eb87cdaffd86e000604b32b",
21+
mission_name: "DemoSat",
22+
launch_date_unix: 1174439400,
23+
launch_success: null,
24+
upcoming: false,
25+
},
26+
},
27+
}
28+
429
const TEST_COMMANDS = [
530
{ type: "SEARCHTYPE" },
631
{ type: "ADUMMYOBJ", payload: { message: "SEARCHMESSAGE" } },
@@ -12,6 +37,7 @@ const TEST_COMMANDS = [
1237
{ type: "ADUMMYOBJ", payload: { request: { url: "SEARCHURL" } } },
1338
{ type: "log", payload: { debug: "LOGDEBUG" } },
1439
{ type: "client.intro", payload: { connection: "SEARCHCONNECTION" } },
40+
{ type: "display", payload: { value: EXAMPLE_VALUE_OBJECT } },
1541
]
1642

1743
const TESTS = [
@@ -71,6 +97,23 @@ const TESTS = [
7197
search: "connection",
7298
result: [{ type: "client.intro", payload: { connection: "SEARCHCONNECTION" } }],
7399
},
100+
{
101+
name: "display => apollo client",
102+
search: "FalconSat",
103+
result: [
104+
{
105+
type: "display",
106+
payload: {
107+
value: EXAMPLE_VALUE_OBJECT,
108+
},
109+
},
110+
],
111+
},
112+
{
113+
name: "display => apollo client",
114+
search: "Falcon 9",
115+
result: [],
116+
},
74117
{
75118
name: "multiple results",
76119
search: "ADUMMYOBJ",

lib/reactotron-core-ui/src/utils/filterCommands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const COMMON_MATCHING_PATHS = [
2323
path("payload", "triggerType"),
2424
path("payload", "description"),
2525
path("payload", "request", "url"),
26+
path("payload", "value"),
2627
]
2728

2829
export function filterSearch(commands: any[], search: string) {
@@ -33,6 +34,8 @@ export function filterSearch(commands: any[], search: string) {
3334
const searchRegex = new RegExp(trimmedSearch.replace(/\s/, "."), "i")
3435

3536
const matching = (value: string) => value && typeof value === "string" && searchRegex.test(value)
37+
const matchingObj = (value: object) =>
38+
value && typeof value === "object" && searchRegex.test(JSON.stringify(value))
3639

3740
return commands.filter(
3841
(command) =>
@@ -44,6 +47,7 @@ export function filterSearch(commands: any[], search: string) {
4447
)
4548
return true
4649
if (command.type === CommandType.ClientIntro && matching("connection")) return true
50+
if (command.type === CommandType.Display && matchingObj(command.payload.value)) return true
4751
return false
4852
}).length > 0
4953
)

0 commit comments

Comments
 (0)