Upload: Namespace all queries with pluginId

This commit is contained in:
Gustav Hansen 2022-03-31 12:45:49 +02:00
parent 648c5bd470
commit 5dfa81a8e5
8 changed files with 22 additions and 11 deletions

View File

@ -137,7 +137,9 @@ describe('useEditFolder', () => {
}); });
await waitFor(() => await waitFor(() =>
expect(queryClient.refetchQueries).toHaveBeenCalledWith(['folder'], { active: true }) expect(queryClient.refetchQueries).toHaveBeenCalledWith(['upload', 'folder'], {
active: true,
})
); );
}); });

View File

@ -2,6 +2,8 @@ import { useQuery } from 'react-query';
import { useNotifyAT } from '@strapi/design-system/LiveRegions'; import { useNotifyAT } from '@strapi/design-system/LiveRegions';
import { useNotification, useQueryParams } from '@strapi/helper-plugin'; import { useNotification, useQueryParams } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import pluginId from '../pluginId';
import { axiosInstance, getRequestUrl } from '../utils'; import { axiosInstance, getRequestUrl } from '../utils';
export const useAssets = ({ skipWhen }) => { 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, enabled: !skipWhen,
staleTime: 0, staleTime: 0,
cacheTime: 0, cacheTime: 0,

View File

@ -1,6 +1,8 @@
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/helper-plugin';
import { deleteRequest } from '../utils/deleteRequest'; import { deleteRequest } from '../utils/deleteRequest';
import pluginId from '../pluginId';
const bulkRemoveQuery = assetIds => { const bulkRemoveQuery = assetIds => {
const promises = assetIds.map(assetId => deleteRequest('files', assetId)); const promises = assetIds.map(assetId => deleteRequest('files', assetId));
@ -15,8 +17,8 @@ export const useBulkRemoveAsset = () => {
const mutation = useMutation(bulkRemoveQuery, { const mutation = useMutation(bulkRemoveQuery, {
onSuccess: () => { onSuccess: () => {
// Coupled with the cache of useAssets // Coupled with the cache of useAssets
queryClient.refetchQueries(['assets'], { active: true }); queryClient.refetchQueries([pluginId, 'assets'], { active: true });
queryClient.refetchQueries(['asset-count'], { active: true }); queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
toggleNotification({ toggleNotification({
type: 'success', type: 'success',

View File

@ -3,6 +3,7 @@ import { useRef, useState } from 'react';
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/helper-plugin';
import { axiosInstance, getTrad } from '../utils'; import { axiosInstance, getTrad } from '../utils';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
@ -46,8 +47,8 @@ export const useEditAsset = () => {
({ asset, file }) => editAssetRequest(asset, file, tokenRef.current, setProgress), ({ asset, file }) => editAssetRequest(asset, file, tokenRef.current, setProgress),
{ {
onSuccess: () => { onSuccess: () => {
queryClient.refetchQueries(['assets'], { active: true }); queryClient.refetchQueries([pluginId, 'assets'], { active: true });
queryClient.refetchQueries(['asset-count'], { active: true }); queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
}, },
onError: reason => { onError: reason => {
if (reason.response.status === 403) { if (reason.response.status === 403) {

View File

@ -1,5 +1,7 @@
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/helper-plugin';
import pluginId from '../pluginId';
import { axiosInstance, getRequestUrl } from '../utils'; import { axiosInstance, getRequestUrl } from '../utils';
const editFolderRequest = folder => { const editFolderRequest = folder => {
@ -15,7 +17,7 @@ export const useEditFolder = () => {
const mutation = useMutation(({ folder }) => editFolderRequest(folder), { const mutation = useMutation(({ folder }) => editFolderRequest(folder), {
onSuccess: () => { onSuccess: () => {
queryClient.refetchQueries(['folder'], { active: true }); queryClient.refetchQueries([pluginId, 'folder'], { active: true });
}, },
onError: reason => { onError: reason => {
toggleNotification({ type: 'warning', message: reason.message }); toggleNotification({ type: 'warning', message: reason.message });

View File

@ -2,6 +2,8 @@ import { useQuery } from 'react-query';
import { useNotifyAT } from '@strapi/design-system/LiveRegions'; import { useNotifyAT } from '@strapi/design-system/LiveRegions';
import { useNotification, useQueryParams } from '@strapi/helper-plugin'; import { useNotification, useQueryParams } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import pluginId from '../pluginId';
import { axiosInstance, getRequestUrl } from '../utils'; import { axiosInstance, getRequestUrl } from '../utils';
export const useFolders = ({ enabled = true }) => { 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, enabled,
staleTime: 0, staleTime: 0,
cacheTime: 0, cacheTime: 0,

View File

@ -1,8 +1,8 @@
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/helper-plugin';
import pluginId from '../pluginId';
import { deleteRequest } from '../utils/deleteRequest'; import { deleteRequest } from '../utils/deleteRequest';
import pluginId from '../pluginId';
export const useRemoveAsset = onSuccess => { export const useRemoveAsset = onSuccess => {
const toggleNotification = useNotification(); const toggleNotification = useNotification();

View File

@ -42,8 +42,8 @@ export const useUpload = () => {
const mutation = useMutation(asset => uploadAsset(asset, tokenRef.current, setProgress), { const mutation = useMutation(asset => uploadAsset(asset, tokenRef.current, setProgress), {
onSuccess: () => { onSuccess: () => {
queryClient.refetchQueries(['assets'], { active: true }); queryClient.refetchQueries([pluginId, 'assets'], { active: true });
queryClient.refetchQueries(['asset-count'], { active: true }); queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });
}, },
}); });