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

[FEATURE] Ajouter un état actif au éléments de la navigation (PIX-2235). #275

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 4 additions & 7 deletions components/PixLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,15 @@ function getRelativeLinkPrefix(url) {
if (!url) {
return ''
}
let defaultPrefixes
if (process.env.isPixPro) {
defaultPrefixes = 'https://pro.pix.fr/'
} else {
defaultPrefixes = 'https://pix.org/,https://pix.fr/'
}
const defaultPrefixes = process.env.isPixPro
? 'https://pro.pix.fr'
: 'https://pix.org,https://pix.fr'
const relativeLinkPrefixes = (
process.env.RELATIVE_LINK_PREFIXES || defaultPrefixes
).split(',')
return relativeLinkPrefixes
.map((relativeLinkPrefix) =>
url.startsWith(relativeLinkPrefix) ? relativeLinkPrefix : ''
url.startsWith(relativeLinkPrefix) ? `${relativeLinkPrefix}/` : ''
)
.filter((relativeLinkPrefix) => relativeLinkPrefix !== '')[0]
}
Expand Down
45 changes: 37 additions & 8 deletions components/slices/NavigationZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<button
:dropdown-index="`${index}`"
class="dropdown-toggle navigation-zone__item links-group"
:class="{
'current-active-link': subIsActive(menuItem.subNavigationLinks),
}"
@click="toggleDropdown(`${index}`)"
@click.stop.prevent
>
Expand Down Expand Up @@ -89,6 +92,16 @@ export default {
this.openDropdownIndex = dropdownIndex
}
},
subIsActive(subNavigationLinks) {
const paths = subNavigationLinks.map((subNavigationLink) => {
const splittedLink = subNavigationLink.link.url.split('/')
const linkIndex = splittedLink.length - 1
return splittedLink[linkIndex]
})
return paths.some((path) => {
return this.$route.path.includes(path)
})
},
},
}

Expand Down Expand Up @@ -126,6 +139,15 @@ class Navigation {
</script>

<style scoped lang="scss">
@mixin active-link($theme: DarkGray) {
border-bottom: 2px solid $blue;

&:active,
&:hover {
color: $blue;
}
}

.navigation-zone {
display: none;

Expand All @@ -143,8 +165,12 @@ class Navigation {
}
}

.navigation-zone-block:last-child {
border-left: 1px solid $grey-20;
.navigation-zone-block {
height: 24px;

&:last-child {
border-left: 1px solid $grey-20;
}
}

& > div {
Expand All @@ -156,6 +182,13 @@ class Navigation {
align-items: center;
height: 100%;

button.dropdown-toggle {
height: 30px;
&.current-active-link {
@include active-link;
}
}

&__item {
color: $grey-60;
font-family: $font-roboto;
Expand All @@ -167,13 +200,9 @@ class Navigation {
padding: 0 8px 10px 8px;
cursor: pointer;
white-space: nowrap;

&.current-active-link {
border-bottom: 2px solid $blue;
}
&.current-active-link,
&:active,
&:hover {
color: $blue;
@include active-link;
}

&.links-group {
Expand Down
24 changes: 14 additions & 10 deletions tests/components/slices/NavigationZone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ jest.mock('~/services/document-fetcher')
describe('NavigationZone slice', () => {
let component
const get = jest.fn()
const $route = {
path: '',
}

beforeEach(() => {
documentFetcher.mockReturnValue({
Expand All @@ -25,23 +28,24 @@ describe('NavigationZone slice', () => {
describe('Slice: NavigationZone', () => {
beforeEach(() => {
component = shallowMount(NavigationZone, {
mocks: { $route },
stubs: { 'pix-link': true, fa: true },
propsData: {
slice: {
items: [
{ name: 'Découvrir Pix', link: '/', group: [] },
{ name: 'Les tests', link: '/tests', group: [] },
{ name: 'Découvrir Pix', link: { url: '/' }, group: [] },
{ name: 'Les tests', link: { url: '/tests' }, group: [] },
{
name: 'Enseignement scolaire',
link: '/sco',
link: { url: '/sco' },
group: [{ text: 'Enseignement' }],
},
{
name: 'Enseignement supérieur',
link: '/sup',
link: { url: '/sup' },
group: [{ text: 'Enseignement' }],
},
{ name: 'Pix Pro', link: '/pro', group: [] },
{ name: 'Pix Pro', link: { url: '/pro' }, group: [] },
],
},
},
Expand All @@ -57,24 +61,24 @@ describe('NavigationZone slice', () => {
it('should aggregate navigation links of the same group', () => {
const navigationLinks = component.vm.navigationLinks
expect(navigationLinks).toEqual([
{ name: 'Découvrir Pix', link: '/', group: [] },
{ name: 'Les tests', link: '/tests', group: [] },
{ name: 'Découvrir Pix', link: { url: '/' }, group: [] },
{ name: 'Les tests', link: { url: '/tests' }, group: [] },
{
name: 'Enseignement',
subNavigationLinks: [
{
name: 'Enseignement scolaire',
link: '/sco',
link: { url: '/sco' },
group: [{ text: 'Enseignement' }],
},
{
name: 'Enseignement supérieur',
link: '/sup',
link: { url: '/sup' },
group: [{ text: 'Enseignement' }],
},
],
},
{ name: 'Pix Pro', group: [], link: '/pro' },
{ name: 'Pix Pro', group: [], link: { url: '/pro' } },
])
})
})
Expand Down