-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Home] Adding file upload to add data page * updating comment * tiny refactor * attempting to reduce bundle size * reverting to original home register import * lazy load tab contents * changes based on review Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: James Gowdy <[email protected]>
- Loading branch information
1 parent
e42fa7a
commit 0d855a1
Showing
15 changed files
with
217 additions
and
8 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
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, | ||
}); | ||
} |