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

[full-ci] Show bell based on capabilities #8450

Merged
merged 8 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-notification-bell
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Rework notifications

We've added the notification capability to enable the notification bell
lookacat marked this conversation as resolved.
Show resolved Hide resolved

https://github.com/owncloud/web/pull/8450
https://github.com/owncloud/web/issues/8452
3 changes: 3 additions & 0 deletions packages/web-client/src/ocs/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import get from 'lodash-es/get'
/* eslint-disable camelcase */
export interface Capabilities {
capabilities: {
notifications: {
ocs_endpoints: string[]
}
core: {
pollinterval: number
status: {
Expand Down
4 changes: 4 additions & 0 deletions packages/web-pkg/src/composables/capability/useCapability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ export const useCapabilityFilesSharingPublicAlias = createCapabilityComposable(
'files_sharing.public.alias',
false
)
export const useCapabilityNotifications = createCapabilityComposable(
'notifications.ocs-endpoints',
[]
)
5 changes: 4 additions & 1 deletion packages/web-runtime/src/components/Topbar/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
class="oc-overflow-auto oc-width-3-4 oc-width-large@s"
padding-size="small"
>
<div v-for="(el, index) in activeNotifications" :key="index" class="oc-width-1-1">
<div v-if="!activeNotifications.length">
<span v-text="$gettext('Nothing new')" />
</div>
<div v-for="(el, index) in activeNotifications" v-else :key="index" class="oc-width-1-1">
lookacat marked this conversation as resolved.
Show resolved Hide resolved
<h4 v-text="el.subject" />
<p v-if="el.message" class="oc-text-small">{{ el.message }}</p>
<p>
Expand Down
17 changes: 13 additions & 4 deletions packages/web-runtime/src/components/Topbar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import UserMenu from './UserMenu.vue'
import Notifications from './Notifications.vue'
import FeedbackLink from './FeedbackLink.vue'
import ThemeSwitcher from './ThemeSwitcher.vue'
import { useCapabilityNotifications } from 'web-pkg/src'
import { computed, unref } from 'vue'

export default {
components: {
Expand All @@ -53,6 +55,17 @@ export default {
default: () => []
}
},
setup() {
const notificationsSupport = useCapabilityNotifications()

const isNotificationBellEnabled = computed(() => {
return unref(notificationsSupport)?.includes('list') || false
lookacat marked this conversation as resolved.
Show resolved Hide resolved
})

return {
isNotificationBellEnabled
}
},
computed: {
...mapGetters(['configuration', 'user']),

Expand Down Expand Up @@ -96,10 +109,6 @@ export default {
}
},

isNotificationBellEnabled() {
return this.user?.id && this.activeNotifications.length
},

isUserMenuEnabled() {
return this.user?.id
}
Expand Down
34 changes: 30 additions & 4 deletions packages/web-runtime/tests/unit/components/Topbar/TopBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,40 @@ jest.spyOn((TopBar as any).mixins[0].methods, 'navigation_getMenuItems').mockImp
describe('Top Bar component', () => {
it('Displays applications menu', () => {
const { wrapper } = getWrapper()
expect(wrapper.html().indexOf('applications-menu-stub')).toBeGreaterThan(-1)
expect(wrapper.find('applications-menu-stub').exists()).toBeTruthy()
expect(wrapper.html()).toMatchSnapshot()
})
it('should display notifications bell', () => {
const { wrapper } = getWrapper({
notifications: {
'ocs-endpoints': ['list', 'get', 'delete']
}
})
expect(wrapper.find('notifications-stub').exists()).toBeTruthy()
})
it('should not display notifications bell if notifications capability is missing', () => {
const { wrapper } = getWrapper()
expect(wrapper.find('notifications-stub').exists()).toBeFalsy()
})
it('should not display notifications bell if endpoint list is missing', () => {
const { wrapper } = getWrapper({
notifications: {
'ocs-endpoints': []
}
})
expect(wrapper.find('notifications-stub').exists()).toBeFalsy()
})
})

const getWrapper = () => {
const getWrapper = (capabilities = {}) => {
const mocks = { ...defaultComponentMocks() }
const storeOptions = defaultStoreMockOptions
const storeOptions = {
...defaultStoreMockOptions,
getters: {
...defaultStoreMockOptions.getters,
capabilities: () => capabilities
}
}
storeOptions.getters.configuration.mockImplementation(() => ({
options: { disableFeedbackLink: false },
themes: {
Expand All @@ -61,7 +87,7 @@ const getWrapper = () => {
},
global: {
plugins: [...defaultPlugins(), store],
stubs: { 'router-link': true, 'portal-target': true },
stubs: { 'router-link': true, 'portal-target': true, notifications: true },
mocks
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ exports[`Top Bar component Displays applications menu 1`] = `
<user-menu-stub applicationslist="[object Object],[object Object],[object Object]"></user-menu-stub>
</div>
</header>
`;
`;