From 3ec15d9e2ade44c85cc647b7d04d7967be5a9f64 Mon Sep 17 00:00:00 2001 From: fxnoob Date: Fri, 11 Oct 2024 09:26:27 +0530 Subject: [PATCH 1/3] Fix parseSelectedSections, Return null if selectedSections is not available in sections. --- .../src/internals/hooks/useField/useField.test.tsx | 8 +++++++- .../src/internals/hooks/useField/useField.utils.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useField.test.tsx b/packages/x-date-pickers/src/internals/hooks/useField/useField.test.tsx index 760e445b9477..c78f3037f089 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.test.tsx +++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.test.tsx @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { getSectionVisibleValue } from './useField.utils'; +import { getSectionVisibleValue, parseSelectedSections } from './useField.utils'; const COMMON_PROPERTIES = { startSeparator: '', @@ -56,4 +56,10 @@ describe('useField utility functions', () => { ).to.equal('\u20681\u2069'); }); }); + + describe('parseSelectedSections', () => { + it('should return null when selectedSections is not available in sections', () => { + expect(parseSelectedSections('year', [])).to.equal(null); + }); + }); }); diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts index e56f7029886f..6e53bfc46749 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts +++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts @@ -812,8 +812,15 @@ export const parseSelectedSections = ( } if (typeof selectedSections === 'string') { - return sections.findIndex((section) => section.type === selectedSections); - } + const index = sections.findIndex((section) => section.type === selectedSections); + return index === -1 ? null : index; + } + /* + * + * if (typeof selectedSections === 'string') { + const index = sections.findIndex((section) => section.type === selectedSections); + return index === -1 ? null : index; + } */ return selectedSections; }; From cf1fb78dc17efdda01664e32ceab731157a1e9ad Mon Sep 17 00:00:00 2001 From: fxnoob Date: Fri, 11 Oct 2024 10:00:39 +0530 Subject: [PATCH 2/3] remove duplicate code --- .../src/internals/hooks/useField/useField.utils.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts index 6e53bfc46749..4713cb93bca7 100644 --- a/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts +++ b/packages/x-date-pickers/src/internals/hooks/useField/useField.utils.ts @@ -815,12 +815,6 @@ export const parseSelectedSections = ( const index = sections.findIndex((section) => section.type === selectedSections); return index === -1 ? null : index; } - /* - * - * if (typeof selectedSections === 'string') { - const index = sections.findIndex((section) => section.type === selectedSections); - return index === -1 ? null : index; - } */ return selectedSections; }; From ca18d22bc6958abe6806a5005bcd1a5e25328927 Mon Sep 17 00:00:00 2001 From: fxnoob Date: Fri, 11 Oct 2024 19:07:01 +0530 Subject: [PATCH 3/3] trigger ci