Skip to content

Commit

Permalink
Merge pull request #45686 from nextcloud/feat/user-row-action-enabled
Browse files Browse the repository at this point in the history
feat(settings): Add user row action enabled callback
  • Loading branch information
Pytal authored Jun 7, 2024
2 parents 512753a + d15ed3f commit 0310df5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
15 changes: 12 additions & 3 deletions apps/settings/src/components/Users/UserRowActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
<NcIconSvgWrapper :key="editSvg" :svg="editSvg" aria-hidden="true" />
</template>
</NcActionButton>
<NcActionButton v-for="({ action, icon, text }, index) in actions"
<NcActionButton v-for="({ action, icon, text }, index) in enabledActions"
:key="index"
:disabled="disabled"
:aria-label="text"
:icon="icon"
close-after-click
@click="(event) => action(event, { ...user })">
{{ text }}
</NcActionButton>
Expand All @@ -38,8 +39,9 @@ import SvgPencil from '@mdi/svg/svg/pencil.svg?raw'
interface UserAction {
action: (event: MouseEvent, user: Record<string, unknown>) => void,
enabled?: (user: Record<string, unknown>) => boolean,
icon: string,
text: string
text: string,
}
export default defineComponent({
Expand Down Expand Up @@ -87,9 +89,16 @@ export default defineComponent({
/**
* Current MDI logo to show for edit toggle
*/
editSvg() {
editSvg(): string {
return this.edit ? SvgCheck : SvgPencil
},
/**
* Enabled user row actions
*/
enabledActions(): UserAction[] {
return this.actions.filter(action => typeof action.enabled === 'function' ? action.enabled(this.user) : true)
},
},
methods: {
Expand Down
4 changes: 3 additions & 1 deletion apps/settings/src/views/UserManagement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ export default defineComponent({
* @param {string} icon the icon class
* @param {string} text the text to display
* @param {Function} action the function to run
* @param {(user: Record<string, unknown>) => boolean} enabled return true if the action is enabled for the user
* @return {Array}
*/
registerAction(icon, text, action) {
registerAction(icon, text, action, enabled) {
this.externalActions.push({
icon,
text,
action,
enabled,
})
return this.externalActions
},
Expand Down
6 changes: 3 additions & 3 deletions dist/settings-users-3239.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-users-3239.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/settings-vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

0 comments on commit 0310df5

Please sign in to comment.