-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list of groups in the vault (monicahq/chandler#228)
- Loading branch information
Showing
10 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\Contact\ManageGroups\Web\ViewHelpers; | ||
|
||
use App\Models\Contact; | ||
use App\Models\Group; | ||
use App\Models\Vault; | ||
use Illuminate\Support\Collection; | ||
|
||
class GroupIndexViewHelper | ||
{ | ||
/** | ||
* Gets the list of groups in the vault. | ||
* | ||
* @param Vault $vault | ||
* @return Collection | ||
*/ | ||
public static function data(Vault $vault): Collection | ||
{ | ||
return $vault->groups()->with('contacts') | ||
->orderBy('name') | ||
->get() | ||
->map(function (Group $group) { | ||
$contactsCollection = $group->contacts() | ||
->get() | ||
->map(fn (Contact $contact) => [ | ||
'id' => $contact->id, | ||
'name' => $contact->name, | ||
'age' => $contact->age, | ||
'avatar' => $contact->avatar, | ||
'url' => route('contact.show', [ | ||
'vault' => $contact->vault_id, | ||
'contact' => $contact->id, | ||
]), | ||
]); | ||
|
||
return [ | ||
'id' => $group->id, | ||
'name' => $group->name, | ||
'url' => [ | ||
'show' => route('group.show', [ | ||
'vault' => $group->vault_id, | ||
'group' => $group->id, | ||
]), | ||
], | ||
'contacts' => $contactsCollection, | ||
]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script setup> | ||
import Layout from '@/Shared/Layout.vue'; | ||
import Avatar from '@/Shared/Avatar.vue'; | ||
defineProps({ | ||
layoutData: Object, | ||
data: Object, | ||
}); | ||
</script> | ||
|
||
<template> | ||
<layout :layout-data="layoutData" :inside-vault="true"> | ||
<main class="relative sm:mt-24"> | ||
<div class="mx-auto max-w-4xl px-2 py-2 sm:py-6 sm:px-6 lg:px-8"> | ||
<!-- group title --> | ||
<h3 class="mb-6 font-semibold"> | ||
<span class="mr-1"> 👥 </span> | ||
{{ $t('vault.show_groups_index') }} | ||
</h3> | ||
|
||
<div v-if="data.length != 0"> | ||
<ul class="group-list mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900"> | ||
<li | ||
v-for="group in data" | ||
:key="group.id" | ||
class="flex items-center justify-between border-b border-gray-200 px-5 py-2 hover:bg-slate-50 dark:border-gray-700 dark:bg-slate-900 hover:dark:bg-slate-800"> | ||
<inertia-link :href="group.url.show" class="text-blue-500 hover:underline">{{ group.name }}</inertia-link> | ||
|
||
<div v-if="group.contacts" class="relative flex -space-x-2 overflow-hidden py-1"> | ||
<div v-for="contact in group.contacts" :key="contact.id" class="inline-block"> | ||
<inertia-link :href="contact.url.show"> | ||
<avatar :data="contact.avatar" :classes="'h-8 w-8 rounded-full ring-2 ring-white'" /> | ||
</inertia-link> | ||
</div> | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<!-- blank state --> | ||
<div | ||
v-if="data.length == 0" | ||
class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900"> | ||
<p class="p-5 text-center"> | ||
{{ $t('vault.show_groups_blank') }} | ||
</p> | ||
</div> | ||
</div> | ||
</main> | ||
</layout> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.group-list { | ||
li:hover:first-child { | ||
border-top-left-radius: 8px; | ||
border-top-right-radius: 8px; | ||
} | ||
li:last-child { | ||
border-bottom: 0; | ||
} | ||
li:hover:last-child { | ||
border-bottom-left-radius: 8px; | ||
border-bottom-right-radius: 8px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/Unit/Domains/Contact/ManageGroups/Web/ViewHelpers/GroupIndexViewHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Domains\Contact\ManageGroups\Web\ViewHelpers; | ||
|
||
use App\Contact\ManageGroups\Web\ViewHelpers\GroupIndexViewHelper; | ||
use App\Models\Contact; | ||
use App\Models\Group; | ||
use App\Models\GroupType; | ||
use App\Models\GroupTypeRole; | ||
use App\Models\User; | ||
use App\Models\Vault; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
class GroupIndexViewHelperTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_gets_all_the_groups_associated_with_the_vault(): void | ||
{ | ||
$user = User::factory()->create(); | ||
$vault = Vault::factory()->create([]); | ||
$contact = Contact::factory()->create([ | ||
'vault_id' => $vault->id, | ||
]); | ||
$groupType = GroupType::factory()->create(); | ||
$parentRole = GroupTypeRole::factory()->create([ | ||
'group_type_id' => $groupType->id, | ||
]); | ||
$group = Group::factory()->create([ | ||
'vault_id' => $contact->vault_id, | ||
'group_type_id' => $groupType->id, | ||
]); | ||
$group->contacts()->syncWithoutDetaching([ | ||
$contact->id => ['group_type_role_id' => $parentRole->id], | ||
]); | ||
|
||
$collection = GroupIndexViewHelper::data($vault, $user); | ||
|
||
$this->assertCount( | ||
1, | ||
$collection | ||
); | ||
|
||
$this->assertEquals( | ||
$group->id, | ||
$collection->toArray()[0]['id'] | ||
); | ||
|
||
$this->assertEquals( | ||
$group->name, | ||
$collection->toArray()[0]['name'] | ||
); | ||
|
||
$this->assertEquals( | ||
env('APP_URL').'/vaults/'.$vault->id.'/groups/'.$group->id, | ||
$collection->toArray()[0]['url']['show'] | ||
); | ||
} | ||
} |