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:
Katherine 2024-05-21 10:31:01 +08:00 committed by GitHub
parent 8fbfd830c9
commit 60ac758b68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 3 deletions

View File

@ -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")}}' },

View File

@ -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

View File

@ -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();