-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate asset id on the frontend in the query editor (#350)
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { QueryType, SitewiseQuery } from '../types'; | ||
import { migrateQuery } from './migrateQuery'; | ||
|
||
describe('migrateQuery()', () => { | ||
it('should return the same query by reference equality if there are no migrations', () => { | ||
const query: SitewiseQuery = { refId: 'a', queryType: QueryType.PropertyAggregate }; | ||
const migratedQuery = migrateQuery(query); | ||
expect(query).toBe(migratedQuery); | ||
}); | ||
|
||
it('should migrate assetId to assetIds if assetIds does not exist', () => { | ||
const query: SitewiseQuery = { refId: 'a', queryType: QueryType.PropertyAggregate, assetId: 'asset-id' }; | ||
const migratedQuery = migrateQuery(query); | ||
expect(query).not.toBe(migratedQuery); | ||
expect(migratedQuery.assetIds).toEqual(expect.arrayContaining(['asset-id'])); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { SitewiseQuery } from '../types'; | ||
|
||
const migrateAssetId = (query: SitewiseQuery): SitewiseQuery => { | ||
if (query.assetId && !query.assetIds) { | ||
return { ...query, assetIds: [query.assetId] }; | ||
} | ||
|
||
return query; | ||
}; | ||
|
||
export const migrateQuery = (query: SitewiseQuery): SitewiseQuery => { | ||
let migratedQuery = migrateAssetId(query); | ||
|
||
return migratedQuery; | ||
}; |