From 803f4680e953a3e1e0e5569d4afd5f9fa0d4e694 Mon Sep 17 00:00:00 2001 From: huy Date: Mon, 20 Feb 2023 12:44:44 +0700 Subject: [PATCH] #195: move to folder --- src/components/MoveToFolder/index.jsx | 167 ++++++++++++------ src/components/MoveToFolder/index.module.scss | 13 ++ src/components/Table/Thumb.jsx | 6 +- src/scss/utils/utilities.scss | 1 + src/scss/utils/variables.scss | 9 +- src/store/DamStore/DamListViewModel.js | 3 +- src/themes/index.scss | 8 +- src/translations/dk/common.json | 3 +- src/translations/en/common.json | 3 +- src/translations/es/common.json | 3 +- src/translations/fr/common.json | 3 +- src/translations/hr/common.json | 3 +- src/translations/th/common.json | 3 +- src/translations/ua/common.json | 3 +- src/translations/vi/common.json | 3 +- 15 files changed, 156 insertions(+), 75 deletions(-) diff --git a/src/components/MoveToFolder/index.jsx b/src/components/MoveToFolder/index.jsx index 19c25240..5ad0f0c7 100644 --- a/src/components/MoveToFolder/index.jsx +++ b/src/components/MoveToFolder/index.jsx @@ -1,26 +1,49 @@ -import { faArrowLeft, faArrowRight, faFolder } from '@fortawesome/free-solid-svg-icons'; +import { + faAngleRight, + faArrowLeft, + faFolder as faFolderSolid, +} from '@fortawesome/free-solid-svg-icons'; +import { faFolder } from '@fortawesome/free-regular-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { observer } from 'mobx-react'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useMemo, useState } from 'react'; import { OverlayTrigger, Tooltip } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; import { useDamViewModel } from 'store/DamStore/DamViewModelContextProvider'; import styles from './index.module.scss'; +import { DAM_ASSETS_FIELD_KEY } from 'aesirx-dma-lib'; let moveToFolder_timer = 0; let moveToFolder_delay = 200; let moveToFolder_prevent = false; const MoveToFolder = observer(({ current = 0 }) => { - const [currentCollection, setCurrentCollection] = useState(current); + const [currentCollection, setCurrentCollection] = useState(0); const [selectCollection, setSelectCollection] = useState(null); - const { collections = [], moveToFolder } = useDamViewModel().getDamListViewModel(); - const { closeMoveToFolder } = useDamViewModel().getDamFormViewModel(); + const { + damListViewModel: { + collections = [], + moveToFolder, + actionState: { selectedCards }, + }, + damFormViewModel: { closeMoveToFolder }, + } = useDamViewModel(); const { t } = useTranslation('common'); + + const mapDataSelectCards = useMemo( + () => selectedCards.map((selectedItem) => +selectedItem?.id) ?? [], + [selectedCards] + ); + + const isNoCollection = useMemo( + () => selectedCards.filter((selectedItem) => !selectedItem?.[DAM_ASSETS_FIELD_KEY.TYPE]) ?? [], + [selectedCards] + ); + console.log(isNoCollection); useEffect(() => { if (current) { const currentItem = collections.find((collection) => +collection.id === +current); - if (currentItem) { + if (currentItem?.id) { setCurrentCollection(currentItem); } } @@ -30,18 +53,19 @@ const MoveToFolder = observer(({ current = 0 }) => { const goToFolder = (curretnId) => { if (curretnId) { setCurrentCollection(curretnId); + setSelectCollection(curretnId); } else { const backCollection = collections.find( (collection) => +collection.id === currentCollection?.parent_id ); if (backCollection) { setCurrentCollection(backCollection); + setSelectCollection(backCollection); } else { setCurrentCollection(0); + setSelectCollection(0); } } - - setSelectCollection(null); }; const onSelect = (collection) => { @@ -49,64 +73,93 @@ const MoveToFolder = observer(({ current = 0 }) => { if (prevState === collection?.id) { return null; } - return collection.id; + return collection; }); }; const moveTo = () => { if (selectCollection) { - moveToFolder('', selectCollection); + moveToFolder(null, selectCollection?.id); } else { - if (currentCollection?.id) { - moveToFolder('', currentCollection.id); - } else { - moveToFolder('', 0); - } + moveToFolder(null, 0); } + closeMoveToFolder(); }; return ( -
+
goToFolder()} - className={`text-body cursor-pointer ${!currentCollection && 'pe-none opacity-0'}`} + className={`text-gray-dark cursor-pointer ${ + !currentCollection ? 'pe-none opacity-0' : null + }`} icon={faArrowLeft} /> -

{t('txt_move_to_folder')}

+

{t('txt_move_to_folder')}

{collections.map((collection, index) => { - if (+collection.parent_id === (currentCollection.id ? +currentCollection.id : 0)) { + if (+collection?.parent_id === (currentCollection.id ? +currentCollection.id : 0)) { return ( collection?.name && ( -

{ - clearTimeout(moveToFolder_timer); - moveToFolder_prevent = true; - goToFolder(collection); - }} - onClick={() => { - moveToFolder_timer = setTimeout(function () { - if (!moveToFolder_prevent) { - onSelect(collection); - } - moveToFolder_prevent = false; - }, moveToFolder_delay); - }} + placement={'bottom'} + overlay={ + + {t('txt_can_not_move_to_itself')} + + } > - <> - - {collection.name} - - -

+ + + + ) ); } @@ -122,25 +175,31 @@ const MoveToFolder = observer(({ current = 0 }) => { overlay={ - {t('txt_item_aldready_in_this_folder')} + {t('txt_item_already_in_this_folder')} } >