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

PRO-5940: working PoC of distinct guest admin bar experience #55

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<template>
Copy link
Member Author

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.

Copy link
Member Author

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-level modules/@apostrophecms/admin-bar folder to make it easier to find this override later.

<div
Copy link
Member Author

@boutell boutell Apr 26, 2024

Choose a reason for hiding this comment

The 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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 script section.

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() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Exposes the fact that the user is a guest. See also the getBrowserData extension below.

return apos.login.user.role === 'guest';
},
bars() {
return this.moduleOptions.bars;
}
},
mounted() {
if (!this.guest) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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>
13 changes: 13 additions & 0 deletions modules/@apostrophecms/login/index.js
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;
Copy link
Member Author

Choose a reason for hiding this comment

The 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;
}
};
}
}