Skip to content

Commit e5eb724

Browse files
committed
Set default variable query
1 parent abafdab commit e5eb724

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/VariableQueryEditor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import defaults from 'lodash/defaults';
2+
13
import React, { useState } from 'react';
2-
import { JsonApiVariableQuery } from './types';
4+
import { JsonApiVariableQuery, defaultVariableQuery } from './types';
35
import { InlineFormLabel } from '@grafana/ui';
46
import { JsonPathQueryField } from './JsonPathQueryField';
57

@@ -9,7 +11,9 @@ interface VariableQueryProps {
911
}
1012

1113
export const VariableQueryEditor: React.FC<VariableQueryProps> = ({ onChange, query }) => {
12-
const [state, setState] = useState<JsonApiVariableQuery>(query);
14+
const init = defaults(query, defaultVariableQuery);
15+
16+
const [state, setState] = useState<JsonApiVariableQuery>(init);
1317

1418
const saveQuery = () => {
1519
onChange(state, state.jsonPath);

src/img/variable.png

-13.8 KB
Loading

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const defaultQuery: Partial<JsonApiQuery> = {
2222
queryParams: '',
2323
};
2424

25+
export const defaultVariableQuery: Partial<JsonApiVariableQuery> = {
26+
jsonPath: '',
27+
queryParams: '',
28+
};
29+
2530
export interface JsonApiDataSourceOptions extends DataSourceJsonData {
2631
queryParams?: string;
2732
}

0 commit comments

Comments
 (0)