mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-02 19:50:59 +00:00
* Enhancements for "custom state" form
- More intuitive form actions
* Improve back-end validation
* Improve table rendering
* Fix lookup for useStatusCodes
* Fix status display for SockDetail page
* Fix SalesOrder status display
* Refactor get_custom_classes
- Add StatusCode.custom_values method
* Fix for status table filters
* Cleanup (and note to self)
* Include custom state values in specific API endpoints
* Add serializer class definition
* Use same serializer for AllStatusView
* Fix API to match existing frontend type StatusCodeListInterface
* Enable filtering by reference status type
* Add option to duplicate an existing custom state
* Improved validation for the InvenTreeCustomUserStateModel class
* Code cleanup
* Fix default value in StockOperationsRow
* Use custom status values in stock operations
* Allow custom values
* Fix migration
* Bump API version
* Fix filtering of stock items by "status"
* Enhance status filter for orders
* Fix status code rendering
* Build Order API filter
* Update playwright tests for build filters
* Additional playwright tests for stock table filters
* Add 'custom' attribute
* Fix unit tests
* Add custom state field validation
* Implement StatusCodeMixin for setting status code values
* Clear out 'custom key' if the base key does not match
* Updated playwright testing
* Remove timeout
* Refactor detail pages which display status
* Update old migrations - add field validator
* Remove dead code
* Simplify API query filtering
* Revert "Simplify API query filtering"
This reverts commit 06c858ae7c
.
* Fix save method
* Unit test fixes
* Fix for ReturnOrderLineItem
* Reorganize code
* Adjust unit test
90 lines
2.0 KiB
TypeScript
90 lines
2.0 KiB
TypeScript
import { IconUsers } from '@tabler/icons-react';
|
|
import { useMemo, useState } from 'react';
|
|
|
|
import type { ApiFormFieldSet } from '../components/forms/fields/ApiFormField';
|
|
import type {
|
|
StatusCodeInterface,
|
|
StatusCodeListInterface
|
|
} from '../components/render/StatusRenderer';
|
|
import { useGlobalStatusState } from '../states/StatusState';
|
|
|
|
export function projectCodeFields(): ApiFormFieldSet {
|
|
return {
|
|
code: {},
|
|
description: {},
|
|
responsible: {
|
|
icon: <IconUsers />
|
|
}
|
|
};
|
|
}
|
|
|
|
export function useCustomStateFields(): ApiFormFieldSet {
|
|
// Status codes
|
|
const statusCodes = useGlobalStatusState();
|
|
|
|
// Selected base status class
|
|
const [statusClass, setStatusClass] = useState<string>('');
|
|
|
|
// Construct a list of status options based on the selected status class
|
|
const statusOptions: any[] = useMemo(() => {
|
|
const options: any[] = [];
|
|
|
|
const valuesList = Object.values(statusCodes.status ?? {}).find(
|
|
(value: StatusCodeListInterface) => value.status_class === statusClass
|
|
);
|
|
|
|
Object.values(valuesList?.values ?? {}).forEach(
|
|
(value: StatusCodeInterface) => {
|
|
options.push({
|
|
value: value.key,
|
|
display_name: value.label
|
|
});
|
|
}
|
|
);
|
|
|
|
return options;
|
|
}, [statusCodes, statusClass]);
|
|
|
|
return useMemo(() => {
|
|
return {
|
|
reference_status: {
|
|
onValueChange(value) {
|
|
setStatusClass(value);
|
|
}
|
|
},
|
|
logical_key: {
|
|
field_type: 'choice',
|
|
choices: statusOptions
|
|
},
|
|
key: {},
|
|
name: {},
|
|
label: {},
|
|
color: {},
|
|
model: {}
|
|
};
|
|
}, [statusOptions]);
|
|
}
|
|
|
|
export function customUnitsFields(): ApiFormFieldSet {
|
|
return {
|
|
name: {},
|
|
definition: {},
|
|
symbol: {}
|
|
};
|
|
}
|
|
|
|
export function extraLineItemFields(): ApiFormFieldSet {
|
|
return {
|
|
order: {
|
|
hidden: true
|
|
},
|
|
reference: {},
|
|
description: {},
|
|
quantity: {},
|
|
price: {},
|
|
price_currency: {},
|
|
notes: {},
|
|
link: {}
|
|
};
|
|
}
|