Skip to content

Commit

Permalink
Add clipboard copy to formatted SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
lunaticusgreen committed Nov 24, 2024
1 parent aa7cb45 commit 1999433
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 330 deletions.
21 changes: 6 additions & 15 deletions src/datasource/adhoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class AdHocFilter {
this.tagKeys = [];
this.tagValues = [];
this.datasource = datasource;
this.adHocValuesQuery = datasource.adHocValuesQuery
this.adHocValuesQuery = datasource.adHocValuesQuery;
let filter = queryFilter;
if (datasource.defaultDatabase.length > 0) {
filter = "database = '" + datasource.defaultDatabase + "' AND " + queryFilter;
Expand Down Expand Up @@ -83,35 +83,26 @@ export default class AdHocFilter {
}
// Split the key to extract database, table, and field
const keyItems = options.key.split('.');
if (
keyItems.length < 2 ||
(keyItems.length === 2 && !this.datasource.defaultDatabase) ||
keyItems.length > 3
) {
if (keyItems.length < 2 || (keyItems.length === 2 && !this.datasource.defaultDatabase) || keyItems.length > 3) {
return Promise.resolve([]);
}

// Destructure key items based on their length
let database, table, field;
if (keyItems.length === 3) {
[
database,
table,
field] = keyItems;
[database, table, field] = keyItems;
} else {
database = this.datasource.defaultDatabase;
[table, field] = keyItems;
}

// Function to build the query
const buildQuery = (queryTemplate) =>
queryTemplate
.replace('{field}', field)
.replace('{database}', database)
.replace('{table}', table);
queryTemplate.replace('{field}', field).replace('{database}', database).replace('{table}', table);

// Execute the initial query
return this.datasource.metricFindQuery(buildQuery(initialQuery))
return this.datasource
.metricFindQuery(buildQuery(initialQuery))
.then((response: any) => {
// Process and cache the response
this.tagValues[options.key] = this.processTagValuesResponse(response);
Expand Down
Loading

0 comments on commit 1999433

Please sign in to comment.