-
Notifications
You must be signed in to change notification settings - Fork 49
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
fixed plugin search issue under pagination section #268
Conversation
@jennydaman For the pagination offset it was showing 1 to -1, which is irrelevant, so I have just tried to replace it according to the |
Ah, thanks @somya51p, Please forgive my bad memory. I do remember this discussion, I'm not sure but I think I might've said somewhere that it'd be better to fix this at the level of the library I also see this line of code which should probably be used:
|
@jennydaman I get your point, in case of no result it should obviously show something like - and would this code be satisfactory for the above case? - |
I don't understand the context of your screenshot, would you generate a patch instead? To do so, you can run
Then paste the contents of changes.patch here. |
@jennydaman Please have a look! diff --git a/src/components/Plugins/Plugins.jsx b/src/components/Plugins/Plugins.jsx
index 1748db8..51047d2 100644
--- a/src/components/Plugins/Plugins.jsx
+++ b/src/components/Plugins/Plugins.jsx
@@ -416,11 +416,11 @@ export class Plugins extends Component {
<p style={{ fontSize: '1.25em', margin: '0', color: 'black', fontWeight: '600' }}>
{pluginsCount} plugins found
</p>
- Showing {paginationOffset + 1} to {' '}
+ Showing {Math.min(pluginsCount, paginationOffset + 1)} to {' '}
{
// eslint-disable-next-line no-nested-ternary
- (paginationOffset + paginationLimit > plugins.totalCount) ?
- plugins.totalCount
+ (paginationOffset + paginationLimit > pluginsCount) ?
+ pluginsCount
:
(paginationOffset > 0) ?
paginationOffset |
@somya51p thank you for the patch, it helped me understand. Showing {Math.min(pluginsCount, paginationOffset + 1)} to {' '} I don't think this would work if you were on the second or third page of plugins. What I meant was to move the logic outside of the return statement. As you see, there's a lint disabling comment diff --git a/src/components/Plugins/Plugins.jsx b/src/components/Plugins/Plugins.jsx
index ad318e6..f52850f 100644
--- a/src/components/Plugins/Plugins.jsx
+++ b/src/components/Plugins/Plugins.jsx
@@ -368,8 +368,11 @@ export class Plugins extends Component {
</div>
)
+ // workaround for library antipattern where, if a search returns no results,
+ // the literal `-1` is returned.
+ // https://github.com/FNNDSC/fnndsc/blob/c5db17c42aef5222faaff08affbeb418234c3af9/js/chrisStoreAPI/src/resource.js#L364
const pluginsCount=plugins.totalCount > 0 ? plugins.totalCount : 0;
-
+
return (
<article>
@@ -420,7 +423,7 @@ export class Plugins extends Component {
{
// eslint-disable-next-line no-nested-ternary
(paginationOffset + paginationLimit > plugins.totalCount) ?
- (plugins.totalCount === -1 ? 1 : plugins.totalCount)
+ (pluginsCount)
:
(paginationOffset > 0) ?
paginationOffset |
@jennydaman Please review, I have tested for the plugins it is working and added these outside the return statement for code quality improvement. For lint disabling comment
|
src/components/Plugins/Plugins.jsx
Outdated
: | ||
paginationLimit | ||
} | ||
Showing {Math.min(pluginsCount, paginationOffset + 1)} to {pluginsLast} |
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.
The only situation where pluginCount < paginationOffset + 1
would be where pluginCount == 0
, in which case, it might be better to instead conditionally render something like "No plugins shown" or just omit this text instead. If we can get rid of this Math.min
call, the what and why of this line of code would be more apparent by a quick glance.
@jennydaman I have tried to implement the logic which you have suggested. Please have a look into it and suggest changes if any. |
We should fix this in the upstream client library FNNDSC/fnndsc#76 |
@jennydaman Please review the PR and suggest changes if any. It resolved issue #246 from my end.