From 49f8f4fe45d93fa6a534d337cdd6de8d267617bc Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 14 May 2024 12:15:16 +0530 Subject: [PATCH] fix(UX): colour duration to highlight bad rows --- frappe/core/doctype/recorder/recorder.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frappe/core/doctype/recorder/recorder.js b/frappe/core/doctype/recorder/recorder.js index 37d387b711..2335424a76 100644 --- a/frappe/core/doctype/recorder/recorder.js +++ b/frappe/core/doctype/recorder/recorder.js @@ -9,6 +9,9 @@ frappe.ui.form.on("Recorder", { frm.disable_save(); frm._sort_order = {}; frm.trigger("setup_sort"); + frm.fields_dict.sql_queries.grid.grid_pagination.page_length = 500; + refresh_field("sql_queries"); + frm.trigger("format_grid"); }, setup_sort: function (frm) { @@ -25,6 +28,21 @@ frappe.ui.form.on("Recorder", { }); }); }, + + /// Format duration and copy cells + format_grid(frm) { + const max_duration = Math.max(20, ...frm.doc.sql_queries.map((d) => d.duration)); + + const heatmap = (table, field, max) => { + frm.fields_dict[table].grid.grid_rows.forEach((row) => { + const percent = Math.round((row.doc[field] / max) * 100); + $(row.columns[field]).css({ + "background-color": `color-mix(in srgb, var(--bg-red) ${percent}%, var(--bg-color))`, + }); + }); + }; + heatmap("sql_queries", "duration", max_duration); + }, }); frappe.ui.form.on("Recorder Query", "form_render", function (frm, cdt, cdn) {