mirror of
https://github.com/inventree/InvenTree.git
synced 2026-05-09 03:03:41 +00:00
d1354fc147
* Move useFilterSet state to the @lib
* Refactor useTable hook into @lib
* Refactor string helper functions
* Refactor constructFormUrl func
* Refactor Boundary component
* Refactor StoredTableState
* More refactoring
* Refactor CopyButton and CopyableCell
* Pass table render func to plugins
* Provide internal wrapper function, while allowing the "api" and "navigate" functions to be provided by the caller
* Adds <InvenTreeTable /> component which is exposed to plugins
* Update frontend versioning
* Update docs
* Handle condition where UI does not provide table rendering function
* Move queryFilters out of custom state
* Fix exported type
* Extract searchParams
- Cannot be used outside of router component
- Only provide when the table is generated internally
* Bump UI version
* Fix for right-click context menu
- Function needs to be defined with the context menu provider
(cherry picked from commit 23f43ffd33)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import type { ApiEndpoints } from '../enums/ApiEndpoints';
|
|
import type { PathParams } from '../types/Core';
|
|
import type { ApiFormFieldSet, ApiFormFieldType } from '../types/Forms';
|
|
import { apiUrl } from './Api';
|
|
|
|
/**
|
|
* Construct an API url from the provided ApiFormProps object
|
|
*/
|
|
export function constructFormUrl(
|
|
url: ApiEndpoints | string,
|
|
pk?: string | number,
|
|
pathParams?: PathParams,
|
|
queryParams?: URLSearchParams
|
|
): string {
|
|
let formUrl = apiUrl(url, pk, pathParams);
|
|
|
|
if (queryParams) {
|
|
formUrl += `?${queryParams.toString()}`;
|
|
}
|
|
|
|
return formUrl;
|
|
}
|
|
|
|
export type NestedDict = { [key: string]: string | number | NestedDict };
|
|
|
|
export function mapFields(
|
|
fields: ApiFormFieldSet,
|
|
fieldFunction: (path: string, value: ApiFormFieldType, key: string) => any,
|
|
_path?: string
|
|
): NestedDict {
|
|
const res: NestedDict = {};
|
|
|
|
for (const [k, v] of Object.entries(fields)) {
|
|
const path = _path ? `${_path}.${k}` : k;
|
|
let value: any;
|
|
|
|
if (v.field_type === 'nested object' && v.children) {
|
|
value = mapFields(v.children, fieldFunction, path);
|
|
} else {
|
|
value = fieldFunction(path, v, k);
|
|
}
|
|
|
|
if (value !== undefined) res[k] = value;
|
|
}
|
|
|
|
return res;
|
|
}
|