Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(asset): remove includeOnlyDataInTimeRange query param, default true #104

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/datasources/asset/data-sources/AssetDataSourceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ export abstract class AssetDataSourceBase extends DataSourceBase<AssetQuery, Ass
}
}

getQueryParams(): URLSearchParams {
return new URLSearchParams(window.location.search);
}

getQueryParam(param: string): string | null {
return this.getQueryParams().get(param);
}

public getCachedSystems(): SystemMetadata[] {
return Array.from(this.systemAliasCache.values());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,87 +688,3 @@ describe('Time based data links', () => {
expect(builtUrl).toMatchSnapshot();
});
});

describe('Run query with IncludeOnlyDataInTimeRange flag', () => {
let processCalibrationForecastQuerySpy: jest.SpyInstance;

beforeEach(() => {
processCalibrationForecastQuerySpy = jest.spyOn(datastore, 'processCalibrationForecastQuery').mockImplementation();
});

test('should set IncludeOnlyDataInTimeRange to true', async () => {
const query = buildCalibrationForecastQuery({
refId: '',
type: AssetQueryType.CalibrationForecast,
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
});

jest.spyOn(datastore, 'getQueryParam').mockReturnValue('true');
await datastore.query(query);

expect(processCalibrationForecastQuerySpy).toHaveBeenCalledWith(
expect.objectContaining({
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
IncludeOnlyDataInTimeRange: true
}),
expect.anything()
);
});

test('should set IncludeOnlyDataInTimeRange to true case insensitive', async () => {
const query = buildCalibrationForecastQuery({
refId: '',
type: AssetQueryType.CalibrationForecast,
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
});

jest.spyOn(datastore, 'getQueryParam').mockReturnValue('tRUe');
await datastore.query(query);

expect(processCalibrationForecastQuerySpy).toHaveBeenCalledWith(
expect.objectContaining({
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
IncludeOnlyDataInTimeRange: true
}),
expect.anything()
);
});

test('should set IncludeOnlyDataInTimeRange to false', async () => {
const query = buildCalibrationForecastQuery({
refId: '',
type: AssetQueryType.CalibrationForecast,
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
});

jest.spyOn(datastore, 'getQueryParam').mockReturnValue('false');
await datastore.query(query);

expect(processCalibrationForecastQuerySpy).toHaveBeenCalledWith(
expect.objectContaining({
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
IncludeOnlyDataInTimeRange: false
}),
expect.anything()
);
});

test('should set IncludeOnlyDataInTimeRange to false if missing', async () => {
const query = buildCalibrationForecastQuery({
refId: '',
type: AssetQueryType.CalibrationForecast,
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
});

jest.spyOn(datastore, 'getQueryParam').mockReturnValue(null);
await datastore.query(query);

expect(processCalibrationForecastQuerySpy).toHaveBeenCalledWith(
expect.objectContaining({
groupBy: [AssetCalibrationTimeBasedGroupByType.Month],
IncludeOnlyDataInTimeRange: false
}),
expect.anything()
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
);
}

calibrationForecastQuery.IncludeOnlyDataInTimeRange = this.getQueryParam('IncludeOnlyDataInTimeRange')?.toLowerCase() === 'true';
return await this.processCalibrationForecastQuery(calibrationForecastQuery, options);
}

Expand All @@ -74,8 +73,7 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
query.groupBy,
from,
to,
query.filter,
query.IncludeOnlyDataInTimeRange
query.filter
);

result.fields = calibrationForecastResponse.calibrationForecast.columns || [];
Expand Down Expand Up @@ -115,7 +113,7 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
field.values = field.values!.map(formatter);
}

if (!formatter && !Boolean(this.getQueryParam('IncludeOnlyDataInTimeRange'))) {
if (!formatter) {
field.config = { links: this.createDataLinks(timeGrouping, startDate) };
}
});
Expand All @@ -133,8 +131,6 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
}

const value = options.replaceVariables(`\${__data.fields.${timeGrouping}}`);
const IncludeOnlyDataInTimeRange = value !== startDate;

let from, to;

const parseDate = (dateStr: string) => {
Expand Down Expand Up @@ -162,7 +158,7 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
break;
}

return `${url}&from=${from}&to=${to}&IncludeOnlyDataInTimeRange=${IncludeOnlyDataInTimeRange}`;
return `${url}&from=${from}&to=${to}`;
}
}
];
Expand Down Expand Up @@ -225,8 +221,8 @@ export class CalibrationForecastDataSource extends AssetDataSourceBase {
}
}

async queryCalibrationForecast(groupBy: string[], startTime: string, endTime: string, filter = '', IncludeOnlyDataInTimeRange = false): Promise<CalibrationForecastResponse> {
let data = { groupBy, startTime, endTime, filter, IncludeOnlyDataInTimeRange };
async queryCalibrationForecast(groupBy: string[], startTime: string, endTime: string, filter = '', includeOnlyDataInTimeRange = true): Promise<CalibrationForecastResponse> {
let data = { groupBy, startTime, endTime, filter, includeOnlyDataInTimeRange };
try {
let response = await this.post<CalibrationForecastResponse>(this.baseUrl + '/assets/calibration-forecast', data);
return response;
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&IncludeOnlyDataInTimeRange=true"`;
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 Month grouping 1`] = `"http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641081600000&to=1643760000000&IncludeOnlyDataInTimeRange=true"`;
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 Week grouping 1`] = `"http://localhost//d/\${__dashboard.uid}/\${__dashboard}?orgId=\${__org.id}&\${__all_variables}&from=1641168000000&to=1641689999999&IncludeOnlyDataInTimeRange=true"`;
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[`queries asset calibration forecast with day groupBy 1`] = `
[
Expand Down
Loading