handle "null" in "timepicker:quickRanges" migration (#95767)

This commit is contained in:
Anton Dosov 2021-04-06 16:27:10 +02:00 committed by GitHub
parent 357c4a5457
commit 2745a6e957
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -76,6 +76,23 @@ describe('ui_settings 7.12.0 migrations', () => {
const migrated = migration(doc);
expect(JSON.parse(migrated.attributes['timepicker:quickRanges'])).toEqual([migratedQuickRange]);
});
// https://github.com/elastic/kibana/issues/95616
test('returns doc when "timepicker:quickRanges" is null', () => {
const doc = {
type: 'config',
id: '8.0.0',
attributes: {
buildNum: 9007199254740991,
'timepicker:quickRanges': null,
},
references: [],
updated_at: '2020-06-09T20:18:20.349Z',
migrationVersion: {},
};
const migrated = migration(doc);
expect(migrated).toEqual(doc);
});
});
describe('ui_settings 7.13.0 migrations', () => {

View file

@ -32,7 +32,7 @@ export const migrations = {
...doc,
...(doc.attributes && {
attributes: Object.keys(doc.attributes).reduce((acc, key) => {
if (key === 'timepicker:quickRanges' && doc.attributes[key].indexOf('section') > -1) {
if (key === 'timepicker:quickRanges' && doc.attributes[key]?.indexOf('section') > -1) {
const ranges = JSON.parse(doc.attributes[key]).map(
({ from, to, display }: { from: string; to: string; display: string }) => {
return {