From 86b7328f397fcc72eb684939a7c31a126ec75658 Mon Sep 17 00:00:00 2001 From: Jocelyn Collado-Kuri Date: Tue, 28 Oct 2025 19:57:55 -0700 Subject: [PATCH] Variables: Allow fetching disabled items for Item type variable (#2109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds support for showing disabled items when using the `Item` type template variable. Similar to how we support disabled items today in our query editor: Screenshot 2025-10-21 at 9 00 11 AM In this example, the host contains a disabled item `CPU iowait time` Screenshot 2025-10-21 at 9 02 08 AM Which we can now show and hide from the variable in Grafana: https://github.com/user-attachments/assets/eca9327e-40a6-4852-92e9-71ff1ad9ea32 I also removed some deprecated types and packages :)! Fixes: #2025 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .changeset/nasty-webs-repeat.md | 5 ++ .../components/VariableQueryEditor.tsx | 55 ++++++++++++----- src/datasource/datasource.ts | 19 +++--- src/datasource/specs/datasource.spec.ts | 61 ++++++++++++++----- src/datasource/types.ts | 7 ++- 5 files changed, 107 insertions(+), 40 deletions(-) create mode 100644 .changeset/nasty-webs-repeat.md diff --git a/.changeset/nasty-webs-repeat.md b/.changeset/nasty-webs-repeat.md new file mode 100644 index 0000000..a1f328d --- /dev/null +++ b/.changeset/nasty-webs-repeat.md @@ -0,0 +1,5 @@ +--- +'grafana-zabbix': minor +--- + +Add support for disabled items in Item variable type diff --git a/src/datasource/components/VariableQueryEditor.tsx b/src/datasource/components/VariableQueryEditor.tsx index c6086f3..ce2ead2 100644 --- a/src/datasource/components/VariableQueryEditor.tsx +++ b/src/datasource/components/VariableQueryEditor.tsx @@ -1,12 +1,11 @@ import React, { PureComponent } from 'react'; import { parseLegacyVariableQuery } from '../utils'; -import { SelectableValue } from '@grafana/data'; import { VariableQuery, VariableQueryData, VariableQueryProps, VariableQueryTypes } from '../types'; import { ZabbixInput } from './ZabbixInput'; -import { InlineField, InlineFieldRow, InlineFormLabel, Input, Select } from '@grafana/ui'; +import { Combobox, ComboboxOption, InlineField, InlineFieldRow, InlineFormLabel, Input, Switch } from '@grafana/ui'; export class ZabbixVariableQueryEditor extends PureComponent { - queryTypes: Array> = [ + queryTypes: Array> = [ { value: VariableQueryTypes.Group, label: 'Group' }, { value: VariableQueryTypes.Host, label: 'Host' }, { value: VariableQueryTypes.Application, label: 'Application' }, @@ -23,6 +22,7 @@ export class ZabbixVariableQueryEditor extends PureComponent { - const { queryType, group, host, application, itemTag, item } = this.state; - const queryModel = { queryType, group, host, application, itemTag, item }; + const { queryType, group, host, application, itemTag, item, showDisabledItems } = this.state; + const queryModel = { queryType, group, host, application, itemTag, item, showDisabledItems }; this.props.onChange(queryModel, `Zabbix - ${queryType}`); }; - handleQueryTypeChange = (selectedItem: SelectableValue) => { + handleQueryTypeChange = (selectedItem: ComboboxOption) => { this.setState({ ...this.state, selectedQueryType: selectedItem, queryType: selectedItem.value, }); - const { group, host, application, itemTag, item } = this.state; + const { group, host, application, itemTag, item, showDisabledItems } = this.state; const queryType = selectedItem.value; - const queryModel = { queryType, group, host, application, itemTag, item }; + const queryModel = { queryType, group, host, application, itemTag, item, showDisabledItems }; + this.props.onChange(queryModel, `Zabbix - ${queryType}`); + }; + + handleShowDisabledItemsChange = (evt: React.FormEvent) => { + const showDisabledItems = (evt.target as any).checked; + this.setState((prevState: VariableQueryData) => { + return { + ...prevState, + showDisabledItems: showDisabledItems, + }; + }); + + const { queryType, group, host, application, itemTag, item } = this.state; + const queryModel = { queryType, group, host, application, itemTag, item, showDisabledItems }; this.props.onChange(queryModel, `Zabbix - ${queryType}`); }; render() { - const { selectedQueryType, legacyQuery, group, host, application, itemTag, item } = this.state; + const { selectedQueryType, legacyQuery, group, host, application, itemTag, item, showDisabledItems } = this.state; const { datasource } = this.props; const supportsItemTags = datasource?.zabbix?.isZabbix54OrHigherSync() || false; return ( <> - -