Skip to content

Commit

Permalink
fix(asset): data link creation on deployed envs
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Aradei committed Oct 29, 2024
1 parent bcf60f0 commit eaba53c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataQueryRequest, DataFrameDTO, DataSourceInstanceSettings, FieldDTO, TestDataSourceResponse, DataLink } from '@grafana/data';
import { AssetDataSourceOptions, AssetQuery, AssetQueryType, AssetType, AssetTypeOptions, BusType, BusTypeOptions } from '../../types/types';
import { BackendSrv, getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { BackendSrv, config, getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
import { AssetDataSourceBase } from '../AssetDataSourceBase';
import { AssetCalibrationForecastKey, AssetCalibrationTimeBasedGroupByType, CalibrationForecastQuery, CalibrationForecastResponse, ColumnDescriptorType, FieldDTOWithDescriptor } from '../../types/CalibrationForecastQuery.types';
import { transformComputedFieldsQuery } from '../../../../core/query-builder.utils';
Expand Down Expand Up @@ -102,9 +102,6 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
}

processResultsGroupedByTime(result: DataFrameDTO, timeGrouping: AssetCalibrationForecastKey) {
const timeFieldFirstValue = result.fields.find(field => field.name === timeGrouping)?.values?.at(0);
const startDate = this.forecastDateFormatterMap.get(timeGrouping)!(timeFieldFirstValue);

result.fields.forEach(field => {
field.name = this.createColumnNameFromDescriptor(field as FieldDTOWithDescriptor);
const formatter = this.forecastDateFormatterMap.get(field.name as AssetCalibrationForecastKey);
Expand All @@ -114,17 +111,17 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
}

if (!formatter) {
field.config = { links: this.createDataLinks(timeGrouping, startDate) };
field.config = { links: this.createDataLinks(timeGrouping) };
}
});
}

private createDataLinks(timeGrouping: AssetCalibrationForecastKey, startDate: string): DataLink[] {
const url = window.location.href.split('/d/')[0] + '/d/${__dashboard.uid}/${__dashboard}?orgId=${__org.id}&${__all_variables}';
private createDataLinks(timeGrouping: AssetCalibrationForecastKey): DataLink[] {
const url = config.appUrl + 'd/${__dashboard.uid}/${__dashboard}?orgId=${__org.id}&${__all_variables}';

return [
{
title: `View ${timeGrouping}`, targetBlank: true, url: `${url}`,
title: `View ${timeGrouping}`, targetBlank: false, url: `${url}`,
onBuildUrl: function (options) {
if (!options.replaceVariables) {
return url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Time based data links creates data links for Day grouping 1`] = `"http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1640995200000&to=1641081600000"`;
exports[`Time based data links creates data links for Day grouping 1`] = `"/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1640995200000&to=1641081600000"`;

exports[`Time based data links creates data links for Month grouping 1`] = `"http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641081600000&to=1643760000000"`;
exports[`Time based data links creates data links for Month grouping 1`] = `"/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641081600000&to=1643760000000"`;

exports[`Time based data links creates data links for Week grouping 1`] = `"http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641168000000&to=1641689999999"`;
exports[`Time based data links creates data links for Week grouping 1`] = `"/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641168000000&to=1641689999999"`;

exports[`queries asset calibration forecast with day groupBy 1`] = `
[
Expand Down Expand Up @@ -37,7 +37,7 @@ exports[`queries asset calibration forecast with day groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Day",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -85,7 +85,7 @@ exports[`queries asset calibration forecast with month groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -133,7 +133,7 @@ exports[`queries asset calibration forecast with week groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Week",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -353,7 +353,7 @@ exports[`queries calibration forecast with month and assetType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -377,7 +377,7 @@ exports[`queries calibration forecast with month and assetType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -401,7 +401,7 @@ exports[`queries calibration forecast with month and assetType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -449,7 +449,7 @@ exports[`queries calibration forecast with month and busType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -473,7 +473,7 @@ exports[`queries calibration forecast with month and busType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -497,7 +497,7 @@ exports[`queries calibration forecast with month and busType groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -545,7 +545,7 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -569,7 +569,7 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -593,7 +593,7 @@ exports[`queries calibration forecast with month and location groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -641,7 +641,7 @@ exports[`queries calibration forecast with month and vendor groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -665,7 +665,7 @@ exports[`queries calibration forecast with month and vendor groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -689,7 +689,7 @@ exports[`queries calibration forecast with month and vendor groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down Expand Up @@ -737,7 +737,7 @@ exports[`queries calibration forecast with month and workspace groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -761,7 +761,7 @@ exports[`queries calibration forecast with month and workspace groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand All @@ -785,7 +785,7 @@ exports[`queries calibration forecast with month and workspace groupBy 1`] = `
"onBuildUrl": [Function],
"targetBlank": true,
"title": "View Month",
"url": "http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
"url": "/d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}",
},
],
},
Expand Down

0 comments on commit eaba53c

Please sign in to comment.