Merge pull request #17439 from strapi/chore/drop-getRequestUrl

Chore: Drop getRequestUrl from the admin app
This commit is contained in:
Gustav Hansen 2023-07-25 15:29:35 +02:00 committed by GitHub
commit a3df0f9937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 33 additions and 96 deletions

View File

@ -1,3 +0,0 @@
const getRequestUrl = (path) => `/admin/${path}`;
export default getRequestUrl;

View File

@ -4,7 +4,6 @@ export { default as formatAPIErrors } from './formatAPIErrors';
export { default as getAttributesToDisplay } from './getAttributesToDisplay'; export { default as getAttributesToDisplay } from './getAttributesToDisplay';
export { default as getExistingActions } from './getExistingActions'; export { default as getExistingActions } from './getExistingActions';
export { default as getFullName } from './getFullName'; export { default as getFullName } from './getFullName';
export { default as getRequestUrl } from './getRequestUrl';
export { default as makeUniqueRoutes } from './makeUniqueRoutes'; export { default as makeUniqueRoutes } from './makeUniqueRoutes';
export { default as sortLinks } from './sortLinks'; export { default as sortLinks } from './sortLinks';
export { default as hashAdminUserEmail } from './uniqueAdminHash'; export { default as hashAdminUserEmail } from './uniqueAdminHash';

View File

