Skip to content

Commit f5ab0fe

Browse files
committed
fix: empty block handling + duplicate toasts on component save
1 parent 4701f36 commit f5ab0fe

6 files changed

Lines changed: 12 additions & 10 deletions

File tree

frontend/src/components/AppComponent.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import { computed, onMounted, ref, useAttrs, inject, type ComputedRef } from "vu
5757
import type { ComponentPublicInstance } from "vue"
5858
import { useRouter } from "vue-router"
5959
import { createResource } from "frappe-ui"
60-
import { getComponentRoot, isHTML } from "@/utils/helpers"
60+
import { getComponentRoot, isHTML, isObjectEmpty } from "@/utils/helpers"
6161
import { useScreenSize } from "@/utils/useScreenSize"
6262
import { isDynamicValue } from "@/utils/code"
6363
@@ -108,7 +108,7 @@ const evaluationContext = computed(() => {
108108
})
109109
110110
const getComponentProps = () => {
111-
if (!props.block || props.block.isRoot()) return []
111+
if (isObjectEmpty(props.block) || props.block.isRoot()) return []
112112
113113
const propValues = props.block.getPropsAndAttributes()
114114
Object.entries(propValues).forEach(([propName, propValue]) => {
@@ -123,7 +123,7 @@ const getComponentProps = () => {
123123
124124
// 2-way binding
125125
const vModelListeners = computed(() => {
126-
if (!props.block || props.block.isRoot()) return {}
126+
if (isObjectEmpty(props.block) || props.block.isRoot()) return {}
127127
128128
const listeners: Record<string, Function> = {}
129129
const propValues = props.block.getPropsAndAttributes()

frontend/src/components/StudioComponent.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import ComponentEditor from "@/components/ComponentEditor.vue"
119119
120120
import Block from "@/utils/block"
121121
import useCanvasStore from "@/stores/canvasStore"
122-
import { getComponentRoot, isHTML } from "@/utils/helpers"
122+
import { getComponentRoot, isHTML, isObjectEmpty } from "@/utils/helpers"
123123
import { isDynamicValue } from "@/utils/code"
124124
125125
import type { CanvasProps } from "@/types/StudioCanvas"
@@ -184,7 +184,7 @@ const evaluationContext = computed(() => {
184184
})
185185
186186
const getComponentProps = () => {
187-
if (!props.block || props.block.isRoot()) return []
187+
if (isObjectEmpty(props.block) || props.block.isRoot()) return []
188188
189189
const propValues = props.block.getPropsAndAttributes()
190190
Object.entries(propValues).forEach(([propName, propValue]) => {
@@ -199,7 +199,7 @@ const getComponentProps = () => {
199199
200200
// 2-way binding
201201
const vModelListeners = computed(() => {
202-
if (!props.block || props.block.isRoot()) return {}
202+
if (isObjectEmpty(props.block) || props.block.isRoot()) return {}
203203
204204
const listeners: Record<string, Function> = {}
205205
const propValues = props.block.getPropsAndAttributes()

frontend/src/components/StudioComponentEditorWrapper.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const componentEditorStore = useComponentEditorStore()
1717
const componentBlock = computed(() => componentEditorStore.studioComponentBlock!)
1818
1919
const componentContext = computed(() => {
20-
const context = componentBlock.value.getPropsAndAttributes()
20+
const context = componentBlock.value?.getPropsAndAttributes() || {}
2121
componentEditorStore.componentInputs.forEach((input) => {
2222
if (!(input.input_name in context) && input.default !== undefined) {
2323
context[input.input_name] = input.default

frontend/src/components/StudioComponentRenderer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const componentStore = useComponentStore()
1818
const codeStore = useCodeStore()
1919
2020
const componentContext = computed(() => {
21-
const context = props.studioComponent.getPropsAndAttributes()
21+
const context = props.studioComponent?.getPropsAndAttributes() || {}
2222
const componentDoc = componentStore.getComponentDoc(props.studioComponent.componentName)
2323
if (componentDoc?.inputs) {
2424
componentDoc.inputs.forEach((input: any) => {

frontend/src/components/StudioComponentWrapper.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const componentStore = useComponentStore()
1818
const codeStore = useCodeStore()
1919
2020
const componentContext = computed(() => {
21-
const context = props.studioComponent.getPropsAndAttributes()
21+
const context = props.studioComponent?.getPropsAndAttributes() || {}
2222
const componentDoc = componentStore.getComponentDoc(props.studioComponent.componentName)
2323
if (componentDoc?.inputs) {
2424
componentDoc.inputs.forEach((input: any) => {

frontend/src/pages/StudioPage.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ watchEffect(() => {
199199
200200
async function saveFragmentMode() {
201201
canvasStore.fragmentData.saveAction?.(fragmentCanvas.value?.getRootBlock())
202-
toast.success(`${canvasStore.fragmentData.fragmentName} saved successfully`)
202+
if (canvasStore.editingMode === "fragment") {
203+
toast.success(`${canvasStore.fragmentData.fragmentName} saved successfully`)
204+
}
203205
}
204206
205207
const debouncedPageSave = useDebounceFn(store.savePage, 300)

0 commit comments

Comments
 (0)