2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

enable passing of free-form urls to apiUrl (#6012)

This commit is contained in:
Matthias Mair 2023-12-02 12:35:12 +01:00 committed by GitHub
parent fb42878c11
commit bbf4d2f206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -60,7 +60,7 @@ export interface ApiFormAction {
* @param onFormError : A callback function to call when the form is submitted with errors. * @param onFormError : A callback function to call when the form is submitted with errors.
*/ */
export interface ApiFormProps { export interface ApiFormProps {
url: ApiPaths; url: ApiPaths | string;
pk?: number | string | undefined; pk?: number | string | undefined;
pathParams?: PathParams; pathParams?: PathParams;
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';

View File

@ -19,7 +19,7 @@ import { generateUniqueId } from './uid';
* Construct an API url from the provided ApiFormProps object * Construct an API url from the provided ApiFormProps object
*/ */
export function constructFormUrl( export function constructFormUrl(
url: ApiPaths, url: ApiPaths | string,
pk?: string | number, pk?: string | number,
pathParams?: PathParams pathParams?: PathParams
): string { ): string {

View File

@ -196,11 +196,14 @@ export type PathParams = Record<string, string | number>;
* Construct an API URL with an endpoint and (optional) pk value * Construct an API URL with an endpoint and (optional) pk value
*/ */
export function apiUrl( export function apiUrl(
path: ApiPaths, path: ApiPaths | string,
pk?: any, pk?: any,
pathParams?: PathParams pathParams?: PathParams
): string { ): string {
let _url = apiEndpoint(path); let _url = path;
if (Object.values(ApiPaths).includes(path as ApiPaths)) {
_url = apiEndpoint(path as ApiPaths);
}
// If the URL does not start with a '/', add the API prefix // If the URL does not start with a '/', add the API prefix
if (!_url.startsWith('/')) { if (!_url.startsWith('/')) {