Skip to content

Commit

Permalink
Drop legacy variable query support
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jul 10, 2021
1 parent d842bc6 commit 77a042f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Component/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const QueryEditor: ComponentType<Props> = ({ datasource, onChange, onRunQ
(type: SelectableValue<Format>) => {
const typeValue = type.value!;

return datasource.metricFindQuery('', undefined, typeValue).then(
return datasource.metricFindQuery({ query: '', format: 'string' }, undefined, typeValue).then(
(result) => {
const metrics = result.map((value) => ({ label: value.text, value: value.value }));

Expand Down
11 changes: 1 addition & 10 deletions src/Component/VariableQueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export const VariableQueryEditor: React.FC<Props> = ({ onChange, query }) => {
[event.currentTarget.name]: event.currentTarget.checked === true ? 'json' : 'string',
});

const legacySupport = (legacyOrNew: VariableQuery | string) => {
if (typeof legacyOrNew === 'string') {
setVariableQuery({ ['query']: legacyOrNew, ['format']: 'string' });
return legacyOrNew;
}

return legacyOrNew.query;
};

const checkValidJSON = (query: VariableQuery) => {
if (variableQuery.format === 'json') {
const jsonString = getTemplateSrv().replace(variableQuery.query, undefined, 'json');
Expand All @@ -60,7 +51,7 @@ export const VariableQueryEditor: React.FC<Props> = ({ onChange, query }) => {
<>
<InlineFieldRow>
<InlineField label="Query" invalid={checkValidJSON(variableQuery)} grow>
<Input name="query" onBlur={saveQuery} onChange={handleChange} value={legacySupport(variableQuery)} />
<Input name="query" onBlur={saveQuery} onChange={handleChange} value={variableQuery.query} />
</InlineField>
<InlineField
labelWidth={14}
Expand Down
11 changes: 4 additions & 7 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ export class DataSource extends DataSourceApi<GrafanaQuery, GenericOptions> {
});
}

metricFindQuery(legacyOrNew: VariableQuery | string, options?: any, type?: string): Promise<MetricFindValue[]> {
const query: VariableQuery =
typeof legacyOrNew === 'string' ? { query: legacyOrNew, format: 'string' } : legacyOrNew;

metricFindQuery(variableQuery: VariableQuery, options?: any, type?: string): Promise<MetricFindValue[]> {
const interpolated =
query.format === 'json'
? JSON.parse(getTemplateSrv().replace(query.query, undefined, 'json'))
variableQuery.format === 'json'
? JSON.parse(getTemplateSrv().replace(variableQuery.query, undefined, 'json'))
: {
type,
target: getTemplateSrv().replace(query.query, undefined, 'regex'),
target: getTemplateSrv().replace(variableQuery.query, undefined, 'regex'),
};

return this.doRequest({
Expand Down

0 comments on commit 77a042f

Please sign in to comment.