Skip to content

Commit

Permalink
Feat: Add macros autocomplete for code editor (#217)
Browse files Browse the repository at this point in the history
* Feat: Add macros autocomplete for code editor

* Add directly instead
  • Loading branch information
zoltanbedi authored Nov 21, 2023
1 parent 19c4cf2 commit 51b9c74
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"TINYINT",
"tokenprovider",
"typecheck",
"UNIXTIME",
"uuidv",
"vectorator"
],
Expand Down
2 changes: 2 additions & 0 deletions src/components/query-editor-raw/bigqueryCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { PartitioningType, TableSchema } from 'api';
import { BQ_AGGREGATE_FNS } from './bigQueryFunctions';
import { BQ_OPERATORS } from './bigQueryOperators';
import { MACROS } from './macros';

interface CompletionProviderGetterArgs {
getColumns: React.MutableRefObject<(t: string) => Promise<ColumnDefinition[]>>;
Expand Down Expand Up @@ -56,6 +57,7 @@ export const getBigQueryCompletionProvider: (args: CompletionProviderGetterArgs)
supportedOperators: () => BQ_OPERATORS,
customSuggestionKinds: customSuggestionKinds(getTables, getTableSchema),
customStatementPlacement,
supportedMacros: () => MACROS,
});

export enum CustomStatementPlacement {
Expand Down
40 changes: 40 additions & 0 deletions src/components/query-editor-raw/macros.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { MacroType } from '@grafana/experimental';

export const MACROS = [
{
id: '$__timeFilter(dateColumn)',
name: '$__timeFilter(dateColumn)',
text: '$__timeFilter',
args: ['dateColumn'],
type: MacroType.Filter,
description:
'Will be replaced by a time range filter using the specified column name. For example, dateColumn BETWEEN FROM_UNIXTIME(1494410783) AND FROM_UNIXTIME(1494410983)',
},
{
id: '$__timeFrom()',
name: '$__timeFrom()',
text: '$__timeFrom',
args: [],
type: MacroType.Filter,
description:
'Will be replaced by the start of the currently active time selection. For example, FROM_UNIXTIME(1494410783)',
},
{
id: '$__timeTo()',
name: '$__timeTo()',
text: '$__timeTo',
args: [],
type: MacroType.Filter,
description:
'Will be replaced by the end of the currently active time selection. For example, FROM_UNIXTIME(1494410983)',
},
{
id: "$__timeGroup(dateColumn, '5m')",
name: "$__timeGroup(dateColumn, '5m')",
text: '$__timeGroup',
args: ['dateColumn', "'5m'"],
type: MacroType.Value,
description:
'Will be replaced by an expression usable in GROUP BY clause. For example, *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed),*',
},
];

0 comments on commit 51b9c74

Please sign in to comment.