Skip to content

Commit 6fa914a

Browse files
fix: Makes query fields nullable
This reflects observed behavior in Grafana operation
1 parent 0372e3e commit 6fa914a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/components/HaystackQueryTypeSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { DataSource, queryTypes } from '../datasource';
55

66
export interface HaystackQueryTypeSelectorProps {
77
datasource: DataSource | null;
8-
type: string;
8+
type?: string;
99
refId: string;
1010
onChange: (type: string) => void;
1111
}
@@ -16,7 +16,7 @@ export function HaystackQueryTypeSelector({ datasource, type, refId, onChange }:
1616
};
1717

1818
const queryTypeDefault = queryTypes[0];
19-
function queryTypeFromValue(value: string): QueryType | null {
19+
function queryTypeFromValue(value?: string): QueryType | null {
2020
return queryTypes.find((queryType) => queryType.value === value) ?? null;
2121
}
2222

src/components/VariableQueryEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export const VariableQueryEditor: React.FC<VariableQueryProps> = ({ onChange, qu
2222
let type = query.type;
2323
let queryCmd = "";
2424
if (query.type === "eval") {
25-
queryCmd = query.eval
25+
queryCmd = query.eval ?? "";
2626
} else if (query.type === "hisRead") {
27-
queryCmd = query.hisRead
27+
queryCmd = query.hisRead ?? "";
2828
} else if (query.type === "hisReadFilter") {
29-
queryCmd = query.hisReadFilter
29+
queryCmd = query.hisReadFilter ?? "";
3030
} else if (query.type === "read") {
31-
queryCmd = query.read
31+
queryCmd = query.read ?? "";
3232
}
3333
let column = "none";
3434
if (query.column !== undefined && query.column !== '') {

src/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { DataSourceJsonData, SelectableValue } from '@grafana/data';
22
import { DataQuery } from '@grafana/schema';
33

44
export interface HaystackQuery extends DataQuery {
5-
type: string; // Defines the type of query that should be executed
6-
eval: string;
7-
hisRead: string;
8-
hisReadFilter: string;
9-
read: string;
5+
type?: string; // Defines the type of query that should be executed
6+
eval?: string;
7+
hisRead?: string;
8+
hisReadFilter?: string;
9+
read?: string;
1010
}
1111

1212
// OpsQuery is a query that is used to get the available ops from the datasource.

0 commit comments

Comments
 (0)