forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data view editor] Fix data view timestamp validation (elastic#150398)
## Summary Previously - If you changed a data view's index pattern AND the new pattern didn't contain the timestamp field, you'd see a blank timestamp field and it would let you save. The data view would have been saved with the previous timestamp field which doesn't exist. Now - The timestamp validator checks to make sure the selected timestamp field is in the list of available options. This is helpful because it keeps the previous timestamp value in case you do select an index pattern that contains it. Closes: elastic#150219
- Loading branch information
Showing
5 changed files
with
77 additions
and
5 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
47 changes: 47 additions & 0 deletions
47
src/plugins/data_view_editor/public/components/form_fields/timestamp_field.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,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { requireTimestampOptionValidator } from './timestamp_field'; | ||
import { TimestampOption } from '../../types'; | ||
|
||
const noOptions: TimestampOption[] = []; | ||
const options: TimestampOption[] = [ | ||
{ display: 'a', fieldName: 'a' }, | ||
{ display: 'a', fieldName: 'b' }, | ||
]; | ||
|
||
describe('timestamp field validator', () => { | ||
test('no timestamp options - pass without value', async () => { | ||
const result = await requireTimestampOptionValidator(noOptions).validator({ | ||
value: undefined, | ||
} as any); | ||
// no error | ||
expect(result).toBeUndefined(); | ||
}); | ||
test('timestamp options - fail without value', async () => { | ||
const result = await requireTimestampOptionValidator(options).validator({ | ||
value: undefined, | ||
} as any); | ||
// returns error | ||
expect(result).toBeDefined(); | ||
}); | ||
test('timestamp options - pass with value', async () => { | ||
const result = await requireTimestampOptionValidator(options).validator({ | ||
value: { label: 'a', value: 'a' }, | ||
} as any); | ||
// no error | ||
expect(result).toBeUndefined(); | ||
}); | ||
test('timestamp options - fail, value not in list', async () => { | ||
const result = await requireTimestampOptionValidator(options).validator({ | ||
value: { label: 'c', value: 'c' }, | ||
} as any); | ||
// returns error | ||
expect(result).toBeDefined(); | ||
}); | ||
}); |
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