mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-10-07 16:02:27 +00:00
fix codeViewer for non deno scripts
This commit is contained in:
@@ -6,13 +6,11 @@
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import ItemPicker from './ItemPicker.svelte'
|
||||
import Modal from './Modal.svelte'
|
||||
import { Highlight } from 'svelte-highlight'
|
||||
import typescript from 'svelte-highlight/languages/typescript'
|
||||
import python from 'svelte-highlight/languages/python'
|
||||
|
||||
import { getScriptByPath } from '$lib/utils'
|
||||
import RadioButton from './RadioButton.svelte'
|
||||
import { Button } from './common'
|
||||
import HighlightCode from './HighlightCode.svelte'
|
||||
|
||||
export let scriptPath: string | undefined = undefined
|
||||
export let allowFlow = false
|
||||
@@ -99,10 +97,6 @@
|
||||
<Modal bind:this={modalViewer}>
|
||||
<div slot="title">Script {scriptPath}</div>
|
||||
<div slot="content">
|
||||
{#if lang == 'python3'}
|
||||
<Highlight language={python} {code} />
|
||||
{:else if lang == 'deno'}
|
||||
<Highlight language={typescript} {code} />
|
||||
{/if}
|
||||
<HighlightCode {code} language={lang} />
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
@@ -56,9 +56,8 @@ export function displayDate(dateString: string | undefined): string {
|
||||
if (date.toString() === 'Invalid Date') {
|
||||
return ''
|
||||
} else {
|
||||
return `${date.getFullYear()}/${
|
||||
date.getMonth() + 1
|
||||
}/${date.getDate()} at ${date.toLocaleTimeString()}`
|
||||
return `${date.getFullYear()}/${date.getMonth() + 1
|
||||
}/${date.getDate()} at ${date.toLocaleTimeString()}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,14 +469,16 @@ export function scriptPathToHref(path: string): string {
|
||||
|
||||
export async function getScriptByPath(path: string): Promise<{
|
||||
content: string
|
||||
language: 'deno' | 'python3' | 'go'
|
||||
language: 'deno' | 'python3' | 'go',
|
||||
schema: any
|
||||
}> {
|
||||
if (path.startsWith('hub/')) {
|
||||
const { content, language, schema } = await ScriptService.getHubScriptByPath({ path })
|
||||
|
||||
return {
|
||||
content,
|
||||
language
|
||||
language,
|
||||
schema
|
||||
}
|
||||
} else {
|
||||
const script = await ScriptService.getScriptByPath({
|
||||
@@ -486,7 +487,8 @@ export async function getScriptByPath(path: string): Promise<{
|
||||
})
|
||||
return {
|
||||
content: script.content,
|
||||
language: script.language
|
||||
language: script.language,
|
||||
schema: script.schema
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,9 @@
|
||||
import ShareModal from '$lib/components/ShareModal.svelte'
|
||||
import Tooltip from '$lib/components/Tooltip.svelte'
|
||||
import TableCustom from '$lib/components/TableCustom.svelte'
|
||||
import { Highlight } from 'svelte-highlight'
|
||||
import { typescript } from 'svelte-highlight/languages/typescript'
|
||||
import { Button, Tabs, Tab, Badge, Skeleton } from '$lib/components/common'
|
||||
import CreateActions from '$lib/components/scripts/CreateActions.svelte'
|
||||
import HighlightCode from '$lib/components/HighlightCode.svelte'
|
||||
|
||||
type Tab = 'all' | 'personal' | 'groups' | 'shared' | 'examples' | 'hub'
|
||||
type Section = [string, ScriptW[]]
|
||||
@@ -70,6 +69,7 @@
|
||||
|
||||
let codeViewer: Modal
|
||||
let codeViewerContent: string = ''
|
||||
let codeViewerLanguage: 'deno' | 'python3' | 'go' = 'deno'
|
||||
let codeViewerPath: string = ''
|
||||
|
||||
$: filteredScripts =
|
||||
@@ -131,7 +131,9 @@
|
||||
}
|
||||
|
||||
async function viewCode(path: string) {
|
||||
codeViewerContent = (await getScriptByPath(path)).content
|
||||
const { content, language } = await getScriptByPath(path)
|
||||
codeViewerContent = content
|
||||
codeViewerLanguage = language
|
||||
codeViewerPath = path
|
||||
codeViewer.openModal()
|
||||
}
|
||||
@@ -153,7 +155,7 @@
|
||||
<Modal bind:this={codeViewer}>
|
||||
<div slot="title">{codeViewerPath}</div>
|
||||
<div slot="content">
|
||||
<Highlight language={typescript} code={codeViewerContent} />
|
||||
<HighlightCode language={codeViewerLanguage} code={codeViewerContent} />
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user