datatrails: hide "add to filter" button when there is no label value to add to filter (#85270)

fix: hide add to filters button when it won't work
This commit is contained in:
Darren Janeczek 2024-03-27 10:33:21 -04:00 committed by GitHub
parent d4953f4a1f
commit 2ecc1bb646
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,15 @@ export class AddToFiltersGraphAction extends SceneObjectBase<AddToFiltersGraphAc
};
public static Component = ({ model }: SceneComponentProps<AddToFiltersGraphAction>) => {
const state = model.useState();
const labels = state.frame.fields[1]?.labels || {};
const canAddToFilters = Object.keys(labels).length !== 0;
if (!canAddToFilters) {
return null;
}
return (
<Button variant="secondary" size="sm" fill="solid" onClick={model.onClick}>
Add to filters