@ -2,8 +2,6 @@ import { useEffect, useReducer } from 'react';
import { useFetchClient, useNotification } from '@strapi/helper-plugin'; import { useFetchClient, useNotification } from '@strapi/helper-plugin';
import { getRequestUrl } from '../../../../admin/src/utils';
import reducer, { initialState } from './reducer'; import reducer, { initialState } from './reducer';
const useAuthProviders = ({ ssoEnabled }) => { const useAuthProviders = ({ ssoEnabled }) => {
@ -23,7 +21,7 @@ const useAuthProviders = ({ ssoEnabled }) => {
return; return;
} }
const { data } = await get(getRequestUrl('providers')); const { data } = await get('/admin/providers');
dispatch({ dispatch({
type: 'GET_DATA_SUCCEEDED', type: 'GET_DATA_SUCCEEDED',

View File

@ -5,8 +5,6 @@ import Cookies from 'js-cookie';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { useHistory, useRouteMatch } from 'react-router-dom'; import { useHistory, useRouteMatch } from 'react-router-dom';
import { getRequestUrl } from '../../../../admin/src/utils';
export const AuthResponse = () => { export const AuthResponse = () => {
const { const {
params: { authResponse }, params: { authResponse },
@ -36,7 +34,7 @@ export const AuthResponse = () => {
if (jwtToken) { if (jwtToken) {
auth.setToken(jwtToken, true); auth.setToken(jwtToken, true);
const requestUrl = getRequestUrl('users/me'); const requestUrl = '/admin/users/me';
const { const {
data: { data }, data: { data },
} = await get(requestUrl); } = await get(requestUrl);

View File

@ -30,7 +30,6 @@ import { useSelector } from 'react-redux';
import { useRolesList, useSettingsForm } from '../../../../../../admin/src/hooks'; import { useRolesList, useSettingsForm } from '../../../../../../admin/src/hooks';
import { selectAdminPermissions } from '../../../../../../admin/src/pages/App/selectors'; import { selectAdminPermissions } from '../../../../../../admin/src/pages/App/selectors';
import { getRequestUrl } from '../../../../../../admin/src/utils';
import schema from './utils/schema'; import schema from './utils/schema';
@ -51,7 +50,7 @@ export const SingleSignOn = () => {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
dispatch, dispatch,
{ handleChange, handleSubmit }, { handleChange, handleSubmit },
] = useSettingsForm(getRequestUrl('providers/options'), schema, () => {}, [ ] = useSettingsForm('/admin/providers/options', schema, () => {}, [
'autoRegister', 'autoRegister',
'defaultRole', 'defaultRole',
'ssoLockedRoles', 'ssoLockedRoles',

View File

@ -6,14 +6,12 @@ import { useIntl } from 'react-intl';
import { useQuery } from 'react-query'; import { useQuery } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl } from '../utils';
export const useAssets = ({ skipWhen = false, query = {} } = {}) => { export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const { notifyStatus } = useNotifyAT(); const { notifyStatus } = useNotifyAT();
const { get } = useFetchClient(); const { get } = useFetchClient();
const dataRequestURL = getRequestUrl('files');
const { folderPath, _q, ...paramsExceptFolderAndQ } = query; const { folderPath, _q, ...paramsExceptFolderAndQ } = query;
let params; let params;
@ -40,7 +38,7 @@ export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
const { data, error, isLoading } = useQuery( const { data, error, isLoading } = useQuery(
[pluginId, 'assets', params], [pluginId, 'assets', params],
async () => { async () => {
const { data } = await get(dataRequestURL, { params }); const { data } = await get('/upload/files', { params });
return data; return data;
}, },

View File

@ -2,12 +2,11 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl, getTrad } from '../utils'; import { getTrad } from '../utils';
export const useBulkMove = () => { export const useBulkMove = () => {
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const url = getRequestUrl('actions/bulk-move');
const { post } = useFetchClient(); const { post } = useFetchClient();
const bulkMoveQuery = ({ destinationFolderId, filesAndFolders }) => { const bulkMoveQuery = ({ destinationFolderId, filesAndFolders }) => {
@ -24,7 +23,7 @@ export const useBulkMove = () => {
return acc; return acc;
}, {}); }, {});
return post(url, { ...payload, destinationFolderId }); return post('/upload/actions/bulk-move', { ...payload, destinationFolderId });
}; };
const mutation = useMutation(bulkMoveQuery, { const mutation = useMutation(bulkMoveQuery, {

View File

@ -2,12 +2,11 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl, getTrad } from '../utils'; import { getTrad } from '../utils';
export const useBulkRemove = () => { export const useBulkRemove = () => {
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const url = getRequestUrl('actions/bulk-delete');
const { post } = useFetchClient(); const { post } = useFetchClient();
const bulkRemoveQuery = (filesAndFolders) => { const bulkRemoveQuery = (filesAndFolders) => {
@ -24,7 +23,7 @@ export const useBulkRemove = () => {
return acc; return acc;
}, {}); }, {});
return post(url, payload); return post('/upload/actions/bulk-delete', payload);
}; };
const mutation = useMutation(bulkRemoveQuery, { const mutation = useMutation(bulkRemoveQuery, {

View File

@ -2,14 +2,12 @@ import { useFetchClient } from '@strapi/helper-plugin';
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl } from '../utils';
const editFolderRequest = (put, post, { attrs, id }) => { const editFolderRequest = (put, post, { attrs, id }) => {
const isEditing = !!id; const isEditing = !!id;
const method = isEditing ? put : post; const method = isEditing ? put : post;
const url = getRequestUrl(`folders/${id ?? ''}`);
return method(url, attrs).then((res) => res.data); return method(`/upload/folders/${id ?? ''}`, attrs).then((res) => res.data);
}; };
export const useEditFolder = () => { export const useEditFolder = () => {

View File

@ -2,11 +2,10 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
import { useQuery } from 'react-query'; import { useQuery } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl, getTrad } from '../utils'; import { getTrad } from '../utils';
export const useFolder = (id, { enabled = true }) => { export const useFolder = (id, { enabled = true }) => {
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const dataRequestURL = getRequestUrl('folders');
const { get } = useFetchClient(); const { get } = useFetchClient();
const fetchFolder = async () => { const fetchFolder = async () => {
@ -20,9 +19,11 @@ export const useFolder = (id, { enabled = true }) => {
}, },
}, },
}; };
const { data } = await get(`${dataRequestURL}/${id}`, { params }); const {
data: { data },
} = await get(`/upload/folders/${id}`, { params });
return data.data; return data;
} catch (err) { } catch (err) {
toggleNotification({ toggleNotification({
type: 'warning', type: 'warning',

View File

@ -3,7 +3,7 @@ import { useIntl } from 'react-intl';
import { useQuery } from 'react-query'; import { useQuery } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl, getTrad } from '../utils'; import { getTrad } from '../utils';
import { recursiveRenameKeys } from './utils/rename-keys'; import { recursiveRenameKeys } from './utils/rename-keys';
@ -14,13 +14,12 @@ const FIELD_MAPPING = {
export const useFolderStructure = ({ enabled = true } = {}) => { export const useFolderStructure = ({ enabled = true } = {}) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const dataRequestURL = getRequestUrl('folder-structure');
const { get } = useFetchClient(); const { get } = useFetchClient();
const fetchFolderStructure = async () => { const fetchFolderStructure = async () => {
const { const {
data: { data }, data: { data },
} = await get(dataRequestURL); } = await get('/upload/folder-structure');
const children = data.map((f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key)); const children = data.map((f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key));

View File

@ -5,13 +5,11 @@ import { useIntl } from 'react-intl';
import { useQuery } from 'react-query'; import { useQuery } from 'react-query';
import pluginId from '../pluginId'; import pluginId from '../pluginId';
import { getRequestUrl } from '../utils';
export const useFolders = ({ enabled = true, query = {} }) => { export const useFolders = ({ enabled = true, query = {} }) => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const toggleNotification = useNotification(); const toggleNotification = useNotification();
const { notifyStatus } = useNotifyAT(); const { notifyStatus } = useNotifyAT();
const dataRequestURL = getRequestUrl('folders');
const { folder, _q, ...paramsExceptFolderAndQ } = query; const { folder, _q, ...paramsExceptFolderAndQ } = query;
const { get } = useFetchClient(); const { get } = useFetchClient();
@ -48,7 +46,9 @@ export const useFolders = ({ enabled = true, query = {} }) => {
const fetchFolders = async () => { const fetchFolders = async () => {
try { try {
const { data } = await get(dataRequestURL, { params }); const {
data: { data },
} = await get('/upload/folders', { params });
notifyStatus( notifyStatus(
formatMessage({ formatMessage({
@ -57,7 +57,7 @@ export const useFolders = ({ enabled = true, query = {} }) => {
}) })
); );
return data.data; return data;
} catch (err) { } catch (err) {
toggleNotification({ toggleNotification({
type: 'warning', type: 'warning',

View File

@ -28,7 +28,7 @@ import { Helmet } from 'react-helmet';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { PERMISSIONS } from '../../constants'; import { PERMISSIONS } from '../../constants';
import { getRequestUrl, getTrad } from '../../utils'; import { getTrad } from '../../utils';
import init from './init'; import init from './init';
import reducer, { initialState } from './reducer'; import reducer, { initialState } from './reducer';
@ -56,7 +56,7 @@ export const SettingsPage = () => {
try { try {
const { const {
data: { data }, data: { data },
} = await get(getRequestUrl('settings'), { } = await get('/upload/settings', {
cancelToken: source.token, cancelToken: source.token,
}); });
@ -94,7 +94,7 @@ export const SettingsPage = () => {
dispatch({ type: 'ON_SUBMIT' }); dispatch({ type: 'ON_SUBMIT' });
try { try {
await put(getRequestUrl('settings'), modifiedData); await put('/upload/settings', modifiedData);
dispatch({ dispatch({
type: 'SUBMIT_SUCCEEDED', type: 'SUBMIT_SUCCEEDED',

View File

@ -1,10 +1,7 @@
import { getFetchClient } from '@strapi/helper-plugin'; import { getFetchClient } from '@strapi/helper-plugin';
import getRequestUrl from './getRequestUrl';
export const deleteRequest = (type, id) => { export const deleteRequest = (type, id) => {
const { del } = getFetchClient(); const { del } = getFetchClient();
const url = getRequestUrl(`/${type}/${id}`);
return del(url); return del(`/upload/${type}/${id}`);
}; };

View File

@ -1,11 +0,0 @@
import pluginId from '../pluginId';
const getRequestUrl = (path) => {
if (path.startsWith('/')) {
return `/${pluginId}${path}`;
}
return `/${pluginId}/${path}`;
};
export default getRequestUrl;

View File

@ -8,6 +8,5 @@ export { default as getBreadcrumbDataCM } from './getBreadcrumbDataCM';
export { default as getBreadcrumbDataML } from './getBreadcrumbDataML'; export { default as getBreadcrumbDataML } from './getBreadcrumbDataML';
export { default as getFolderParents } from './getFolderParents'; export { default as getFolderParents } from './getFolderParents';
export { default as getFolderURL } from './getFolderURL'; export { default as getFolderURL } from './getFolderURL';
export { default as getRequestUrl } from './getRequestUrl';
export { default as getTrad } from './getTrad'; export { default as getTrad } from './getTrad';
export { default as toSingularTypes } from './toSingularTypes'; export { default as toSingularTypes } from './toSingularTypes';

View File

@ -1,17 +0,0 @@
import getRequestUrl from '../getRequestUrl';
describe('upload || utils || getRequestUrl', () => {
test('return right format url if argument starts with /', () => {
const result = getRequestUrl('/test');
const expected = '/upload/test';
expect(result).toEqual(expected);
});
test('return right format url if argument does not start with /', () => {
const result = getRequestUrl('test');
const expected = '/upload/test';
expect(result).toEqual(expected);
});
});

View File

@ -2,8 +2,6 @@ import { useCallback, useEffect, useReducer, useRef } from 'react';
import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin'; import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
import { getRequestURL } from '../../utils';
import reducer, { initialState } from './reducer'; import reducer, { initialState } from './reducer';
const useUserForm = (endPoint, permissions) => { const useUserForm = (endPoint, permissions) => {
@ -21,7 +19,7 @@ const useUserForm = (endPoint, permissions) => {
type: 'GET_DATA', type: 'GET_DATA',
}); });
const { data } = await get(getRequestURL(endPoint)); const { data } = await get(`/users-permissions/${endPoint}`);
dispatch({ dispatch({
type: 'GET_DATA_SUCCEEDED', type: 'GET_DATA_SUCCEEDED',

View File

@ -1,10 +1,8 @@
import { getFetchClient } from '@strapi/helper-plugin'; import { getFetchClient } from '@strapi/helper-plugin';
import { getRequestURL } from '../../../utils';
const fetchData = async () => { const fetchData = async () => {
const { get } = getFetchClient(); const { get } = getFetchClient();
const { data } = await get(getRequestURL('advanced')); const { data } = await get('/users-permissions/advanced');
return data; return data;
}; };
@ -12,7 +10,7 @@ const fetchData = async () => {
const putAdvancedSettings = (body) => { const putAdvancedSettings = (body) => {
const { put } = getFetchClient(); const { put } = getFetchClient();
return put(getRequestURL('advanced'), body); return put('/users-permissions/advanced', body);
}; };
export { fetchData, putAdvancedSettings }; export { fetchData, putAdvancedSettings };

View File

@ -1,10 +1,8 @@
import { getFetchClient } from '@strapi/helper-plugin'; import { getFetchClient } from '@strapi/helper-plugin';
import { getRequestURL } from '../../../utils';
const fetchData = async () => { const fetchData = async () => {
const { get } = getFetchClient(); const { get } = getFetchClient();
const { data } = await get(getRequestURL('email-templates')); const { data } = await get('/users-permissions/email-templates');
return data; return data;
}; };
@ -12,7 +10,7 @@ const fetchData = async () => {
const putEmailTemplate = (body) => { const putEmailTemplate = (body) => {
const { put } = getFetchClient(); const { put } = getFetchClient();
return put(getRequestURL('email-templates'), body); return put('/users-permissions/email-templates', body);
}; };
export { fetchData, putEmailTemplate }; export { fetchData, putEmailTemplate };

View File

@ -1,12 +1,10 @@
import { getFetchClient } from '@strapi/helper-plugin'; import { getFetchClient } from '@strapi/helper-plugin';
import { getRequestURL } from '../../../utils';
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export const fetchData = async (toggleNotification) => { export const fetchData = async (toggleNotification) => {
try { try {
const { get } = getFetchClient(); const { get } = getFetchClient();
const { data } = await get(getRequestURL('providers')); const { data } = await get('/users-permissions/providers');
return data; return data;
} catch (err) { } catch (err) {
@ -22,5 +20,5 @@ export const fetchData = async (toggleNotification) => {
export const putProvider = (body) => { export const putProvider = (body) => {
const { put } = getFetchClient(); const { put } = getFetchClient();
return put(getRequestURL('providers'), body); return put('/users-permissions/providers', body);
}; };

View File

@ -1,11 +1,9 @@
import { getFetchClient } from '@strapi/helper-plugin'; import { getFetchClient } from '@strapi/helper-plugin';
import { getRequestURL } from '../../../../utils';
export const fetchData = async (toggleNotification, notifyStatus) => { export const fetchData = async (toggleNotification, notifyStatus) => {
try { try {
const { get } = getFetchClient(); const { get } = getFetchClient();
const { data } = await get(getRequestURL('roles')); const { data } = await get('/users-permissions/roles');
notifyStatus('The roles have loaded successfully'); notifyStatus('The roles have loaded successfully');
return data; return data;
@ -22,7 +20,7 @@ export const fetchData = async (toggleNotification, notifyStatus) => {
export const deleteData = async (id, toggleNotification) => { export const deleteData = async (id, toggleNotification) => {
try { try {
const { del } = getFetchClient(); const { del } = getFetchClient();
await del(`${getRequestURL('roles')}/${id}`); await del(`/users-permissions/roles/${id}`);
} catch (error) { } catch (error) {
toggleNotification({ toggleNotification({
type: 'warning', type: 'warning',

View File

@ -1,5 +0,0 @@
import pluginId from '../pluginId';
const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
export default getRequestURL;

View File

@ -1,4 +1,3 @@
export { default as cleanPermissions } from './cleanPermissions'; export { default as cleanPermissions } from './cleanPermissions';
export { default as formatPolicies } from './formatPolicies'; export { default as formatPolicies } from './formatPolicies';
export { default as getRequestURL } from './getRequestURL';
export { default as getTrad } from './getTrad'; export { default as getTrad } from './getTrad';