-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In this PR: - Display a workflow version visualizer for the version of the workflow the run was executed on. - Display the output of the run as code. https://github.com/user-attachments/assets/d617300a-bff4-4328-a35c-291dc86d81cf
- Loading branch information
Showing
12 changed files
with
334 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...modules/settings/serverless-functions/components/SettingsServerlessFunctionCodeEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { SettingsServerlessFunctionCodeEditorContainer } from '@/settings/serverless-functions/components/SettingsServerlessFunctionCodeEditorContainer'; | ||
import { useGetAvailablePackages } from '@/settings/serverless-functions/hooks/useGetAvailablePackages'; | ||
import { CodeEditor } from '@/ui/input/code-editor/components/CodeEditor'; | ||
import { EditorProps, Monaco } from '@monaco-editor/react'; | ||
import dotenv from 'dotenv'; | ||
import { editor, MarkerSeverity } from 'monaco-editor'; | ||
import { AutoTypings } from 'monaco-editor-auto-typings'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export type File = { | ||
language: string; | ||
content: string; | ||
path: string; | ||
}; | ||
|
||
type SettingsServerlessFunctionCodeEditorProps = Omit< | ||
EditorProps, | ||
'onChange' | ||
> & { | ||
currentFilePath: string; | ||
files: File[]; | ||
onChange: (value: string) => void; | ||
setIsCodeValid: (isCodeValid: boolean) => void; | ||
}; | ||
|
||
export const SettingsServerlessFunctionCodeEditor = ({ | ||
currentFilePath, | ||
files, | ||
onChange, | ||
setIsCodeValid, | ||
height = 450, | ||
options = undefined, | ||
}: SettingsServerlessFunctionCodeEditorProps) => { | ||
const { availablePackages } = useGetAvailablePackages(); | ||
|
||
const currentFile = files.find((file) => file.path === currentFilePath); | ||
const environmentVariablesFile = files.find((file) => file.path === '.env'); | ||
|
||
const handleEditorDidMount = async ( | ||
editor: editor.IStandaloneCodeEditor, | ||
monaco: Monaco, | ||
) => { | ||
if (files.length > 1) { | ||
files.forEach((file) => { | ||
const model = monaco.editor.getModel(monaco.Uri.file(file.path)); | ||
if (!isDefined(model)) { | ||
monaco.editor.createModel( | ||
file.content, | ||
file.language, | ||
monaco.Uri.file(file.path), | ||
); | ||
} | ||
}); | ||
|
||
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ | ||
...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(), | ||
moduleResolution: | ||
monaco.languages.typescript.ModuleResolutionKind.NodeJs, | ||
baseUrl: 'file:///src', | ||
paths: { | ||
'src/*': ['file:///src/*'], | ||
}, | ||
allowSyntheticDefaultImports: true, | ||
esModuleInterop: true, | ||
noEmit: true, | ||
target: monaco.languages.typescript.ScriptTarget.ESNext, | ||
}); | ||
|
||
if (isDefined(environmentVariablesFile)) { | ||
const environmentVariables = dotenv.parse( | ||
environmentVariablesFile.content, | ||
); | ||
|
||
const environmentDefinition = ` | ||
declare namespace NodeJS { | ||
interface ProcessEnv { | ||
${Object.keys(environmentVariables) | ||
.map((key) => `${key}: string;`) | ||
.join('\n')} | ||
} | ||
} | ||
declare const process: { | ||
env: NodeJS.ProcessEnv; | ||
}; | ||
`; | ||
|
||
monaco.languages.typescript.typescriptDefaults.addExtraLib( | ||
environmentDefinition, | ||
'ts:process-env.d.ts', | ||
); | ||
} | ||
|
||
await AutoTypings.create(editor, { | ||
monaco, | ||
preloadPackages: true, | ||
onlySpecifiedPackages: true, | ||
versions: availablePackages, | ||
debounceDuration: 0, | ||
}); | ||
} | ||
}; | ||
|
||
const handleEditorValidation = (markers: editor.IMarker[]) => { | ||
for (const marker of markers) { | ||
if (marker.severity === MarkerSeverity.Error) { | ||
setIsCodeValid?.(false); | ||
return; | ||
} | ||
} | ||
setIsCodeValid?.(true); | ||
}; | ||
|
||
return ( | ||
isDefined(currentFile) && | ||
isDefined(availablePackages) && ( | ||
<SettingsServerlessFunctionCodeEditorContainer> | ||
<CodeEditor | ||
height={height} | ||
value={currentFile.content} | ||
language={currentFile.language} | ||
onMount={handleEditorDidMount} | ||
onChange={onChange} | ||
onValidate={handleEditorValidation} | ||
options={options} | ||
/> | ||
</SettingsServerlessFunctionCodeEditorContainer> | ||
) | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
...ettings/serverless-functions/components/SettingsServerlessFunctionCodeEditorContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
const StyledEditorContainer = styled.div` | ||
border: 1px solid ${({ theme }) => theme.border.color.medium}; | ||
border-top: none; | ||
border-radius: 0 0 ${({ theme }) => theme.border.radius.sm} | ||
${({ theme }) => theme.border.radius.sm}; | ||
`; | ||
|
||
export const SettingsServerlessFunctionCodeEditorContainer = | ||
StyledEditorContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.