diff --git a/packages/gooddata-sdk/src/gooddata_sdk/visualization.py b/packages/gooddata-sdk/src/gooddata_sdk/visualization.py index 424ee91ff..35e5a9c14 100644 --- a/packages/gooddata-sdk/src/gooddata_sdk/visualization.py +++ b/packages/gooddata-sdk/src/gooddata_sdk/visualization.py @@ -185,6 +185,13 @@ def _convert_filter_to_computable(filter_obj: dict[str, Any]) -> Filter: not_in_values = f["notIn"]["values"] if "values" in f["notIn"] else f["notIn"]["uris"] return NegativeAttributeFilter(label=ref_extract(f["displayForm"]), values=not_in_values) + elif "arbitraryAttributeFilter" in filter_obj: + f = filter_obj["arbitraryAttributeFilter"] + label = ref_extract(f["label"]) + values = f.get("values", []) + if f.get("negativeSelection", False): + return NegativeAttributeFilter(label=label, values=values) + return PositiveAttributeFilter(label=label, values=values) elif "matchAttributeFilter" in filter_obj: f = filter_obj["matchAttributeFilter"] return MatchAttributeFilter( diff --git a/packages/gooddata-sdk/tests/visualization/resources/with_arbitrary_attribute_filter.json b/packages/gooddata-sdk/tests/visualization/resources/with_arbitrary_attribute_filter.json new file mode 100644 index 000000000..100e3d3ba --- /dev/null +++ b/packages/gooddata-sdk/tests/visualization/resources/with_arbitrary_attribute_filter.json @@ -0,0 +1,86 @@ +{ + "buckets": [ + { + "items": [ + { + "measure": { + "definition": { + "measureDefinition": { + "item": { + "identifier": { + "id": "aangOxLSeztu", + "type": "metric" + } + } + } + }, + "localIdentifier": "m_aangOxLSeztu" + } + } + ], + "localIdentifier": "measures" + }, + { + "items": [ + { + "attribute": { + "displayForm": { + "identifier": { + "id": "label.opportunity.id.name", + "type": "label" + } + }, + "localIdentifier": "a_label.opportunity.id.name" + } + } + ], + "localIdentifier": "view" + }, + { + "items": [], + "localIdentifier": "stack" + } + ], + "filters": [ + { + "arbitraryAttributeFilter": { + "localIdentifier": "9f2db153ca1f4beaa79d09e6ff43ce69", + "label": { + "identifier": { + "id": "attr.f_opportunitysnapshot.oppsnapshot", + "type": "label" + } + }, + "values": [ + "245519", + "237519", + "241519" + ] + } + }, + { + "arbitraryAttributeFilter": { + "localIdentifier": "abc123", + "label": { + "identifier": { + "id": "attr.f_opportunitysnapshot.oppsnapshot", + "type": "label" + } + }, + "negativeSelection": true, + "values": [ + "245519", + "237519" + ] + } + } + ], + "identifier": "AreaChart.arbitrary_filter_test", + "properties": { + "controls": {} + }, + "sorts": [], + "title": "AreaChart - arbitrary attribute filter test", + "uri": "AreaChart.arbitrary_filter_test", + "visualizationUrl": "local:area" +} diff --git a/packages/gooddata-sdk/tests/visualization/snapshots/with_arbitrary_attribute_filter.snapshot.json b/packages/gooddata-sdk/tests/visualization/snapshots/with_arbitrary_attribute_filter.snapshot.json new file mode 100644 index 000000000..d47d693f3 --- /dev/null +++ b/packages/gooddata-sdk/tests/visualization/snapshots/with_arbitrary_attribute_filter.snapshot.json @@ -0,0 +1,65 @@ +{ + "attributes": [ + { + "label": { + "identifier": { + "id": "label.opportunity.id.name", + "type": "label" + } + }, + "local_identifier": "a_label.opportunity.id.name" + } + ], + "filters": [ + { + "positive_attribute_filter": { + "_in": { + "values": [ + "245519", + "237519", + "241519" + ] + }, + "label": { + "identifier": { + "id": "attr.f_opportunitysnapshot.oppsnapshot", + "type": "label" + } + } + } + }, + { + "negative_attribute_filter": { + "label": { + "identifier": { + "id": "attr.f_opportunitysnapshot.oppsnapshot", + "type": "label" + } + }, + "not_in": { + "values": [ + "245519", + "237519" + ] + } + } + } + ], + "measures": [ + { + "definition": { + "measure": { + "compute_ratio": false, + "filters": [], + "item": { + "identifier": { + "id": "aangOxLSeztu", + "type": "metric" + } + } + } + }, + "local_identifier": "m_aangOxLSeztu" + } + ] +} \ No newline at end of file