Skip to content
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

Rewrite plugin Search to es6. #4892

Merged
merged 19 commits into from Apr 4, 2018
Merged

Rewrite plugin Search to es6. #4892

merged 19 commits into from Apr 4, 2018

Conversation

pnowak
Copy link
Contributor

@pnowak pnowak commented Mar 2, 2018

Context

Search is now based on BasePlugin.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature or improvement (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issue(s):

  1. Rewrite plugin Search on es6. #4629

Checklist:

  • My code follows the code style of this project,
  • My change requires a change to the documentation.

@pnowak pnowak requested a review from wszymanski March 2, 2018 13:59
@wszymanski wszymanski removed their request for review March 6, 2018 09:49
@pnowak pnowak requested a review from wszymanski March 23, 2018 10:58
@wszymanski wszymanski assigned pnowak and unassigned wszymanski Mar 27, 2018
@pnowak pnowak assigned wszymanski and unassigned pnowak Mar 28, 2018
disablePlugin() {
this.hot.addHook('beforeRenderer', (TD, row, col, prop, value, cellProperties) => this.onBeforeRenderer(TD, row, col, prop, value, cellProperties));
this.hot.addHookOnce('afterRender', () => {
this.hot.removeHook('beforeRender', (TD, row, col, prop, value, cellProperties) => this.onBeforeRenderer(TD, row, col, prop, value, cellProperties));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a reference to the proper function.

function init() {
var instance = this;
if (this.isEnabled() && cellProperties.isSearchResult) {
if (!cellProperties.className.includes(this.searchResultClass)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done within util. Property className can be also an array.

const searchSettings = this.hot.getSettings().search;
this.checkPluginSettings(searchSettings);

this.addHook('beforeRenderer', (TD, row, col, prop, value, cellProperties) => this.onBeforeRenderer(TD, row, col, prop, value, cellProperties));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rest parameters would look more clear? Please apply that also to rest of places where hooks are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}
let cell = hot.getCell(0, 0);
expect($(cell).hasClass(hot.getPlugin('search').searchResultClass)).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please simplify this calls here and in next tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

for (var rowIndex = 0, rowCount = countRows(); rowIndex < rowCount; rowIndex++) {
for (var colIndex = 0, colCount = countCols(); colIndex < colCount; colIndex++) {
var callArgs = searchCallback.calls.argsFor((rowIndex * 5) + colIndex);
for (let rowIndex = 0, rowCount = countRows(); rowIndex < rowCount; rowIndex += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test it without looping.

function SearchCellDecorator(instance, TD, row, col, prop, value, cellProperties) {
var searchResultClass = (cellProperties.search !== null && typeof cellProperties.search == 'object' &&
cellProperties.search.searchResultClass) || Search.global.getDefaultSearchResultClass();
if (cellProperties.className) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests. Please cache the cellProperties.className.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

disablePlugin() {
const beforeRendererCallback = (TD, row, col, prop, value, cellProperties) => this.onBeforeRenderer(TD, row, col, prop, value, cellProperties);

this.hot.addHook('beforeRenderer', beforeRendererCallback);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests.

*/
this.queryMethod = DEFAULT_QUERY_METHOD;
/**
* Class added to each cell that belongs to the search.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good direction 👍 Maybe change it yet to: Class added to each cell that belongs to the searched query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

constructor(hotInstance) {
super(hotInstance);
/**
* Callback function is responsible for marking the cells belonging to the search by setting property to it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe the property, not the value.

* Query method - used inside search input listener.
*
* @param {String} queryStr Searched value.
* @param {Function} [callback=DEFAULT_CALLBACK] Callback function responsible for setting the cell's `isSearchResult` property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change from [callback=DEFAULT_CALLBACK] to [callback]. Apply the same rule below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@wszymanski wszymanski assigned pnowak and unassigned wszymanski Mar 28, 2018
@mrpiotr-dev mrpiotr-dev assigned mrpiotr-dev and unassigned pnowak Apr 3, 2018
@mrpiotr-dev mrpiotr-dev added this to the April 2018 milestone Apr 3, 2018
@mrpiotr-dev mrpiotr-dev assigned wszymanski and unassigned mrpiotr-dev Apr 3, 2018
@wszymanski wszymanski assigned mrpiotr-dev and unassigned wszymanski Apr 4, 2018
@wszymanski wszymanski assigned wszymanski and pnowak and unassigned mrpiotr-dev and wszymanski Apr 4, 2018
@wszymanski wszymanski merged commit 964c091 into develop Apr 4, 2018
mohammed90 pushed a commit to mohammed90/handsontable that referenced this pull request Apr 28, 2018
* Rewrite the search plugin to ES6 handsontable#4629

* Problem: default that were not default. Solution: method rename, use helpers and afterInit hook instead of beforeRenderer handsontable#4629

* After CR - rename searchResultClass to elementClass, use helper function isUndefined, cost  handsontable#4629

* Rest parametrs replace arguments handsontable#4629

* After CR - Default parameter and more descritions handsontable#4629

* Fix demo page handsontable#4629

* const and cell(td) not element handsontable#4629

* searchResultClass come back handsontable#4629

* searchResultClass come back in test too handsontable#4629

* improvement of comments handsontable#4629

* After CR: new method, settings descriptive, improve test handsontable#4629

* beforeRenederer hook replace extension base renderer handsontable#4629

* Improve hooks after disablePlugin plus write test handsontable#4629

* After CR: beforeRenderer instance, className can also be Array and more readable tests handsontable#4629

* After CR - more test and tiny fixes handsontable#4629

* Changed: variables descriptions. Added: test for onBeforeRenderer. handsontable#4629

* Changed: simple comparision instead of loops. handsontable#4629

* onBeforeRenderer adjustments. handsontable#4629
@wojciechczerniak wojciechczerniak deleted the feature/issue-4629 branch October 17, 2018 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants