From 5cbbfd761f50e454fd78ce0c6c8caf58ceae75f7 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 14 Jan 2023 09:10:39 +0100 Subject: [PATCH] add hub compatible json export to apps --- .../apps/editor/AppEditorHeader.svelte | 27 +++++++++---------- .../apps/editor/AppExportButton.svelte | 9 ++++--- frontend/src/lib/components/apps/utils.ts | 14 +++++++++- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte index 3e97ea7598..fa9e67719f 100644 --- a/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte +++ b/frontend/src/lib/components/apps/editor/AppEditorHeader.svelte @@ -42,7 +42,8 @@ import { Pane, Splitpanes } from 'svelte-splitpanes' import { appToHubUrl, classNames, copyToClipboard, sendUserToast } from '../../../utils' import type { AppInput } from '../inputType' - import type { App, AppComponent, AppEditorContext } from '../types' + import type { AppComponent, AppEditorContext } from '../types' + import { toStatic } from '../utils' import AppExportButton from './AppExportButton.svelte' import PanelSection from './settingsPanel/common/PanelSection.svelte' @@ -76,17 +77,6 @@ saveDrawerOpen = false } - function toStatic(): { app: App; summary: string } { - const newApp: App = JSON.parse(JSON.stringify($app)) - newApp.grid.forEach((x) => { - let c: AppComponent = x.data - if (c.componentInput?.type == 'runnable') { - c.componentInput.value = $staticExporter[x.id]() - } - }) - return { app: newApp, summary: $summary } - } - async function computeTriggerables() { const allTriggers = await Promise.all( $app.grid @@ -421,16 +411,23 @@ displayName: 'JSON', icon: faFileExport, action: () => { - appExport.open() + appExport.open($app) } }, { displayName: 'Publish to Hub', icon: faGlobe, action: () => { - const url = appToHubUrl(toStatic()) + const url = appToHubUrl(toStatic($app, $staticExporter, $summary)) window.open(url.toString(), '_blank') } + }, + { + displayName: 'Hub compatible JSON', + icon: faFileExport, + action: () => { + appExport.open(toStatic($app, $staticExporter, $summary).app) + } } ]} > @@ -447,7 +444,7 @@ - + - + diff --git a/frontend/src/lib/components/apps/utils.ts b/frontend/src/lib/components/apps/utils.ts index d12f93e4f6..26610e4943 100644 --- a/frontend/src/lib/components/apps/utils.ts +++ b/frontend/src/lib/components/apps/utils.ts @@ -24,7 +24,7 @@ import { SlidersHorizontal } from 'lucide-svelte' import type { AppInput, InputType, ResultAppInput, StaticAppInput } from './inputType' -import type { AppComponent } from './types' +import type { App, AppComponent } from './types' export async function loadSchema( workspace: string, @@ -233,3 +233,15 @@ export function clearResultAppInput(appInput: ResultAppInput): ResultAppInput { } return appInput } + + +export function toStatic(app: App, staticExporter: Record any>, summary: string): { app: App; summary: string } { + const newApp: App = JSON.parse(JSON.stringify(app)) + newApp.grid.forEach((x) => { + let c: AppComponent = x.data + if (c.componentInput?.type == 'runnable') { + c.componentInput.value = staticExporter[x.id]() + } + }) + return { app: newApp, summary } +} \ No newline at end of file