From 424f98961f591798449cddf6f6cb0183485bf5f0 Mon Sep 17 00:00:00 2001 From: Luca Stauble Date: Tue, 23 May 2023 09:13:47 +0200 Subject: [PATCH] fix: fix the folder selector filter behaviour --- src/ui-actions/move-conv-msg.jsx | 6 +- src/views/sidebar/commons/folder-selector.tsx | 2 +- .../commons/tests/folder-selector.test.tsx | 61 +++++++++++++++++++ .../edit/modal-accordion-custom-component.tsx | 2 - translations/de.json | 2 +- translations/en.json | 4 +- translations/es.json | 2 +- translations/fr.json | 2 +- translations/hi.json | 2 +- translations/id.json | 2 +- translations/it.json | 2 +- translations/ja.json | 2 +- translations/nl.json | 2 +- translations/pl.json | 2 +- translations/pt.json | 2 +- translations/pt_BR.json | 2 +- translations/ru.json | 2 +- translations/th.json | 2 +- translations/tr.json | 2 +- translations/vi.json | 2 +- translations/zh_Hans.json | 2 +- 21 files changed, 85 insertions(+), 22 deletions(-) diff --git a/src/ui-actions/move-conv-msg.jsx b/src/ui-actions/move-conv-msg.jsx index b023399bc..1e1324768 100644 --- a/src/ui-actions/move-conv-msg.jsx +++ b/src/ui-actions/move-conv-msg.jsx @@ -172,10 +172,12 @@ const MoveConvMessage = ({ if (isRestore) { return t('label.restore', 'Restore'); } - return t('folder_panel.modal.move.title_modal', 'Move Conversation'); + return isMessageView + ? t('folder_panel.modal.move.title_modal_message', 'Move Message') + : t('folder_panel.modal.move.title_modal_conversation', 'Move Conversation'); } return t('folder_panel.modal.new.title', 'Create a new folder'); - }, [isRestore, moveConvModal]); + }, [isMessageView, isRestore, moveConvModal]); const footerConfirm = useMemo(() => { if (moveConvModal) { diff --git a/src/views/sidebar/commons/folder-selector.tsx b/src/views/sidebar/commons/folder-selector.tsx index 37e25fed6..a0c1c2870 100644 --- a/src/views/sidebar/commons/folder-selector.tsx +++ b/src/views/sidebar/commons/folder-selector.tsx @@ -73,7 +73,7 @@ export const FolderSelector = ({ result.push({ ...item, - name: FOLDERS.USER_ROOT ? accountName : item.name, + name: item.id === FOLDERS.USER_ROOT ? accountName : item.name, // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore CustomComponent: ModalAccordionCustomComponent, diff --git a/src/views/sidebar/commons/tests/folder-selector.test.tsx b/src/views/sidebar/commons/tests/folder-selector.test.tsx index c67593a93..b115de103 100644 --- a/src/views/sidebar/commons/tests/folder-selector.test.tsx +++ b/src/views/sidebar/commons/tests/folder-selector.test.tsx @@ -8,6 +8,7 @@ import React from 'react'; import { screen } from '@testing-library/react'; import { Folder, useFoldersByView } from '@zextras/carbonio-shell-ui'; import { + getFolder, getFoldersArray, getFoldersArrayByRoot, getRootsArray, @@ -66,4 +67,64 @@ describe('Folder selector', () => { } ); }); + + describe('Filter', () => { + test('if the user type "inbox" in the filter only the Inbox folder is displayed', async () => { + populateFoldersStore(); + + const props: FolderSelectorProps = { + folderId: FOLDERS.INBOX, + folderDestination: undefined, + setFolderDestination: jest.fn() + }; + const { user } = setupTest(, { store }); + const filterInput = screen.getByTestId('folder-name-filter'); + await user.type(filterInput, 'inbox'); + const accordionItems = screen.queryAllByTestId(/^folder-accordion-item-/); + expect(accordionItems.length).toBe(1); + expect(screen.getByTestId(`folder-accordion-item-${FOLDERS.INBOX}`)).toBeVisible(); + }); + + test('if the user type "INBOX" in the filter only the Inbox folder is displayed', async () => { + populateFoldersStore(); + + const props: FolderSelectorProps = { + folderId: FOLDERS.INBOX, + folderDestination: undefined, + setFolderDestination: jest.fn() + }; + const { user } = setupTest(, { store }); + const filterInput = screen.getByTestId('folder-name-filter'); + await user.type(filterInput, 'INBOX'); + const accordionItems = screen.queryAllByTestId(/^folder-accordion-item-/); + expect(accordionItems.length).toBe(1); + expect(screen.getByTestId(`folder-accordion-item-${FOLDERS.INBOX}`)).toBeVisible(); + }); + + test('if the user type an Inbox subfolder name in the filter that subfolder is displayed', async () => { + populateFoldersStore(); + + const inboxFolder = getFolder(FOLDERS.INBOX); + if (!inboxFolder) { + return; + } + + const { children: inboxChildren } = inboxFolder; + if (!inboxChildren.length) { + return; + } + + const inboxFirstChild = inboxChildren[0]; + + const props: FolderSelectorProps = { + folderId: FOLDERS.INBOX, + folderDestination: undefined, + setFolderDestination: jest.fn() + }; + const { user } = setupTest(, { store }); + const filterInput = screen.getByTestId('folder-name-filter'); + await user.type(filterInput, inboxFirstChild.name); + expect(screen.getByTestId(`folder-accordion-item-${inboxFirstChild.id}`)).toBeVisible(); + }); + }); }); diff --git a/src/views/sidebar/parts/edit/modal-accordion-custom-component.tsx b/src/views/sidebar/parts/edit/modal-accordion-custom-component.tsx index e7ce26059..cda0aef99 100644 --- a/src/views/sidebar/parts/edit/modal-accordion-custom-component.tsx +++ b/src/views/sidebar/parts/edit/modal-accordion-custom-component.tsx @@ -47,8 +47,6 @@ const getFolderAbsPathParts = (folder: Folder): Array => { return matches[1].split('/'); }; -const CustomBreadcrumbs = styled(Breadcrumbs)``; - const ModalAccordionCustomComponent: FC<{ item: Folder; }> = ({ item }) => { diff --git a/translations/de.json b/translations/de.json index 580e8b82b..577797dd0 100644 --- a/translations/de.json +++ b/translations/de.json @@ -676,7 +676,7 @@ "message1": "Einen Ordner als Ziel zum Verschieben aussuchen:", "message2": "Wählen Sie einen Ordner für die Wiederherstellung aus:" }, - "title_modal": "Unterhaltung verschieben" + "title_modal_conversation": "Unterhaltung verschieben" } }, "action": { diff --git a/translations/en.json b/translations/en.json index 99cf68956..c2fd292a4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -177,7 +177,9 @@ "message1": "Select a folder to move the considered one to:", "message2": "Select a folder to restore to:" }, - "title_modal": "Move Conversation" + "title_modal": "Move Conversation", + "title_modal_conversation": "Move Conversation", + "title_modal_message": "Move Message" }, "new": { "create_footer": "Create and Move", diff --git a/translations/es.json b/translations/es.json index bb8b6b4be..071bd2dfd 100644 --- a/translations/es.json +++ b/translations/es.json @@ -671,7 +671,7 @@ "message1": "Elige la carpeta hacia donde moverás la seleccionada:", "message2": "Selecciona la carpeta en dónde quieres restaurar:" }, - "title_modal": "Selecciona la carpeta de destino" + "title_modal_conversation": "Selecciona la carpeta de destino" }, "wipe": { "body": { diff --git a/translations/fr.json b/translations/fr.json index e5174a249..49d909c46 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -701,7 +701,7 @@ }, "modal": { "move": { - "title_modal": "Déplacer la Conversation", + "title_modal_conversation": "Déplacer la Conversation", "body": { "message1": "Sélectionnez un dossier dans lequel le déplacer :", "message2": "Sélectionnez un dossier à restaurer dans :" diff --git a/translations/hi.json b/translations/hi.json index cfd9ce39a..aaa5414a2 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -658,7 +658,7 @@ "name_exist_warning": "नाम पहले से मौजूद है" }, "move": { - "title_modal": "बात-चीत भेजें", + "title_modal_conversation": "बात-चीत भेजें", "body": { "message1": "चुने गए को भेजने के लिए कोई फोल्डर चुनें:", "message2": "वापस ले जाने के लिए कोई फोल्डर चुनें:" diff --git a/translations/id.json b/translations/id.json index 68dda40f7..503b99dcd 100644 --- a/translations/id.json +++ b/translations/id.json @@ -654,7 +654,7 @@ "name_exist_warning": "Nama sudah ada" }, "move": { - "title_modal": "Pindahkan Percakapan", + "title_modal_conversation": "Pindahkan Percakapan", "body": { "message1": "Pilih satu folder sebagai tempat memindahkan file yang diinginkan:", "message2": "Pilih folder sebagai tujuan pemulihan:" diff --git a/translations/it.json b/translations/it.json index a43032723..ef446fac2 100644 --- a/translations/it.json +++ b/translations/it.json @@ -722,7 +722,7 @@ } }, "move": { - "title_modal": "Sposta Conversazione", + "title_modal_conversation": "Sposta Conversazione", "body": { "message1": "Seleziona una cartella in cui spostare quella selezionata:", "message2": "Seleziona la cartella da ripristinare in:" diff --git a/translations/ja.json b/translations/ja.json index 0bdc20147..957d68993 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -637,7 +637,7 @@ } }, "move": { - "title_modal": "会話を移動する", + "title_modal_conversation": "会話を移動する", "body": { "message1": "検討対象のフォルダを次の場所に移動するフォルダを選択します:", "message2": "復元するフォルダを選択します:" diff --git a/translations/nl.json b/translations/nl.json index 065dcbfb7..dfa7c5575 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -666,7 +666,7 @@ "name_exist_warning": "Naam bestaat al" }, "move": { - "title_modal": "Gesprek verplaatsen", + "title_modal_conversation": "Gesprek verplaatsen", "body": { "message1": "Selecteer een map om de overwogene naar te verplaatsen:", "message2": "Selecteer een map om naar te herstellen:" diff --git a/translations/pl.json b/translations/pl.json index 457dee892..1518079dd 100644 --- a/translations/pl.json +++ b/translations/pl.json @@ -454,7 +454,7 @@ } }, "move": { - "title_modal": "Przenieś Konwersację", + "title_modal_conversation": "Przenieś Konwersację", "body": { "message1": "Wybierz folder, do którego chcesz przenieść wybrany element:", "message2": "Wybierz folder, do którego trafią przywrócone elementy:" diff --git a/translations/pt.json b/translations/pt.json index 075f8bb60..315e1a1be 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -670,7 +670,7 @@ "message1": "Selecione uma pasta onde mover a selecionada:", "message2": "Selecione uma pasta para restaurar:" }, - "title_modal": "Selecione a pasta de destino" + "title_modal_conversation": "Selecione a pasta de destino" }, "wipe": { "body": { diff --git a/translations/pt_BR.json b/translations/pt_BR.json index 4f5b1c04e..4787f25ad 100644 --- a/translations/pt_BR.json +++ b/translations/pt_BR.json @@ -672,7 +672,7 @@ "message1": "Selecione uma pasta onde mover a selecionada:", "message2": "Selecione uma pasta para restaurar:" }, - "title_modal": "Selecione a pasta de destino" + "title_modal_conversation": "Selecione a pasta de destino" }, "wipe": { "body": { diff --git a/translations/ru.json b/translations/ru.json index cf84182fd..594e9f593 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -712,7 +712,7 @@ }, "modal": { "move": { - "title_modal": "Перенести разговор", + "title_modal_conversation": "Перенести разговор", "body": { "message1": "Выберите папку, в которую нужно переместить эту:", "message2": "Выберите папку для восстановления:" diff --git a/translations/th.json b/translations/th.json index 84cab3f85..88fa5696b 100644 --- a/translations/th.json +++ b/translations/th.json @@ -658,7 +658,7 @@ "message1": "เลือกโฟลเดอร์เพื่อย้ายไปที่:", "message2": "เลือกโฟลเดอร์เพื่อกู้คืนไปที่:" }, - "title_modal": "ย้ายการสนทนา" + "title_modal_conversation": "ย้ายการสนทนา" }, "wipe": { "body": { diff --git a/translations/tr.json b/translations/tr.json index a9df95ba6..794eacffa 100644 --- a/translations/tr.json +++ b/translations/tr.json @@ -702,7 +702,7 @@ "title": "Yeni klasör oluştur" }, "move": { - "title_modal": "Görüşmeyi taşı", + "title_modal_conversation": "Görüşmeyi taşı", "body": { "message1": "İçine taşınmasını istediğiniz bir klasör seçin:", "message2": "İçine geri yüklemek istediğiniz bir klasör seçin:" diff --git a/translations/vi.json b/translations/vi.json index 6bc509921..4305a0cd0 100644 --- a/translations/vi.json +++ b/translations/vi.json @@ -662,7 +662,7 @@ "message1": "Chọn một thư mục mà bạn cân nhắc:", "message2": "Chọn một thư mục để khôi phục:" }, - "title_modal": "Di chuyển cuộc trò chuyện" + "title_modal_conversation": "Di chuyển cuộc trò chuyện" }, "empty": { "body": { diff --git a/translations/zh_Hans.json b/translations/zh_Hans.json index 041c5ed02..62c3c4c90 100644 --- a/translations/zh_Hans.json +++ b/translations/zh_Hans.json @@ -633,7 +633,7 @@ "message1": "选择文件夹以将其移动至:", "message2": "选择要恢复至的文件夹:" }, - "title_modal": "移动会话" + "title_modal_conversation": "移动会话" }, "new": { "create_footer": "创建和移动",