-
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.
De-angularize discover doc_table pager (#40999)
* Convert pager buttons to react * Convert pager text to react * Move pager factory to lib folder * Adapt directives to use react component * Add jest tests
- Loading branch information
Showing
15 changed files
with
193 additions
and
118 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...ic/discover/doc_table/components/pager/__snapshots__/tool_bar_pager_buttons.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...ublic/discover/doc_table/components/pager/__snapshots__/tool_bar_pager_text.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
...plugins/kibana/public/discover/doc_table/components/pager/tool_bar_pager_buttons.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,63 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { ToolBarPagerButtons } from './tool_bar_pager_buttons'; | ||
// @ts-ignore | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
|
||
test('it renders ToolBarPagerButtons', () => { | ||
const props = { | ||
hasPreviousPage: true, | ||
hasNextPage: true, | ||
onPageNext: jest.fn(), | ||
onPagePrevious: jest.fn(), | ||
}; | ||
const wrapper = shallowWithIntl(<ToolBarPagerButtons {...props} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('it renders ToolBarPagerButtons with clickable next and previous button', () => { | ||
const props = { | ||
hasPreviousPage: true, | ||
hasNextPage: true, | ||
onPageNext: jest.fn(), | ||
onPagePrevious: jest.fn(), | ||
}; | ||
const wrapper = mountWithIntl(<ToolBarPagerButtons {...props} />); | ||
findTestSubject(wrapper, 'btnPrevPage').simulate('click'); | ||
expect(props.onPagePrevious).toHaveBeenCalledTimes(1); | ||
findTestSubject(wrapper, 'btnNextPage').simulate('click'); | ||
expect(props.onPageNext).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('it renders ToolBarPagerButtons with disabled next and previous button', () => { | ||
const props = { | ||
hasPreviousPage: false, | ||
hasNextPage: false, | ||
onPageNext: jest.fn(), | ||
onPagePrevious: jest.fn(), | ||
}; | ||
const wrapper = mountWithIntl(<ToolBarPagerButtons {...props} />); | ||
findTestSubject(wrapper, 'btnPrevPage').simulate('click'); | ||
expect(props.onPagePrevious).toHaveBeenCalledTimes(0); | ||
findTestSubject(wrapper, 'btnNextPage').simulate('click'); | ||
expect(props.onPageNext).toHaveBeenCalledTimes(0); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...core_plugins/kibana/public/discover/doc_table/components/pager/tool_bar_pager_buttons.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 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
|
||
interface Props { | ||
hasPreviousPage: boolean; | ||
hasNextPage: boolean; | ||
onPageNext: () => void; | ||
onPagePrevious: () => void; | ||
} | ||
|
||
export function ToolBarPagerButtons(props: Props) { | ||
return ( | ||
<div className="kuiButtonGroup"> | ||
<button | ||
className="kuiButton kuiButton--basic kuiButton--icon" | ||
onClick={() => props.onPagePrevious()} | ||
disabled={!props.hasPreviousPage} | ||
data-test-subj="btnPrevPage" | ||
> | ||
<span className="kuiButton__icon kuiIcon fa-chevron-left"></span> | ||
</button> | ||
<button | ||
className="kuiButton kuiButton--basic kuiButton--icon" | ||
onClick={() => props.onPageNext()} | ||
disabled={!props.hasNextPage} | ||
data-test-subj="btnNextPage" | ||
> | ||
<span className="kuiButton__icon kuiIcon fa-chevron-right"></span> | ||
</button> | ||
</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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions
18
...ver/doc_table/pager_control/components/tool_bar_pager_buttons/tool_bar_pager_buttons.html
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
...cover/doc_table/pager_control/components/tool_bar_pager_buttons/tool_bar_pager_buttons.js
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
...ns/kibana/public/discover/doc_table/pager_control/components/tool_bar_pager_text/index.js
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
.../discover/doc_table/pager_control/components/tool_bar_pager_text/tool_bar_pager_text.html
This file was deleted.
Oops, something went wrong.