mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Upload: Namespace all queries with pluginId
This commit is contained in:
parent
648c5bd470
commit
5dfa81a8e5
@ -137,7 +137,9 @@ describe('useEditFolder', () => {
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(queryClient.refetchQueries).toHaveBeenCalledWith(['folder'], { active: true })
|
||||
expect(queryClient.refetchQueries).toHaveBeenCalledWith(['upload', 'folder'], {
|
||||
active: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -2,6 +2,8 @@ import { useQuery } from 'react-query';
|
||||
import { useNotifyAT } from '@strapi/design-system/LiveRegions';
|
||||
import { useNotification, useQueryParams } from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { axiosInstance, getRequestUrl } from '../utils';
|
||||
|
||||
export const useAssets = ({ skipWhen }) => {
|
||||
@ -33,7 +35,7 @@ export const useAssets = ({ skipWhen }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const { data, error, isLoading } = useQuery([`assets`, rawQuery], getAssets, {
|
||||
const { data, error, isLoading } = useQuery([pluginId, `assets`, rawQuery], getAssets, {
|
||||
enabled: !skipWhen,
|
||||
staleTime: 0,
|
||||
cacheTime: 0,
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useNotification } from '@strapi/helper-plugin';
|
||||
|
||||
import { deleteRequest } from '../utils/deleteRequest';
|
||||
import pluginId from '../pluginId';
|
||||
|
||||
const bulkRemoveQuery = assetIds => {
|
||||
const promises = assetIds.map(assetId => deleteRequest('files', assetId));
|
||||
@ -15,8 +17,8 @@ export const useBulkRemoveAsset = () => {
|
||||
const mutation = useMutation(bulkRemoveQuery, {
|
||||
onSuccess: () => {
|
||||
// Coupled with the cache of useAssets
|
||||
queryClient.refetchQueries(['assets'], { active: true });
|
||||
queryClient.refetchQueries(['asset-count'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'assets'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
|
||||
|
||||
toggleNotification({
|
||||
type: 'success',
|
||||
|
@ -3,6 +3,7 @@ import { useRef, useState } from 'react';
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { useNotification } from '@strapi/helper-plugin';
|
||||
|
||||
import { axiosInstance, getTrad } from '../utils';
|
||||
import pluginId from '../pluginId';
|
||||
|
||||
@ -46,8 +47,8 @@ export const useEditAsset = () => {
|
||||
({ asset, file }) => editAssetRequest(asset, file, tokenRef.current, setProgress),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries(['assets'], { active: true });
|
||||
queryClient.refetchQueries(['asset-count'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'assets'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
|
||||
},
|
||||
onError: reason => {
|
||||
if (reason.response.status === 403) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useNotification } from '@strapi/helper-plugin';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { axiosInstance, getRequestUrl } from '../utils';
|
||||
|
||||
const editFolderRequest = folder => {
|
||||
@ -15,7 +17,7 @@ export const useEditFolder = () => {
|
||||
|
||||
const mutation = useMutation(({ folder }) => editFolderRequest(folder), {
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries(['folder'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'folder'], { active: true });
|
||||
},
|
||||
onError: reason => {
|
||||
toggleNotification({ type: 'warning', message: reason.message });
|
||||
|
@ -2,6 +2,8 @@ import { useQuery } from 'react-query';
|
||||
import { useNotifyAT } from '@strapi/design-system/LiveRegions';
|
||||
import { useNotification, useQueryParams } from '@strapi/helper-plugin';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { axiosInstance, getRequestUrl } from '../utils';
|
||||
|
||||
export const useFolders = ({ enabled = true }) => {
|
||||
@ -33,7 +35,7 @@ export const useFolders = ({ enabled = true }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const { data, error, isLoading } = useQuery([`folders`, rawQuery], fetchFolders, {
|
||||
const { data, error, isLoading } = useQuery([pluginId, `folders`, rawQuery], fetchFolders, {
|
||||
enabled,
|
||||
staleTime: 0,
|
||||
cacheTime: 0,
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
import { useNotification } from '@strapi/helper-plugin';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { deleteRequest } from '../utils/deleteRequest';
|
||||
import pluginId from '../pluginId';
|
||||
|
||||
export const useRemoveAsset = onSuccess => {
|
||||
const toggleNotification = useNotification();
|
||||
|
@ -42,8 +42,8 @@ export const useUpload = () => {
|
||||
|
||||
const mutation = useMutation(asset => uploadAsset(asset, tokenRef.current, setProgress), {
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries(['assets'], { active: true });
|
||||
queryClient.refetchQueries(['asset-count'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'assets'], { active: true });
|
||||
queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user