mirror of
https://github.com/strapi/strapi.git
synced 2025-12-16 17:53:53 +00:00
Merge branch 'features/ML-folder' of https://github.com/strapi/strapi into ML-folder/bulk-move-select
This commit is contained in:
commit
c62640d3eb
@ -79,7 +79,15 @@ const getSelectStyles = (theme, error) => {
|
|||||||
backgroundColor = theme.colors.primary100;
|
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 }),
|
placeholder: base => ({ ...base, marginLeft: 0 }),
|
||||||
singleValue: base => ({ ...base, marginLeft: 0, color: theme.colors.neutral800 }),
|
singleValue: base => ({ ...base, marginLeft: 0, color: theme.colors.neutral800 }),
|
||||||
|
|||||||
@ -80,6 +80,13 @@ export const BrowseStep = ({
|
|||||||
const assetCount = assets.length;
|
const assetCount = assets.length;
|
||||||
const folderCount = folders.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 (
|
return (
|
||||||
<Stack spacing={4}>
|
<Stack spacing={4}>
|
||||||
{onSelectAllAsset && (
|
{onSelectAllAsset && (
|
||||||
@ -181,7 +188,7 @@ export const BrowseStep = ({
|
|||||||
<FolderCard
|
<FolderCard
|
||||||
ariaLabel={folder.name}
|
ariaLabel={folder.name}
|
||||||
id={`folder-${folder.id}`}
|
id={`folder-${folder.id}`}
|
||||||
onClick={() => onChangeFolder(folder.id)}
|
onClick={() => handleClickFolderCard(folder.id)}
|
||||||
cardActions={
|
cardActions={
|
||||||
onEditFolder && (
|
onEditFolder && (
|
||||||
<IconButton
|
<IconButton
|
||||||
@ -196,7 +203,7 @@ export const BrowseStep = ({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<FolderCardBody>
|
<FolderCardBody>
|
||||||
<FolderCardBodyAction onClick={() => onChangeFolder(folder.id)}>
|
<FolderCardBodyAction onClick={() => handleClickFolderCard(folder.id)}>
|
||||||
<Flex as="h2" direction="column" alignItems="start" maxWidth="100%">
|
<Flex as="h2" direction="column" alignItems="start" maxWidth="100%">
|
||||||
<TypographyMaxWidth fontWeight="semiBold" ellipsis>
|
<TypographyMaxWidth fontWeight="semiBold" ellipsis>
|
||||||
{folder.name}
|
{folder.name}
|
||||||
|
|||||||
@ -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 () => {
|
test('it does not fetch, if skipWhen is set', async () => {
|
||||||
const { result, waitFor } = await setup({ skipWhen: true });
|
const { result, waitFor } = await setup({ skipWhen: true });
|
||||||
|
|
||||||
|
|||||||
@ -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 () => {
|
test('fetches data from the right URL if a query param was set', async () => {
|
||||||
const { result, waitFor, waitForNextUpdate } = await setup({ query: { folder: 1 } });
|
const { result, waitFor, waitForNextUpdate } = await setup({ query: { folder: 1 } });
|
||||||
|
|
||||||
|
|||||||
@ -12,15 +12,24 @@ export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const { notifyStatus } = useNotifyAT();
|
const { notifyStatus } = useNotifyAT();
|
||||||
const dataRequestURL = getRequestUrl('files');
|
const dataRequestURL = getRequestUrl('files');
|
||||||
const { folder, ...paramsExceptFolder } = query;
|
const { folder, _q, ...paramsExceptFolderAndQ } = query;
|
||||||
const params = {
|
|
||||||
...paramsExceptFolder,
|
let params;
|
||||||
|
|
||||||
|
if (_q) {
|
||||||
|
params = {
|
||||||
|
...paramsExceptFolderAndQ,
|
||||||
|
_q,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
params = {
|
||||||
|
...paramsExceptFolderAndQ,
|
||||||
filters: {
|
filters: {
|
||||||
$and: [
|
$and: [
|
||||||
...(query?.filters?.$and ?? []),
|
...(paramsExceptFolderAndQ?.filters?.$and ?? []),
|
||||||
{
|
{
|
||||||
folder: {
|
folder: {
|
||||||
id: query?.folder ?? {
|
id: folder ?? {
|
||||||
$null: true,
|
$null: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -28,6 +37,7 @@ export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const getAssets = async () => {
|
const getAssets = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -12,18 +12,30 @@ export const useFolders = ({ enabled = true, query = {} }) => {
|
|||||||
const toggleNotification = useNotification();
|
const toggleNotification = useNotification();
|
||||||
const { notifyStatus } = useNotifyAT();
|
const { notifyStatus } = useNotifyAT();
|
||||||
const dataRequestURL = getRequestUrl('folders');
|
const dataRequestURL = getRequestUrl('folders');
|
||||||
const { folder, ...paramsExceptFolder } = query;
|
const { folder, _q, ...paramsExceptFolderAndQ } = query;
|
||||||
const params = {
|
|
||||||
...paramsExceptFolder,
|
let params;
|
||||||
|
|
||||||
|
if (_q) {
|
||||||
|
params = {
|
||||||
|
...paramsExceptFolderAndQ,
|
||||||
|
pagination: {
|
||||||
|
pageSize: -1,
|
||||||
|
},
|
||||||
|
_q,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
params = {
|
||||||
|
...paramsExceptFolderAndQ,
|
||||||
pagination: {
|
pagination: {
|
||||||
pageSize: -1,
|
pageSize: -1,
|
||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
$and: [
|
$and: [
|
||||||
...(query?.filters?.$and ?? []),
|
...(paramsExceptFolderAndQ?.filters?.$and ?? []),
|
||||||
{
|
{
|
||||||
parent: {
|
parent: {
|
||||||
id: query?.folder ?? {
|
id: folder ?? {
|
||||||
$null: true,
|
$null: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -31,6 +43,7 @@ export const useFolders = ({ enabled = true, query = {} }) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const fetchFolders = async () => {
|
const fetchFolders = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -262,8 +262,12 @@ export const MediaLibrary = () => {
|
|||||||
const isSelected = !!selectedFolders.find(
|
const isSelected = !!selectedFolders.find(
|
||||||
currentFolder => currentFolder.id === folder.id
|
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({
|
const url = `${pathname}?${stringify({
|
||||||
...query,
|
...queryParamsWithoutQ,
|
||||||
folder: folder.id,
|
folder: folder.id,
|
||||||
})}`;
|
})}`;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user