Skip to content

Custom no-results message support#286

Merged
Nikerabbit merged 3 commits intowikimedia:masterfrom
santhoshtr:no-results
Jan 12, 2018
Merged

Custom no-results message support#286
Nikerabbit merged 3 commits intowikimedia:masterfrom
santhoshtr:no-results

Conversation

@santhoshtr
Copy link
Copy Markdown
Member

  • Refactoring and clean up for LanguageCategoryDisplay class
  • Document the options for LanguageCategoryDisplay class
  • Reduce the spreading of no results handler code
  • Add an option to accept no results template
  • Remove unwanted, unused constructor too
  • Use CSS to hide or show the no-results view
  • Remove the unwanted noresults method in jquery.uls.core, directly
    call the same method of lcd.
  • Add an example

We might need some context also to the custom message such as the current query string. But we can revisit it when we really design some custom message for some use cases in mediawiki.

* Refactoring and clean up for LanguageCategoryDisplay class
* Document the options for LanguageCategoryDisplay class
* Reduce the spreading of no results handler code
* Add an option to accept no results template
* Remove unwanted, unused constructor too
* Use CSS to hide or show the no-results view
* Remove the unwanted noresults method in jquery.uls.core, directly
  call the same method of lcd.
* Add an example
Comment thread src/jquery.uls.lcd.js
this.$noResults.siblings( '.uls-lcd-region-section' ).addClass( 'hide' );
var $suggestions, $noResults;

// Only build the data once
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had no idea why this check was done. The quickList is cached anyway. Also this was causing the issue: When I search for something and get no results everything fine, then I do a search and get some result. Then search for some non-existing language-The no-results screen then won't have suggestions.

I just removed this check

Comment thread css/jquery.uls.lcd.css
display: none;
}

.uls-lcd.uls-no-results > .uls-lcd-region-section {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this needed? Shouldn't the layout of the no-results view be fully under control of the code generating it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did not like the hide class usage, I just removed it and added a marker class to the lcd as .uls-no-results - that take care of hiding and showing of regiions. We still use it for regions, but I would like to remove the usage of hide class altogether. It is just a wrapper around display:none

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing hide is good. I initially misread that this to mean we were hiding section headers in the no results template, but I see now this just hides everything else except the no results template.

Comment thread examples/test-no-results.html Outdated
<!-- demo -->
<link href="resources/demo.css" rel="stylesheet">
<!-- Libs -->
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Old jquery?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✔️

Comment thread examples/test-no-results.html Outdated
<script>
$( document ).ready( function() {
$( '.uls-trigger' ).uls( {
onSelect : function( language ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove extra space before colon.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✔️

Comment thread examples/test-no-results.html Outdated
var languageName = $.uls.data.getAutonym( language );
$( '.uls-trigger' ).text( languageName );
},
noResultsTemplate: '<div>No article exist in the language you searched</div>'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: exists

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✔️

noResultsTemplate: '<div>No article exist in the language you searched</div>'
} );
} );
</script>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This demo doesn't really illustrate the difference between "unknown language" and "no search results".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated the demo to use the current search query

Comment thread examples/test-no-results.html Outdated
Demonstration of jQuery plugin
</p>
</div>
<div class="container"></div>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unused?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✔️

Comment thread src/jquery.uls.lcd.js Outdated
* [ 'WW', 'AM', 'EU', 'ME', 'AF', 'AS', 'PA' ],
* @cfg {number} [itemsPerColumn] Number of languages per column.
* @cfg {number} [columns] Number of columns for languages. Default is 4.
* @cfg {function} [languageDecorator] Callback function to be called when a language
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Functions are objects too, right? Should be Function. (also below)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✔️

Comment thread src/jquery.uls.lcd.js Outdated
* @cfg {function} [languageDecorator] Callback function to be called when a language
* link is prepared - for custom decoration.
* @cfg {function|string[]} [quickList] The languages to display as suggestions for quick selectoin.
* @cfg {string|jQuery} [noResultsTemplate]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's not accept strings. It's a bad practice, as there isn't sufficient escaping. I predict we will need to accept functions here so that we can pass parameters (for example to differentiate between no matches or unknown language).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I improved the code to accept functions and passes the current search query as param

Comment thread src/jquery.uls.lcd.js Outdated
.i18n();
this.$noResults.find( 'h2' ).after( $suggestions );

$noResults.find( 'h2' ).after( $suggestions );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks very unreliable now that $noResults is completely out of our control.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I moved this to the default handler for no-results

Comment thread src/jquery.uls.lcd.js Outdated
return;
}
this.$element.addClass( 'uls-no-results' );
$noResults = this.$element.children( '.uls-no-results-view' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why children? why do we need DOM access at all?

Address code review comments from previous commit in this PR
Comment thread src/jquery.uls.lcd.js Outdated
return;
if ( typeof this.options.noResultsTemplate === 'function' ) {
$noResults =
this.options.noResultsTemplate.call( this, currentSearchQuery );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There seems to be one extra tab on ths line.

Comment thread src/jquery.uls.lcd.js Outdated
* @cfg {Function} [languageDecorator] Callback function to be called when a language
* link is prepared - for custom decoration.
* @cfg {Function|string[]} [quickList] The languages to display as suggestions for quick selectoin.
* @cfg {jQuery} [noResultsTemplate]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

{jQuery|Function}

@Nikerabbit Nikerabbit merged commit 2aa4314 into wikimedia:master Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants