mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
fix: bug in public view with hidden group by (#4859)
* Fix public view with hidden group by * Show group by feature in PublicView when fields are hidden * Review feedback * Review feedback v2
This commit is contained in:
1 parent
52a5188ea6
commit
f6a7d302ff
14 files changed
+214
-51
No files matched your search
@@ -2122,11 +2122,14 @@ class PublicViewInfoView(APIView):
|
||||
raise ViewDoesNotExist()
|
||||
|
||||
field_options = view_type.get_visible_field_options_in_order(view_specific)
|
||||
ordered_field_ids = list(field_options.values_list("field_id", flat=True))
|
||||
fields = specific_iterator(
|
||||
Field.objects.filter(id__in=field_options.values_list("field_id"))
|
||||
Field.objects.filter(id__in=ordered_field_ids)
|
||||
.select_related("content_type")
|
||||
.prefetch_related("select_options")
|
||||
)
|
||||
field_id_order = {fid: idx for idx, fid in enumerate(ordered_field_ids)}
|
||||
fields = sorted(fields, key=lambda f: field_id_order.get(f.id, 0))
|
||||
|
||||
return Response(
|
||||
PublicViewInfoSerializer(
|
||||
|
||||
@@ -263,9 +263,12 @@ class GridViewType(ViewType):
|
||||
)
|
||||
|
||||
def get_visible_field_options_in_order(self, grid_view):
|
||||
group_by_field_ids = grid_view.viewgroupby_set.values_list(
|
||||
"field_id", flat=True
|
||||
)
|
||||
return (
|
||||
grid_view.get_field_options(create_if_missing=True)
|
||||
.filter(hidden=False)
|
||||
.filter(Q(hidden=False) | Q(field_id__in=group_by_field_ids))
|
||||
.order_by("-field__primary", "order", "field__id")
|
||||
)
|
||||
|
||||
|
||||
@@ -77,6 +77,23 @@ def public_view_filter_deleted(sender, view_filter_id, view_filter, user, **kwar
|
||||
_send_force_rows_refresh_if_view_public(view_filter.view)
|
||||
|
||||
|
||||
@receiver(view_signals.view_group_by_created)
|
||||
def public_view_group_by_created(sender, view_group_by, user, **kwargs):
|
||||
_send_force_view_refresh_if_view_public(view_group_by.view)
|
||||
|
||||
|
||||
@receiver(view_signals.view_group_by_updated)
|
||||
def public_view_group_by_updated(sender, view_group_by, user, **kwargs):
|
||||
_send_force_view_refresh_if_view_public(view_group_by.view)
|
||||
|
||||
|
||||
@receiver(view_signals.view_group_by_deleted)
|
||||
def public_view_group_by_deleted(
|
||||
sender, view_group_by_id, view_group_by, user, **kwargs
|
||||
):
|
||||
_send_force_view_refresh_if_view_public(view_group_by.view)
|
||||
|
||||
|
||||
@receiver(view_signals.view_field_options_updated)
|
||||
def public_view_field_options_updated(sender, view, user, **kwargs):
|
||||
_send_force_view_refresh_if_view_public(view)
|
||||
@@ -3236,14 +3236,16 @@ def test_get_public_grid_view(api_client, data_fixture):
|
||||
data_fixture.create_grid_view_field_option(grid_view, public_field, hidden=False)
|
||||
data_fixture.create_grid_view_field_option(grid_view, hidden_field, hidden=True)
|
||||
|
||||
# This view sort shouldn't be exposed as it is for a hidden field
|
||||
data_fixture.create_view_sort(view=grid_view, field=hidden_field, order="ASC")
|
||||
hidden_sort = data_fixture.create_view_sort(
|
||||
view=grid_view, field=hidden_field, order="ASC"
|
||||
)
|
||||
visible_sort = data_fixture.create_view_sort(
|
||||
view=grid_view, field=public_field, order="DESC"
|
||||
)
|
||||
|
||||
# This group by shouldn't be exposed as it is for a hidden field
|
||||
data_fixture.create_view_group_by(view=grid_view, field=hidden_field, order="ASC")
|
||||
hidden_group_by = data_fixture.create_view_group_by(
|
||||
view=grid_view, field=hidden_field, order="ASC"
|
||||
)
|
||||
visible_group_by = data_fixture.create_view_group_by(
|
||||
view=grid_view, field=public_field, order="DESC"
|
||||
)
|
||||
@@ -3281,7 +3283,24 @@ def test_get_public_grid_view(api_client, data_fixture):
|
||||
"workspace_id": PUBLIC_PLACEHOLDER_ENTITY_ID,
|
||||
"db_index": False,
|
||||
"field_constraints": [],
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": hidden_field.id,
|
||||
"table_id": PUBLIC_PLACEHOLDER_ENTITY_ID,
|
||||
"name": "hidden",
|
||||
"order": 0,
|
||||
"primary": False,
|
||||
"text_default": "",
|
||||
"type": "text",
|
||||
"read_only": False,
|
||||
"description": None,
|
||||
"immutable_properties": False,
|
||||
"immutable_type": False,
|
||||
"database_id": PUBLIC_PLACEHOLDER_ENTITY_ID,
|
||||
"workspace_id": PUBLIC_PLACEHOLDER_ENTITY_ID,
|
||||
"db_index": False,
|
||||
"field_constraints": [],
|
||||
},
|
||||
],
|
||||
"view": {
|
||||
"id": grid_view.slug,
|
||||
@@ -3290,17 +3309,30 @@ def test_get_public_grid_view(api_client, data_fixture):
|
||||
"public": True,
|
||||
"slug": grid_view.slug,
|
||||
"sortings": [
|
||||
# Note the sorting for the hidden field is not returned
|
||||
{
|
||||
"field": hidden_sort.field.id,
|
||||
"id": hidden_sort.id,
|
||||
"order": "ASC",
|
||||
"type": "default",
|
||||
"view": grid_view.slug,
|
||||
},
|
||||
{
|
||||
"field": visible_sort.field.id,
|
||||
"id": visible_sort.id,
|
||||
"order": "DESC",
|
||||
"type": "default",
|
||||
"view": grid_view.slug,
|
||||
}
|
||||
},
|
||||
],
|
||||
"group_bys": [
|
||||
# Note the group by for the hidden field is not returned
|
||||
{
|
||||
"field": hidden_group_by.field.id,
|
||||
"id": hidden_group_by.id,
|
||||
"order": "ASC",
|
||||
"view": grid_view.slug,
|
||||
"width": 200,
|
||||
"type": "default",
|
||||
},
|
||||
{
|
||||
"field": visible_group_by.field.id,
|
||||
"id": visible_group_by.id,
|
||||
@@ -3308,7 +3340,7 @@ def test_get_public_grid_view(api_client, data_fixture):
|
||||
"view": grid_view.slug,
|
||||
"width": 200,
|
||||
"type": "default",
|
||||
}
|
||||
},
|
||||
],
|
||||
"table": {
|
||||
"database_id": PUBLIC_PLACEHOLDER_ENTITY_ID,
|
||||
@@ -3875,6 +3907,64 @@ def test_list_rows_public_with_query_param_group_by(api_client, data_fixture):
|
||||
assert response_json["error"] == "ERROR_ORDER_BY_FIELD_NOT_POSSIBLE"
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_list_rows_public_with_query_param_group_by_hidden_field_with_stored_group_by(
|
||||
api_client, data_fixture
|
||||
):
|
||||
user, token = data_fixture.create_user_and_token()
|
||||
table = data_fixture.create_database_table(user=user)
|
||||
public_field = data_fixture.create_text_field(table=table, name="public")
|
||||
hidden_field = data_fixture.create_text_field(table=table, name="hidden")
|
||||
grid_view = data_fixture.create_grid_view(
|
||||
table=table, user=user, public=True, create_options=False
|
||||
)
|
||||
data_fixture.create_grid_view_field_option(grid_view, public_field, hidden=False)
|
||||
data_fixture.create_grid_view_field_option(grid_view, hidden_field, hidden=True)
|
||||
|
||||
data_fixture.create_view_group_by(view=grid_view, field=hidden_field, order="ASC")
|
||||
|
||||
first_row = RowHandler().create_row(
|
||||
user,
|
||||
table,
|
||||
values={"public": "a", "hidden": "y"},
|
||||
user_field_names=True,
|
||||
)
|
||||
second_row = RowHandler().create_row(
|
||||
user,
|
||||
table,
|
||||
values={"public": "b", "hidden": "x"},
|
||||
user_field_names=True,
|
||||
)
|
||||
third_row = RowHandler().create_row(
|
||||
user,
|
||||
table,
|
||||
values={"public": "c", "hidden": "y"},
|
||||
user_field_names=True,
|
||||
)
|
||||
|
||||
url = reverse(
|
||||
"api:database:views:grid:public_rows", kwargs={"slug": grid_view.slug}
|
||||
)
|
||||
response = api_client.get(
|
||||
f"{url}?group_by=field_{hidden_field.id}",
|
||||
)
|
||||
response_json = response.json()
|
||||
assert response.status_code == HTTP_200_OK
|
||||
assert len(response_json["results"]) == 3
|
||||
assert response_json["results"][0]["id"] == second_row.id
|
||||
assert response_json["results"][1]["id"] == first_row.id
|
||||
assert response_json["results"][2]["id"] == third_row.id
|
||||
assert response_json["group_by_metadata"] == {
|
||||
f"field_{hidden_field.id}": unordered(
|
||||
[
|
||||
{"count": 1, f"field_{hidden_field.id}": "x"},
|
||||
{"count": 2, f"field_{hidden_field.id}": "y"},
|
||||
]
|
||||
)
|
||||
}
|
||||
assert f"field_{hidden_field.id}" in response_json["results"][0]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_list_rows_public_with_query_param_group_by_and_empty_order_by(
|
||||
api_client, data_fixture
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "bug",
|
||||
"message": "Fix public view with hidden group by field",
|
||||
"issue_origin": "github",
|
||||
"issue_number": 4858,
|
||||
"domain": "database",
|
||||
"bullet_points": [],
|
||||
"created_at": "2026-02-24"
|
||||
}
|
||||
@@ -19,8 +19,8 @@ export default {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
allFieldsInTable: {
|
||||
type: Array,
|
||||
field: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
value: {
|
||||
@@ -33,21 +33,9 @@ export default {
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
field() {
|
||||
return this.getField(this.allFieldsInTable, this.groupBy)
|
||||
},
|
||||
groupByComponent() {
|
||||
return this.getGroupByComponent(this.field, this)
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getField(allFieldsInTable, groupBy) {
|
||||
const field = allFieldsInTable.find((f) => f.id === groupBy.field)
|
||||
return field
|
||||
},
|
||||
getGroupByComponent(field, parent) {
|
||||
const fieldType = parent.$registry.get('field', field.type)
|
||||
return fieldType.getGroupByComponent(field)
|
||||
const fieldType = this.$registry.get('field', this.field.type)
|
||||
return fieldType.getGroupByComponent(this.field)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
>
|
||||
<GridViewGroup
|
||||
:group-by="groupBy"
|
||||
:all-fields-in-table="allFieldsInTable"
|
||||
:field="getGroupByField(groupBy)"
|
||||
:value="groupSpan.value"
|
||||
:count="groupSpan.count"
|
||||
></GridViewGroup>
|
||||
@@ -40,14 +40,6 @@ export default {
|
||||
components: { GridViewGroup },
|
||||
mixins: [gridViewHelpers],
|
||||
props: {
|
||||
/**
|
||||
* All the fields in the table, regardless of the visibility, or whether they
|
||||
* should be rendered.
|
||||
*/
|
||||
allFieldsInTable: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
groupByValueSets: {
|
||||
type: Array,
|
||||
required: true,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<template>
|
||||
<div class="grid-view__head">
|
||||
<div
|
||||
v-for="groupBy in includeGroupBy ? activeGroupBys : []"
|
||||
v-for="{ groupBy, field } in activeGroupBysWithFields"
|
||||
:key="'field-group-' + groupBy.field"
|
||||
class="grid-view__head-group"
|
||||
:style="{ width: groupBy.width + 'px' }"
|
||||
:set="field = $options.methods.getField(allFieldsInTable, groupBy)"
|
||||
>
|
||||
<div class="grid-view__group-cell">
|
||||
<div class="grid-view__group-name">
|
||||
@@ -151,6 +150,15 @@ export default {
|
||||
},
|
||||
},
|
||||
emits: ['dragging', 'field-created', 'refresh'],
|
||||
computed: {
|
||||
activeGroupBysWithFields() {
|
||||
if (!this.includeGroupBy) return []
|
||||
return this.activeGroupBys.map((groupBy) => ({
|
||||
groupBy,
|
||||
field: this.getGroupByField(groupBy),
|
||||
}))
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* After newField is created pressing "insert left" or "insert right" button,
|
||||
@@ -192,10 +200,6 @@ export default {
|
||||
onShownCreateFieldContext() {
|
||||
this.$refs.createFieldContext.showFieldTypesDropdown(this.$el)
|
||||
},
|
||||
getField(allFieldsInTable, groupBy) {
|
||||
const field = allFieldsInTable.find((f) => f.id === groupBy.field)
|
||||
return field
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -75,7 +75,6 @@
|
||||
></GridViewPlaceholder>
|
||||
<GridViewGroups
|
||||
v-if="includeGroupBy && activeGroupBys.length > 0"
|
||||
:all-fields-in-table="allFieldsInTable"
|
||||
:group-by-value-sets="groupByValueSets"
|
||||
:store-prefix="storePrefix"
|
||||
></GridViewGroups>
|
||||
@@ -423,9 +422,7 @@ export default {
|
||||
return false
|
||||
}
|
||||
return groupBys.slice(0, groupByIndex + 1).every((groupBy) => {
|
||||
const groupByField = this.allFieldsInTable.find(
|
||||
(f) => f.id === groupBy.field
|
||||
)
|
||||
const groupByField = this.getGroupByField(groupBy)
|
||||
const groupByFieldType = this.$registry.get(
|
||||
'field',
|
||||
groupByField.type
|
||||
@@ -448,9 +445,7 @@ export default {
|
||||
const groupByFields = groupBys
|
||||
.slice(0, groupByIndex + 1)
|
||||
.map((groupBy) => {
|
||||
return this.allFieldsInTable.find(
|
||||
(f) => f.id === groupBy.field
|
||||
)
|
||||
return this.getGroupByField(groupBy)
|
||||
})
|
||||
return fieldValuesAreEqualInObjects(
|
||||
groupByFields,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<div class="card-many-to-many__list-wrapper">
|
||||
<div class="card-many-to-many__list">
|
||||
<div
|
||||
v-for="item in value"
|
||||
:key="item.id"
|
||||
class="card-many-to-many__item card-link-row"
|
||||
:class="{
|
||||
'card-link-row--unnamed': item.value === null || item.value === '',
|
||||
}"
|
||||
>
|
||||
<span class="card-many-to-many__name">
|
||||
{{ item.value || 'unnamed row ' + item.id }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="isTruncated" class="card-many-to-many__item card-link-row">
|
||||
<span>...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { LINKED_ITEMS_DEFAULT_LOAD_COUNT } from '@baserow/modules/database/constants'
|
||||
|
||||
export default {
|
||||
name: 'GroupByFieldLinkRow',
|
||||
props: {
|
||||
value: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
isTruncated() {
|
||||
return this.value?.length >= LINKED_ITEMS_DEFAULT_LOAD_COUNT
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -114,6 +114,7 @@ import RowCardFieldEmail from '@baserow/modules/database/components/card/RowCard
|
||||
import RowCardFieldFile from '@baserow/modules/database/components/card/RowCardFieldFile'
|
||||
import RowCardFieldFormula from '@baserow/modules/database/components/card/RowCardFieldFormula'
|
||||
import RowCardFieldLinkRow from '@baserow/modules/database/components/card/RowCardFieldLinkRow'
|
||||
import GroupByFieldLinkRow from '@baserow/modules/database/components/view/grid/GroupByFieldLinkRow'
|
||||
import RowCardFieldMultipleSelect from '@baserow/modules/database/components/card/RowCardFieldMultipleSelect'
|
||||
import RowCardFieldNumber from '@baserow/modules/database/components/card/RowCardFieldNumber'
|
||||
import RowCardFieldRating from '@baserow/modules/database/components/card/RowCardFieldRating'
|
||||
@@ -1360,6 +1361,10 @@ export class LinkRowFieldType extends FieldType {
|
||||
return RowCardFieldLinkRow
|
||||
}
|
||||
|
||||
getGroupByComponent() {
|
||||
return GroupByFieldLinkRow
|
||||
}
|
||||
|
||||
getRowHistoryEntryComponent() {
|
||||
return RowHistoryFieldLinkRow
|
||||
}
|
||||
@@ -4262,6 +4267,14 @@ export class FormulaFieldType extends mix(
|
||||
return RowCardFieldFormula
|
||||
}
|
||||
|
||||
getGroupByComponent(field) {
|
||||
const formulaType = this.getFormulaType(field)
|
||||
if (formulaType) {
|
||||
return formulaType.getCardComponent(field)
|
||||
}
|
||||
return this.getCardComponent(field)
|
||||
}
|
||||
|
||||
getFilterInputComponent(field, filterType) {
|
||||
return this.getFormulaType(field)?.getFilterInputComponent(
|
||||
field,
|
||||
|
||||
@@ -51,6 +51,11 @@ export default {
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getGroupByField(groupBy) {
|
||||
return this.$store.getters['field/getAll'].find(
|
||||
(f) => f.id === groupBy.field
|
||||
)
|
||||
},
|
||||
getFieldWidth(field) {
|
||||
const fieldId = field?.id
|
||||
const hasFieldOptions =
|
||||
|
||||
@@ -3830,8 +3830,11 @@ export const getters = {
|
||||
return row._.selected && row._.selectedFieldId !== -1
|
||||
})
|
||||
},
|
||||
getActiveGroupBys(state) {
|
||||
return state.activeGroupBys
|
||||
getActiveGroupBys(state, getters, rootState, rootGetters) {
|
||||
const fields = rootGetters['field/getAll']
|
||||
return state.activeGroupBys.filter((groupBy) =>
|
||||
fields.some((f) => f.id === groupBy.field)
|
||||
)
|
||||
},
|
||||
getGroupByMetadata(state) {
|
||||
return state.groupByMetadata
|
||||
|
||||
@@ -603,6 +603,7 @@ export class GridViewType extends ViewType {
|
||||
includeFieldOptions = false,
|
||||
sourceEvent = null
|
||||
) {
|
||||
await store.dispatch(storePrefix + 'view/grid/updateActiveGroupBys', [])
|
||||
const isPublic = store.getters[storePrefix + 'view/public/getIsPublic']
|
||||
const adhocFiltering = isAdhocFiltering(
|
||||
this.app,
|
||||
|
||||
Reference in new issue
Block a user