From 69bb062c3344c44d361e95f1fd0dade70c24a1b2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov <me@slavatumanov.me> Date: Tue, 30 May 2023 17:03:37 +0500 Subject: [PATCH] UBER-278: add Yes-No to popup, refactor (#3289) Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me> --- .../components/DeleteConfirmationPopup.svelte | 56 ++++++++++--------- tests/sanity/tests/contacts.spec.ts | 2 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte index c2fecefc38b..23add26ecab 100644 --- a/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte +++ b/plugins/contact-resources/src/components/DeleteConfirmationPopup.svelte @@ -13,40 +13,42 @@ // limitations under the License. --> <script lang="ts"> - import { Card, createQuery } from '@hcengineering/presentation' - import { AccountRole, Doc, getCurrentAccount, Ref, SortingOrder } from '@hcengineering/core' + import { Card } from '@hcengineering/presentation' + import { AccountRole, Doc, getCurrentAccount, Ref } from '@hcengineering/core' import view from '@hcengineering/view-resources/src/plugin' import { createEventDispatcher } from 'svelte' - import contact, { Employee, EmployeeAccount } from '@hcengineering/contact' - import EmployeePresenter from './EmployeePresenter.svelte' + import { EmployeeAccount } from '@hcengineering/contact' import { employeeAccountByIdStore } from '../utils' - import ui, { Label } from '@hcengineering/ui' + import ui, { Button, Label } from '@hcengineering/ui' + import EmployeeAccountRefPresenter from './EmployeeAccountRefPresenter.svelte' + import EmployeeAccountPresenter from './EmployeeAccountPresenter.svelte' export let object: Doc | Doc[] export let deleteAction: () => void const objectArray = Array.isArray(object) ? object : [object] - let owners: Ref<Employee>[] = [] - const query = createQuery() - query.query( - contact.class.EmployeeAccount, - { role: AccountRole.Owner }, - (res) => { - owners = res.map((account) => account.employee) - }, - { - sort: { name: SortingOrder.Descending } - } + const owners: EmployeeAccount[] = Array.from($employeeAccountByIdStore.values()).filter( + (acc) => acc.role === AccountRole.Owner ) const dispatch = createEventDispatcher() - const creators = [ - ...new Set(objectArray.map((obj) => $employeeAccountByIdStore.get(obj.createdBy as Ref<EmployeeAccount>)?.employee)) - ] - const me = $employeeAccountByIdStore.get(getCurrentAccount()._id as Ref<EmployeeAccount>)?.employee - const canDelete = (creators.length === 1 && creators.includes(me)) || (me && owners.includes(me)) - const label = canDelete ? view.string.DeleteObject : view.string.DeletePopupNoPermissionTitle + $: creators = [...new Set(objectArray.map((obj) => obj.createdBy as Ref<EmployeeAccount>))] + $: canDelete = + (creators.length === 1 && creators.includes(getCurrentAccount()._id as Ref<EmployeeAccount>)) || + getCurrentAccount().role === AccountRole.Owner + $: label = canDelete ? view.string.DeleteObject : view.string.DeletePopupNoPermissionTitle </script> -<Card {label} okAction={deleteAction} canSave={canDelete} okLabel={ui.string.Ok} on:close={() => dispatch('close')}> +<Card + {label} + okAction={deleteAction} + canSave={canDelete} + okLabel={canDelete ? view.string.LabelYes : ui.string.Ok} + on:close={() => dispatch('close')} +> + <svelte:fragment slot="buttons"> + {#if canDelete} + <Button label={view.string.LabelNo} on:click={() => dispatch('close')} /> + {/if} + </svelte:fragment> <div class="flex-grow flex-col"> {#if canDelete} <div class="mb-2"> @@ -58,17 +60,17 @@ </div> <div class="mb-2"> <Label label={view.string.DeletePopupCreatorLabel} /> - {#each creators as employee} + {#each creators as account} <div class="my-2"> - <EmployeePresenter value={employee} /> + <EmployeeAccountRefPresenter value={account} /> </div> {/each} </div> <div class="mb-2"> <Label label={view.string.DeletePopupOwnerLabel} /> - {#each owners as employee} + {#each owners as owner} <div class="my-2"> - <EmployeePresenter value={employee} /> + <EmployeeAccountPresenter value={owner} /> </div> {/each} </div> diff --git a/tests/sanity/tests/contacts.spec.ts b/tests/sanity/tests/contacts.spec.ts index 5e225801282..74966c63a7e 100644 --- a/tests/sanity/tests/contacts.spec.ts +++ b/tests/sanity/tests/contacts.spec.ts @@ -96,7 +96,7 @@ test.describe('contact tests', () => { }) await page.click('text="Delete"') // Click text=Ok - await page.click('text=Ok') + await page.click('text=Yes') await expect(page.locator(`td:has-text("${first} ${last}")`)).toHaveCount(0) })