-
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.
[Canvas] Use data views service (#139610)
* Use data views service in Canvas * Use getIndexPattern instead of title property * Fix ts errors * Remove console log statement
- Loading branch information
Showing
21 changed files
with
201 additions
and
168 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
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"bfetch", | ||
"charts", | ||
"data", | ||
"dataViews", | ||
"embeddable", | ||
"expressionError", | ||
"expressionImage", | ||
|
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
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/canvas/public/components/es_data_view_select/es_data_view_select.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,51 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { DataView } from '@kbn/data-views-plugin/common'; | ||
import { sortBy } from 'lodash'; | ||
import React, { FC, useRef, useState } from 'react'; | ||
import useEffectOnce from 'react-use/lib/useEffectOnce'; | ||
import { useDataViewsService } from '../../services'; | ||
import { | ||
ESDataViewSelect as Component, | ||
ESDataViewSelectProps as Props, | ||
} from './es_data_view_select.component'; | ||
|
||
type ESDataViewSelectProps = Omit<Props, 'indices' | 'loading'>; | ||
|
||
export const ESDataViewSelect: FC<ESDataViewSelectProps> = (props) => { | ||
const { value, onChange } = props; | ||
|
||
const [dataViews, setDataViews] = useState<Array<Pick<DataView, 'id' | 'name' | 'title'>>>([]); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
const mounted = useRef(true); | ||
const { getDataViews } = useDataViewsService(); | ||
|
||
useEffectOnce(() => { | ||
getDataViews().then((newDataViews) => { | ||
if (!mounted.current) { | ||
return; | ||
} | ||
|
||
if (!newDataViews) { | ||
newDataViews = []; | ||
} | ||
|
||
setLoading(false); | ||
setDataViews(sortBy(newDataViews, 'name')); | ||
if (!value && newDataViews.length) { | ||
onChange(newDataViews[0].title); | ||
} | ||
}); | ||
|
||
return () => { | ||
mounted.current = false; | ||
}; | ||
}); | ||
|
||
return <Component {...props} dataViews={dataViews} loading={loading} />; | ||
}; |
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
48 changes: 0 additions & 48 deletions
48
x-pack/plugins/canvas/public/components/es_index_select/es_index_select.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.