Browse Source

feat(settings): Add action enabled callback

Signed-off-by: Christopher Ng <chrng8@gmail.com>
pull/45686/head
Christopher Ng 1 year ago
parent
commit
1de77edfdf
  1. 14
      apps/settings/src/components/Users/UserRowActions.vue
  2. 4
      apps/settings/src/views/UserManagement.vue

14
apps/settings/src/components/Users/UserRowActions.vue

@ -15,7 +15,7 @@
<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"
@ -38,8 +38,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 +88,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: {

4
apps/settings/src/views/UserManagement.vue

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

Loading…
Cancel
Save