-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix connecting y values for ql timeline chart (#167)
- Loading branch information
Vladimir Chernitsyn
authored
Nov 7, 2023
1 parent
ff6ee6e
commit 6a0b27e
Showing
14 changed files
with
324 additions
and
67 deletions.
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
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
25 changes: 25 additions & 0 deletions
25
src/shared/modules/config/ql/__tests__/mapQlConfigToLatestVersion.test.ts
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,25 @@ | ||
import type {QLEntryDataShared} from '../../../../types'; | ||
import {QlConfigVersions} from '../../../../types/ql/versions'; | ||
import {mapQlConfigToLatestVersion} from '../mapQlConfigToLatestVersion'; | ||
|
||
describe('mapQlConfigToLatestVersion', () => { | ||
it('should return config of the latest version', () => { | ||
const versions = Object.values(QlConfigVersions); | ||
|
||
const latest = versions[versions.length - 1]; | ||
|
||
const config = {} as QLEntryDataShared; | ||
|
||
const latestConfig = mapQlConfigToLatestVersion(config); | ||
|
||
expect(latestConfig.version).toEqual(latest); | ||
}); | ||
|
||
it('should use only string versions', () => { | ||
const versions = Object.values(QlConfigVersions); | ||
|
||
for (const version of versions) { | ||
expect(typeof version).toBe('string'); | ||
} | ||
}); | ||
}); |
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,63 @@ | ||
import {QLEntryDataShared} from '../../../../types'; | ||
import {mapUndefinedConfigToV1} from '../v1/mapUndefinedConfigToV1'; | ||
|
||
describe('mapUndefinedConfigToV1', () => { | ||
it('should set "nulls" setting for y placeholder to connect, if it is ignore', () => { | ||
const config = { | ||
visualization: { | ||
placeholders: [ | ||
{id: 'y', settings: {nulls: 'ignore'}}, | ||
{id: 'y', settings: {nulls: 'ignore'}}, | ||
], | ||
}, | ||
version: undefined, | ||
} as unknown as QLEntryDataShared; | ||
|
||
const result = mapUndefinedConfigToV1(config); | ||
|
||
expect(result).toMatchObject({ | ||
version: '1', | ||
visualization: { | ||
placeholders: [ | ||
{id: 'y', settings: {nulls: 'connect'}}, | ||
{id: 'y', settings: {nulls: 'connect'}}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it('should leave "nulls" setting for y placeholder as it is, if it is not ignore', () => { | ||
const config = { | ||
visualization: { | ||
placeholders: [ | ||
{id: 'y', settings: {nulls: 'ignore'}}, | ||
{id: 'y', settings: {nulls: 'as-0'}}, | ||
{id: 'y', settings: {nulls: 'connect'}}, | ||
], | ||
}, | ||
version: undefined, | ||
} as unknown as QLEntryDataShared; | ||
|
||
const result = mapUndefinedConfigToV1(config); | ||
|
||
expect(result).toMatchObject({ | ||
version: '1', | ||
visualization: { | ||
placeholders: [ | ||
{id: 'y', settings: {nulls: 'connect'}}, | ||
{id: 'y', settings: {nulls: 'as-0'}}, | ||
{id: 'y', settings: {nulls: 'connect'}}, | ||
], | ||
}, | ||
}); | ||
}); | ||
|
||
it.each([{version: undefined, visualization: {id: 'line'}}, {version: undefined}])( | ||
'should return same config if placeholders does not exists', | ||
(config) => { | ||
const result = mapUndefinedConfigToV1(config as QLEntryDataShared); | ||
|
||
expect(result).toMatchObject({...config, version: '1'}); | ||
}, | ||
); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import type {QlConfig, QlExtendedConfig} from '../../../types'; | ||
|
||
export const mapQlConfigToLatestVersion = (config: QlExtendedConfig): QlConfig => { | ||
import {mapUndefinedConfigToV1} from './v1/mapUndefinedConfigToV1'; | ||
|
||
export const mapQlConfigToLatestVersion = (extendedConfig: QlExtendedConfig): QlConfig => { | ||
let config = extendedConfig; | ||
|
||
if (typeof config.version === 'undefined') { | ||
config = mapUndefinedConfigToV1(config); | ||
} | ||
|
||
return config; | ||
}; |
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,41 @@ | ||
import {PlaceholderId} from '../../../../constants'; | ||
import {QLEntryDataShared} from '../../../../types'; | ||
import {QlConfigV1} from '../../../../types/config/ql/v1'; | ||
import {QlConfigVersions} from '../../../../types/ql/versions'; | ||
|
||
export const mapUndefinedConfigToV1 = (config: QLEntryDataShared): QlConfigV1 => { | ||
const isPlaceholdersExists = config.visualization && 'placeholders' in config.visualization; | ||
|
||
if (!isPlaceholdersExists) { | ||
return { | ||
...config, | ||
version: QlConfigVersions.V1, | ||
}; | ||
} | ||
|
||
const updatedVisualization = { | ||
...config.visualization, | ||
placeholders: config.visualization.placeholders.map((placeholder) => { | ||
if (placeholder.id === PlaceholderId.Y || placeholder.id === PlaceholderId.Y2) { | ||
return { | ||
...placeholder, | ||
settings: { | ||
...placeholder.settings, | ||
nulls: | ||
placeholder.settings?.nulls === 'ignore' | ||
? 'connect' | ||
: placeholder.settings?.nulls, | ||
}, | ||
}; | ||
} | ||
|
||
return placeholder; | ||
}), | ||
}; | ||
|
||
return { | ||
...config, | ||
visualization: updatedVisualization, | ||
version: QlConfigVersions.V1, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import type { | ||
MonitoringPresetV1, | ||
MonitoringPresetV2, | ||
QLEntryDataShared, | ||
QLParam, | ||
QLParamInterval, | ||
QLPreviewTableData, | ||
QLPreviewTableDataColumn, | ||
QLPreviewTableDataRow, | ||
QLQuery, | ||
QLRequestParam, | ||
QLResultEntryMetadataDataColumn, | ||
QLResultEntryMetadataDataColumnOrGroup, | ||
QLResultEntryMetadataDataGroup, | ||
} from '../../ql/common'; | ||
import type {MonitoringPresetV1, MonitoringPresetV2, QLEntryDataShared} from '../../ql/common'; | ||
|
||
export type QlConfig = QLEntryDataShared; | ||
import { | ||
QLParamIntervalV1, | ||
QLParamV1, | ||
QLPreviewTableDataColumnV1, | ||
QLPreviewTableDataRowV1, | ||
QLPreviewTableDataV1, | ||
QLQueryV1, | ||
QLRequestParamV1, | ||
QLResultEntryMetadataDataColumnOrGroupV1, | ||
QLResultEntryMetadataDataColumnV1, | ||
QLResultEntryMetadataDataGroupV1, | ||
QlConfigV1, | ||
} from './v1'; | ||
|
||
export type QlExtendedConfig = QlConfig; | ||
export type QlConfig = QlConfigV1; | ||
|
||
export type QLConfigQuery = QLQuery; | ||
export type QlPreviousConfig = QLEntryDataShared; | ||
|
||
export type QlConfigResultEntryMetadataDataGroup = QLResultEntryMetadataDataGroup; | ||
export type QlExtendedConfig = QlConfig | QlPreviousConfig; | ||
|
||
export type QlConfigResultEntryMetadataDataColumn = QLResultEntryMetadataDataColumn; | ||
export type QLConfigQuery = QLQueryV1; | ||
|
||
export type QlConfigParamInterval = QLParamInterval; | ||
export type QlConfigResultEntryMetadataDataGroup = QLResultEntryMetadataDataGroupV1; | ||
|
||
export type QlConfigParam = QLParam; | ||
export type QlConfigResultEntryMetadataDataColumn = QLResultEntryMetadataDataColumnV1; | ||
|
||
export type QlConfigRequestParam = QLRequestParam; | ||
export type QlConfigParamInterval = QLParamIntervalV1; | ||
|
||
export type QlConfigResultEntryMetadataDataColumnOrGroup = QLResultEntryMetadataDataColumnOrGroup; | ||
export type QlConfigParam = QLParamV1; | ||
|
||
export type QlConfigPreviewTableDataColumn = QLPreviewTableDataColumn; | ||
export type QlConfigRequestParam = QLRequestParamV1; | ||
|
||
export type QlConfigPreviewTableDataRow = QLPreviewTableDataRow; | ||
export type QlConfigResultEntryMetadataDataColumnOrGroup = QLResultEntryMetadataDataColumnOrGroupV1; | ||
|
||
export type QlConfigPreviewTableData = QLPreviewTableData; | ||
export type QlConfigPreviewTableDataColumn = QLPreviewTableDataColumnV1; | ||
|
||
export type QlConfigPreviewTableDataRow = QLPreviewTableDataRowV1; | ||
|
||
export type QlConfigPreviewTableData = QLPreviewTableDataV1; | ||
|
||
export type MonitoringPreset = MonitoringPresetV1 | MonitoringPresetV2; |
Oops, something went wrong.