-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Changes from 8 commits
1350425
7908c10
0dbb1f4
3cb64d2
cd1388f
c16ce24
a7b490e
79a5440
b532118
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
}; |
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); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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: { | ||
[key: string]: AddDataTab; | ||
} = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in b532118 |
||
|
||
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']>; |
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'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
"embeddable", | ||
"share", | ||
"discover", | ||
"fileUpload" | ||
"fileUpload", | ||
"home" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in b532118 |
||
], | ||
"optionalPlugins": [ | ||
"security", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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, useState, useEffect } from 'react'; | ||
|
||
export const FileDataVisualizerWrapper: FC = () => { | ||
const [FileDataVisualizerComponent, setFileDataVisualizerComponent] = useState<FC<{}> | null>( | ||
null | ||
); | ||
|
||
useEffect(() => { | ||
if (FileDataVisualizerComponent === null) { | ||
import('../application/file_datavisualizer').then(({ FileDataVisualizer }) => { | ||
setFileDataVisualizerComponent(FileDataVisualizer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, that is much nicer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in b532118 |
||
}); | ||
} | ||
}, [FileDataVisualizerComponent]); | ||
|
||
return <>{FileDataVisualizerComponent}</>; | ||
}; |
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, | ||
}); | ||
} |
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.
NIT:
if (tab?.content)
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.
Updated in b532118