-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
46 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ublic/lib/panel/panel_header/panel_actions/customize_panel/can_inherit_time_range.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,44 @@ | ||
/* | ||
* 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 { canInheritTimeRange } from './can_inherit_time_range'; | ||
import { | ||
HelloWorldContainer, | ||
TimeRangeContainer, | ||
TimeRangeEmbeddable, | ||
} from '../../../../test_samples'; | ||
import { HelloWorldEmbeddable } from '../../../../../tests/fixtures'; | ||
|
||
test('canInheritTimeRange returns false if embeddable is inside container without a time range', () => { | ||
const embeddable = new TimeRangeEmbeddable( | ||
{ id: '1234', timeRange: { from: 'noxw-15m', to: 'now' } }, | ||
new HelloWorldContainer({ id: '123', panels: {} }, {}) | ||
); | ||
|
||
expect(canInheritTimeRange(embeddable)).toBe(false); | ||
}); | ||
|
||
test('canInheritTimeRange returns false if embeddable is without a time range', () => { | ||
const embeddable = new HelloWorldEmbeddable( | ||
{ id: '1234' }, | ||
new HelloWorldContainer({ id: '123', panels: {} }, {}) | ||
); | ||
// @ts-ignore | ||
expect(canInheritTimeRange(embeddable)).toBe(false); | ||
}); | ||
|
||
test('canInheritTimeRange returns true if embeddable is inside a container with a time range', () => { | ||
const embeddable = new TimeRangeEmbeddable( | ||
{ id: '1234', timeRange: { from: 'noxw-15m', to: 'now' } }, | ||
new TimeRangeContainer( | ||
{ id: '123', panels: {}, timeRange: { from: 'noxw-15m', to: 'now' } }, | ||
() => undefined | ||
) | ||
); | ||
expect(canInheritTimeRange(embeddable)).toBe(true); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...ble/public/lib/panel/panel_header/panel_actions/customize_panel/can_inherit_time_range.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 @@ | ||
/* | ||
* 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 type { TimeRange } from '@kbn/es-query'; | ||
import { Embeddable, IContainer, ContainerInput } from '../../../../..'; | ||
import { TimeRangeInput } from './customize_panel_action'; | ||
|
||
interface ContainerTimeRangeInput extends ContainerInput<TimeRangeInput> { | ||
timeRange: TimeRange; | ||
} | ||
|
||
export function canInheritTimeRange(embeddable: Embeddable<TimeRangeInput>) { | ||
if (!embeddable.parent) { | ||
return false; | ||
} | ||
|
||
const parent = embeddable.parent as IContainer<TimeRangeInput, ContainerTimeRangeInput>; | ||
|
||
return parent.getInput().timeRange !== undefined; | ||
} |
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