Skip to content

Commit 119ddda

Browse files
committed
feat: migrate DataclipViewer
1 parent dc91ece commit 119ddda

File tree

5 files changed

+61
-117
lines changed

5 files changed

+61
-117
lines changed

assets/js/app.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ import topbar from '../vendor/topbar.cjs';
3030
import * as Hooks from './hooks';
3131
import JobEditor from './job-editor';
3232
import WorkflowEditor from './workflow-editor';
33-
import DataclipViewer from './dataclip-viewer';
3433
import LogViewer from './log-viewer';
3534

3635
let hooks = {
3736
JobEditor,
3837
WorkflowEditor,
39-
DataclipViewer,
4038
LogViewer,
4139
...Hooks,
4240
};
@@ -123,6 +121,6 @@ window.liveSocket = liveSocket;
123121

124122
// Testing helper to simulate a reconnect
125123
window.triggerReconnect = function triggerReconnect(timeout = 5000) {
126-
liveSocket.disconnect(() => {});
124+
liveSocket.disconnect(() => { });
127125
setTimeout(liveSocket.connect.bind(liveSocket), timeout);
128126
};

assets/js/dataclip-viewer/component.tsx

-67
This file was deleted.

assets/js/dataclip-viewer/index.tsx

-35
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { MonacoEditor } from '#/monaco';
2+
import { useEffect, useState } from 'react';
3+
4+
async function fetchDataclipContent(dataclipId: string) {
5+
try {
6+
const response = await fetch(`/dataclip/body/${dataclipId}`, {
7+
cache: 'default',
8+
});
9+
if (!response.ok && response.status !== 304) {
10+
throw new Error('Network response was not ok');
11+
}
12+
13+
return await response.text();
14+
} catch (error) {
15+
console.error('Error fetching content:', error);
16+
return 'Failed to load content';
17+
}
18+
}
19+
20+
export const DataclipViewer = ({ dataclipId }: { dataclipId: string }) => {
21+
const [content, setContent] = useState<string>('');
22+
console.log("farhan:", dataclipId)
23+
24+
useEffect(() => {
25+
fetchDataclipContent(dataclipId).then(setContent);
26+
}, [dataclipId]);
27+
28+
return (
29+
<div className='h-full relative'>
30+
<MonacoEditor
31+
defaultLanguage="json"
32+
theme="default"
33+
value={content}
34+
loading={<div>Loading...</div>}
35+
options={{
36+
readOnly: true,
37+
lineNumbersMinChars: 3,
38+
tabSize: 2,
39+
scrollBeyondLastLine: false,
40+
overviewRulerLanes: 0,
41+
overviewRulerBorder: false,
42+
fontFamily: 'Fira Code VF',
43+
fontSize: 14,
44+
fontLigatures: true,
45+
minimap: {
46+
enabled: false,
47+
},
48+
wordWrap: 'on',
49+
}}
50+
/>
51+
</div>
52+
);
53+
};

lib/lightning_web/components/viewers.ex

+7-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ defmodule LightningWeb.Components.Viewers do
2020

2121
require Lightning.Run
2222

23+
import React
24+
2325
@doc """
2426
Renders out a log line stream
2527
@@ -191,21 +193,14 @@ defmodule LightningWeb.Components.Viewers do
191193
end
192194

193195
attr :id, :string, required: true
194-
attr :dataclip, :map, required: true
196+
attr :dataclipId, :map, required: true
197+
198+
# react imports
199+
jsx("assets/js/react/components/DataclipViewer.tsx")
195200

196201
def dataclip_viewer(assigns) do
197202
~H"""
198-
<div
199-
id={@id}
200-
class="h-full relative"
201-
phx-hook="DataclipViewer"
202-
phx-update="ignore"
203-
data-id={@dataclip.id}
204-
data-target={"#{@id}-viewer"}
205-
>
206-
<.dataclip_type id={"#{@id}-type"} type={@dataclip.type} />
207-
<div id={"#{@id}-viewer"} class="h-full"></div>
208-
</div>
203+
<.DataclipViewer id={@id} dataclipId={@dataclip.id} />
209204
"""
210205
end
211206

0 commit comments

Comments
 (0)