Skip to content

Migration and entity field updates

Custom widget overview.

Differences between integrated and editable widgets

Section titled “Differences between integrated and editable widgets”
-Integrated widgetEditable widget
Importing Moduleimport { Module } from '@kibro/brezel-spa'import Module from 'module'
Importing Apiimport { Api } from '@kibro/brezel-spa'import Api from 'api'
Using componentscomponents: { MyComponent }Available components are predefined
Section titled “Recommended: Converting editable widgets to integrated widgets”

If you want to convert an editable widget to an integrated widget, you can follow these steps:

  1. Move the widget to the src/components directory.

  2. Update the naming of the widget to match the Vue component naming conventions:

    • Rename the file to PascalCase.
    • Rename the component to PascalCase.
    • Update the component registration in src/main.ts to use PascalCase.
  3. Update the imports to use the @kibro/brezel-spa package.

  4. Declare the prop entity and any component you want to use in the widget explicitly.

  5. Update the widget registration in the layout to use the component property instead of the view property.

  6. Update the widget registration in the systems/<system>/widgets.bake.json file (or any other file where the widget is registered) to remove the widget registration.

Vue prohibits directly mutating props, so you need to emit an event to update the entity fields.

You must emit the event “event” with an object that contains the _type property set to “update-entity”, an entity property containing the full updated entity object.

<script lang="ts">
import { defineComponent, type PropType } from 'vue'
import type { Product } from '@/types/modules/Products'
export default defineComponent({
name: 'MyWidget',
props: {
entity: {
type: Object as PropType<Product>,
required: true,
},
},
emits: ['event'],
methods: {
updatePrice (value: number) {
this.$emit('event', {
_type: 'update-entity',
entity: { ...this.entity, price: value },
})
},
},
})
</script>
<template>
<div class="my-widget">
Product: {{ entity.name }}
<button @click="updatePrice(100)">Set price to 100</button>
</div>
</template>
<style scoped lang="scss">
.my-widget {
}
</style>