-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] Search Sessions with relative time range (#84405)
- Loading branch information
Showing
48 changed files
with
672 additions
and
276 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
11 changes: 11 additions & 0 deletions
11
...a/public/kibana-plugin-plugins-data-public.datapublicpluginstart.nowprovider.md
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [DataPublicPluginStart](./kibana-plugin-plugins-data-public.datapublicpluginstart.md) > [nowProvider](./kibana-plugin-plugins-data-public.datapublicpluginstart.nowprovider.md) | ||
|
||
## DataPublicPluginStart.nowProvider property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
nowProvider: NowProviderPublicContract; | ||
``` |
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
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
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,24 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { | ||
NowProvider, | ||
NowProviderInternalContract, | ||
NowProviderPublicContract, | ||
} from './now_provider'; |
50 changes: 50 additions & 0 deletions
50
src/plugins/data/public/now_provider/lib/get_force_now_from_url.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,50 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getForceNowFromUrl } from './get_force_now_from_url'; | ||
const originalLocation = window.location; | ||
afterAll(() => { | ||
window.location = originalLocation; | ||
}); | ||
|
||
function mockLocation(url: string) { | ||
// @ts-ignore | ||
delete window.location; | ||
// @ts-ignore | ||
window.location = new URL(url); | ||
} | ||
|
||
test('should get force now from URL', () => { | ||
const dateString = '1999-01-01T00:00:00.000Z'; | ||
mockLocation(`https://elastic.co/?forceNow=${dateString}`); | ||
|
||
expect(getForceNowFromUrl()).toEqual(new Date(dateString)); | ||
}); | ||
|
||
test('should throw if force now is invalid', () => { | ||
const dateString = 'invalid-date'; | ||
mockLocation(`https://elastic.co/?forceNow=${dateString}`); | ||
|
||
expect(() => getForceNowFromUrl()).toThrowError(); | ||
}); | ||
|
||
test('should return undefined if no forceNow', () => { | ||
mockLocation(`https://elastic.co/`); | ||
expect(getForceNowFromUrl()).toBe(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export { getForceNowFromUrl } from './get_force_now_from_url'; |
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,55 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { NowProvider, NowProviderInternalContract } from './now_provider'; | ||
|
||
let mockDateFromUrl: undefined | Date; | ||
let nowProvider: NowProviderInternalContract; | ||
|
||
jest.mock('./lib', () => ({ | ||
// @ts-ignore | ||
...jest.requireActual('./lib'), | ||
getForceNowFromUrl: () => mockDateFromUrl, | ||
})); | ||
|
||
beforeEach(() => { | ||
nowProvider = new NowProvider(); | ||
}); | ||
afterEach(() => { | ||
mockDateFromUrl = undefined; | ||
}); | ||
|
||
test('should return Date.now() by default', async () => { | ||
const now = Date.now(); | ||
await new Promise((r) => setTimeout(r, 10)); | ||
expect(nowProvider.get().getTime()).toBeGreaterThan(now); | ||
}); | ||
|
||
test('should forceNow from URL', async () => { | ||
mockDateFromUrl = new Date('1999-01-01T00:00:00.000Z'); | ||
nowProvider = new NowProvider(); | ||
expect(nowProvider.get()).toEqual(mockDateFromUrl); | ||
}); | ||
|
||
test('should forceNow from URL if custom now is set', async () => { | ||
mockDateFromUrl = new Date('1999-01-01T00:00:00.000Z'); | ||
nowProvider = new NowProvider(); | ||
nowProvider.set(new Date()); | ||
expect(nowProvider.get()).toEqual(mockDateFromUrl); | ||
}); |
Oops, something went wrong.