diff --git a/packages/core/helper-plugin/lib/src/components/ReactSelect/utils/getSelectStyles.js b/packages/core/helper-plugin/lib/src/components/ReactSelect/utils/getSelectStyles.js index 88e843ad87..1de09ee4e3 100644 --- a/packages/core/helper-plugin/lib/src/components/ReactSelect/utils/getSelectStyles.js +++ b/packages/core/helper-plugin/lib/src/components/ReactSelect/utils/getSelectStyles.js @@ -79,7 +79,15 @@ const getSelectStyles = (theme, error) => { backgroundColor = theme.colors.primary100; } - return { ...base, lineHeight: theme.spaces[5], backgroundColor, borderRadius: 4 }; + return { + ...base, + lineHeight: theme.spaces[5], + backgroundColor, + borderRadius: theme.borderRadius, + '&:active': { + backgroundColor: theme.colors.primary100, + }, + }; }, placeholder: base => ({ ...base, marginLeft: 0 }), singleValue: base => ({ ...base, marginLeft: 0, color: theme.colors.neutral800 }), 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 215512f10d..876241a35a 100644 --- a/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js +++ b/packages/core/upload/admin/src/components/AssetDialog/BrowseStep/index.js @@ -80,6 +80,13 @@ export const BrowseStep = ({ 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 + onChangeSearch(''); + onChangeFolder(...args); + }; + return ( {onSelectAllAsset && ( @@ -181,7 +188,7 @@ export const BrowseStep = ({ onChangeFolder(folder.id)} + onClick={() => handleClickFolderCard(folder.id)} cardActions={ onEditFolder && ( - onChangeFolder(folder.id)}> + handleClickFolderCard(folder.id)}> {folder.name} diff --git a/packages/core/upload/admin/src/hooks/tests/useAssets.test.js b/packages/core/upload/admin/src/hooks/tests/useAssets.test.js index 9baf353cfb..bbf1c4531a 100644 --- a/packages/core/upload/admin/src/hooks/tests/useAssets.test.js +++ b/packages/core/upload/admin/src/hooks/tests/useAssets.test.js @@ -152,6 +152,30 @@ describe('useAssets', () => { ); }); + test('does not use folder filter in params if _q', async () => { + const { result, waitFor, waitForNextUpdate } = await setup({ + query: { folder: 5, _q: 'something', filters: { $and: [{ something: 'true' }] } }, + }); + + await waitFor(() => result.current.isSuccess); + await waitForNextUpdate(); + + const expected = { + filters: { + $and: [ + { + something: true, + }, + ], + }, + _q: 'something', + }; + + expect(axiosInstance.get).toBeCalledWith( + `/upload/files?${stringify(expected, { encode: false })}` + ); + }); + test('it does not fetch, if skipWhen is set', async () => { const { result, waitFor } = await setup({ skipWhen: true }); diff --git a/packages/core/upload/admin/src/hooks/tests/useFolders.test.js b/packages/core/upload/admin/src/hooks/tests/useFolders.test.js index d757598291..f28338c9bf 100644 --- a/packages/core/upload/admin/src/hooks/tests/useFolders.test.js +++ b/packages/core/upload/admin/src/hooks/tests/useFolders.test.js @@ -104,6 +104,33 @@ describe('useFolders', () => { ); }); + test('does not use parent filter in params if _q', async () => { + const { result, waitFor, waitForNextUpdate } = await setup({ + query: { folder: 5, _q: 'something', filters: { $and: [{ something: 'true' }] } }, + }); + + await waitFor(() => result.current.isSuccess); + await waitForNextUpdate(); + + const expected = { + filters: { + $and: [ + { + something: 'true', + }, + ], + }, + pagination: { + pageSize: -1, + }, + _q: 'something', + }; + + expect(axiosInstance.get).toBeCalledWith( + `/upload/folders?${stringify(expected, { encode: false })}` + ); + }); + test('fetches data from the right URL if a query param was set', async () => { const { result, waitFor, waitForNextUpdate } = await setup({ query: { folder: 1 } }); diff --git a/packages/core/upload/admin/src/hooks/useAssets.js b/packages/core/upload/admin/src/hooks/useAssets.js index 73c1032a84..b9beb41eab 100644 --- a/packages/core/upload/admin/src/hooks/useAssets.js +++ b/packages/core/upload/admin/src/hooks/useAssets.js @@ -12,22 +12,32 @@ export const useAssets = ({ skipWhen = false, query = {} } = {}) => { const toggleNotification = useNotification(); const { notifyStatus } = useNotifyAT(); const dataRequestURL = getRequestUrl('files'); - const { folder, ...paramsExceptFolder } = query; - const params = { - ...paramsExceptFolder, - filters: { - $and: [ - ...(query?.filters?.$and ?? []), - { - folder: { - id: query?.folder ?? { - $null: true, + const { folder, _q, ...paramsExceptFolderAndQ } = query; + + let params; + + if (_q) { + params = { + ...paramsExceptFolderAndQ, + _q, + }; + } else { + params = { + ...paramsExceptFolderAndQ, + filters: { + $and: [ + ...(paramsExceptFolderAndQ?.filters?.$and ?? []), + { + folder: { + id: folder ?? { + $null: true, + }, }, }, - }, - ], - }, - }; + ], + }, + }; + } const getAssets = async () => { try { diff --git a/packages/core/upload/admin/src/hooks/useFolders.js b/packages/core/upload/admin/src/hooks/useFolders.js index 3671b73007..58eb1ad794 100644 --- a/packages/core/upload/admin/src/hooks/useFolders.js +++ b/packages/core/upload/admin/src/hooks/useFolders.js @@ -12,25 +12,38 @@ export const useFolders = ({ enabled = true, query = {} }) => { const toggleNotification = useNotification(); const { notifyStatus } = useNotifyAT(); const dataRequestURL = getRequestUrl('folders'); - const { folder, ...paramsExceptFolder } = query; - const params = { - ...paramsExceptFolder, - pagination: { - pageSize: -1, - }, - filters: { - $and: [ - ...(query?.filters?.$and ?? []), - { - parent: { - id: query?.folder ?? { - $null: true, + const { folder, _q, ...paramsExceptFolderAndQ } = query; + + let params; + + if (_q) { + params = { + ...paramsExceptFolderAndQ, + pagination: { + pageSize: -1, + }, + _q, + }; + } else { + params = { + ...paramsExceptFolderAndQ, + pagination: { + pageSize: -1, + }, + filters: { + $and: [ + ...(paramsExceptFolderAndQ?.filters?.$and ?? []), + { + parent: { + id: folder ?? { + $null: true, + }, }, }, - }, - ], - }, - }; + ], + }, + }; + } const fetchFolders = async () => { try { diff --git a/packages/core/upload/admin/src/pages/App/MediaLibrary.js b/packages/core/upload/admin/src/pages/App/MediaLibrary.js index c08e7ae257..233cedf8af 100644 --- a/packages/core/upload/admin/src/pages/App/MediaLibrary.js +++ b/packages/core/upload/admin/src/pages/App/MediaLibrary.js @@ -262,8 +262,12 @@ export const MediaLibrary = () => { const isSelected = !!selectedFolders.find( currentFolder => currentFolder.id === folder.id ); + + // 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 + const { _q, ...queryParamsWithoutQ } = query; const url = `${pathname}?${stringify({ - ...query, + ...queryParamsWithoutQ, folder: folder.id, })}`;