diff --git a/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js b/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js index 876241a35a..26beec4ecd 100644 --- a/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js +++ b/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js @@ -4,7 +4,6 @@ import styled from 'styled-components'; import { useIntl } from 'react-intl'; import { Button } from '@strapi/design-system/Button'; import { Flex } from '@strapi/design-system/Flex'; -import { Stack } from '@strapi/design-system/Stack'; import { Box } from '@strapi/design-system/Box'; import { Divider } from '@strapi/design-system/Divider'; import { BaseCheckbox } from '@strapi/design-system/BaseCheckbox'; @@ -17,11 +16,14 @@ import PlusIcon from '@strapi/icons/Plus'; import { FolderDefinition, AssetDefinition } from '../../../constants'; import getTrad from '../../../utils/getTrad'; +import { getBreadcrumbDataCM } from '../../../utils'; import getAllowedFiles from '../../../utils/getAllowedFiles'; import { AssetList } from '../../AssetList'; import { FolderList } from '../../FolderList'; import { EmptyAssets } from '../../EmptyAssets'; +import { Breadcrumbs } from '../../Breadcrumbs'; import SortPicker from '../../SortPicker'; +import { useFolder } from '../../../hooks/useFolder'; import { FolderCard, FolderCardBody, FolderCardBodyAction } from '../../FolderCard'; import { Filters } from './Filters'; import PaginationFooter from './PaginationFooter'; @@ -32,7 +34,6 @@ const StartBlockActions = styled(Flex)` & > * + * { margin-left: ${({ theme }) => theme.spaces[2]}; } - margin-left: ${({ pullRight }) => (pullRight ? 'auto' : undefined)}; `; @@ -48,6 +49,7 @@ export const BrowseStep = ({ allowedTypes, assets, canCreate, + canRead, folders, multiple, onAddAsset, @@ -66,6 +68,16 @@ export const BrowseStep = ({ selectedAssets, }) => { const { formatMessage } = useIntl(); + + const { data: currentFolder, isLoading: isCurrentFolderLoading } = useFolder( + queryObject?.folder, + { + enabled: canRead && !!queryObject?.folder, + } + ); + + const breadcrumbs = !isCurrentFolderLoading && getBreadcrumbDataCM(currentFolder); + const allAllowedAsset = getAllowedFiles(allowedTypes, assets); const areAllAssetSelected = allAllowedAsset.every( @@ -79,7 +91,6 @@ export const BrowseStep = ({ const isSearchingOrFiltering = isSearching || isFiltering; const assetCount = assets.length; const folderCount = folders.length; - const handleClickFolderCard = (...args) => { // Search query will always fetch the same results // we remove it here to allow navigating in a folder and see the result of this navigation @@ -88,48 +99,58 @@ export const BrowseStep = ({ }; return ( - + {onSelectAllAsset && ( - - - {(assetCount > 0 || folderCount > 0 || isFiltering) && ( - - {multiple && ( - - - - )} - - - - )} + + {(assetCount > 0 || folderCount > 0 || isFiltering) && ( + + {multiple && ( + + + + )} + + + + )} - {(assetCount > 0 || folderCount > 0 || isSearching) && ( - - - - )} - - + {(assetCount > 0 || folderCount > 0 || isSearching) && ( + + + + )} + + + )} + + {canRead && !isCurrentFolderLoading && ( + + )} @@ -175,10 +196,13 @@ export const BrowseStep = ({ 0) || !isSearchingOrFiltering) && - formatMessage({ - id: getTrad('list.folders.title'), - defaultMessage: 'Folders', - })) || + formatMessage( + { + id: getTrad('list.folders.title'), + defaultMessage: 'Folders ({count})', + }, + { count: folderCount } + )) || '' } > @@ -209,7 +233,6 @@ export const BrowseStep = ({ {folder.name} : - {formatMessage( { @@ -234,33 +257,38 @@ export const BrowseStep = ({ )} {assetCount > 0 && folderCount > 0 && ( - + )} {assetCount > 0 && ( - 0)) && - queryObject.page === 1 && - formatMessage({ - id: getTrad('list.assets.title'), - defaultMessage: 'Assets', - })) || - '' - } - /> + + 0)) && + queryObject.page === 1 && + formatMessage( + { + id: getTrad('list.assets.title'), + defaultMessage: 'Assets ({count})', + }, + { count: assetCount } + )) || + '' + } + /> + )} {pagination.pageCount > 0 && ( - + )} - + ); }; @@ -281,11 +309,11 @@ BrowseStep.defaultProps = { onEditAsset: undefined, onEditFolder: undefined, }; - BrowseStep.propTypes = { allowedTypes: PropTypes.arrayOf(PropTypes.string), assets: PropTypes.arrayOf(AssetDefinition).isRequired, canCreate: PropTypes.bool.isRequired, + canRead: PropTypes.bool.isRequired, folders: PropTypes.arrayOf(FolderDefinition), multiple: PropTypes.bool, onAddAsset: PropTypes.func.isRequired, @@ -304,6 +332,7 @@ BrowseStep.propTypes = { page: PropTypes.number.isRequired, pageSize: PropTypes.number.isRequired, _q: PropTypes.string, + folder: PropTypes.number, }).isRequired, pagination: PropTypes.shape({ pageCount: PropTypes.number.isRequired }).isRequired, selectedAssets: PropTypes.arrayOf(PropTypes.shape({})).isRequired, diff --git a/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/tests/__snapshots__/index.test.js.snap b/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/tests/__snapshots__/index.test.js.snap index c46ff03d8e..faa5f1ef33 100644 --- a/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/tests/__snapshots__/index.test.js.snap +++ b/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/tests/__snapshots__/index.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`BrowseStep renders and match snapshot 1`] = ` -.c74 { +.c78 { border: 0; -webkit-clip: rect(0 0 0 0); clip: rect(0 0 0 0); @@ -13,18 +13,50 @@ exports[`BrowseStep renders and match snapshot 1`] = ` width: 1px; } -.c19 { +.c22 { + padding-top: 12px; +} + +.c28 { + padding-top: 8px; + padding-bottom: 8px; +} + +.c32 { + position: relative; +} + +.c37 { + background: #eaf5ff; + color: #66b7f1; + padding-top: 8px; + padding-right: 12px; + padding-bottom: 8px; + padding-left: 12px; + border-radius: 4px; +} + +.c42 { + padding: 4px; + max-width: 100%; +} + +.c69 { + padding-left: 8px; +} + +.c16 { font-weight: 600; color: #32324d; font-size: 0.75rem; line-height: 1.33; } -.c16 { +.c13 { padding-right: 8px; } -.c13 { +.c10 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -38,21 +70,21 @@ exports[`BrowseStep renders and match snapshot 1`] = ` outline: none; } -.c13 svg { +.c10 svg { height: 12px; width: 12px; } -.c13 svg > g, -.c13 svg path { +.c10 svg > g, +.c10 svg path { fill: #ffffff; } -.c13[aria-disabled='true'] { +.c10[aria-disabled='true'] { pointer-events: none; } -.c13:after { +.c10:after { -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: 0.2s; @@ -67,11 +99,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid transparent; } -.c13:focus-visible { +.c10:focus-visible { outline: none; } -.c13:focus-visible:after { +.c10:focus-visible:after { border-radius: 8px; content: ''; position: absolute; @@ -82,11 +114,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid #4945ff; } -.c17 { +.c14 { height: 100%; } -.c14 { +.c11 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -98,7 +130,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` background: #ffffff; } -.c14 .c15 { +.c11 .c12 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -109,66 +141,70 @@ exports[`BrowseStep renders and match snapshot 1`] = ` align-items: center; } -.c14 .c18 { +.c11 .c15 { color: #ffffff; } -.c14[aria-disabled='true'] { +.c11[aria-disabled='true'] { border: 1px solid #dcdce4; background: #eaeaef; } -.c14[aria-disabled='true'] .c18 { +.c11[aria-disabled='true'] .c15 { color: #666687; } -.c14[aria-disabled='true'] svg > g, -.c14[aria-disabled='true'] svg path { +.c11[aria-disabled='true'] svg > g, +.c11[aria-disabled='true'] svg path { fill: #666687; } -.c14[aria-disabled='true']:active { +.c11[aria-disabled='true']:active { border: 1px solid #dcdce4; background: #eaeaef; } -.c14[aria-disabled='true']:active .c18 { +.c11[aria-disabled='true']:active .c15 { color: #666687; } -.c14[aria-disabled='true']:active svg > g, -.c14[aria-disabled='true']:active svg path { +.c11[aria-disabled='true']:active svg > g, +.c11[aria-disabled='true']:active svg path { fill: #666687; } -.c14:hover { +.c11:hover { background-color: #f6f6f9; } -.c14:active { +.c11:active { background-color: #eaeaef; } -.c14 .c18 { +.c11 .c15 { color: #32324d; } -.c14 svg > g, -.c14 svg path { +.c11 svg > g, +.c11 svg path { fill: #32324d; } -.c36 { +.c39 { position: relative; overflow: hidden; max-width: 100%; } -.c41 { +.c44 { max-width: 100%; } -.c3 { +.c55 { + padding-top: 16px; +} + +.c0 { -webkit-align-items: flex-start; -webkit-box-align: flex-start; -ms-flex-align: flex-start; @@ -186,7 +222,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` justify-content: space-between; } -.c4 { +.c1 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -203,7 +239,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-wrap: wrap; } -.c20 { +.c17 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -217,7 +253,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: row; } -.c37 { +.c40 { -webkit-align-items: flex-start; -webkit-box-align: flex-start; -ms-flex-align: flex-start; @@ -231,7 +267,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: column; } -.c42 { +.c45 { -webkit-align-items: start; -webkit-box-align: start; -ms-flex-align: start; @@ -245,7 +281,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: column; } -.c52 { +.c56 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -263,162 +299,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` justify-content: space-between; } -.c31 { - background: #ffffff; - padding: 12px; - border-radius: 4px; - border-style: solid; - border-width: 1px; - border-color: #eaeaef; - box-shadow: 0px 1px 4px rgba(33,33,52,0.1); - cursor: pointer; - cursor: pointer; -} - -.c0 { - -webkit-align-items: stretch; - -webkit-box-align: stretch; - -ms-flex-align: stretch; - align-items: stretch; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; -} - -.c32 { - -webkit-align-items: center; - -webkit-box-align: center; - -ms-flex-align: center; - align-items: center; - display: -webkit-box; - display: -webkit-flex; - display: -ms-flexbox; - display: flex; - -webkit-flex-direction: row; - -ms-flex-direction: row; - flex-direction: row; -} - -.c1 > * { - margin-top: 0; - margin-bottom: 0; -} - -.c1 > * + * { - margin-top: 16px; -} - -.c33 > * { - margin-left: 0; - margin-right: 0; -} - -.c33 > * + * { - margin-left: 8px; -} - -.c2 { - padding-bottom: 16px; -} - -.c25 { - padding-top: 8px; - padding-bottom: 8px; -} - -.c29 { - position: relative; -} - -.c34 { - background: #eaf5ff; - color: #66b7f1; - padding-top: 8px; - padding-right: 12px; - padding-bottom: 8px; - padding-left: 12px; - border-radius: 4px; -} - -.c39 { - padding: 4px; - max-width: 100%; -} - -.c65 { - padding-left: 8px; -} - -.c27 { - display: grid; - grid-template-columns: repeat(12,1fr); - gap: 16px; -} - -.c28 { - grid-column: span 3; - max-width: 100%; -} - -.c26 { - font-weight: 500; - color: #32324d; - font-weight: 500; - font-size: 1rem; - line-height: 1.25; -} - -.c43 { - font-weight: 500; - color: #32324d; - display: block; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - font-size: 0.875rem; - line-height: 1.43; -} - -.c46 { - color: #666687; - display: block; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - font-size: 0.75rem; - line-height: 1.33; -} - -.c66 { - color: #666687; - font-size: 0.875rem; - line-height: 1.43; -} - -.c72 { - font-weight: 600; - color: #32324d; - font-size: 0.75rem; - line-height: 1.33; -} - -.c45 { - border: 0; - -webkit-clip: rect(0 0 0 0); - clip: rect(0 0 0 0); - height: 1px; - margin: -1px; - overflow: hidden; - padding: 0; - position: absolute; - width: 1px; -} - -.c23 { +.c20 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -432,21 +313,21 @@ exports[`BrowseStep renders and match snapshot 1`] = ` outline: none; } -.c23 svg { +.c20 svg { height: 12px; width: 12px; } -.c23 svg > g, -.c23 svg path { +.c20 svg > g, +.c20 svg path { fill: #ffffff; } -.c23[aria-disabled='true'] { +.c20[aria-disabled='true'] { pointer-events: none; } -.c23:after { +.c20:after { -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: 0.2s; @@ -461,11 +342,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid transparent; } -.c23:focus-visible { +.c20:focus-visible { outline: none; } -.c23:focus-visible:after { +.c20:focus-visible:after { border-radius: 8px; content: ''; position: absolute; @@ -476,7 +357,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid #4945ff; } -.c24 { +.c21 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -493,30 +374,30 @@ exports[`BrowseStep renders and match snapshot 1`] = ` width: 2rem; } -.c24 svg > g, -.c24 svg path { +.c21 svg > g, +.c21 svg path { fill: #8e8ea9; } -.c24:hover svg > g, -.c24:hover svg path { +.c21:hover svg > g, +.c21:hover svg path { fill: #666687; } -.c24:active svg > g, -.c24:active svg path { +.c21:active svg > g, +.c21:active svg path { fill: #a5a5ba; } -.c24[aria-disabled='true'] { +.c21[aria-disabled='true'] { background-color: #eaeaef; } -.c24[aria-disabled='true'] svg path { +.c21[aria-disabled='true'] svg path { fill: #666687; } -.c57 { +.c61 { position: absolute; left: 0; right: 0; @@ -527,24 +408,24 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: none; } -.c57:focus { +.c61:focus { outline: none; } -.c57[aria-disabled='true'] { +.c61[aria-disabled='true'] { cursor: not-allowed; } -.c60 { +.c64 { padding-right: 16px; padding-left: 16px; } -.c62 { +.c66 { padding-left: 12px; } -.c53 { +.c57 { -webkit-align-items: stretch; -webkit-box-align: stretch; -ms-flex-align: stretch; @@ -558,7 +439,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: column; } -.c55 { +.c59 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -572,7 +453,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: row; } -.c58 { +.c62 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -590,7 +471,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` justify-content: space-between; } -.c61 { +.c65 { color: #32324d; display: block; white-space: nowrap; @@ -600,12 +481,12 @@ exports[`BrowseStep renders and match snapshot 1`] = ` line-height: 1.43; } -.c54 > * { +.c58 > * { margin-top: 0; margin-bottom: 0; } -.c56 { +.c60 { position: relative; border: 1px solid #dcdce4; padding-right: 12px; @@ -621,28 +502,28 @@ exports[`BrowseStep renders and match snapshot 1`] = ` transition-duration: 0.2s; } -.c56:focus-within { +.c60:focus-within { border: 1px solid #4945ff; box-shadow: #4945ff 0px 0px 0px 2px; } -.c63 { +.c67 { background: transparent; border: none; position: relative; z-index: 1; } -.c63 svg { +.c67 svg { height: 0.6875rem; width: 0.6875rem; } -.c63 svg path { +.c67 svg path { fill: #666687; } -.c64 { +.c68 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -651,19 +532,27 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: none; } -.c64 svg { +.c68 svg { width: 0.375rem; } -.c59 { +.c63 { width: 100%; } -.c48 { - right: 16px; +.c34 { + background: #ffffff; + padding: 12px; + border-radius: 4px; + border-style: solid; + border-width: 1px; + border-color: #eaeaef; + box-shadow: 0px 1px 4px rgba(33,33,52,0.1); + cursor: pointer; + cursor: pointer; } -.c49 { +.c35 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -677,32 +566,168 @@ exports[`BrowseStep renders and match snapshot 1`] = ` flex-direction: row; } -.c50 > * { +.c36 > * { margin-left: 0; margin-right: 0; } -.c50 > * + * { +.c36 > * + * { margin-left: 8px; } -.c51 { - position: absolute; - top: 12px; +.c29 { + font-weight: 500; + color: #32324d; + font-weight: 500; + font-size: 1rem; + line-height: 1.25; } -.c9 { +.c46 { + font-weight: 500; + color: #32324d; + display: block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + font-size: 0.875rem; + line-height: 1.43; +} + +.c49 { + color: #666687; + display: block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + font-size: 0.75rem; + line-height: 1.33; +} + +.c70 { + color: #666687; + font-size: 0.875rem; + line-height: 1.43; +} + +.c76 { font-weight: 600; color: #32324d; font-size: 0.75rem; line-height: 1.33; } -.c11 { - padding-left: 8px; +.c48 { + border: 0; + -webkit-clip: rect(0 0 0 0); + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; +} + +.c30 { + display: grid; + grid-template-columns: repeat(12,1fr); + gap: 16px; +} + +.c31 { + grid-column: span 3; + max-width: 100%; +} + +.c51 { + right: 16px; +} + +.c52 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; +} + +.c53 > * { + margin-left: 0; + margin-right: 0; +} + +.c53 > * + * { + margin-left: 8px; +} + +.c54 { + position: absolute; + top: 12px; +} + +.c26 { + padding-right: 4px; + padding-left: 4px; +} + +.c27 { + font-weight: 600; + color: #32324d; + font-size: 0.75rem; + line-height: 1.33; +} + +.c23 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; +} + +.c25 { + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: -ms-inline-flexbox; + display: inline-flex; + -webkit-flex-direction: row; + -ms-flex-direction: row; + flex-direction: row; +} + +.c24:first-child { + margin-left: calc(-1*8px); } .c6 { + font-weight: 600; + color: #32324d; + font-size: 0.75rem; + line-height: 1.33; +} + +.c8 { + padding-left: 8px; +} + +.c3 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -716,21 +741,21 @@ exports[`BrowseStep renders and match snapshot 1`] = ` outline: none; } -.c6 svg { +.c3 svg { height: 12px; width: 12px; } -.c6 svg > g, -.c6 svg path { +.c3 svg > g, +.c3 svg path { fill: #ffffff; } -.c6[aria-disabled='true'] { +.c3[aria-disabled='true'] { pointer-events: none; } -.c6:after { +.c3:after { -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: 0.2s; @@ -745,11 +770,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid transparent; } -.c6:focus-visible { +.c3:focus-visible { outline: none; } -.c6:focus-visible:after { +.c3:focus-visible:after { border-radius: 8px; content: ''; position: absolute; @@ -760,7 +785,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid #4945ff; } -.c7 { +.c4 { -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; @@ -772,7 +797,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` background: #ffffff; } -.c7 .c10 { +.c4 .c7 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -783,56 +808,56 @@ exports[`BrowseStep renders and match snapshot 1`] = ` align-items: center; } -.c7 .c8 { +.c4 .c5 { color: #ffffff; } -.c7[aria-disabled='true'] { +.c4[aria-disabled='true'] { border: 1px solid #dcdce4; background: #eaeaef; } -.c7[aria-disabled='true'] .c8 { +.c4[aria-disabled='true'] .c5 { color: #666687; } -.c7[aria-disabled='true'] svg > g, -.c7[aria-disabled='true'] svg path { +.c4[aria-disabled='true'] svg > g, +.c4[aria-disabled='true'] svg path { fill: #666687; } -.c7[aria-disabled='true']:active { +.c4[aria-disabled='true']:active { border: 1px solid #dcdce4; background: #eaeaef; } -.c7[aria-disabled='true']:active .c8 { +.c4[aria-disabled='true']:active .c5 { color: #666687; } -.c7[aria-disabled='true']:active svg > g, -.c7[aria-disabled='true']:active svg path { +.c4[aria-disabled='true']:active svg > g, +.c4[aria-disabled='true']:active svg path { fill: #666687; } -.c7:hover { +.c4:hover { background-color: #f6f6f9; } -.c7:active { +.c4:active { background-color: #eaeaef; } -.c7 .c8 { +.c4 .c5 { color: #32324d; } -.c7 svg > g, -.c7 svg path { +.c4 svg > g, +.c4 svg path { fill: #32324d; } -.c12 { +.c9 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -843,12 +868,12 @@ exports[`BrowseStep renders and match snapshot 1`] = ` align-items: center; } -.c12 svg { +.c9 svg { height: 4px; width: 6px; } -.c30 { +.c33 { height: 100%; left: 0; position: absolute; @@ -857,41 +882,41 @@ exports[`BrowseStep renders and match snapshot 1`] = ` width: 100%; } -.c30:hover, -.c30:focus { +.c33:hover, +.c33:focus { -webkit-text-decoration: none; text-decoration: none; } -.c35 path { +.c38 path { fill: currentColor; } -.c47 { +.c50 { display: none; } -.c38 { +.c41 { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } -.c40:focus { +.c43:focus { outline: 2px solid #4945ff; outline-offset: -2px; } -.c67 > * + * { +.c71 > * + * { margin-left: 4px; } -.c73 { +.c77 { line-height: revert; } -.c68 { +.c72 { padding: 12px; border-radius: 4px; -webkit-text-decoration: none; @@ -904,7 +929,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` outline: none; } -.c68:after { +.c72:after { -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: 0.2s; @@ -919,11 +944,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid transparent; } -.c68:focus-visible { +.c72:focus-visible { outline: none; } -.c68:focus-visible:after { +.c72:focus-visible:after { border-radius: 8px; content: ''; position: absolute; @@ -934,7 +959,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid #4945ff; } -.c70 { +.c74 { padding: 12px; border-radius: 4px; box-shadow: 0px 1px 4px rgba(33,33,52,0.1); @@ -948,7 +973,7 @@ exports[`BrowseStep renders and match snapshot 1`] = ` outline: none; } -.c70:after { +.c74:after { -webkit-transition-property: all; transition-property: all; -webkit-transition-duration: 0.2s; @@ -963,11 +988,11 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid transparent; } -.c70:focus-visible { +.c74:focus-visible { outline: none; } -.c70:focus-visible:after { +.c74:focus-visible:after { border-radius: 8px; content: ''; position: absolute; @@ -978,226 +1003,248 @@ exports[`BrowseStep renders and match snapshot 1`] = ` border: 2px solid #4945ff; } -.c71 { +.c75 { color: #271fe0; background: #ffffff; } -.c71:hover { +.c75:hover { box-shadow: 0px 1px 4px rgba(33,33,52,0.1); } -.c69 { +.c73 { font-size: 0.7rem; pointer-events: none; } -.c69 svg path { +.c73 svg path { fill: #c0c0cf; } -.c69:focus svg path, -.c69:hover svg path { +.c73:focus svg path, +.c73:hover svg path { fill: #c0c0cf; } -.c5 > * + * { +.c2 > * + * { margin-left: 8px; } -.c21 { +.c18 { margin-left: auto; } -.c21 > * + * { +.c18 > * + * { margin-left: 8px; } -.c22 { +.c19 { -webkit-flex-shrink: 0; -ms-flex-negative: 0; flex-shrink: 0; } -.c44 { +.c47 { max-width: 100%; } @media (max-width:68.75rem) { - .c28 { + .c31 { grid-column: span; } } @media (max-width:34.375rem) { - .c28 { + .c31 { grid-column: span; } }
-
-
- -
+
-
- - + + +
+ + Filters -
+ +
+
+ + +
+
+ +

- Folders + Folders (1)

@@ -1255,17 +1302,17 @@ exports[`BrowseStep renders and match snapshot 1`] = `

{ return ( - - - - - - - + + + + + {}}> + + + + + + ); }; const setup = props => render(); - describe('BrowseStep', () => { afterEach(() => { jest.clearAllMocks(); @@ -101,14 +115,12 @@ describe('BrowseStep', () => { it('renders and match snapshot', () => { const { container } = setup(); - expect(container).toMatchSnapshot(); }); it('calls onAddAsset callback', () => { const spy = jest.fn(); const { getByText } = setup({ onAddAsset: spy, folders: [] }); - fireEvent.click(getByText('Add new assets')); expect(spy).toHaveBeenCalled(); }); @@ -116,19 +128,16 @@ describe('BrowseStep', () => { it('calls onChangeFolder callback', () => { const spy = jest.fn(); const { getByRole } = setup({ onChangeFolder: spy }); - fireEvent.click( getByRole('button', { name: /folder 1 : 1 folder, 1 asset/i, }) ); - expect(spy).toHaveBeenCalled(); }); it('does display empty state upload first assets if no folder or assets', () => { setup({ folders: [], assets: [] }); - expect(screen.getByText('Upload your first assets...')).toBeInTheDocument(); }); @@ -138,7 +147,6 @@ describe('BrowseStep', () => { assets: [], queryObject: { page: 1, pageSize: 10, filters: { $and: [] }, _q: 'true' }, }); - expect(screen.getByText('There are no assets with the applied filters')).toBeInTheDocument(); }); @@ -148,7 +156,6 @@ describe('BrowseStep', () => { assets: [], queryObject: { page: 1, pageSize: 10, filters: { $and: [{ mime: 'audio' }] }, _q: '' }, }); - expect(screen.getByText('Filters')).toBeInTheDocument(); }); @@ -158,7 +165,6 @@ describe('BrowseStep', () => { assets: FIXTURE_ASSETS, queryObject: { page: 1, pageSize: 10, filters: { $and: [] }, _q: 'true' }, }); - expect(screen.queryByText('Assets')).not.toBeInTheDocument(); }); @@ -166,7 +172,6 @@ describe('BrowseStep', () => { setup({ queryObject: { page: 1, pageSize: 10, filters: { $and: [] }, _q: 'true' }, }); - expect(screen.queryByText('Folders')).not.toBeInTheDocument(); }); @@ -175,7 +180,7 @@ describe('BrowseStep', () => { assets: FIXTURE_ASSETS, }); - expect(screen.getByText('Folders')).toBeInTheDocument(); - expect(screen.getByText('Assets')).toBeInTheDocument(); + expect(screen.getByText('Folders (1)')).toBeInTheDocument(); + expect(screen.getByText('Assets (1)')).toBeInTheDocument(); }); }); diff --git a/packages/core/upload/admin/src/components/AssetDialog/DialogHeader.js b/packages/core/upload/admin/src/components/AssetDialog/DialogHeader.js deleted file mode 100644 index 2c1726d011..0000000000 --- a/packages/core/upload/admin/src/components/AssetDialog/DialogHeader.js +++ /dev/null @@ -1,91 +0,0 @@ -import React from 'react'; -import styled from 'styled-components'; -import PropTypes from 'prop-types'; -import { useIntl } from 'react-intl'; -import { Breadcrumbs, Crumb } from '@strapi/design-system/Breadcrumbs'; -import { ModalHeader } from '@strapi/design-system/ModalLayout'; -import { Stack } from '@strapi/design-system/Stack'; -import { Icon } from '@strapi/design-system/Icon'; -import ArrowLeft from '@strapi/icons/ArrowLeft'; -import { findRecursiveFolderMetadatas, getTrad } from '../../utils'; -import { useFolderStructure } from '../../hooks/useFolderStructure'; - -const BackButton = styled.button` - height: ${({ theme }) => theme.spaces[4]}; - color: ${({ theme }) => theme.colors.neutral500}; - - &:hover, - &:focus { - color: ${({ theme }) => theme.colors.neutral600}; - } -`; - -const BackIcon = styled(Icon)` - path { - fill: currentColor; - } -`; - -export const DialogHeader = ({ currentFolder, onChangeFolder, canRead }) => { - const { formatMessage } = useIntl(); - - const { data, isLoading } = useFolderStructure({ - enabled: canRead, - }); - - const folderMetadatas = - !isLoading && Array.isArray(data) && findRecursiveFolderMetadatas(data[0], currentFolder); - const folderLabel = - folderMetadatas?.currentFolderLabel && - (folderMetadatas.currentFolderLabel.length > 60 - ? `${folderMetadatas.currentFolderLabel.slice(0, 60)}...` - : folderMetadatas.currentFolderLabel); - - return ( - - - {currentFolder && ( - onChangeFolder(folderMetadatas?.parentId)} - > - - - )} - - - {formatMessage({ - id: getTrad('header.actions.add-assets'), - defaultMessage: 'Add new assets', - })} - - {folderLabel && {folderLabel}} - - - - ); -}; - -DialogHeader.defaultProps = { - currentFolder: undefined, - onChangeFolder: undefined, -}; - -DialogHeader.propTypes = { - canRead: PropTypes.bool.isRequired, - currentFolder: PropTypes.number, - onChangeFolder: PropTypes.func, -}; diff --git a/packages/core/upload/admin/src/components/AssetDialog/index.js b/packages/core/upload/admin/src/components/AssetDialog/index.js index f4d13c42cf..d27c7cadae 100644 --- a/packages/core/upload/admin/src/components/AssetDialog/index.js +++ b/packages/core/upload/admin/src/components/AssetDialog/index.js @@ -1,17 +1,17 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; -import { ModalLayout, ModalBody } from '@strapi/design-system/ModalLayout'; +import { useIntl } from 'react-intl'; +import { ModalLayout, ModalBody, ModalHeader } from '@strapi/design-system/ModalLayout'; import { Flex } from '@strapi/design-system/Flex'; import { Button } from '@strapi/design-system/Button'; import { Divider } from '@strapi/design-system/Divider'; -import { useIntl } from 'react-intl'; +import { Typography } from '@strapi/design-system/Typography'; import { Tabs, Tab, TabGroup, TabPanels, TabPanel } from '@strapi/design-system/Tabs'; import { Badge } from '@strapi/design-system/Badge'; import { Loader } from '@strapi/design-system/Loader'; import { Stack } from '@strapi/design-system/Stack'; import { NoPermissions, AnErrorOccurred, useSelectionState, pxToRem } from '@strapi/helper-plugin'; - import { getTrad, containsAssetFilter } from '../../utils'; import { SelectedStep } from './SelectedStep'; import { BrowseStep } from './BrowseStep'; @@ -21,7 +21,6 @@ import { useFolders } from '../../hooks/useFolders'; import useModalQueryParams from '../../hooks/useModalQueryParams'; import { AssetDefinition } from '../../constants'; import getAllowedFiles from '../../utils/getAllowedFiles'; -import { DialogHeader } from './DialogHeader'; import { DialogFooter } from './DialogFooter'; import { EditAssetDialog } from '../EditAssetDialog'; import { moveElement } from '../../utils/moveElement'; @@ -55,6 +54,7 @@ export const AssetDialog = ({ canCopyLink, canDownload, } = useMediaLibraryPermissions(); + const [ { queryObject }, { @@ -66,11 +66,13 @@ export const AssetDialog = ({ onChangeFolder: onChangeFolderParam, }, ] = useModalQueryParams({ folder: folderId }); + const { data: { pagination, results: assets } = {}, isLoading: isLoadingAssets, error: errorAssets, } = useAssets({ skipWhen: !canRead, query: queryObject }); + const { data: folders, isLoading: isLoadingFolders, error: errorFolders } = useFolders({ enabled: canRead && !containsAssetFilter(queryObject) && pagination?.page === 1, query: queryObject, @@ -84,6 +86,7 @@ export const AssetDialog = ({ const [initialSelectedTabIndex, setInitialSelectedTabIndex] = useState( selectedAssets.length > 0 ? 1 : 0 ); + const handleSelectAllAssets = () => { const hasAllAssets = assets.every( asset => selectedAssets.findIndex(curr => curr.id === asset.id) !== -1 @@ -97,6 +100,7 @@ export const AssetDialog = ({ return multiple ? selectAll(allowedAssets) : undefined; }; + const handleSelectAsset = asset => { return multiple ? selectOne(asset) : selectOnly(asset); }; @@ -107,7 +111,14 @@ export const AssetDialog = ({ if (isLoading) { return ( - + + + {formatMessage({ + id: getTrad('header.actions.add-assets'), + defaultMessage: 'Add new assets', + })} + + {formatMessage({ @@ -124,7 +135,14 @@ export const AssetDialog = ({ if (hasError) { return ( - + + + {formatMessage({ + id: getTrad('header.actions.add-assets'), + defaultMessage: 'Add new assets', + })} + + @@ -134,7 +152,14 @@ export const AssetDialog = ({ if (!canRead) { return ( - + + + {formatMessage({ + id: getTrad('header.actions.add-assets'), + defaultMessage: 'Add new assets', + })} + + @@ -168,7 +193,6 @@ export const AssetDialog = ({ const offset = destIndex - hoverIndex; const orderedAssetsClone = selectedAssets.slice(); const nextAssets = moveElement(orderedAssetsClone, hoverIndex, offset); - setSelections(nextAssets); }; @@ -179,11 +203,14 @@ export const AssetDialog = ({ return ( - + + + {formatMessage({ + id: getTrad('header.actions.add-assets'), + defaultMessage: 'Add new assets', + })} + + {selectedAssets.length} -