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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
@import './custom_spacing_helpers';
@import './bulma_simple_form_customization';

@import './yearbook'; // TODO: remove this once listings/new is refactored
@import './listings'; // TODO: remove this once listings/new is refactored
@import './yearbook'; // TODO: remove this once listings/new is refactored
@import './listings'; // TODO: remove this once listings/new is refactored

@import './custom_text';

@import './mapbox-gl';
@import './maps';
@import "./actiontext.scss";
@import './actiontext.scss';

// TODO: use has-text-centered instead
// TODO: use has-text-centered instead
.text-center {
text-align: center;
}

.section-detail {
padding: 0rem 1.5rem 3rem 0rem;
}

.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?

30 changes: 21 additions & 9 deletions app/javascript/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,51 @@
</template>

<template slot="end">
<b-navbar-item tag="div" v-if="visible('Feedback')">
<FeedbackButton action="software_feedbacks/new">Feedback</FeedbackButton>
</b-navbar-item>
<b-navbar-item href="/glossary" v-if="visible('Glossary')">Glossary</b-navbar-item>
<b-navbar-item href="/contributions" v-if="visible('Contributions')"
>Contributions</b-navbar-item
>
<b-navbar-item href="/matches" v-if="visible('Matches')">Matches</b-navbar-item>
<b-navbar-item href="/admin" v-if="visible('Admin')">Admin</b-navbar-item>
<b-navbar-item tag="div" v-if="visible('Login')">
<a href="/users/sign_in" class="button is-outlined">Login</a>
</b-navbar-item>
<b-navbar-item tag="div" v-if="visible('Sign Up')">
<a href="/users/sign_up" class="button is-outlined">Sign Up</a>
</b-navbar-item>
<b-navbar-item tag="div" v-if="visible('Logout')">
<DeleteButton action="/users/sign_out">Logout</DeleteButton>
<b-navbar-item href="/admin" v-if="visible('Admin')">
Admin
</b-navbar-item>

<b-navbar-dropdown label="Account" collapsible right v-if="visible('Logout')">
<div class="sub-item">
<a class="navbar-item" href="/users/edit">My profile</a>
</div>
<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).

v-if="visible('Feedback')"
>Feedback</FeedbackButton
>
</div>
<div class="sub-item">
<DeleteLink classes="navbar-item" action="/users/sign_out">Logout</DeleteLink>
</div>
</b-navbar-dropdown>
</template>
</b-navbar>
</template>

<script>
import {DeleteButton} from 'components/forms'
import {DeleteLink} from 'components/forms'
import {FeedbackButton} from 'components/forms'

export default {
props: {
logoUrl: {type: String},
visibleButtons: {type: Array, default: []},
},
components: {
DeleteButton,
DeleteLink,
FeedbackButton,
},
methods: {
Expand Down
31 changes: 31 additions & 0 deletions app/javascript/components/forms/DeleteLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<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.

</form>
</template>

<script>
import AuthTokenInput from './AuthTokenInput'
export default {
components: {AuthTokenInput},
props: {
action: String,
classes: {
default: '',
type: String,
},
},
methods: {
submit: function () {
this.$refs.form.submit()
},
},
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.

}
</script>
8 changes: 7 additions & 1 deletion app/javascript/components/forms/FeedbackButton.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<template>
<a :href="url" class="button is-outlined">
<a :href="url" :class="classes">
Feedback
</a>
</template>

<script>
export default {
props: {
classes: {
default: 'button is-outlined',
type: String,
},
},
computed: {
url() {
const pathname = window.location.pathname
Expand Down
27 changes: 14 additions & 13 deletions app/javascript/components/forms/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import AuthTokenInput from './AuthTokenInput'
import CategoryFields from './CategoryFields'
import CommentsField from './CommentsField'
import ContactFields from './ContactFields'
import CustomQuestions from './CustomQuestions'
import DeleteButton from './DeleteButton'
import ErrorMessages from './ErrorMessages'
import FeedbackButton from './FeedbackButton'
import LocationFields from './LocationFields'
import NameField from './NameField'
import AuthTokenInput from './AuthTokenInput'
import CategoryFields from './CategoryFields'
import CommentsField from './CommentsField'
import ContactFields from './ContactFields'
import CustomQuestions from './CustomQuestions'
import DeleteButton from './DeleteButton'
import ErrorMessages from './ErrorMessages'
import FeedbackButton from './FeedbackButton'
import LocationFields from './LocationFields'
import NameField from './NameField'
import ServiceAreaField from './ServiceAreaField'
import SpacerField from './SpacerField'
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.


export {
AuthTokenInput,
Expand All @@ -26,5 +27,5 @@ export {
ServiceAreaField,
SpacerField,
SubmitButton,
DeleteLink,
}

28 changes: 15 additions & 13 deletions spec/javascript/components/NavBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import {configure} from 'vue_config'
import NavBar from 'components/NavBar'

describe('NavBar', () => {
def('wrapper', () => mount(NavBar, {
localVue: configure(createLocalVue()),
propsData: {
logoUrl: '/some-url',
visibleButtons: $visibleButtons,
},
}))
def('wrapper', () =>
mount(NavBar, {
localVue: configure(createLocalVue()),
propsData: {
logoUrl: '/some-url',
visibleButtons: $visibleButtons,
},
})
)

def('renderedNavItems', () => {
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())
const navLinks = $wrapper.findAll('a:not(.burger)').wrappers
return [...navLinks].map((link) => link.text())
})

describe('visible buttons', () => {
Expand Down Expand Up @@ -49,7 +49,8 @@ describe('NavBar', () => {
})

describe('when instructed to show all admin buttons', () => {
def('visibleButtons', ['Contributions', 'Matches', 'Admin', 'Feedback', 'Logout'])
def('visibleButtons', ['Contributions', 'Matches', 'Admin', 'Account', 'Feedback', 'Logout'])

it('includes specified buttons', () => {
assert.sameMembers($renderedNavItems, [
'',
Expand All @@ -59,11 +60,12 @@ describe('NavBar', () => {
'Contributions',
'Matches',
'Admin',
'Account',
'My profile',
'Feedback',
'Logout',
])
})
})
})
})

8 changes: 8 additions & 0 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
get "/users/#{user.id}/edit"
expect(response).to be_successful
end

it "must redirect to the sign in page if the user is not authenticated" do
sign_out :user
get "/users/1/edit"
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

end
end

describe "POST /create" do
Expand Down