Migration and entity field updates
Differences between integrated and editable widgets
Section titled “Differences between integrated and editable widgets”| - | Integrated widget | Editable widget |
|---|---|---|
| Importing Module | import { Module } from '@kibro/brezel-spa' | import Module from 'module' |
| Importing Api | import { Api } from '@kibro/brezel-spa' | import Api from 'api' |
| Using components | components: { MyComponent } | Available components are predefined |
Recommended: Converting editable widgets to integrated widgets
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:
-
Move the widget to the
src/componentsdirectory. -
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.tsto use PascalCase.
-
Update the imports to use the
@kibro/brezel-spapackage. -
Declare the prop
entityand any component you want to use in the widget explicitly. -
Update the widget registration in the layout to use the
componentproperty instead of theviewproperty. -
Update the widget registration in the
systems/<system>/widgets.bake.jsonfile (or any other file where the widget is registered) to remove the widget registration.
Updating entity fields
Section titled “Updating entity fields”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>