Skip to content

Commit 64b9232

Browse files
authored
Ensure that table element fields can be styled. (baserow#4427)
* Ensure that nested styles work in the new custom style components.
1 parent a9d4cf4 commit 64b9232

File tree

11 files changed

+83
-18
lines changed

11 files changed

+83
-18
lines changed

backend/src/baserow/contrib/builder/elements/element_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def serializer_field_overrides(self):
322322
)
323323
from baserow.contrib.builder.theme.theme_config_block_types import (
324324
ButtonThemeConfigBlockType,
325+
TypographyThemeConfigBlockType,
325326
)
326327

327328
return {
@@ -336,7 +337,10 @@ def serializer_field_overrides(self):
336337
property_name=["button", "table", "header_button"],
337338
theme_config_block_type_name=[
338339
ButtonThemeConfigBlockType.type,
339-
TableThemeConfigBlockType.type,
340+
[
341+
TableThemeConfigBlockType.type,
342+
TypographyThemeConfigBlockType.type,
343+
],
340344
ButtonThemeConfigBlockType.type,
341345
],
342346
serializer_kwargs={"required": False},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "bug",
3+
"message": "Resolved a bug which prevented the table element fields from being styled.",
4+
"issue_origin": "github",
5+
"issue_number": null,
6+
"domain": "builder",
7+
"bullet_points": [],
8+
"created_at": "2025-12-11"
9+
}

web-frontend/modules/builder/components/elements/components/collectionField/form/BooleanFieldForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
style-key="cell"
1818
:config-block-types="['table']"
1919
:theme="baseTheme"
20+
:on-styles-changed="onFieldStylesChanged"
2021
:extra-args="{ onlyCell: true, noAlignment: true }"
2122
variant="normal"
2223
/>

web-frontend/modules/builder/components/elements/components/collectionField/form/LinkFieldForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
style-key="cell"
1919
:config-block-types="linkFieldBlockTypes"
2020
:theme="baseTheme"
21+
:on-styles-changed="onFieldStylesChanged"
2122
:extra-args="{ onlyCell: true, noAlignment: true }"
2223
variant="normal"
2324
/>

web-frontend/modules/builder/components/elements/components/collectionField/form/TagsFieldForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
style-key="cell"
1818
:config-block-types="['table', 'typography']"
1919
:theme="baseTheme"
20+
:on-styles-changed="onFieldStylesChanged"
2021
:extra-args="{ onlyCell: true, onlyBody: true, noAlignment: true }"
2122
variant="normal"
2223
/>

web-frontend/modules/builder/components/elements/components/collectionField/form/TextFieldForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
style-key="cell"
1818
:config-block-types="['table', 'typography']"
1919
:theme="baseTheme"
20+
:on-styles-changed="onFieldStylesChanged"
2021
:extra-args="{ onlyCell: true, onlyBody: true, noAlignment: true }"
2122
variant="normal"
2223
/>

