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
Conversation
…re readable tests #4629
src/plugins/search/search.js
Outdated
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)); |
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.
There should be a reference to the proper function.
src/plugins/search/search.js
Outdated
function init() { | ||
var instance = this; | ||
if (this.isEnabled() && cellProperties.isSearchResult) { | ||
if (!cellProperties.className.includes(this.searchResultClass)) { |
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.
It could be done within util
. Property className
can be also an array.
src/plugins/search/search.js
Outdated
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)); |
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.
Maybe rest parameters would look more clear? Please apply that also to rest of places where hooks are added.
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.
Done.
} | ||
} | ||
let cell = hot.getCell(0, 0); | ||
expect($(cell).hasClass(hot.getPlugin('search').searchResultClass)).toBe(false); |
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.
Please simplify this calls here and in next tests.
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.
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) { |
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.
Please test it without looping.
src/plugins/search/search.js
Outdated
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) { |
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.
Please add tests. Please cache the cellProperties.className
.
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.
Done.
src/plugins/search/search.js
Outdated
disablePlugin() { | ||
const beforeRendererCallback = (TD, row, col, prop, value, cellProperties) => this.onBeforeRenderer(TD, row, col, prop, value, cellProperties); | ||
|
||
this.hot.addHook('beforeRenderer', beforeRendererCallback); |
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.
Please add tests.
src/plugins/search/search.js
Outdated
*/ | ||
this.queryMethod = DEFAULT_QUERY_METHOD; | ||
/** | ||
* Class added to each cell that belongs to the search. |
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.
Good direction 👍 Maybe change it yet to: Class added to each cell that belongs to the searched query.
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.
Done.
src/plugins/search/search.js
Outdated
constructor(hotInstance) { | ||
super(hotInstance); | ||
/** | ||
* Callback function is responsible for marking the cells belonging to the search by setting property to it. |
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.
Please describe the property, not the value.
src/plugins/search/search.js
Outdated
* 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. |
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.
Please change from [callback=DEFAULT_CALLBACK]
to [callback]
. Apply the same rule below.
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.
Done.
* 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
Context
Search is now based on BasePlugin.
Types of changes
Related issue(s):
Checklist: