mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:47:10 +00:00
refactor: the default accuracy of the UnixTimestamp field is second (#4418)
* refactor: the default accuracy of the UnixTimestamp field is second * refactor: the default accuracy of the UnixTimestamp field is second * fix: bug
This commit is contained in:
parent
8fbfd830c9
commit
60ac758b68
@ -23,7 +23,7 @@ export class UnixTimestampFieldInterface extends CollectionFieldInterface {
|
|||||||
type: 'number',
|
type: 'number',
|
||||||
'x-component': 'UnixTimestamp',
|
'x-component': 'UnixTimestamp',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
accuracy: 'millisecond',
|
accuracy: 'second',
|
||||||
showTime: true,
|
showTime: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -37,7 +37,7 @@ export class UnixTimestampFieldInterface extends CollectionFieldInterface {
|
|||||||
title: '{{t("Accuracy")}}',
|
title: '{{t("Accuracy")}}',
|
||||||
'x-component': 'Radio.Group',
|
'x-component': 'Radio.Group',
|
||||||
'x-decorator': 'FormItem',
|
'x-decorator': 'FormItem',
|
||||||
default: 'millisecond',
|
default: 'second',
|
||||||
enum: [
|
enum: [
|
||||||
{ value: 'millisecond', label: '{{t("Millisecond")}}' },
|
{ value: 'millisecond', label: '{{t("Millisecond")}}' },
|
||||||
{ value: 'second', label: '{{t("Second")}}' },
|
{ value: 'second', label: '{{t("Second")}}' },
|
||||||
|
@ -42,7 +42,7 @@ interface UnixTimestampProps {
|
|||||||
|
|
||||||
export const UnixTimestamp = connect(
|
export const UnixTimestamp = connect(
|
||||||
(props: UnixTimestampProps) => {
|
(props: UnixTimestampProps) => {
|
||||||
const { value, onChange, accuracy } = props;
|
const { value, onChange, accuracy = 'second' } = props;
|
||||||
const v = useMemo(() => toValue(value, accuracy), [value]);
|
const v = useMemo(() => toValue(value, accuracy), [value]);
|
||||||
return (
|
return (
|
||||||
<DatePicker
|
<DatePicker
|
||||||
|
@ -14,6 +14,9 @@ describe('UnixTimestamp', () => {
|
|||||||
it('renders without errors', async () => {
|
it('renders without errors', async () => {
|
||||||
const { container } = await renderApp({
|
const { container } = await renderApp({
|
||||||
Component: UnixTimestamp,
|
Component: UnixTimestamp,
|
||||||
|
props: {
|
||||||
|
accuracy: 'millisecond',
|
||||||
|
},
|
||||||
value: 0,
|
value: 0,
|
||||||
});
|
});
|
||||||
expect(container).toMatchInlineSnapshot(`
|
expect(container).toMatchInlineSnapshot(`
|
||||||
@ -70,6 +73,9 @@ describe('UnixTimestamp', () => {
|
|||||||
await renderApp({
|
await renderApp({
|
||||||
Component: UnixTimestamp,
|
Component: UnixTimestamp,
|
||||||
value: 1712819630000,
|
value: 1712819630000,
|
||||||
|
props: {
|
||||||
|
accuracy: 'millisecond',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByRole('textbox')).toHaveValue('2024-04-11');
|
expect(screen.getByRole('textbox')).toHaveValue('2024-04-11');
|
||||||
@ -94,6 +100,9 @@ describe('UnixTimestamp', () => {
|
|||||||
await renderApp({
|
await renderApp({
|
||||||
Component: UnixTimestamp,
|
Component: UnixTimestamp,
|
||||||
value: '2024-04-11',
|
value: '2024-04-11',
|
||||||
|
props: {
|
||||||
|
accuracy: 'millisecond',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
@ -107,6 +116,9 @@ describe('UnixTimestamp', () => {
|
|||||||
Component: UnixTimestamp,
|
Component: UnixTimestamp,
|
||||||
value: '2024-04-11',
|
value: '2024-04-11',
|
||||||
onChange,
|
onChange,
|
||||||
|
props: {
|
||||||
|
accuracy: 'millisecond',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await userEvent.click(screen.getByRole('textbox'));
|
await userEvent.click(screen.getByRole('textbox'));
|
||||||
|
|
||||||
@ -126,6 +138,9 @@ describe('UnixTimestamp', () => {
|
|||||||
const { container } = await renderReadPrettyApp({
|
const { container } = await renderReadPrettyApp({
|
||||||
Component: UnixTimestamp,
|
Component: UnixTimestamp,
|
||||||
value: '2024-04-11',
|
value: '2024-04-11',
|
||||||
|
props: {
|
||||||
|
accuracy: 'millisecond',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(screen.getByText('2024-04-11')).toBeInTheDocument();
|
expect(screen.getByText('2024-04-11')).toBeInTheDocument();
|
||||||
|
Loading…
Reference in New Issue
Block a user