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

433-365 : dropdown on navbar and profile #963

Merged
merged 5 commits into from
Dec 10, 2021

Conversation

vurtn
Copy link
Contributor

@vurtn vurtn commented May 20, 2021

Sorry for my english.

Why

The main issue i tried to solve (#433) is about adding a dropdown in the right part of the navbar. I added a link to edit the profile of the current user (#365).

What

  • Add a dropdown menu in the navbar
  • Create some items in it
  • Change the z-index of the navbar
  • Add a new component DeleteLink
  • Change the FeedbackButton
  • Change some things in NavBar.spec.js
  • Add a test in user_spec.rb

How

I added the dropdown in the navbar with Buefy and had to make some changes.

First was the buttons/button style in the navbar. I added a parameter to FeedbackButton because it is already a link and the value by default is the button style (it's keeping the current style by default to not break some code elsewhere (and it's name is Button so... 😄 ). The button to disconnect the user is a real button so i created another component to have the same behavior but with a link.

I used the Logout condition to show the dropdown in the navbar and added a z-index on the navbar because some components are above sometimes. It's visible on small screens like on this gif :
nav-zindex
The burger on the page is above the navbar.

In the dropdown menu there is a link to edit our profile :
nav-profile

Testing

Some test failed due to the new structure of the navbar in NavBar.spec.js. The main issue was this part :

const navLinks = $wrapper.findAll('a.navbar-item').wrappers
const navButtons = $wrapper.findAll('.navbar-item a').wrappers
const navForms = $wrapper.findAll('.navbar-item form').wrappers
return [...navLinks, ...navButtons, ...navForms].map(link => link.text())

The dropdown div is a navbar-item, so the links inside it match a.navbar-item and .navbar-item a selectors. The return is an array and not a set so i had duplicates and the test failed. I changed the lines above to :

const navLinks = $wrapper.findAll('a:not(.burger)').wrappers
return [...navLinks].map((link) => link.text())

I kept the spread operator because if we need to select something else, we will just add the new catches to this array like before. The navbar contains only links now so the only duplicate i had was the root page because of the burger link for the small screens. I excluded it of the query selector. I added the new links to the test of admin buttons.

I added a test in user_spec.rb to verify that the user is redirected to the sign in page if he is not logged in while trying to access the profile page.

Next Steps

Unknown. Maybe create some tests with a context like "with the right credentials" (and its complementary of course) to check the access to resources.

Outstanding Questions, Concerns and Other Notes

Webpack throwing this error sometimes when i'm testing and i still don't understand why :

ActionView::Template::Error:
       Webpacker can't find application.css in /my-path/mutual-aid/public/packs-test/manifest.json.   

Accessibility

Not seem to be concerned now.

Security

Not seem to be concerned (now ?).

Meta

I didn't search why but i created a new account in the app and have the volonteer profile. The FeedbackButton is shown in the navbar but when i click on it i have this message :

Sorry, you aren't authorized to do that.
If you think this is wrong, please contact your administrator.

I think something is wrong 😄 The FeedbackButton have the v-if="visible('Feedback')" condition and the item is shown but i am not authorized to access it.

Pre-Merge Checklist

I think the reviewer will check this so i let it empty.

  • Security & accessibility have been considered
  • Tests have been added, or an explanation has been given why the features cannot be tested
  • Documentation and comments have been added to the codebase where required
  • Entry added to CHANGELOG.md if appropriate
  • Outstanding questions and concerns have been resolved
  • Any next steps have been turned into Issues or Discussions as appropriate

Best regards and stay safe !

@solebared solebared mentioned this pull request Oct 15, 2021
26 tasks
Comment on lines 25 to 29
computed: {
authenticityToken() {
return document.querySelector('meta[name="csrf-token"]').content
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this authenticityToken is required. I see the existing DeleteButton has it as well but i think that was left there by mistake and is not used there either.

Copy link
Collaborator

@solebared solebared left a comment

Choose a reason for hiding this comment

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

Thanks so much for working on this @vurtn 🙏🏾 , the changes look great! 🚀 .
Apologies for the long delay in reviewing this.
A few minor comments and questions below. No worries if you don't get to them, i'm happy to merge this in and tackle any further changes ourselves.

import SubmitButton from './SubmitButton'
import SpacerField from './SpacerField'
import SubmitButton from './SubmitButton'
import DeleteLink from './DeleteLink'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing you have prettier or some other auto-formatting tool enabled. Not a big deal in this case, but for future changes, would be great if you could disable it or have it respect our project settings (based on StandardRB with some customizations.

Comment on lines 40 to 42
expect(response).not_to be_successful
expect(response.response_code).to eq(302) # Redirection
expect(response.header["Location"]).to eq('http://www.example.com/users/sign_in')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding this spec! I think the expectations above can be simplified to:

Suggested change
expect(response).not_to be_successful
expect(response.response_code).to eq(302) # Redirection
expect(response.header["Location"]).to eq('http://www.example.com/users/sign_in')
expect(response).to redirect_to new_user_session_path

Comment on lines 24 to 27

.navbar {
z-index: 10;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wasn't able to recreate the problem you mentioned with the 'burger' showing up in the wrong place. When i comment out this z-index, everything still seems to work fine. Could you double check and describe steps to recreate if you're still seeing it happen?

<div class="sub-item">
<FeedbackButton
classes="navbar-item"
action="software_feedbacks/new"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This action property seems to be obsolete (i know it existed before your changes -- must've been inadvertently left behind previously).

<form :action="action" method="post" ref="form">
<AuthTokenInput />
<input type="hidden" name="_method" value="delete" />
<a href="#" :class="classes" v-on:click="submit"><slot /></a>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: i have a slight preference to put <slot /> on its own line, to give it a little more visibility.
When scanning a component template, it's helpful to be able to quickly spot any slots defined.

@solebared
Copy link
Collaborator

Webpack throwing this error sometimes when i'm testing and i still don't understand why :

ActionView::Template::Error:
       Webpacker can't find application.css in /my-path/mutual-aid/public/packs-test/manifest.json.   

Yes, i run into this sometimes too and don't fully understand it.
I think it has to do with switching between dev and test, but i need to pin down exact steps to recreate.
Thanks for noting this.

@solebared
Copy link
Collaborator

I didn't search why but i created a new account in the app and have the volonteer profile. The FeedbackButton is shown in the navbar but when i click on it i have this message :

Sorry, you aren't authorized to do that.
If you think this is wrong, please contact your administrator.

I think something is wrong 😄 The FeedbackButton have the v-if="visible('Feedback')" condition and the item is shown but i am not authorized to access it.

Great find @vurtn! I created #992 to track this.

Also, i appreciate the level of detail in your PR description, including the screenshots and explanations of some of the decisions you made and things you ran into. Very helpful! 🔥

Copy link
Collaborator

@solebared solebared left a comment

Choose a reason for hiding this comment

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

@vurtn , i went ahead and made the minor changes from the previous review.
Thanks so much for your work on this! 🙌🏾 .

@solebared solebared merged commit ef0ded1 into rubyforgood:main Dec 10, 2021
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