-
Notifications
You must be signed in to change notification settings - Fork 159
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
Add context menu to users #8324
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Enhancement: Add context menu to users | ||
|
||
A context menu has been added to the users management page in the admin settings. It can be toggled via right-click and quick-action. | ||
|
||
https://github.com/owncloud/web/pull/8324 | ||
https://github.com/owncloud/web/issues/8323 |
62 changes: 62 additions & 0 deletions
62
packages/web-app-admin-settings/src/components/Users/ContextActions.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<div> | ||
<context-action-menu :menu-sections="menuSections" :items="items" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import ShowDetails from '../../mixins/showDetails' | ||
import Delete from '../../mixins/users/delete' | ||
import Edit from '../../mixins/users/edit' | ||
import { computed, defineComponent, getCurrentInstance, PropType, unref } from 'vue' | ||
import ContextActionMenu from 'web-pkg/src/components/ContextActions/ContextActionMenu.vue' | ||
import { User } from 'web-client/src/generated' | ||
|
||
export default defineComponent({ | ||
name: 'ContextActions', | ||
components: { ContextActionMenu }, | ||
mixins: [Delete, Edit, ShowDetails], | ||
props: { | ||
items: { | ||
type: Array as PropType<User[]>, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const instance = getCurrentInstance().proxy | ||
|
||
const filterParams = computed(() => ({ resources: props.items })) | ||
const menuItemsPrimaryActions = computed(() => | ||
[...instance.$_edit_items, ...instance.$_delete_items].filter((item) => | ||
item.isEnabled(unref(filterParams)) | ||
) | ||
) | ||
|
||
const menuItemsSidebar = computed(() => | ||
[...instance.$_showDetails_items].filter((item) => item.isEnabled(unref(filterParams))) | ||
) | ||
|
||
const menuSections = computed(() => { | ||
const sections = [] | ||
|
||
if (unref(menuItemsPrimaryActions).length) { | ||
sections.push({ | ||
name: 'primaryActions', | ||
items: unref(menuItemsPrimaryActions) | ||
}) | ||
} | ||
if (unref(menuItemsSidebar).length) { | ||
sections.push({ | ||
name: 'sidebar', | ||
items: unref(menuItemsSidebar) | ||
}) | ||
} | ||
return sections | ||
}) | ||
|
||
return { | ||
menuSections | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/web-app-admin-settings/src/mixins/users/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { mapActions } from 'vuex' | ||
import { clientService, configurationManager, eventBus } from 'web-pkg' | ||
|
||
export default { | ||
computed: { | ||
$_delete_items() { | ||
return [ | ||
{ | ||
name: 'delete', | ||
icon: 'delete-bin', | ||
label: () => { | ||
return this.$gettext('Delete') | ||
}, | ||
handler: this.$_delete_trigger, | ||
isEnabled: ({ resources }) => { | ||
return !!resources.length | ||
}, | ||
componentType: 'button', | ||
class: 'oc-users-actions-delete-trigger' | ||
} | ||
] | ||
} | ||
}, | ||
methods: { | ||
...mapActions(['createModal', 'hideModal', 'showMessage']), | ||
|
||
$_delete_trigger({ resources }) { | ||
if (!resources.length) { | ||
return | ||
} | ||
|
||
const modal = { | ||
variation: 'danger', | ||
icon: 'alarm-warning', | ||
title: this.$ngettext( | ||
'Delete user %{user}?', | ||
'Delete %{userCount} selected users?', | ||
resources.length, | ||
{ | ||
user: resources[0].displayName, | ||
userCount: resources.length | ||
} | ||
), | ||
cancelText: this.$gettext('Cancel'), | ||
confirmText: this.$gettext('Delete'), | ||
message: this.$ngettext( | ||
'Are you sure you want to delete this user?', | ||
'Are you sure you want to delete all selected users?', | ||
resources.length | ||
), | ||
hasInput: false, | ||
onCancel: this.hideModal, | ||
onConfirm: () => this.$_delete_deleteUsers(resources) | ||
} | ||
|
||
this.createModal(modal) | ||
}, | ||
|
||
async $_delete_deleteUsers(users) { | ||
const accessToken = this.$store.getters['runtime/auth/accessToken'] | ||
const graphClient = clientService.graphAuthenticated( | ||
configurationManager.serverUrl, | ||
accessToken | ||
) | ||
const promises = users.map((user) => graphClient.users.deleteUser(user.id)) | ||
|
||
try { | ||
await Promise.all(promises) | ||
this.hideModal() | ||
this.showMessage({ | ||
title: this.$ngettext( | ||
'User "%{user}" was deleted successfully', | ||
'%{userCount} users were deleted successfully', | ||
users.length, | ||
{ userCount: users.length, user: users[0].displayName }, | ||
true | ||
) | ||
}) | ||
eventBus.publish('app.admin-settings.list.load') | ||
} catch (error) { | ||
console.error(error) | ||
this.hideModal() | ||
this.showMessage({ | ||
title: this.$ngettext( | ||
'Failed to delete user "%{user}"', | ||
'Failed to delete %{userCount} users', | ||
users.length, | ||
{ userCount: users.length, user: users[0].displayName }, | ||
true | ||
), | ||
status: 'danger' | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { eventBus } from 'web-pkg' | ||
import { SideBarEventTopics } from 'web-pkg/src/composables/sideBar' | ||
|
||
export default { | ||
computed: { | ||
$_edit_items() { | ||
return [ | ||
{ | ||
name: 'edit', | ||
icon: 'pencil', | ||
label: () => this.$gettext('Edit'), | ||
handler: this.$_edit_trigger, | ||
isEnabled: ({ resources }) => { | ||
return resources.length > 0 | ||
}, | ||
componentType: 'button', | ||
class: 'oc-users-actions-edit-trigger' | ||
} | ||
] | ||
} | ||
}, | ||
methods: { | ||
$_edit_trigger() { | ||
eventBus.publish(SideBarEventTopics.openWithPanel, 'EditPanel') | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think we can refactor this component to be more generic in the future - at least for the admin settings.