From a160b4aa288a16aa59edb63bd4b95bcc46957182 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Tue, 24 Sep 2024 13:39:06 +0300 Subject: [PATCH] =?UTF-8?q?split=20predefined=20and=C2=A0custom=20granular?= =?UTF-8?q?ities=20into=C2=A0separate=20lists=20to=C2=A0be=20able=20to?= =?UTF-8?q?=C2=A0use=20different=20styles/icons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/TimeListMember.tsx | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/packages/cubejs-playground/src/QueryBuilderV2/components/TimeListMember.tsx b/packages/cubejs-playground/src/QueryBuilderV2/components/TimeListMember.tsx index 8ce50f90a9850..799ea400751b9 100644 --- a/packages/cubejs-playground/src/QueryBuilderV2/components/TimeListMember.tsx +++ b/packages/cubejs-playground/src/QueryBuilderV2/components/TimeListMember.tsx @@ -7,6 +7,7 @@ import { TimeIcon, CalendarIcon, TooltipProvider, + CubeIcon, } from '@cube-dev/ui-kit'; import { Cube, TCubeDimension, TimeDimensionGranularity } from '@cubejs-client/core'; @@ -32,7 +33,7 @@ interface ListMemberProps { onToggleDataRange?: (name: string) => void; } -const GRANULARITIES: TimeDimensionGranularity[] = [ +const PREDEFINED_GRANULARITIES: TimeDimensionGranularity[] = [ 'second', 'minute', 'hour', @@ -67,12 +68,16 @@ export function TimeListMember(props: ListMemberProps) { const description = member.description; const isTimestampSelected = isSelected(); + const customGranularities = (member.type === 'time' && member.granularities) ? + member.granularities.map(g => g.name) : []; const memberGranularities = (member.type === 'time' && member.granularities) ? - member.granularities.map(g => g.name).concat(GRANULARITIES) : - GRANULARITIES; - const isGranularitySelectedList = memberGranularities.map((granularity) => isSelected(granularity)); + member.granularities.map(g => g.name).concat(PREDEFINED_GRANULARITIES) : + PREDEFINED_GRANULARITIES; + const isGranularitySelectedMap = {}; + memberGranularities.forEach((granularity) => { + isGranularitySelectedMap[granularity] = isSelected(granularity) + }); const selectedGranularity = memberGranularities.find((granularity) => isSelected(granularity)); - // const isGranularitySelected = !!isGranularitySelectedList.find((gran) => gran); open = isCompact ? false : open; @@ -134,6 +139,26 @@ export function TimeListMember(props: ListMemberProps) { ); + const granularityItems = (items, icon) => { + if (!open || isCompact) { + return null; + } + + return items.map((granularity, i) => ( { + onGranularityToggle(member.name, granularity); + setOpen(false); + }} + > + {granularity} + + )); + } + return ( <> {hasOverflow ? ( @@ -166,22 +191,9 @@ export function TimeListMember(props: ListMemberProps) { value ) : null} - {memberGranularities.map((granularity, i) => { - return open && !isCompact ? ( - } - data-member="timeDimension" - isSelected={isGranularitySelectedList[i]} - onPress={() => { - onGranularityToggle(member.name, granularity); - setOpen(false); - }} - > - {granularity} - - ) : null; - })} + {/* TODO: Add special icon for custom granularities and use it here */} + {granularityItems(customGranularities, )} + {granularityItems(PREDEFINED_GRANULARITIES, )} ) : null}