-
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.
[ML] Add Create a data view button to index or saved search selector …
…in ML pages and Transforms management (#166668) Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
ede8d61
commit 007c341
Showing
13 changed files
with
152 additions
and
24 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
59 changes: 59 additions & 0 deletions
59
...gins/ml/public/application/components/create_data_view_button/create_data_view_button.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,59 @@ | ||
/* | ||
* 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 { EuiButton } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import React, { useCallback, useEffect, useRef } from 'react'; | ||
import { useMlKibana } from '../../contexts/kibana'; | ||
|
||
export const CreateDataViewButton = ({ | ||
onDataViewCreated, | ||
allowAdHocDataView = false, | ||
}: { | ||
onDataViewCreated: (id: string, type: string, name?: string) => void; | ||
allowAdHocDataView?: boolean; | ||
}) => { | ||
const { dataViewEditor } = useMlKibana().services; | ||
const canEditDataView = Boolean(dataViewEditor?.userPermissions.editDataView()); | ||
const closeDataViewEditorRef = useRef<() => void | undefined>(); | ||
|
||
const createNewDataView = useCallback(() => { | ||
closeDataViewEditorRef.current = dataViewEditor?.openEditor({ | ||
onSave: async (dataView) => { | ||
if (dataView.id && onDataViewCreated) { | ||
onDataViewCreated(dataView.id, 'index-pattern', dataView.name); | ||
} | ||
}, | ||
|
||
allowAdHocDataView, | ||
}); | ||
}, [onDataViewCreated, dataViewEditor, allowAdHocDataView]); | ||
|
||
useEffect(function cleanUpFlyout() { | ||
return () => { | ||
// Close the editor when unmounting | ||
if (closeDataViewEditorRef.current) { | ||
closeDataViewEditorRef.current(); | ||
} | ||
}; | ||
}, []); | ||
|
||
return canEditDataView ? ( | ||
<EuiButton | ||
onClick={createNewDataView} | ||
fill | ||
iconType="plusInCircle" | ||
data-test-subj="newDataViewButton" | ||
disabled={!canEditDataView} | ||
> | ||
<FormattedMessage | ||
id="xpack.ml.savedObjectFinder.createADataView" | ||
defaultMessage="Create a data view" | ||
/> | ||
</EuiButton> | ||
) : null; | ||
}; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/ml/public/application/components/create_data_view_button/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { CreateDataViewButton } from './create_data_view_button'; |
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
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