Skip to content

Commit ce91c57

Browse files
committed
WIP: pretty print context in client
1 parent ffd95e9 commit ce91c57

File tree

3 files changed

+6029
-9
lines changed

3 files changed

+6029
-9
lines changed

assets/js/app.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,36 @@ let socketPath = document.querySelector("meta[name='socket-path']").getAttribute
88
let socketTransport = document.querySelector("meta[name='socket-transport']").getAttribute("content");
99
let normalizedTransport = (socketTransport == "longpoll") ? LongPoll : WebSocket;
1010

11-
let liveSocket = new LiveSocket(socketPath, Socket, { transport: normalizedTransport, params: { _csrf_token: csrfToken }});
11+
12+
const Hooks = {
13+
JsonPrettyPrint: {
14+
mounted() {
15+
this.formatJson();
16+
},
17+
updated() {
18+
this.formatJson();
19+
},
20+
formatJson() {
21+
try {
22+
// Get the raw JSON content
23+
const rawJson = this.el.textContent.trim();
24+
// Parse and stringify with indentation
25+
const formattedJson = JSON.stringify(JSON.parse(rawJson), null, 2);
26+
// Update the element content
27+
this.el.textContent = formattedJson;
28+
} catch (error) {
29+
console.error("Error formatting JSON:", error);
30+
// Keep the original content if there's an error
31+
}
32+
}
33+
}
34+
};
35+
36+
let liveSocket = new LiveSocket(socketPath, Socket, {
37+
transport: normalizedTransport,
38+
params: { _csrf_token: csrfToken },
39+
hooks: Hooks
40+
});
1241

1342
// Show progress bar on live navigation and form submits
1443
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });

lib/error_tracker/web/live/show.html.heex

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
</.section>
7878

7979
<.section title="Context">
80-
<pre class="overflow-auto text-sm p-4 rounded-lg bg-gray-300/10 border border-gray-900">
80+
<pre
81+
id="context"
82+
class="overflow-auto text-sm p-4 rounded-lg bg-gray-300/10 border border-gray-900"
83+
phx-hook="JsonPrettyPrint"
84+
>
8185
<%= ErrorTracker.__default_json_encoder__().encode_to_iodata!(@occurrence.context) %>
8286
</pre>
8387
</.section>

priv/static/app.js

+5,994-7
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)