From a0f6d7444a3b48df8fc03484bed46ce012aa77b5 Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Tue, 9 Jul 2024 05:42:12 +0200 Subject: [PATCH] feat(web): improve show & hide people accessibility (#10954) --- .../manage-people-visibility.spec.ts | 32 +++++++++---------- .../manage-people-visibility.svelte | 26 +++++++++------ web/src/lib/i18n/en.json | 5 ++- web/src/routes/(user)/people/+page.svelte | 8 +++-- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/web/src/lib/components/faces-page/manage-people-visibility.spec.ts b/web/src/lib/components/faces-page/manage-people-visibility.spec.ts index e9120553ae..a6ad24ac2c 100644 --- a/web/src/lib/components/faces-page/manage-people-visibility.spec.ts +++ b/web/src/lib/components/faces-page/manage-people-visibility.spec.ts @@ -3,6 +3,7 @@ import ManagePeopleVisibility from '$lib/components/faces-page/manage-people-vis import type { PersonResponseDto } from '@immich/sdk'; import { personFactory } from '@test-data/factories/person-factory'; import { render } from '@testing-library/svelte'; +import { tick } from 'svelte'; describe('ManagePeopleVisibility Component', () => { let personVisible: PersonResponseDto; @@ -48,10 +49,8 @@ describe('ManagePeopleVisibility Component', () => { }, }); - const toggleButton = getByTitle('toggle_visibility'); - toggleButton.click(); - const saveButton = getByText('done'); - saveButton.click(); + getByTitle('hide_unnamed_people').click(); + getByText('done').click(); expect(sdkMock.updatePeople).toHaveBeenCalledWith({ peopleUpdateDto: { @@ -60,7 +59,7 @@ describe('ManagePeopleVisibility Component', () => { }); }); - it('hides all people on second button press', () => { + it('hides all people on second button press', async () => { const { getByText, getByTitle } = render(ManagePeopleVisibility, { props: { people: [personVisible, personHidden, personWithoutName], @@ -68,11 +67,10 @@ describe('ManagePeopleVisibility Component', () => { }, }); - const toggleButton = getByTitle('toggle_visibility'); - toggleButton.click(); - toggleButton.click(); - const saveButton = getByText('done'); - saveButton.click(); + getByTitle('hide_unnamed_people').click(); + await tick(); + getByTitle('hide_all_people').click(); + getByText('done').click(); expect(sdkMock.updatePeople).toHaveBeenCalledWith({ peopleUpdateDto: { @@ -84,7 +82,7 @@ describe('ManagePeopleVisibility Component', () => { }); }); - it('shows all people on third button press', () => { + it('shows all people on third button press', async () => { const { getByText, getByTitle } = render(ManagePeopleVisibility, { props: { people: [personVisible, personHidden, personWithoutName], @@ -92,12 +90,12 @@ describe('ManagePeopleVisibility Component', () => { }, }); - const toggleButton = getByTitle('toggle_visibility'); - toggleButton.click(); - toggleButton.click(); - toggleButton.click(); - const saveButton = getByText('done'); - saveButton.click(); + getByTitle('hide_unnamed_people').click(); + await tick(); + getByTitle('hide_all_people').click(); + await tick(); + getByTitle('show_all_people').click(); + getByText('done').click(); expect(sdkMock.updatePeople).toHaveBeenCalledWith({ peopleUpdateDto: { diff --git a/web/src/lib/components/faces-page/manage-people-visibility.svelte b/web/src/lib/components/faces-page/manage-people-visibility.svelte index 8744950111..1fa9ea5b9b 100644 --- a/web/src/lib/components/faces-page/manage-people-visibility.svelte +++ b/web/src/lib/components/faces-page/manage-people-visibility.svelte @@ -25,12 +25,13 @@ export let people: PersonResponseDto[]; export let onClose: () => void; + export let titleId: string | undefined = undefined; let toggleVisibility = ToggleVisibility.SHOW_ALL; let showLoadingSpinner = false; $: personIsHidden = getPersonIsHidden(people); - $: toggleIcon = toggleIconOptions[toggleVisibility]; + $: toggleButton = toggleButtonOptions[getNextVisibility(toggleVisibility)]; const getPersonIsHidden = (people: PersonResponseDto[]) => { const personIsHidden: Record = {}; @@ -40,11 +41,13 @@ return personIsHidden; }; - const toggleIconOptions: Record = { - [ToggleVisibility.HIDE_ALL]: mdiEyeOff, - [ToggleVisibility.HIDE_UNNANEMD]: mdiEyeSettings, - [ToggleVisibility.SHOW_ALL]: mdiEye, - }; + $: toggleButtonOptions = ((): Record => { + return { + [ToggleVisibility.HIDE_ALL]: { icon: mdiEyeOff, label: $t('hide_all_people') }, + [ToggleVisibility.HIDE_UNNANEMD]: { icon: mdiEyeSettings, label: $t('hide_unnamed_people') }, + [ToggleVisibility.SHOW_ALL]: { icon: mdiEye, label: $t('show_all_people') }, + }; + })(); const getNextVisibility = (toggleVisibility: ToggleVisibility) => { if (toggleVisibility === ToggleVisibility.SHOW_ALL) { @@ -117,14 +120,14 @@
-

{$t('show_and_hide_people')}

+

{$t('show_and_hide_people')}

({people.length.toLocaleString($locale)})

- +
{#if !showLoadingSpinner} @@ -137,14 +140,17 @@
{#each people as person, index (person.id)} + {@const hidden = personIsHidden[person.id]}