|
| 1 | +--- |
| 2 | +name: Add Or Update Builder Element Type |
| 3 | +description: Add or update a Baserow Application Builder element type across backend models, backend ElementType registration, frontend element registry/components/forms/icons/translations, migrations, and targeted tests. Use when creating or changing an element shown in the builder add-element modal, page preview, public page rendering, form elements, collection elements, container elements, or enterprise-only builder elements. |
| 4 | +version: 1.0.0 |
| 5 | +--- |
| 6 | + |
| 7 | +# Add Or Update Builder Element Type |
| 8 | + |
| 9 | +Use this skill when a task involves a new or changed Application Builder element |
| 10 | +type. Builder elements usually have both backend and frontend representations, and |
| 11 | +many also need migrations, public rendering behavior, import/export behavior, and |
| 12 | +tests. |
| 13 | + |
| 14 | +Prefer copying the nearest existing element with the same behavior: |
| 15 | + |
| 16 | +- Basic display element: `HeadingElement`, `TextElement`, `ImageElement` |
| 17 | +- Navigation/action element: `LinkElement`, `ButtonElement`, `MenuElement` |
| 18 | +- Form input: `InputTextElement`, `CheckboxElement`, `ChoiceElement` |
| 19 | +- Collection-backed element: `TableElement`, `RepeatElement`, `RecordSelectorElement` |
| 20 | +- Container element: `ColumnElement`, `SimpleContainerElement`, `FormContainerElement` |
| 21 | +- Multi-page container: `HeaderElement`, `FooterElement` |
| 22 | +- Enterprise-only element: `AuthFormElement`, `FileInputElement` |
| 23 | + |
| 24 | +## First Step |
| 25 | + |
| 26 | +Before editing, identify: |
| 27 | + |
| 28 | +1. Open source core OSC, or Enterprise licensing (no premium for app builder elements). |
| 29 | + Prompt the user for that information. |
| 30 | +2. Basic, form, collection, container, or multi-page behavior. |
| 31 | +3. Whether the type adds persisted fields. |
| 32 | +4. Whether fields are formulas and need formula import/export support. |
| 33 | +5. Whether the element has workflow events, form data, child elements, or data source |
| 34 | + content. |
| 35 | + |
| 36 | +Then inspect the closest existing implementation with `grep` instead of starting |
| 37 | +from the base class. If `rg` is available, it is a faster equivalent for the same |
| 38 | +patterns and target paths. |
| 39 | + |
| 40 | +Useful searches: |
| 41 | + |
| 42 | +- `grep -RInE "class .*Element\\(" backend/src/baserow/contrib/builder/elements/models.py enterprise/backend/src/baserow_enterprise/builder/elements/models.py` |
| 43 | +- `grep -RInE "class .*ElementType\\(" backend/src/baserow/contrib/builder/elements/element_types.py enterprise/backend/src/baserow_enterprise/builder/elements/element_types.py` |
| 44 | +- `grep -RInE "element_type_registry.register" backend/src/baserow/contrib/builder/apps.py enterprise/backend/src/baserow_enterprise/apps.py` |
| 45 | +- `grep -RInE "class .*ElementType extends" web-frontend/modules/builder/elementTypes.js enterprise/web-frontend/modules/baserow_enterprise/builder/elementTypes.js` |
| 46 | +- `grep -RInE "\\$registry.register\\('element'" web-frontend/modules/builder/plugin.js enterprise/web-frontend/modules/baserow_enterprise/plugin.js` |
| 47 | +- `grep -RInE "\"elementType\\." web-frontend/modules/builder/locales/en.json enterprise/web-frontend/modules/baserow_enterprise/locales/en.json` |
| 48 | + |
| 49 | +## Backend Checklist |
| 50 | + |
| 51 | +For an OSC element, start in: |
| 52 | + |
| 53 | +- `backend/src/baserow/contrib/builder/elements/models.py` |
| 54 | +- `backend/src/baserow/contrib/builder/elements/element_types.py` |
| 55 | +- `backend/src/baserow/contrib/builder/apps.py` |
| 56 | +- `backend/src/baserow/contrib/builder/migrations/` |
| 57 | + |
| 58 | +For an enterprise element, use: |
| 59 | + |
| 60 | +- `enterprise/backend/src/baserow_enterprise/builder/elements/models.py` |
| 61 | +- `enterprise/backend/src/baserow_enterprise/builder/elements/element_types.py` |
| 62 | +- `enterprise/backend/src/baserow_enterprise/apps.py` |
| 63 | +- `enterprise/backend/src/baserow_enterprise/migrations/` |
| 64 | + |
| 65 | +When adding or updating a backend element: |
| 66 | + |
| 67 | +1. Add or update the Django model if new fields are persisted. |
| 68 | +2. Pick the right base model or mixin: `Element`, `FormElement`, `CollectionElement`, |
| 69 | + `ContainerElement`, `MultiPageElement`, or the enterprise equivalent. |
| 70 | +3. Add an `ElementType` subclass with stable `type` and `model_class`. |
| 71 | +4. Set `allowed_fields`, `serializer_field_names`, and |
| 72 | + `request_serializer_field_names` when create/update input differs from output. |
| 73 | +5. Add `simple_formula_fields` for fields stored as formulas. |
| 74 | +6. Define `SerializedDict` annotations for all serialized custom fields. |
| 75 | +7. Override `serializer_field_overrides` for formula fields, files, nested objects, |
| 76 | + or custom validation. |
| 77 | +8. Implement `get_pytest_params` with enough valid data for generic element tests. |
| 78 | +9. Add hooks such as `prepare_value_for_db`, `after_create`, `after_update`, |
| 79 | + `before_delete`, `import_context_addition`, or `import_serialized` only when the |
| 80 | + element has nested records, workflow events, files, or derived state. |
| 81 | +10. Register the type in the relevant `apps.py`. |
| 82 | +11. Add a migration for model changes. |
| 83 | + |
| 84 | +Formula-backed Django fields should use the repo's formula field types and serializer |
| 85 | +patterns from nearby elements. Do not treat formula objects as plain strings unless |
| 86 | +the existing equivalent does. |
| 87 | + |
| 88 | +## Frontend Checklist |
| 89 | + |
| 90 | +For an OSC element, start in: |
| 91 | + |
| 92 | +- `web-frontend/modules/builder/elementTypes.js` |
| 93 | +- `web-frontend/modules/builder/plugin.js` |
| 94 | +- `web-frontend/modules/builder/components/elements/components/` |
| 95 | +- `web-frontend/modules/builder/components/elements/components/forms/general/` |
| 96 | +- `web-frontend/modules/builder/assets/icons/` |
| 97 | +- `web-frontend/modules/builder/locales/en.json` |
| 98 | +- `web-frontend/modules/core/assets/scss/components/builder/elements/` |
| 99 | + |
| 100 | +For an enterprise element, use: |
| 101 | + |
| 102 | +- `enterprise/web-frontend/modules/baserow_enterprise/builder/elementTypes.js` |
| 103 | +- `enterprise/web-frontend/modules/baserow_enterprise/plugin.js` |
| 104 | +- `enterprise/web-frontend/modules/baserow_enterprise/builder/components/elements/` |
| 105 | +- `enterprise/web-frontend/modules/baserow_enterprise/assets/images/builder/` |
| 106 | +- `enterprise/web-frontend/modules/baserow_enterprise/assets/scss/components/` |
| 107 | + |
| 108 | +When adding or updating frontend behavior: |
| 109 | + |
| 110 | +1. Add or update the Vue render component used in preview/public rendering. |
| 111 | +2. Add or update the general form component if the element has editable fields. |
| 112 | +3. Use existing mixins when relevant: `formElement`, `formElementForm`, |
| 113 | + `collectionElement`, `collectionElementForm`, `containerElement`, |
| 114 | + `elementForm`, `styleForm`, or `resolveFormula`. |
| 115 | +4. Add or update the frontend `ElementType` class with `static getType()`, `name`, |
| 116 | + `description`, `image`, `component`, `generalFormComponent`, defaults, validators, |
| 117 | + `getDisplayName`, and error handling as needed. |
| 118 | +5. Register the type in the relevant plugin with `$registry.register('element', ...)`. |
| 119 | +6. Add an icon import and matching SVG asset for the add-element modal. |
| 120 | +7. Add translations for the element name, description, form labels, validation |
| 121 | + messages, and empty/error states. |
| 122 | +8. Add SCSS only when the component needs element-specific styling; otherwise rely on |
| 123 | + shared builder styles. |
| 124 | + |
| 125 | +Match existing Vue 3 semantics. If a file contains JSX, use `.jsx` or `.tsx`. |
| 126 | + |
| 127 | +## Common Behavior Hooks |
| 128 | + |
| 129 | +Check these hooks before inventing new behavior: |
| 130 | + |
| 131 | +- Placement and child restrictions: backend `validate_place`, frontend |
| 132 | + `isDisallowedReason`, `child_types_allowed`, and container mixins. |
| 133 | +- Form elements: backend `FormElementTypeMixin` or `InputElementType`; frontend |
| 134 | + `FormElementType`, `formElement`, `formElementForm`, `formDataType`, `isValid`, |
| 135 | + `getError`, and `isInError`. |
| 136 | +- Collection elements: backend `CollectionElementTypeMixin` or |
| 137 | + `CollectionElementWithFieldsTypeMixin`; frontend `CollectionElementTypeMixin`, |
| 138 | + `collectionElement`, `collectionElementForm`, `schema_property`, fields, sorting, |
| 139 | + filtering, search, and `data_source_id`. |
| 140 | +- Containers: backend `ContainerElementTypeMixin`; frontend |
| 141 | + `ContainerElementTypeMixin` and child rendering/drop zones. |
| 142 | +- Workflow events: use existing `ClickEvent`, `SubmitEvent`, dynamic event UID, and |
| 143 | + import/export patterns from button, form container, table, or menu elements. |
| 144 | +- Files: use existing user file serializer/import/export patterns from image or |
| 145 | + enterprise file input elements. |
| 146 | + |
| 147 | +## Testing Expectations |
| 148 | + |
| 149 | +Add or update targeted tests for the behavior touched. |
| 150 | + |
| 151 | +Backend starting points: |
| 152 | + |
| 153 | +- `backend/tests/baserow/contrib/builder/elements/test_element_types.py` |
| 154 | +- `backend/tests/baserow/contrib/builder/elements/test_element_handler.py` |
| 155 | +- `backend/tests/baserow/contrib/builder/elements/test_element_service.py` |
| 156 | +- `backend/tests/baserow/contrib/builder/api/elements/` |
| 157 | +- `enterprise/backend/tests/baserow_enterprise_tests/builder/elements/test_element_types.py` |
| 158 | + |
| 159 | +Frontend starting points: |
| 160 | + |
| 161 | +- `web-frontend/test/unit/builder/elementTypes.spec.js` |
| 162 | +- `web-frontend/test/unit/builder/components/elements/components/` |
| 163 | +- `enterprise/web-frontend/test/unit/enterprise/builder/elementTypes.spec.js` |
| 164 | + |
| 165 | +Useful validation commands: |
| 166 | + |
| 167 | +- `just b test tests/baserow/contrib/builder/elements/test_element_types.py` |
| 168 | +- `just b test tests/baserow/contrib/builder/api/elements/` |
| 169 | +- `just b test enterprise/backend/tests/baserow_enterprise_tests/builder/elements/test_element_types.py` |
| 170 | +- `just f yarn test:core --run test/unit/builder/elementTypes.spec.js` |
| 171 | +- `just f yarn test:core --run test/unit/builder/components/elements/components/<Element>.spec.js` |
| 172 | +- `just f yarn test:enterprise --run ../enterprise/web-frontend/test/unit/enterprise/builder/elementTypes.spec.js` |
| 173 | + |
| 174 | +Minimum checks before finishing: |
| 175 | + |
| 176 | +1. Backend and frontend type strings match exactly. |
| 177 | +2. The element is registered in both backend and frontend where applicable. |
| 178 | +3. Create/update serializers accept only intended fields. |
| 179 | +4. Public serialization includes all required fields. |
| 180 | +5. Formula fields resolve, import, export, and duplicate correctly. |
| 181 | +6. Migrations exist for model changes. |
| 182 | +7. Required translations and icon assets exist. |
| 183 | +8. The narrowest relevant backend and frontend tests pass, or failures are reported. |
| 184 | + |
| 185 | +## Guardrails |
| 186 | + |
| 187 | +- Do not rename a persisted `type` string unless the user explicitly wants a breaking |
| 188 | + migration. |
| 189 | +- Do not add frontend-only elements when the backend API needs to persist them. |
| 190 | +- Do not add backend fields without a migration. |
| 191 | +- Do not forget generic `get_pytest_params`; many builder tests rely on it. |
| 192 | +- Do not bypass formula serializers for fields declared in `simple_formula_fields`. |
| 193 | +- Do not add broad abstractions for one element. Copy the closest local pattern first. |
| 194 | +- Do not place enterprise-only types in core registries. |
0 commit comments