Skip to content

Commit 9834a23

Browse files
add docs panel to IDE (#3966)
* close #3857 * more * snippets working * tests * cl * tests
1 parent baeaef7 commit 9834a23

File tree

9 files changed

+1458
-350
lines changed

9 files changed

+1458
-350
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ and this project adheres to
5151
[#3887](https://github.com/OpenFn/lightning/issues/3887)
5252
- Mix task to merge project state files without database access
5353
[#3615](https://github.com/OpenFn/lightning/issues/3615)
54+
- Added adaptor docs & metadata panel to IDE
55+
[#3857](https://github.com/OpenFn/lightning/issues/3857)
5456
- Show Error indication on workflow settings button
5557
[#3632](https://github.com/OpenFn/lightning/issues/3632)
5658

assets/js/collaborative-editor/components/Button.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import type { ReactNode } from "react";
1+
import type { ReactNode } from 'react';
22

33
interface ButtonProps {
44
children?: ReactNode;
5-
variant?: "primary" | "danger" | "secondary" | "nakedClose";
5+
variant?: 'primary' | 'danger' | 'secondary' | 'nakedClose';
66
disabled?: boolean;
77
loading?: boolean;
88
onClick?: () => void;
9-
type?: "button" | "submit";
9+
type?: 'button' | 'submit';
1010
className?: string;
11+
'aria-label'?: string;
1112
}
1213

1314
/**
@@ -21,12 +22,13 @@ interface ButtonProps {
2122
*/
2223
export function Button({
2324
children,
24-
variant = "primary",
25+
variant = 'primary',
2526
disabled = false,
2627
loading = false,
2728
onClick,
28-
type = "button",
29-
className = "",
29+
type = 'button',
30+
className = '',
31+
'aria-label': ariaLabel,
3032
}: ButtonProps) {
3133
const isDisabled = disabled || loading;
3234

@@ -68,25 +70,26 @@ export function Button({
6870
};
6971

7072
const buttonClasses =
71-
variant === "nakedClose" ? nakedCloseBaseClasses : baseClasses;
73+
variant === 'nakedClose' ? nakedCloseBaseClasses : baseClasses;
7274

7375
return (
7476
<button
7577
type={type}
7678
onClick={onClick}
7779
disabled={isDisabled}
80+
aria-label={ariaLabel}
7881
className={`
7982
${buttonClasses}
8083
${variantClasses[variant]}
8184
${className}
8285
`
83-
.replace(/\s+/g, " ")
86+
.replace(/\s+/g, ' ')
8487
.trim()}
8588
>
86-
{variant === "nakedClose" ? (
89+
{variant === 'nakedClose' ? (
8790
<>
8891
<span className="absolute -inset-2.5" />
89-
<span className="sr-only">Close panel</span>
92+
<span className="sr-only">{ariaLabel || 'Close panel'}</span>
9093
<div className="hero-x-mark size-6" />
9194
</>
9295
) : (

assets/js/collaborative-editor/components/CollaborativeJobEditor.tsx

Lines changed: 0 additions & 192 deletions
This file was deleted.

assets/js/collaborative-editor/components/CollaborativeMonaco.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,70 @@ export function CollaborativeMonaco({
170170
}
171171
}, [disabled]);
172172

173+
// Effect to handle insert-snippet events from docs panel
174+
useEffect(() => {
175+
const handleInsertSnippet = (e: Event) => {
176+
const editor = editorRef.current;
177+
const monaco = monacoRef.current;
178+
if (!editor || !monaco) {
179+
logger.log('❌ Insert snippet: editor or monaco not ready');
180+
return;
181+
}
182+
183+
// @ts-ignore - custom event property
184+
const snippetText = e.snippet;
185+
if (!snippetText) {
186+
logger.log('❌ Insert snippet: no snippet text in event');
187+
return;
188+
}
189+
190+
logger.log('✨ Inserting snippet at cursor position:', snippetText);
191+
192+
const model = editor.getModel();
193+
if (!model) return;
194+
195+
// Get current cursor position
196+
const selection = editor.getSelection();
197+
if (!selection) return;
198+
199+
const position = selection.getStartPosition();
200+
201+
// Insert at current cursor position
202+
const op = {
203+
range: new monaco.Range(
204+
position.lineNumber,
205+
position.column,
206+
position.lineNumber,
207+
position.column
208+
),
209+
text: `\n${snippetText}\n`,
210+
forceMoveMarkers: true,
211+
};
212+
213+
// Execute the edit
214+
editor.executeEdits('insert-snippet', [op]);
215+
216+
// Move cursor to after the inserted snippet
217+
const lines = snippetText.split('\n');
218+
const newLineNumber = position.lineNumber + lines.length + 1;
219+
editor.setPosition({ lineNumber: newLineNumber, column: 1 });
220+
221+
// Reveal the inserted snippet
222+
editor.revealLineInCenter(newLineNumber);
223+
224+
// Focus the editor
225+
editor.focus();
226+
227+
logger.log('✅ Snippet inserted successfully');
228+
};
229+
230+
document.addEventListener('insert-snippet', handleInsertSnippet);
231+
232+
return () => {
233+
document.removeEventListener('insert-snippet', handleInsertSnippet);
234+
};
235+
}, []);
236+
173237
const editorOptions: editor.IStandaloneEditorConstructionOptions = {
174238
fontSize: 14,
175239
minimap: { enabled: false },

0 commit comments

Comments
 (0)