-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Home] Adding file upload to add data page #100863
Merged
jgowdyelastic
merged 9 commits into
elastic:master
from
jgowdyelastic:adding-file-upload-tab-to-home-add-data-page
Jun 2, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1350425
[Home] Adding file upload to add data page
jgowdyelastic 7908c10
updating comment
jgowdyelastic 0dbb1f4
tiny refactor
jgowdyelastic 3cb64d2
attempting to reduce bundle size
jgowdyelastic cd1388f
Merge branch 'master' into adding-file-upload-tab-to-home-add-data-page
kibanamachine c16ce24
Merge branch 'master' into adding-file-upload-tab-to-home-add-data-page
kibanamachine a7b490e
reverting to original home register import
jgowdyelastic 79a5440
lazy load tab contents
jgowdyelastic b532118
changes based on review
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 31 additions & 0 deletions
31
src/plugins/home/public/services/add_data/add_data_service.mock.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,31 @@ | ||
/* | ||
* 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 { PublicMethodsOf } from '@kbn/utility-types'; | ||
import { AddDataService, AddDataServiceSetup } from './add_data_service'; | ||
|
||
const createSetupMock = (): jest.Mocked<AddDataServiceSetup> => { | ||
const setup = { | ||
registerAddDataTab: jest.fn(), | ||
}; | ||
return setup; | ||
}; | ||
|
||
const createMock = (): jest.Mocked<PublicMethodsOf<AddDataService>> => { | ||
const service = { | ||
setup: jest.fn(), | ||
getAddDataTabs: jest.fn(() => []), | ||
}; | ||
service.setup.mockImplementation(createSetupMock); | ||
return service; | ||
}; | ||
|
||
export const addDataServiceMock = { | ||
createSetup: createSetupMock, | ||
create: createMock, | ||
}; |
49 changes: 49 additions & 0 deletions
49
src/plugins/home/public/services/add_data/add_data_service.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,49 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { AddDataService } from './add_data_service'; | ||
|
||
describe('AddDataService', () => { | ||
describe('setup', () => { | ||
test('allows multiple register directory header link calls', () => { | ||
const setup = new AddDataService().setup(); | ||
expect(() => { | ||
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>123</a> }); | ||
setup.registerAddDataTab({ id: 'def', name: 'a b c', component: () => <a>456</a> }); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('throws when same directory header link is registered twice', () => { | ||
const setup = new AddDataService().setup(); | ||
expect(() => { | ||
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>123</a> }); | ||
setup.registerAddDataTab({ id: 'abc', name: 'a b c', component: () => <a>456</a> }); | ||
}).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('getDirectoryHeaderLinks', () => { | ||
test('returns empty array', () => { | ||
const service = new AddDataService(); | ||
expect(service.getAddDataTabs()).toEqual([]); | ||
}); | ||
|
||
test('returns last state of register calls', () => { | ||
const service = new AddDataService(); | ||
const setup = service.setup(); | ||
const links = [ | ||
{ id: 'abc', name: 'a b c', component: () => <a>123</a> }, | ||
{ id: 'def', name: 'a b c', component: () => <a>456</a> }, | ||
]; | ||
setup.registerAddDataTab(links[0]); | ||
setup.registerAddDataTab(links[1]); | ||
expect(service.getAddDataTabs()).toEqual(links); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
src/plugins/home/public/services/add_data/add_data_service.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,40 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
/** @public */ | ||
export interface AddDataTab { | ||
id: string; | ||
name: string; | ||
component: React.FC; | ||
} | ||
|
||
export class AddDataService { | ||
private addDataTabs: Record<string, AddDataTab> = {}; | ||
|
||
public setup() { | ||
return { | ||
/** | ||
* Registers a component that will be rendered as a new tab in the Add data page | ||
*/ | ||
registerAddDataTab: (tab: AddDataTab) => { | ||
if (this.addDataTabs[tab.id]) { | ||
throw new Error(`Tab ${tab.id} already exists`); | ||
} | ||
this.addDataTabs[tab.id] = tab; | ||
}, | ||
}; | ||
} | ||
|
||
public getAddDataTabs() { | ||
return Object.values(this.addDataTabs); | ||
} | ||
} | ||
|
||
export type AddDataServiceSetup = ReturnType<AddDataService['setup']>; |
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 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { AddDataService } from './add_data_service'; | ||
|
||
export type { AddDataServiceSetup, AddDataTab } from './add_data_service'; |
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,7 +14,8 @@ | |
], | ||
"optionalPlugins": [ | ||
"security", | ||
"maps" | ||
"maps", | ||
"home" | ||
], | ||
"requiredBundles": [ | ||
"kibanaReact", | ||
|
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
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/file_data_visualizer/public/lazy_load_bundle/component_wrapper.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,18 @@ | ||
/* | ||
* 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 React, { FC } from 'react'; | ||
|
||
const FileDataVisualizerComponent = React.lazy(() => import('../application/file_datavisualizer')); | ||
|
||
export const FileDataVisualizerWrapper: FC = () => { | ||
return ( | ||
<React.Suspense fallback={<div />}> | ||
<FileDataVisualizerComponent /> | ||
</React.Suspense> | ||
); | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/file_data_visualizer/public/register_home.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,20 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import type { HomePublicPluginSetup } from '../../../../src/plugins/home/public'; | ||
import { FileDataVisualizerWrapper } from './lazy_load_bundle/component_wrapper'; | ||
|
||
export function registerHomeAddData(home: HomePublicPluginSetup) { | ||
home.addData.registerAddDataTab({ | ||
id: 'fileDataViz', | ||
name: i18n.translate('xpack.fileDataVisualizer.embeddedTabTitle', { | ||
defaultMessage: 'Upload file', | ||
}), | ||
component: FileDataVisualizerWrapper, | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a permission check here to only register the file upload tab if the user has the minimum permissions needed to analyze a file?
Would this be a good time to remove
access:fileUpload:analyzeFile
andaccess:fileUpload:import
tags from file upload routes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a good time to decouple file data visualizer permissions from ML so that users can upload a file and not have kibana access to ml or any ml user roles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ML has run in to race condition issues before when registering links in home and the management app where, due to the time it takes to check the license and in this case maybe the capabilities, the registration happens too late for the links to actually appear.
I'll take a look to see if this is possible, but we might just have to always register and perform the capabilities check later when the user navigates to the "Upload file" tab.
I might have missed something, why would we want to remove the capabilities checks from the routes?