Skip to content

Commit

Permalink
fixup! feat: delete tags
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Sep 25, 2023
1 parent 77a2b7e commit 3f1de0b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
],
[
'name' => 'tags#delete',
'url' => '/api/tags/{id}/tags/{accountId}',
'url' => '/api/tags/{accountId}/delete/{id}',
'verb' => 'DELETE'
],
[
Expand Down
16 changes: 11 additions & 5 deletions src/components/DeleteTagModal.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
- @copyright 2023 Hamza Mahjoubi <hamza.mahjoubi221@proton.me>
- @copyright 2023 Hamza Mahjoubi <hamzamahjoubi221@proton.me>
-
- @author 2023 Hamza Mahjoubi <hamza.mahjoubi221@proton.me>
- @author 2023 Hamza Mahjoubi <hamzamahjoubi221@proton.me>
-
- @license AGPL-3.0-or-later
-
Expand All @@ -19,12 +19,15 @@
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<Modal class="modal" size="large" @close="onClose">
<Modal class="modal"
size="large"
container="body"
@close="onClose">
<div class="modal__content">
{{ t('mail', 'The tag will be deleted from all messages.') }}
</div>
<div class="modal__footer">
<Button @click="onClose">
<Button :disabled="deleting" @click="onClose">
{{ t('mail', 'Cancel') }}
</Button>
<Button :disabled="deleting" @click="deleteTag">
Expand Down Expand Up @@ -68,11 +71,14 @@ export default {
tag: this.tag,
accountId: this.accountId,
})
this.$store.commit('deleteTag', {
tagId: this.tag.id,
})
showSuccess(t('mail', 'Tag: {name} deleted', { name: this.tag.displayName }))
this.$emit('close')
} catch (error) {
showInfo(t('mail', 'An error occurred, unable to delete the tag.'))
}
this.$emit('close')
},
},
Expand Down
11 changes: 5 additions & 6 deletions src/components/TagModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
-->

<template>
<Modal size="large" @close="onClose">
<DeleteTagModal v-if="deleteTagModal"
:tag="tagToDelete"
:account-id="envelopes[0].accountId"
@close="closeDeleteModal" />
<Modal v-else size="large" @close="onClose">
<div class="modal-content">
<h2 class="tag-title">
{{ t('mail', 'Add default tags') }}
Expand Down Expand Up @@ -97,10 +101,6 @@
</ActionText>
</div>
</div>
<DeleteTagModal v-if="deleteTagModal"
:tag="tagToDelete"
:account-id="envelopes[0].accountId"
@close="closeDeleteModal" />
</Modal>
</template>

Expand Down Expand Up @@ -186,7 +186,6 @@ export default {
},
closeDeleteModal() {
this.deleteTagModal = false
this.onClose()
},
isSet(imapLabel) {
return this.envelopes.some(
Expand Down
4 changes: 2 additions & 2 deletions src/service/MessageService.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ export async function updateEnvelopeTag(id, displayName, color) {
}

export async function deleteTag(id, accountId) {
const url = generateUrl('/apps/mail/api/tags/{id}/tags/{accountId}', {
id, accountId,
const url = generateUrl('/apps/mail/api/tags/{accountId}/delete/{id}', {
accountId, id,
})

await axios.delete(url)
Expand Down
4 changes: 4 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ export default {
Vue.set(state.tags, tag.id, tag)
state.tagList.push(tag.id)
},
deleteTag(state, { tagId }) {
Vue.delete(state.tags, tagId)
state.tagList = state.tagList.filter((id) => id !== tagId)
},
addEnvelopeTag(state, { envelope, tagId }) {
Vue.set(envelope, 'tags', uniq([...envelope.tags, tagId]))
},
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Service/MailManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\Message;
use OCA\Mail\Db\MessageMapper as DbMessageMapper;
use OCA\Mail\Db\MessageTagsMapper;
use OCA\Mail\Db\Tag;
use OCA\Mail\Db\TagMapper;
use OCA\Mail\Db\ThreadMapper;
Expand Down Expand Up @@ -80,9 +81,14 @@ class MailManagerTest extends TestCase {
/** @var MockObject|TagMapper */
private $tagMapper;

/** @var MessageTagsMapper|MockObject */
private $messageTagsMapper;

/** @var ThreadMapper|MockObject */
private $threadMapper;



protected function setUp(): void {
parent::setUp();

Expand All @@ -95,6 +101,7 @@ protected function setUp(): void {
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->tagMapper = $this->createMock(TagMapper::class);
$this->messageTagsMapper = $this->createMock(MessageTagsMapper::class);
$this->threadMapper = $this->createMock(ThreadMapper::class);

$this->manager = new MailManager(
Expand All @@ -107,6 +114,7 @@ protected function setUp(): void {
$this->eventDispatcher,
$this->logger,
$this->tagMapper,
$this->messageTagsMapper,
$this->threadMapper
);
}
Expand Down

0 comments on commit 3f1de0b

Please sign in to comment.