-
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
1 parent
ef007f7
commit 8b8d494
Showing
8 changed files
with
122 additions
and
31 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
30 changes: 30 additions & 0 deletions
30
...scover/public/application/components/common/__snapshots__/loading_indicator.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/plugins/discover/public/application/components/common/loading_indicator.test.tsx
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,17 @@ | ||
/* | ||
* 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 { LoadingIndicator } from './loading_indicator'; | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
describe('Loading indicator', () => { | ||
it('renders correctly', () => { | ||
const component = mount(<LoadingIndicator />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
src/plugins/discover/public/application/components/common/loading_indicator.tsx
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,19 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui'; | ||
import React from 'react'; | ||
|
||
export const LoadingIndicator = () => { | ||
return ( | ||
<EuiFlexGroup justifyContent="spaceAround" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLoadingSpinner size="l" /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/plugins/discover/public/application/helpers/use_index_pattern.test.tsx
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,19 @@ | ||
/* | ||
* 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 { useIndexPattern } from './use_index_pattern'; | ||
import { indexPatternMock } from '../../__mocks__/index_pattern'; | ||
import { indexPatternsMock } from '../../__mocks__/index_patterns'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
describe('Use Index Pattern', () => { | ||
test('returning a valid index pattern', async () => { | ||
const { result } = renderHook(() => useIndexPattern(indexPatternsMock, 'the-index-pattern-id')); | ||
await act(() => Promise.resolve()); | ||
expect(result.current).toBe(indexPatternMock); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/plugins/discover/public/application/helpers/use_index_pattern.tsx
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,22 @@ | ||
/* | ||
* 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 { useEffect, useState } from 'react'; | ||
import { IndexPattern, IndexPatternsContract } from '../../../../data/common'; | ||
|
||
export const useIndexPattern = (indexPatterns: IndexPatternsContract, indexPatternId: string) => { | ||
const [indexPattern, setIndexPattern] = useState<IndexPattern | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
async function loadIndexPattern() { | ||
const ip = await indexPatterns.get(indexPatternId); | ||
setIndexPattern(ip); | ||
} | ||
loadIndexPattern(); | ||
}); | ||
return indexPattern; | ||
}; |