Merge pull request #45686 from nextcloud/feat/user-row-action-enabled

feat(settings): Add user row action enabled callback
pull/45684/head
Pytal 2024-06-06 17:00:37 +07:00 committed by GitHub
commit 0310df5d3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 12 deletions

@ -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>
@ -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({
@ -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: {

@ -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
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long