From 635a3540516bb809e1d8f42627d7f77290d83390 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 2 Aug 2021 12:06:16 +1000 Subject: [PATCH] 6236/date time picker default (#6237) * remove empty timeValue validation * changeset * update unit test --- .changeset/fast-guests-tickle.md | 5 +++++ .../src/types/timestamp/views/__tests__/index.tsx | 14 +++++++++----- .../fields/src/types/timestamp/views/index.tsx | 3 +-- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .changeset/fast-guests-tickle.md diff --git a/.changeset/fast-guests-tickle.md b/.changeset/fast-guests-tickle.md new file mode 100644 index 00000000000..6fcc1576912 --- /dev/null +++ b/.changeset/fast-guests-tickle.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/fields': patch +--- + +Updated timestamp field to default time to 00:00 when no time is selected. diff --git a/packages/fields/src/types/timestamp/views/__tests__/index.tsx b/packages/fields/src/types/timestamp/views/__tests__/index.tsx index 82d08f229ec..d3230e7b253 100644 --- a/packages/fields/src/types/timestamp/views/__tests__/index.tsx +++ b/packages/fields/src/types/timestamp/views/__tests__/index.tsx @@ -33,7 +33,7 @@ describe('controller', () => { dateValue: formatISO(new Date(), { representation: 'date' }), timeValue: '', }) - ).toBe(false); + ).toBe(true); }); }); describe('serialize', () => { @@ -61,11 +61,15 @@ describe('controller', () => { [STUBCONFIG.path]: null, }); }); - it('should return null if no timeValue is specified', () => { + it('should return a valid ISO8601 string if no timeValue is specified but a valid date value is specified', () => { const { serialize } = controller(STUBCONFIG); - expect(serialize({ dateValue: '2020-10-20', timeValue: '' })).toStrictEqual({ - [STUBCONFIG.path]: null, - }); + expect( + Boolean( + parseISO( + serialize({ dateValue: '2020-10-20', timeValue: '' })[STUBCONFIG.path] + ).toISOString() + ) + ).toBe(true); }); it('should return a valid ISO8601 string if a valid time and date value are specified', () => { const { serialize } = controller(STUBCONFIG); diff --git a/packages/fields/src/types/timestamp/views/index.tsx b/packages/fields/src/types/timestamp/views/index.tsx index 0c04f4ac682..b9a2f54abc8 100644 --- a/packages/fields/src/types/timestamp/views/index.tsx +++ b/packages/fields/src/types/timestamp/views/index.tsx @@ -155,7 +155,7 @@ export const controller = ( return { dateValue: '', timeValue: '' }; }, serialize: ({ dateValue, timeValue }) => { - if (dateValue && timeValue && isValidISO({ dateValue, timeValue })) { + if (dateValue && isValidISO({ dateValue, timeValue })) { let formattedDate = constructTimestamp({ dateValue, timeValue }); return { [config.path]: formattedDate }; } @@ -164,7 +164,6 @@ export const controller = ( validate({ dateValue, timeValue }) { if (!dateValue && !timeValue) return true; if (!dateValue) return false; - if (!timeValue) return false; return isValidISO({ dateValue, timeValue }); }, };