mirror of
https://github.com/strapi/strapi.git
synced 2025-09-18 04:47:27 +00:00
Merge pull request #17439 from strapi/chore/drop-getRequestUrl
Chore: Drop getRequestUrl from the admin app
This commit is contained in:
commit
a3df0f9937
@ -1,3 +0,0 @@
|
||||
const getRequestUrl = (path) => `/admin/${path}`;
|
||||
|
||||
export default getRequestUrl;
|
@ -4,7 +4,6 @@ export { default as formatAPIErrors } from './formatAPIErrors';
|
||||
export { default as getAttributesToDisplay } from './getAttributesToDisplay';
|
||||
export { default as getExistingActions } from './getExistingActions';
|
||||
export { default as getFullName } from './getFullName';
|
||||
export { default as getRequestUrl } from './getRequestUrl';
|
||||
export { default as makeUniqueRoutes } from './makeUniqueRoutes';
|
||||
export { default as sortLinks } from './sortLinks';
|
||||
export { default as hashAdminUserEmail } from './uniqueAdminHash';
|
||||
|
@ -2,8 +2,6 @@ import { useEffect, useReducer } from 'react';
|
||||
|
||||
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestUrl } from '../../../../admin/src/utils';
|
||||
|
||||
import reducer, { initialState } from './reducer';
|
||||
|
||||
const useAuthProviders = ({ ssoEnabled }) => {
|
||||
@ -23,7 +21,7 @@ const useAuthProviders = ({ ssoEnabled }) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = await get(getRequestUrl('providers'));
|
||||
const { data } = await get('/admin/providers');
|
||||
|
||||
dispatch({
|
||||
type: 'GET_DATA_SUCCEEDED',
|
||||
|
@ -5,8 +5,6 @@ import Cookies from 'js-cookie';
|
||||
import { useIntl } from 'react-intl';
|
||||
import { useHistory, useRouteMatch } from 'react-router-dom';
|
||||
|
||||
import { getRequestUrl } from '../../../../admin/src/utils';
|
||||
|
||||
export const AuthResponse = () => {
|
||||
const {
|
||||
params: { authResponse },
|
||||
@ -36,7 +34,7 @@ export const AuthResponse = () => {
|
||||
|
||||
if (jwtToken) {
|
||||
auth.setToken(jwtToken, true);
|
||||
const requestUrl = getRequestUrl('users/me');
|
||||
const requestUrl = '/admin/users/me';
|
||||
const {
|
||||
data: { data },
|
||||
} = await get(requestUrl);
|
||||
|
@ -30,7 +30,6 @@ import { useSelector } from 'react-redux';
|
||||
|
||||
import { useRolesList, useSettingsForm } from '../../../../../../admin/src/hooks';
|
||||
import { selectAdminPermissions } from '../../../../../../admin/src/pages/App/selectors';
|
||||
import { getRequestUrl } from '../../../../../../admin/src/utils';
|
||||
|
||||
import schema from './utils/schema';
|
||||
|
||||
@ -51,7 +50,7 @@ export const SingleSignOn = () => {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
dispatch,
|
||||
{ handleChange, handleSubmit },
|
||||
] = useSettingsForm(getRequestUrl('providers/options'), schema, () => {}, [
|
||||
] = useSettingsForm('/admin/providers/options', schema, () => {}, [
|
||||
'autoRegister',
|
||||
'defaultRole',
|
||||
'ssoLockedRoles',
|
||||
|
@ -6,14 +6,12 @@ import { useIntl } from 'react-intl';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl } from '../utils';
|
||||
|
||||
export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const toggleNotification = useNotification();
|
||||
const { notifyStatus } = useNotifyAT();
|
||||
const { get } = useFetchClient();
|
||||
const dataRequestURL = getRequestUrl('files');
|
||||
const { folderPath, _q, ...paramsExceptFolderAndQ } = query;
|
||||
|
||||
let params;
|
||||
@ -40,7 +38,7 @@ export const useAssets = ({ skipWhen = false, query = {} } = {}) => {
|
||||
const { data, error, isLoading } = useQuery(
|
||||
[pluginId, 'assets', params],
|
||||
async () => {
|
||||
const { data } = await get(dataRequestURL, { params });
|
||||
const { data } = await get('/upload/files', { params });
|
||||
|
||||
return data;
|
||||
},
|
||||
|
@ -2,12 +2,11 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl, getTrad } from '../utils';
|
||||
import { getTrad } from '../utils';
|
||||
|
||||
export const useBulkMove = () => {
|
||||
const toggleNotification = useNotification();
|
||||
const queryClient = useQueryClient();
|
||||
const url = getRequestUrl('actions/bulk-move');
|
||||
const { post } = useFetchClient();
|
||||
|
||||
const bulkMoveQuery = ({ destinationFolderId, filesAndFolders }) => {
|
||||
@ -24,7 +23,7 @@ export const useBulkMove = () => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return post(url, { ...payload, destinationFolderId });
|
||||
return post('/upload/actions/bulk-move', { ...payload, destinationFolderId });
|
||||
};
|
||||
|
||||
const mutation = useMutation(bulkMoveQuery, {
|
||||
|
@ -2,12 +2,11 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl, getTrad } from '../utils';
|
||||
import { getTrad } from '../utils';
|
||||
|
||||
export const useBulkRemove = () => {
|
||||
const toggleNotification = useNotification();
|
||||
const queryClient = useQueryClient();
|
||||
const url = getRequestUrl('actions/bulk-delete');
|
||||
const { post } = useFetchClient();
|
||||
|
||||
const bulkRemoveQuery = (filesAndFolders) => {
|
||||
@ -24,7 +23,7 @@ export const useBulkRemove = () => {
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
return post(url, payload);
|
||||
return post('/upload/actions/bulk-delete', payload);
|
||||
};
|
||||
|
||||
const mutation = useMutation(bulkRemoveQuery, {
|
||||
|
@ -2,14 +2,12 @@ import { useFetchClient } from '@strapi/helper-plugin';
|
||||
import { useMutation, useQueryClient } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl } from '../utils';
|
||||
|
||||
const editFolderRequest = (put, post, { attrs, id }) => {
|
||||
const isEditing = !!id;
|
||||
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 = () => {
|
||||
|
@ -2,11 +2,10 @@ import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl, getTrad } from '../utils';
|
||||
import { getTrad } from '../utils';
|
||||
|
||||
export const useFolder = (id, { enabled = true }) => {
|
||||
const toggleNotification = useNotification();
|
||||
const dataRequestURL = getRequestUrl('folders');
|
||||
const { get } = useFetchClient();
|
||||
|
||||
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) {
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
|
@ -3,7 +3,7 @@ import { useIntl } from 'react-intl';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl, getTrad } from '../utils';
|
||||
import { getTrad } from '../utils';
|
||||
|
||||
import { recursiveRenameKeys } from './utils/rename-keys';
|
||||
|
||||
@ -14,13 +14,12 @@ const FIELD_MAPPING = {
|
||||
|
||||
export const useFolderStructure = ({ enabled = true } = {}) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const dataRequestURL = getRequestUrl('folder-structure');
|
||||
const { get } = useFetchClient();
|
||||
|
||||
const fetchFolderStructure = async () => {
|
||||
const {
|
||||
data: { data },
|
||||
} = await get(dataRequestURL);
|
||||
} = await get('/upload/folder-structure');
|
||||
|
||||
const children = data.map((f) => recursiveRenameKeys(f, (key) => FIELD_MAPPING?.[key] ?? key));
|
||||
|
||||
|
@ -5,13 +5,11 @@ import { useIntl } from 'react-intl';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import pluginId from '../pluginId';
|
||||
import { getRequestUrl } from '../utils';
|
||||
|
||||
export const useFolders = ({ enabled = true, query = {} }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const toggleNotification = useNotification();
|
||||
const { notifyStatus } = useNotifyAT();
|
||||
const dataRequestURL = getRequestUrl('folders');
|
||||
const { folder, _q, ...paramsExceptFolderAndQ } = query;
|
||||
const { get } = useFetchClient();
|
||||
|
||||
@ -48,7 +46,9 @@ export const useFolders = ({ enabled = true, query = {} }) => {
|
||||
|
||||
const fetchFolders = async () => {
|
||||
try {
|
||||
const { data } = await get(dataRequestURL, { params });
|
||||
const {
|
||||
data: { data },
|
||||
} = await get('/upload/folders', { params });
|
||||
|
||||
notifyStatus(
|
||||
formatMessage({
|
||||
@ -57,7 +57,7 @@ export const useFolders = ({ enabled = true, query = {} }) => {
|
||||
})
|
||||
);
|
||||
|
||||
return data.data;
|
||||
return data;
|
||||
} catch (err) {
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
|
@ -28,7 +28,7 @@ import { Helmet } from 'react-helmet';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { PERMISSIONS } from '../../constants';
|
||||
import { getRequestUrl, getTrad } from '../../utils';
|
||||
import { getTrad } from '../../utils';
|
||||
|
||||
import init from './init';
|
||||
import reducer, { initialState } from './reducer';
|
||||
@ -56,7 +56,7 @@ export const SettingsPage = () => {
|
||||
try {
|
||||
const {
|
||||
data: { data },
|
||||
} = await get(getRequestUrl('settings'), {
|
||||
} = await get('/upload/settings', {
|
||||
cancelToken: source.token,
|
||||
});
|
||||
|
||||
@ -94,7 +94,7 @@ export const SettingsPage = () => {
|
||||
dispatch({ type: 'ON_SUBMIT' });
|
||||
|
||||
try {
|
||||
await put(getRequestUrl('settings'), modifiedData);
|
||||
await put('/upload/settings', modifiedData);
|
||||
|
||||
dispatch({
|
||||
type: 'SUBMIT_SUCCEEDED',
|
||||
|
@ -1,10 +1,7 @@
|
||||
import { getFetchClient } from '@strapi/helper-plugin';
|
||||
|
||||
import getRequestUrl from './getRequestUrl';
|
||||
|
||||
export const deleteRequest = (type, id) => {
|
||||
const { del } = getFetchClient();
|
||||
const url = getRequestUrl(`/${type}/${id}`);
|
||||
|
||||
return del(url);
|
||||
return del(`/upload/${type}/${id}`);
|
||||
};
|
||||
|
@ -1,11 +0,0 @@
|
||||
import pluginId from '../pluginId';
|
||||
|
||||
const getRequestUrl = (path) => {
|
||||
if (path.startsWith('/')) {
|
||||
return `/${pluginId}${path}`;
|
||||
}
|
||||
|
||||
return `/${pluginId}/${path}`;
|
||||
};
|
||||
|
||||
export default getRequestUrl;
|
@ -8,6 +8,5 @@ export { default as getBreadcrumbDataCM } from './getBreadcrumbDataCM';
|
||||
export { default as getBreadcrumbDataML } from './getBreadcrumbDataML';
|
||||
export { default as getFolderParents } from './getFolderParents';
|
||||
export { default as getFolderURL } from './getFolderURL';
|
||||
export { default as getRequestUrl } from './getRequestUrl';
|
||||
export { default as getTrad } from './getTrad';
|
||||
export { default as toSingularTypes } from './toSingularTypes';
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
@ -2,8 +2,6 @@ import { useCallback, useEffect, useReducer, useRef } from 'react';
|
||||
|
||||
import { useFetchClient, useNotification, useRBAC } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestURL } from '../../utils';
|
||||
|
||||
import reducer, { initialState } from './reducer';
|
||||
|
||||
const useUserForm = (endPoint, permissions) => {
|
||||
@ -21,7 +19,7 @@ const useUserForm = (endPoint, permissions) => {
|
||||
type: 'GET_DATA',
|
||||
});
|
||||
|
||||
const { data } = await get(getRequestURL(endPoint));
|
||||
const { data } = await get(`/users-permissions/${endPoint}`);
|
||||
|
||||
dispatch({
|
||||
type: 'GET_DATA_SUCCEEDED',
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { getFetchClient } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestURL } from '../../../utils';
|
||||
|
||||
const fetchData = async () => {
|
||||
const { get } = getFetchClient();
|
||||
const { data } = await get(getRequestURL('advanced'));
|
||||
const { data } = await get('/users-permissions/advanced');
|
||||
|
||||
return data;
|
||||
};
|
||||
@ -12,7 +10,7 @@ const fetchData = async () => {
|
||||
const putAdvancedSettings = (body) => {
|
||||
const { put } = getFetchClient();
|
||||
|
||||
return put(getRequestURL('advanced'), body);
|
||||
return put('/users-permissions/advanced', body);
|
||||
};
|
||||
|
||||
export { fetchData, putAdvancedSettings };
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { getFetchClient } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestURL } from '../../../utils';
|
||||
|
||||
const fetchData = async () => {
|
||||
const { get } = getFetchClient();
|
||||
const { data } = await get(getRequestURL('email-templates'));
|
||||
const { data } = await get('/users-permissions/email-templates');
|
||||
|
||||
return data;
|
||||
};
|
||||
@ -12,7 +10,7 @@ const fetchData = async () => {
|
||||
const putEmailTemplate = (body) => {
|
||||
const { put } = getFetchClient();
|
||||
|
||||
return put(getRequestURL('email-templates'), body);
|
||||
return put('/users-permissions/email-templates', body);
|
||||
};
|
||||
|
||||
export { fetchData, putEmailTemplate };
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { getFetchClient } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestURL } from '../../../utils';
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const fetchData = async (toggleNotification) => {
|
||||
try {
|
||||
const { get } = getFetchClient();
|
||||
const { data } = await get(getRequestURL('providers'));
|
||||
const { data } = await get('/users-permissions/providers');
|
||||
|
||||
return data;
|
||||
} catch (err) {
|
||||
@ -22,5 +20,5 @@ export const fetchData = async (toggleNotification) => {
|
||||
export const putProvider = (body) => {
|
||||
const { put } = getFetchClient();
|
||||
|
||||
return put(getRequestURL('providers'), body);
|
||||
return put('/users-permissions/providers', body);
|
||||
};
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { getFetchClient } from '@strapi/helper-plugin';
|
||||
|
||||
import { getRequestURL } from '../../../../utils';
|
||||
|
||||
export const fetchData = async (toggleNotification, notifyStatus) => {
|
||||
try {
|
||||
const { get } = getFetchClient();
|
||||
const { data } = await get(getRequestURL('roles'));
|
||||
const { data } = await get('/users-permissions/roles');
|
||||
notifyStatus('The roles have loaded successfully');
|
||||
|
||||
return data;
|
||||
@ -22,7 +20,7 @@ export const fetchData = async (toggleNotification, notifyStatus) => {
|
||||
export const deleteData = async (id, toggleNotification) => {
|
||||
try {
|
||||
const { del } = getFetchClient();
|
||||
await del(`${getRequestURL('roles')}/${id}`);
|
||||
await del(`/users-permissions/roles/${id}`);
|
||||
} catch (error) {
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
|
@ -1,5 +0,0 @@
|
||||
import pluginId from '../pluginId';
|
||||
|
||||
const getRequestURL = (endPoint) => `/${pluginId}/${endPoint}`;
|
||||
|
||||
export default getRequestURL;
|
@ -1,4 +1,3 @@
|
||||
export { default as cleanPermissions } from './cleanPermissions';
|
||||
export { default as formatPolicies } from './formatPolicies';
|
||||
export { default as getRequestURL } from './getRequestURL';
|
||||
export { default as getTrad } from './getTrad';
|
||||
|
Loading…
x
Reference in New Issue
Block a user