web-frontend/modules/builder/components/elements/components/forms/style/CustomStyleButton.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export default {
4848
required: false,
4949
default: () => null,
5050
},
51+
onStylesChanged: {
52+
type: Function,
53+
required: false,
54+
default: null,
55+
},
5156
},
5257
methods: {
5358
/**
@@ -59,8 +64,9 @@ export default {
5964
theme: this.theme,
6065
styleKey: this.styleKey,
6166
extraArgs: this.extraArgs,
67+
onStylesChanged: this.onStylesChanged,
6268
configBlockTypes: this.configBlockTypes,
63-
defaultValues: this.value?.[this.styleKey],
69+
defaultStyleValues: this.value?.[this.styleKey],
6470
})
6571
},
6672
},

web-frontend/modules/builder/components/elements/components/forms/style/CustomStyleForm.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<div class="custom-style__config-block-content">
1717
<ThemeConfigBlock
1818
ref="configBlocks"
19-
:theme="customStylesContext.theme"
20-
:default-values="customStylesContext.defaultValues"
2119
:preview="false"
20+
:theme="customStylesContext.theme"
21+
:default-values="customStylesContext.defaultStyleValues"
2222
:theme-config-block-type="themeConfigBlock"
2323
:extra-args="customStylesContext.extraArgs"
2424
@values-changed="$emit('values-changed', $event)"
@@ -41,7 +41,7 @@ export default {
4141
* @property {object} theme - The current theme object.
4242
* @property {string} styleKey - The key of the style being edited.
4343
* @property {object|null} extraArgs - Any extra args needed for the blocks.
44-
* @property {object} defaultValues - The default values for the styles.
44+
* @property {object} defaultStyleValues - The default values for the styles.
4545
* @property {Array<string>} configBlockTypes - The types of config blocks
4646
* to render for this custom style form.
4747
*/

web-frontend/modules/builder/components/page/sidePanels/GeneralSidePanel.vue

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<div class="general-side-panel">
33
<component
44
:is="elementType.generalFormComponent"
5-
v-show="elementFormVisible"
5+
v-if="elementFormVisible"
66
:key="`element-form-${element.id}`"
77
ref="panelForm"
88
class="element-form"
99
:default-values="defaultValues"
1010
@values-changed="onChange($event)"
1111
/>
1212
<CustomStyleForm
13-
v-if="!elementFormVisible"
13+
v-else
1414
:key="`style-form-${element.id}`"
1515
:custom-styles-context="customStylesContext"
1616
@hide="elementFormVisible = true"
@@ -39,12 +39,14 @@ export default {
3939
theme: {},
4040
styleKey: '',
4141
extraArgs: null,
42-
defaultValues: {},
42+
defaultStyleValues: {},
4343
configBlockTypes: [],
44+
// Optional callback to allow the form component to
45+
// modify the final object before sending it to onChange.
46+
onStylesChanged: null,
4447
},
4548
}
4649
},
47-
4850
methods: {
4951
/**
5052
* The handler that is injected into the element's general form
@@ -57,17 +59,32 @@ export default {
5759
this.elementFormVisible = !this.elementFormVisible
5860
},
5961
/**
60-
* Called when the values in the `CustomStyleForm` change. It merges
61-
* the new values with the default values and emits the `onChange`
62-
* event to update the element's styles.
62+
* Called when the values in the `CustomStyleForm` change. If the form
63+
* component provided an onStylesChanged callback, use that to build the
64+
* update object. Otherwise, apply to root element styles (default behavior).
6365
*/
64-
onThemeValuesChanged(newValues) {
65-
const { styleKey, defaultValues } = this.customStylesContext
66-
this.onChange({
66+
onThemeValuesChanged(newStyleValues) {
67+
const { styleKey, onStylesChanged } = this.customStylesContext
68+
69+
// The default behaviour is to just update the styles on the root element.
70+
let updatedElement = {
6771
styles: {
68-
[styleKey]: { ...defaultValues, ...newValues },
72+
...this.element.styles,
73+
[styleKey]: newStyleValues,
6974
},
70-
})
75+
}
76+
if (onStylesChanged) {
77+
// If we have an onStylesChanged callback, use that to build the final update
78+
// object. This is probably going to be for a table element's field styles.
79+
updatedElement = onStylesChanged(
80+
newStyleValues,
81+
this.customStylesContext
82+
)
83+
}
84+
this.onChange(updatedElement)
85+
// Update the context so that other theme blocks
86+
// are aware of the new default style values.
87+
this.customStylesContext.defaultStyleValues = newStyleValues
7188
},
7289
},
7390
}

web-frontend/modules/builder/mixins/collectionFieldForm.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,29 @@ export default {
1313
required: true,
1414
},
1515
},
16+
methods: {
17+
/**
18+
* Handles the field style changes made in the form. When the custom style form
19+
* is changed, this method is called with the new style values and the context
20+
* of the custom styles. It updates the styles of the specific field within the
21+
* element's fields array and returns the updated table element.
22+
* @param newStyleValues - The new style values to be applied to the field.
23+
* @param customStylesContext - The custom style context
24+
* @return {object} - The updated table element with the modified field styles.
25+
*/
26+
onFieldStylesChanged(newStyleValues, customStylesContext) {
27+
const elementToUpdate = { ...this.element }
28+
const { styleKey } = customStylesContext
29+
elementToUpdate.fields = elementToUpdate.fields.map((field) => {
30+
if (field.id === this.defaultValues.id) {
31+
return {
32+
...field,
33+
styles: { ...field.styles, [styleKey]: newStyleValues },
34+
}
35+
}
36+
return field
37+
})
38+
return elementToUpdate
39+
},
40+
},
1641
}

0 commit comments

Comments
 (0)