-
Notifications
You must be signed in to change notification settings - Fork 19
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
PRO-5940: working PoC of distinct guest admin bar experience #55
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<template> | ||
<div | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditionally emit different markup when the user is a guest. |
||
v-if="guest" | ||
class="admin-bar-guest" | ||
> | ||
<button @click="logout">Log Out</button> | ||
</div> | ||
<div v-else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The HTML from here down is unmodified. There are a few changes separately called out in the |
||
data-apos-test="adminBar" | ||
class="apos-admin-bar-wrapper" | ||
:class="themeClass" | ||
> | ||
<div ref="spacer" class="apos-admin-bar-spacer" /> | ||
<nav ref="adminBar" class="apos-admin-bar"> | ||
<div class="apos-admin-bar__row"> | ||
<AposLogoPadless class="apos-admin-bar__logo" /> | ||
<TheAposAdminBarMenu :items="menuItems" /> | ||
<TheAposAdminBarLocale v-if="hasLocales()" /> | ||
<TheAposAdminBarUser | ||
data-apos-test="authenticatedUserMenuTrigger" | ||
class="apos-admin-bar__user" | ||
:items="userItems" | ||
/> | ||
</div> | ||
<TheAposContextBar @visibility-changed="setSpacer" /> | ||
<component | ||
v-bind="bar.props || {}" | ||
:is="bar.componentName" | ||
v-for="bar in bars" | ||
:key="bar.id" | ||
/> | ||
</nav> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import AposThemeMixin from 'Modules/@apostrophecms/ui/mixins/AposThemeMixin'; | ||
|
||
export default { | ||
name: 'TheAposAdminBar', | ||
mixins: [ AposThemeMixin ], | ||
props: { | ||
items: { | ||
type: Array, | ||
required: true | ||
} | ||
}, | ||
computed: { | ||
menuItems() { | ||
return this.items.filter(item => !item.options?.user); | ||
}, | ||
userItems() { | ||
return this.items.filter(item => item.options?.user); | ||
}, | ||
moduleOptions() { | ||
return window.apos.adminBar; | ||
}, | ||
guest() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exposes the fact that the user is a guest. See also the |
||
return apos.login.user.role === 'guest'; | ||
}, | ||
bars() { | ||
return this.moduleOptions.bars; | ||
} | ||
}, | ||
mounted() { | ||
if (!this.guest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last change in this file: don't invoke a method that manipulates markup we won't have for guests. |
||
this.setSpacer(); | ||
} | ||
}, | ||
methods: { | ||
setSpacer() { | ||
window.apos.adminBar.height = this.$refs.adminBar.offsetHeight; | ||
this.$refs.spacer.style.height = `${this.$refs.adminBar.offsetHeight}px`; | ||
apos.bus.$emit('admin-menu-height-changed'); | ||
}, | ||
hasLocales() { | ||
return Object.keys(window.apos.i18n.locales).length > 1; | ||
}, | ||
logout() { | ||
apos.bus.$emit('admin-menu-click', '@apostrophecms/login-logout'); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
|
||
.apos-admin-bar-wrapper { | ||
z-index: $z-index-admin-bar; | ||
position: relative; | ||
} | ||
|
||
.apos-admin-bar { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
left: 0; | ||
background: var(--a-background-primary); | ||
} | ||
|
||
:deep(.apos-admin-bar__row) { | ||
display: flex; | ||
align-items: center; | ||
height: 35px; | ||
padding: 10px 20px; | ||
border-bottom: 1px solid var(--a-base-9); | ||
} | ||
|
||
.apos-admin-bar__logo { | ||
display: inline-block; | ||
height: 26px; | ||
margin-right: 10px; | ||
} | ||
|
||
:deep(.apos-admin-bar__control-set) { | ||
@include type-base; | ||
display: flex; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.apos-admin-bar__user { | ||
margin-left: auto; | ||
} | ||
|
||
:deep(.apos-context-menu__pane) { | ||
min-width: 150px; | ||
} | ||
:deep(.flip-enter) { // to the ground | ||
transform: translateY(-20%); | ||
opacity: 0; | ||
} | ||
:deep(.flip-leave) { // in the frame | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
:deep(.flip-enter-to) { // from the ground | ||
transform: translateY(0); | ||
opacity: 1; | ||
} | ||
:deep(.flip-leave-to) { // to the sky | ||
transform: translateY(20%); | ||
opacity: 0; | ||
} | ||
|
||
:deep(.flip-enter-active), :deep(.flip-leave-active) { | ||
transition: all 150ms; | ||
&.apos-admin-bar__control-set__group { | ||
position: absolute; | ||
} | ||
} | ||
|
||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
extendMethods(self) { | ||
return { | ||
getBrowserData(_super, req) { | ||
const data = _super(req); | ||
if (data.user) { | ||
data.user.role = req.user.role; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't expose the logged-in user's role on the front end by default, so add that information. |
||
} | ||
return data; | ||
} | ||
}; | ||
} | ||
} |
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.
99% of this file is directly copied from the original in the
apostrophe
module, see below for the changes.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.
You could place this file in any module, as long as it is in the
ui/apos/components
subdirectory of that module. I chose the project-levelmodules/@apostrophecms/admin-bar
folder to make it easier to find this override later.