mirror of
https://github.com/grafana/grafana.git
synced 2026-09-05 04:40:13 -05:00
Templating: Replace __data , __field and __cell_n with macros (#65324)
* Templating: __data __field and __series macros * filter out datacontext from json serialization * Fix condition * Update * Added test cases for formatting data, and field macros
This commit is contained in:
@@ -191,7 +191,7 @@ async function getJSONObject(show: ShowContent, panel?: PanelModel, data?: Panel
|
||||
function getPrettyJSON(obj: any): string {
|
||||
let r = '';
|
||||
try {
|
||||
r = JSON.stringify(obj, null, 2);
|
||||
r = JSON.stringify(obj, getCircularReplacer(), 2);
|
||||
} catch (e) {
|
||||
if (
|
||||
e instanceof Error &&
|
||||
@@ -204,3 +204,21 @@ function getPrettyJSON(obj: any): string {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function getCircularReplacer() {
|
||||
const seen = new WeakSet();
|
||||
|
||||
return (key: string, value: unknown) => {
|
||||
if (key === '__dataContext') {
|
||||
return 'Filtered out in JSON serialization';
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (seen.has(value)) {
|
||||
return;
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user