Skip to content

Commit

Permalink
fixup! feat(contacts-menu): implement custom javascript hook action
Browse files Browse the repository at this point in the history
  • Loading branch information
st3iny committed Nov 26, 2024
1 parent 202fa02 commit b48320c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 133 deletions.
40 changes: 18 additions & 22 deletions core/src/components/ContactsMenu/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<NcActions v-if="actions.length"
:inline="contact.topAction ? 1 : 0">
<template v-for="(action, idx) in actions">
<NcActionLink v-if="action.type === 'LinkAction' && action.hyperlink !== '#'"
<NcActionLink v-if="action.hyperlink !== '#'"
:key="`${idx}-link`"
:href="action.hyperlink"
class="other-actions">
Expand All @@ -31,25 +31,23 @@
</template>
{{ action.title }}
</NcActionLink>
<NcActionText v-else-if="action.type === 'LinkAction'"
:key="`${idx}-text`"
class="other-actions">
<NcActionText v-else :key="`${idx}-text`" class="other-actions">
<template #icon>
<img aria-hidden="true" class="contact__action__icon" :src="action.icon">
</template>
{{ action.title }}
</NcActionText>
<NcActionButton v-else-if="action.type === 'JavascriptAction' && hasContactsMenuHook(action.hook)"
:key="`${idx}-hook`"
:close-after-click="true"
class="other-actions"
@click="callContactsMenuHook(action.hook, contact)">
<template #icon>
<img aria-hidden="true" class="contact__action__icon" :src="action.icon">
</template>
{{ action.title }}
</NcActionButton>
</template>
<NcActionButton v-for="action in jsActions"
:key="action.id"
:close-after-click="true"
class="other-actions"
@click="action.callback(contact)">
<template #icon>
<NcIconSvgWrapper :svg="action.iconSvg(contact)" />
</template>
{{ action.displayName(contact) }}
</NcActionButton>
</NcActions>
</li>
</template>
Expand All @@ -60,10 +58,8 @@ import NcActionText from '@nextcloud/vue/dist/Components/NcActionText.js'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcAvatar from '@nextcloud/vue/dist/Components/NcAvatar.js'
import {
callContactsMenuHook,
hasContactsMenuHook,
} from '@nextcloud/vue/dist/Functions/contactsMenu.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import { getEnabledContactsMenuActions } from '@nextcloud/vue/dist/Functions/contactsMenu.js'

export default {
name: 'Contact',
Expand All @@ -73,6 +69,7 @@ export default {
NcActionButton,
NcActions,
NcAvatar,
NcIconSvgWrapper,
},
props: {
contact: {
Expand All @@ -87,6 +84,9 @@ export default {
}
return this.contact.actions
},
jsActions() {
return getEnabledContactsMenuActions(this.contact)
},
preloadedUserStatus() {
if (this.contact.status) {
return {
Expand All @@ -98,10 +98,6 @@ export default {
return undefined
},
},
methods: {
hasContactsMenuHook,
callContactsMenuHook,
},
}
</script>

Expand Down
19 changes: 0 additions & 19 deletions lib/private/Contacts/ContactsMenu/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
namespace OC\Contacts\ContactsMenu;

use OC\Contacts\ContactsMenu\Actions\JavascriptAction;
use OC\Contacts\ContactsMenu\Actions\LinkAction;
use OCP\Contacts\ContactsMenu\IAction;
use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\ILinkAction;

Expand All @@ -30,21 +28,4 @@ public function newLinkAction(string $icon, string $name, string $href, string $
public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction {
return $this->newLinkAction($icon, $name, 'mailto:' . $email, $appId);
}

/**
* {@inheritDoc}
*/
public function newJavascriptAction(
string $icon,
string $name,
string $hook,
string $appId = '',
): IAction {
$action = new JavascriptAction();
$action->setIcon($icon);
$action->setName($name);
$action->setHook($hook);
$action->setAppId($appId);
return $action;
}
}
71 changes: 0 additions & 71 deletions lib/private/Contacts/ContactsMenu/Actions/JavascriptAction.php

This file was deleted.

3 changes: 0 additions & 3 deletions lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use OCP\Contacts\ContactsMenu\ILinkAction;

class LinkAction implements ILinkAction {
public const TYPE = 'LinkAction';

private string $icon = '';
private string $name = '';
private string $href = '';
Expand Down Expand Up @@ -66,7 +64,6 @@ public function getAppId(): string {
*/
public function jsonSerialize(): array {
return [
'type' => self::TYPE,
'title' => $this->name,
'icon' => $this->icon,
'hyperlink' => $this->href,
Expand Down
18 changes: 0 additions & 18 deletions lib/public/Contacts/ContactsMenu/IActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,4 @@ public function newLinkAction(string $icon, string $name, string $href, string $
* @return ILinkAction
*/
public function newEMailAction(string $icon, string $name, string $email, string $appId = ''): ILinkAction;

/**
* Construct and return a new javascript hook action for the contacts menu
*
* @since 31.0.0
*
* @param string $icon full path to the action's icon
* @param string $name localized name of the action
* @param string $hook id of the javascript hook as registered in the frontend
* @param string $appId the appName registering the action
* @return IAction
*/
public function newJavascriptAction(
string $icon,
string $name,
string $hook,
string $appId = '',
): IAction;
}

0 comments on commit b48320c

Please sign in to comment.