mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add test start, end date and test station to the next gen UI (#6883)
* Add test start, end date and test station to the next gen UI * [PUI]Add new test fields to the forms too * Fix review comments * Fix review comments #2
This commit is contained in:
parent
7640df7c63
commit
e04fd3dac1
@ -64,6 +64,7 @@ export type ApiFormFieldType = {
|
|||||||
| 'string'
|
| 'string'
|
||||||
| 'boolean'
|
| 'boolean'
|
||||||
| 'date'
|
| 'date'
|
||||||
|
| 'datetime'
|
||||||
| 'integer'
|
| 'integer'
|
||||||
| 'decimal'
|
| 'decimal'
|
||||||
| 'float'
|
| 'float'
|
||||||
@ -215,6 +216,7 @@ export function ApiFormField({
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
case 'date':
|
case 'date':
|
||||||
|
case 'datetime':
|
||||||
return <DateField controller={controller} definition={definition} />;
|
return <DateField controller={controller} definition={definition} />;
|
||||||
case 'integer':
|
case 'integer':
|
||||||
case 'decimal':
|
case 'decimal':
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import { DateInput } from '@mantine/dates';
|
import { DateInput } from '@mantine/dates';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
||||||
import { useCallback, useId, useMemo } from 'react';
|
import { useCallback, useId, useMemo } from 'react';
|
||||||
import { FieldValues, UseControllerReturn } from 'react-hook-form';
|
import { FieldValues, UseControllerReturn } from 'react-hook-form';
|
||||||
|
|
||||||
import { ApiFormFieldType } from './ApiFormField';
|
import { ApiFormFieldType } from './ApiFormField';
|
||||||
|
|
||||||
|
dayjs.extend(customParseFormat);
|
||||||
|
|
||||||
export default function DateField({
|
export default function DateField({
|
||||||
controller,
|
controller,
|
||||||
definition
|
definition
|
||||||
@ -18,13 +22,16 @@ export default function DateField({
|
|||||||
fieldState: { error }
|
fieldState: { error }
|
||||||
} = controller;
|
} = controller;
|
||||||
|
|
||||||
|
const valueFormat =
|
||||||
|
definition.field_type == 'date' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss';
|
||||||
|
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(value: any) => {
|
(value: any) => {
|
||||||
// Convert the returned date object to a string
|
// Convert the returned date object to a string
|
||||||
if (value) {
|
if (value) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
let date = new Date(value);
|
let date = new Date(value);
|
||||||
value = date.toISOString().split('T')[0];
|
value = dayjs(value).format(valueFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
field.onChange(value);
|
field.onChange(value);
|
||||||
@ -50,7 +57,7 @@ export default function DateField({
|
|||||||
value={dateValue}
|
value={dateValue}
|
||||||
clearable={!definition.required}
|
clearable={!definition.required}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
valueFormat="YYYY-MM-DD"
|
valueFormat={valueFormat}
|
||||||
label={definition.label}
|
label={definition.label}
|
||||||
description={definition.description}
|
description={definition.description}
|
||||||
placeholder={definition.placeholder}
|
placeholder={definition.placeholder}
|
||||||
|
@ -88,6 +88,7 @@ export function formatPriceRange(
|
|||||||
|
|
||||||
interface renderDateOptionsType {
|
interface renderDateOptionsType {
|
||||||
showTime?: boolean;
|
showTime?: boolean;
|
||||||
|
showSeconds?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -106,6 +107,9 @@ export function renderDate(date: string, options: renderDateOptionsType = {}) {
|
|||||||
|
|
||||||
if (options.showTime) {
|
if (options.showTime) {
|
||||||
fmt += ' HH:mm';
|
fmt += ' HH:mm';
|
||||||
|
if (options.showSeconds) {
|
||||||
|
fmt += ':ss';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const m = dayjs(date);
|
const m = dayjs(date);
|
||||||
|
@ -202,6 +202,41 @@ export default function StockItemTestResultTable({
|
|||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessor: 'test_station',
|
||||||
|
sortable: true,
|
||||||
|
title: t`Test station`
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessor: 'started_datetime',
|
||||||
|
sortable: true,
|
||||||
|
title: t`Started`,
|
||||||
|
render: (record: any) => {
|
||||||
|
return (
|
||||||
|
<Group position="apart">
|
||||||
|
{renderDate(record.started_datetime, {
|
||||||
|
showTime: true,
|
||||||
|
showSeconds: true
|
||||||
|
})}
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessor: 'finished_datetime',
|
||||||
|
sortable: true,
|
||||||
|
title: t`Finished`,
|
||||||
|
render: (record: any) => {
|
||||||
|
return (
|
||||||
|
<Group position="apart">
|
||||||
|
{renderDate(record.finished_datetime, {
|
||||||
|
showTime: true,
|
||||||
|
showSeconds: true
|
||||||
|
})}
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}, [itemId]);
|
}, [itemId]);
|
||||||
@ -218,6 +253,9 @@ export default function StockItemTestResultTable({
|
|||||||
value: {},
|
value: {},
|
||||||
attachment: {},
|
attachment: {},
|
||||||
notes: {},
|
notes: {},
|
||||||
|
test_station: {},
|
||||||
|
started_datetime: {},
|
||||||
|
finished_datetime: {},
|
||||||
stock_item: {
|
stock_item: {
|
||||||
value: itemId,
|
value: itemId,
|
||||||
hidden: true
|
hidden: true
|
||||||
|
Loading…
Reference in New Issue
Block a user