-
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.
Browse files
Browse the repository at this point in the history
* refactor: 💡 use .story for Storybook and standartize dir struct * feat: 🎸 add <FlyoutFrame> component * feat: 🎸 add <FlyoutCreateDrilldown> component * refactor: 💡 improve FlyoutCreateDrilldownAction * test: 💍 add <FlyoutFrame> tests * docs: ✏️ add @todo for <DrilldownHelloBar> * feat: 🎸 make name editable in <FormCreateDrilldown> * test: 💍 add <FormCreateDrilldown> name field tests * chore: 🤖 change drilldown translation keys
- Loading branch information
Showing
24 changed files
with
528 additions
and
86 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
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/drilldowns/public/components/drilldown_hello_bar/drilldown_hello_bar.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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
export interface DrilldownHelloBarProps { | ||
docsLink?: string; | ||
} | ||
|
||
/** | ||
* @todo https://github.com/elastic/kibana/issues/55311 | ||
*/ | ||
export const DrilldownHelloBar: React.FC<DrilldownHelloBarProps> = ({ docsLink }) => { | ||
return ( | ||
<div> | ||
<p> | ||
Drilldowns provide the ability to define a new behavior when interacting with a panel. You | ||
can add multiple options or simply override the default filtering behavior. | ||
</p> | ||
<a href={docsLink}>View docs</a> | ||
</div> | ||
); | ||
}; |
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
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/drilldowns/public/components/drilldown_picker/drilldown_picker.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,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
// eslint-disable-next-line | ||
export interface DrilldownPickerProps {} | ||
|
||
export const DrilldownPicker: React.FC<DrilldownPickerProps> = () => { | ||
return ( | ||
<img | ||
src={ | ||
'https://user-images.githubusercontent.com/9773803/72725665-9e8e3e00-3b86-11ea-9314-8724c521b41f.png' | ||
} | ||
alt="" | ||
/> | ||
); | ||
}; |
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
24 changes: 24 additions & 0 deletions
24
...ns/drilldowns/public/components/flyout_create_drilldown/flyout_create_drilldown.story.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,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import * as React from 'react'; | ||
import { EuiFlyout } from '@elastic/eui'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { FlyoutCreateDrilldown } from '.'; | ||
|
||
storiesOf('components/FlyoutCreateDrilldown', module) | ||
.add('default', () => { | ||
return <FlyoutCreateDrilldown context={{} as any} />; | ||
}) | ||
.add('open in flyout', () => { | ||
return ( | ||
<EuiFlyout> | ||
<FlyoutCreateDrilldown context={{} as any} /> | ||
</EuiFlyout> | ||
); | ||
}); |
34 changes: 34 additions & 0 deletions
34
.../plugins/drilldowns/public/components/flyout_create_drilldown/flyout_create_drilldown.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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { FormCreateDrilldown } from '../form_create_drilldown'; | ||
import { FlyoutFrame } from '../flyout_frame'; | ||
import { txtCreateDrilldown } from './i18n'; | ||
import { FlyoutCreateDrilldownActionContext } from '../../actions'; | ||
|
||
export interface FlyoutCreateDrilldownProps { | ||
context: FlyoutCreateDrilldownActionContext; | ||
onClose?: () => void; | ||
} | ||
|
||
export const FlyoutCreateDrilldown: React.FC<FlyoutCreateDrilldownProps> = ({ | ||
context, | ||
onClose, | ||
}) => { | ||
const footer = ( | ||
<EuiButton onClick={() => {}} fill> | ||
{txtCreateDrilldown} | ||
</EuiButton> | ||
); | ||
|
||
return ( | ||
<FlyoutFrame title={txtCreateDrilldown} footer={footer} onClose={onClose}> | ||
<FormCreateDrilldown /> | ||
</FlyoutFrame> | ||
); | ||
}; |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/drilldowns/public/components/flyout_create_drilldown/i18n.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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const txtCreateDrilldown = i18n.translate( | ||
'xpack.drilldowns.components.FlyoutCreateDrilldown.CreateDrilldown', | ||
{ | ||
defaultMessage: 'Create drilldown', | ||
} | ||
); |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/drilldowns/public/components/flyout_create_drilldown/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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './flyout_create_drilldown'; |
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/drilldowns/public/components/flyout_frame/flyout_frame.story.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,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import * as React from 'react'; | ||
import { EuiFlyout, EuiButton } from '@elastic/eui'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { FlyoutFrame } from '.'; | ||
|
||
storiesOf('components/FlyoutFrame', module) | ||
.add('default', () => { | ||
return <FlyoutFrame>test</FlyoutFrame>; | ||
}) | ||
.add('with title', () => { | ||
return <FlyoutFrame title="Hello world">test</FlyoutFrame>; | ||
}) | ||
.add('with onClose', () => { | ||
return <FlyoutFrame onClose={() => console.log('onClose')}>test</FlyoutFrame>; | ||
}) | ||
.add('custom footer', () => { | ||
return <FlyoutFrame footer={<button>click me!</button>}>test</FlyoutFrame>; | ||
}) | ||
.add('open in flyout', () => { | ||
return ( | ||
<EuiFlyout> | ||
<FlyoutFrame | ||
title="Create drilldown" | ||
footer={<EuiButton>Save</EuiButton>} | ||
onClose={() => console.log('onClose')} | ||
> | ||
test | ||
</FlyoutFrame> | ||
</EuiFlyout> | ||
); | ||
}); |
102 changes: 102 additions & 0 deletions
102
x-pack/plugins/drilldowns/public/components/flyout_frame/flyout_frame.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,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { render as renderTestingLibrary, fireEvent } from '@testing-library/react'; | ||
import { FlyoutFrame } from '.'; | ||
|
||
describe('<FlyoutFrame>', () => { | ||
test('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
render(<FlyoutFrame />, div); | ||
}); | ||
|
||
describe('[title=]', () => { | ||
test('renders title in <h1> tag', () => { | ||
const div = document.createElement('div'); | ||
render(<FlyoutFrame title={'foobar'} />, div); | ||
|
||
const title = div.querySelector('h1'); | ||
expect(title?.textContent).toBe('foobar'); | ||
}); | ||
|
||
test('title can be any react node', () => { | ||
const div = document.createElement('div'); | ||
render( | ||
<FlyoutFrame | ||
title={ | ||
<> | ||
foo <strong>bar</strong> | ||
</> | ||
} | ||
/>, | ||
div | ||
); | ||
|
||
const title = div.querySelector('h1'); | ||
expect(title?.innerHTML).toBe('foo <strong>bar</strong>'); | ||
}); | ||
}); | ||
|
||
describe('[footer=]', () => { | ||
test('if [footer=] prop not provided, does not render footer', () => { | ||
const div = document.createElement('div'); | ||
render(<FlyoutFrame />, div); | ||
|
||
const footer = div.querySelector('[data-test-subj="flyoutFooter"]'); | ||
expect(footer).toBe(null); | ||
}); | ||
|
||
test('can render anything in footer', () => { | ||
const div = document.createElement('div'); | ||
render( | ||
<FlyoutFrame | ||
footer={ | ||
<> | ||
a <em>b</em> | ||
</> | ||
} | ||
/>, | ||
div | ||
); | ||
|
||
const footer = div.querySelector('[data-test-subj="flyoutFooter"]'); | ||
expect(footer?.innerHTML).toBe('a <em>b</em>'); | ||
}); | ||
}); | ||
|
||
describe('[onClose=]', () => { | ||
test('does not render close button if "onClose" prop is missing', () => { | ||
const div = document.createElement('div'); | ||
render(<FlyoutFrame />, div); | ||
|
||
const closeButton = div.querySelector('[data-test-subj="flyoutCloseButton"]'); | ||
expect(closeButton).toBe(null); | ||
}); | ||
|
||
test('renders close button if "onClose" prop is provided', () => { | ||
const div = document.createElement('div'); | ||
render(<FlyoutFrame onClose={() => {}} />, div); | ||
|
||
const closeButton = div.querySelector('[data-test-subj="flyoutCloseButton"]'); | ||
expect(closeButton).not.toBe(null); | ||
}); | ||
|
||
test('calls onClose prop when close button clicked', async () => { | ||
const onClose = jest.fn(); | ||
const el = renderTestingLibrary(<FlyoutFrame onClose={onClose} />); | ||
|
||
const closeButton = el.queryByText('Close'); | ||
|
||
expect(onClose).toHaveBeenCalledTimes(0); | ||
|
||
fireEvent.click(closeButton!); | ||
|
||
expect(onClose).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.