Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ declare module 'vue' {
FitScreenIcon: typeof import('./src/components/Icons/FitScreenIcon.vue')['default']
FormDescription: typeof import('./src/components/FormDescription.vue')['default']
FormDialog: typeof import('./src/components/FormDialog.vue')['default']
FormInputLabel: typeof import('./src/components/FormInputLabel.vue')['default']
GlobeOff: typeof import('./src/components/Icons/GlobeOff.vue')['default']
Grid: typeof import('./src/components/Grid.vue')['default']
HTML: typeof import('./src/components/AppLayout/HTML.vue')['default']
Expand Down Expand Up @@ -84,6 +85,7 @@ declare module 'vue' {
ResourceDialog: typeof import('./src/components/ResourceDialog.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
ScriptPanel: typeof import('./src/components/ScriptPanel.vue')['default']
ScriptSection: typeof import('./src/components/ScriptSection.vue')['default']
SearchBlock: typeof import('./src/components/SearchBlock.vue')['default']
SectionContainer: typeof import('./src/components/SectionContainer.vue')['default']
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/Code.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<template>
<div class="group relative flex h-full w-full flex-col gap-1.5">
<InputLabel v-if="label" :class="[required ? `after:text-red-600 after:content-['_*']` : '']">
{{ label }}
</InputLabel>
<template v-if="label">
<FormInputLabel v-if="isFormInput">{{ label }}</FormInputLabel>
<InputLabel v-else :class="[required ? `after:text-red-600 after:content-['_*']` : '']">
{{ label }}
</InputLabel>
</template>
<div v-if="actionButton" class="absolute bottom-[3px] right-[3px] z-10 flex gap-1">
<Button
@click="actionButton?.handler"
Expand Down Expand Up @@ -40,7 +43,7 @@

<script setup lang="ts">
import { ref, computed, watch } from "vue"
import { Button } from "frappe-ui"
import { Button, ErrorMessage } from "frappe-ui"
import { Codemirror } from "vue-codemirror"
import {
autocompletion,
Expand All @@ -60,6 +63,7 @@ import { normalizeCode } from "@/utils/code"
import { jsonReplacer, parseObjectString } from "@/utils/serializer"

import InputLabel from "@/components/InputLabel.vue"
import FormInputLabel from "@/components/FormInputLabel.vue"

const props = withDefaults(
defineProps<{
Expand All @@ -82,6 +86,7 @@ const props = withDefaults(
label: string
handler: () => void
}
isFormInput?: boolean
}>(),
{
language: "javascript",
Expand Down
174 changes: 92 additions & 82 deletions frontend/src/components/CodePanel.vue
Original file line number Diff line number Diff line change
@@ -1,94 +1,103 @@
<template>
<CollapsibleSection sectionName="Watchers">
<div class="flex flex-col gap-1">
<div
v-if="studioPageWatchers.data?.length"
v-for="watcher in studioPageWatchers.data"
:key="watcher.name"
class="group/item flex flex-row items-center justify-between"
>
<div class="flex flex-row justify-between">
<div class="font-mono text-xs font-semibold text-pink-700">{{ watcher.source }}</div>
<div class="flex flex-col gap-3">
<CollapsibleSection sectionName="Watchers">
<div class="flex flex-col gap-1">
<div
v-if="studioPageWatchers.data?.length"
v-for="watcher in studioPageWatchers.data"
:key="watcher.name"
class="group/item flex flex-row items-center justify-between"
>
<div class="flex flex-row justify-between">
<div class="font-mono text-xs font-semibold text-pink-700">{{ watcher.source }}</div>
</div>
<ItemActions :menuOptions="getWatcherMenu(watcher)" @edit="openWatcher(watcher)" />
</div>
<ItemActions :menuOptions="getWatcherMenu(watcher)" @edit="openWatcher(watcher)" />
<EmptyState v-else message="No watchers added" />
</div>
<EmptyState v-else message="No watchers added" />
</div>

<div class="mt-2 flex flex-col">
<Button icon-left="plus" @click="showWatcherDialog = true">Add Watcher</Button>
<Dialog
v-model="showWatcherDialog"
:title="pageWatcher.name ? 'Edit Watcher' : 'Add Watcher'"
size="3xl"
@after-leave="
() => {
pageWatcher = {
source: '',
script: '',
immediate: false,
deep: false,
parent: '',
name: '',
<div class="mt-2 flex flex-col">
<Button icon-left="plus" @click="showWatcherDialog = true">Add Watcher</Button>
<Dialog
v-model="showWatcherDialog"
:title="pageWatcher.name ? 'Edit Watcher' : 'Add Watcher'"
size="3xl"
@after-leave="
() => {
pageWatcher = {
source: '',
script: '',
immediate: false,
deep: false,
parent: '',
name: '',
}
}
}
"
:dismissible="false"
>
<template #default>
<div class="flex flex-col space-y-4">
<FormControl
type="combobox"
:options="store.variableOptions"
label="Source"
placeholder="Select variable"
:openOnFocus="true"
v-model="pageWatcher.source"
/>
<Code
label="Script"
language="javascript"
height="400px"
maxHeight="400px"
v-model="pageWatcher.script"
:emitOnChange="true"
:completions="getCompletions"
@save="editPageWatcher(pageWatcher)"
/>
<FormControl
type="number"
label="Debounce (ms)"
placeholder="300"
v-model="pageWatcher.debounce"
description="Delay the execution until the set time has passed since the last change"
/>
<div class="flex flex-col space-y-1">
"
:dismissible="false"
>
<template #default>
<div class="flex flex-col space-y-4">
<FormControl
type="checkbox"
label="Immediate: Run on page load"
v-model="pageWatcher.immediate"
type="combobox"
:options="store.variableOptions"
label="Source"
placeholder="Select variable"
:openOnFocus="true"
v-model="pageWatcher.source"
/>
<FormDescription description="Trigger when the page loads, not just when the source changes" />
</div>
<div class="flex flex-col space-y-1">
<FormControl type="checkbox" label="Deep: Watch nested properties" v-model="pageWatcher.deep" />
<FormDescription
description="Trigger when nested properties within the source change, in addition to the source itself"
<Code
label="Script"
language="javascript"
height="400px"
maxHeight="400px"
v-model="pageWatcher.script"
:emitOnChange="true"
:completions="getCompletions"
@save="editPageWatcher(pageWatcher)"
/>
<FormControl
type="number"
label="Debounce (ms)"
placeholder="300"
v-model="pageWatcher.debounce"
description="Delay the execution until the set time has passed since the last change"
/>
<div class="flex flex-col space-y-1">
<FormControl
type="checkbox"
label="Immediate: Run on page load"
v-model="pageWatcher.immediate"
/>
<FormDescription
description="Trigger when the page loads, not just when the source changes"
/>
</div>
<div class="flex flex-col space-y-1">
<FormControl
type="checkbox"
label="Deep: Watch nested properties"
v-model="pageWatcher.deep"
/>
<FormDescription
description="Trigger when nested properties within the source change, in addition to the source itself"
/>
</div>
</div>
</div>
</template>
<template #actions>
<Button
variant="solid"
:label="pageWatcher.name ? 'Update' : 'Add'"
@click="savePageWatcher(pageWatcher)"
class="w-full"
/>
</template>
</Dialog>
</div>
</CollapsibleSection>
</template>
<template #actions>
<Button
variant="solid"
:label="pageWatcher.name ? 'Update' : 'Add'"
@click="savePageWatcher(pageWatcher)"
class="w-full"
/>
</template>
</Dialog>
</div>
</CollapsibleSection>
<ScriptPanel :page="page" />
</div>
</template>

<script setup lang="ts">
Expand All @@ -105,6 +114,7 @@ import { confirm } from "@/utils/helpers"
import { useStudioCompletions } from "@/utils/useStudioCompletions"
import ItemActions from "@/components/ItemActions.vue"
import FormDescription from "@/components/FormDescription.vue"
import ScriptPanel from "@/components/ScriptPanel.vue"

const props = defineProps<{
page: StudioPage
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/FormInputLabel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<span class="block text-p-sm font-medium text-ink-gray-7">
<slot />
</span>
</template>
Loading
Loading