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

fixed plugin search issue under pagination section #268

Closed
wants to merge 1 commit into from

Conversation

somya51p
Copy link
Contributor

@somya51p somya51p commented Apr 5, 2022

@jennydaman Please review the PR and suggest changes if any. It resolved issue #246 from my end.

Screenshot from 2022-04-05 13-10-47

@jennydaman
Copy link
Collaborator

Hey @somya51p sorry for not noticing your comment on issue #246.

Could you explain to me why this bug is happening? Your fix seems like a band-aid solution.

@somya51p
Copy link
Contributor Author

somya51p commented Apr 6, 2022

Hey @somya51p sorry for not noticing your comment on issue #246.

Could you explain to me why this bug is happening? Your fix seems like a band-aid solution.

@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 plugins.totalCount as totalCount = -1 is coming from the backend side as discussed in issue #246 earlier.

@jennydaman
Copy link
Collaborator

jennydaman commented Apr 7, 2022

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 @fnndsc/chrisstoreapi? Or perhaps at a higher level, with an explanation? Ideally we would like to separate application logic from display logic.

I also see this line of code which should probably be used:

const pluginsCount=plugins.totalCount > 0 ? plugins.totalCount : 0;

@somya51p
Copy link
Contributor Author

somya51p commented Apr 7, 2022

@jennydaman I get your point, in case of no result it should obviously show something like -
Screenshot from 2022-04-07 17-48-50

and would this code be satisfactory for the above case? -

Screenshot from 2022-04-07 17-52-47

@jennydaman
Copy link
Collaborator

I don't understand the context of your screenshot, would you generate a patch instead? To do so, you can run

git diff > changes.patch

Then paste the contents of changes.patch here.

@somya51p
Copy link
Contributor Author

somya51p commented Apr 9, 2022

I don't understand the context of your screenshot, would you generate a patch instead? To do so, you can run

git diff > changes.patch

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

Screenshot from 2022-04-09 15-37-54

@jennydaman
Copy link
Collaborator

@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 // eslint-disable-next-line no-nested-ternary, indicating that a messy code pattern was used. I think the code quality could be improved by moving these outside the return statement and adding comments for why its necessary,

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

@somya51p
Copy link
Contributor Author

@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 // eslint-disable-next-line no-nested-ternary
we can implement that way, but I don't think it's as good a way.

// no-nested-ternary rule disallows nested ternary expressions
    const pluginsLast=(paginationOffset + paginationLimit > pluginsCount) ?
    pluginsCount : paginationLimit;
    if (paginationOffset + paginationLimit > pluginsCount)
          pluginsLast = pluginsCount;
    else if (paginationOffset > 0)
          pluginsLast = paginationOffset;
    else
          pluginsLast = paginationLimit;
    

:
paginationLimit
}
Showing {Math.min(pluginsCount, paginationOffset + 1)} to {pluginsLast}
Copy link
Collaborator

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.

src/components/Plugins/Plugins.jsx Outdated Show resolved Hide resolved
@somya51p
Copy link
Contributor Author

@jennydaman I have tried to implement the logic which you have suggested. Please have a look into it and suggest changes if any.
Screenshot from 2022-04-30 20-32-25
Screenshot from 2022-04-30 20-34-13

@jennydaman
Copy link
Collaborator

We should fix this in the upstream client library FNNDSC/fnndsc#76

@jennydaman jennydaman closed this Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants