Skip to content

Commit 8cd6daa

Browse files
Handle source as both string and json object
Signed-off-by: Emily Guo <[email protected]>
1 parent 511b80c commit 8cd6daa

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

public/pages/QueryDetails/QueryDetails.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,19 @@ const QueryDetails = ({
132132
}, [query, history, core.chrome, convertTime, initPlotlyChart]);
133133

134134
const queryString = query
135-
? JSON.stringify(JSON.parse(JSON.stringify(query.source)), null, 2)
135+
? JSON.stringify(
136+
typeof query.source === 'string'
137+
? (() => {
138+
try {
139+
return JSON.parse(query.source);
140+
} catch {
141+
return query.source;
142+
}
143+
})()
144+
: query.source,
145+
null,
146+
2
147+
)
136148
: '';
137149
const queryDisplay = `{\n "query": ${queryString ? queryString.replace(/\n/g, '\n ') : ''}\n}`;
138150

public/pages/QueryGroupDetails/QueryGroupDetails.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@ export const QueryGroupDetails = ({
138138
}, [query]);
139139

140140
const queryString = query
141-
? JSON.stringify(JSON.parse(JSON.stringify(query.source)), null, 2)
141+
? JSON.stringify(
142+
typeof query.source === 'string'
143+
? (() => {
144+
try {
145+
return JSON.parse(query.source);
146+
} catch {
147+
return query.source;
148+
}
149+
})()
150+
: query.source,
151+
null,
152+
2
153+
)
142154
: '';
143155
const queryDisplay = `{\n "query": ${queryString ? queryString.replace(/\n/g, '\n ') : ''}\n}`;
144156

types/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface SearchQueryRecord {
1414
};
1515
total_shards: number;
1616
node_id: string;
17-
source: ISearchSource;
17+
source: ISearchSource | string;
1818
labels: Record<string, string>;
1919
search_type: string;
2020
indices: string[];

0 commit comments

Comments
 (0)