@@ -32,17 +32,9 @@ export function pickDefaultDrilldowns(dimensions: TesseractDimension[], cube: Te
3232 levels . length < 4
3333 ) {
3434 const hierarchy = findDefaultHierarchy ( dimension ) ;
35- const hierarchyDepth = Math . max ( ...hierarchy . levels . map ( l => l . depth ) ) ;
3635 // uses deepest level for geo dimensions
3736 const levelIndex = dimension . type === "geo" ? hierarchy . levels . length - 1 : 0 ;
3837 const defaultLevel = hierarchy . levels [ levelIndex ] ;
39- if (
40- dimension . type === "time" &&
41- dimension . annotations . de_time_complete === "true" &&
42- defaultLevel . depth < hierarchyDepth
43- ) {
44- timeComplete = defaultLevel . name ;
45- }
4638 levels . push ( { ...defaultLevel , type : dimension . type } ) ;
4739 }
4840 }
@@ -71,6 +63,35 @@ export function pickDefaultDrilldowns(dimensions: TesseractDimension[], cube: Te
7163 }
7264 }
7365
66+ for ( const dimension of dimensions ) {
67+ if ( dimension . annotations . de_time_complete === "true" ) {
68+ const hierarchy = findDefaultHierarchy ( dimension ) ;
69+ const hierarchyLevels = hierarchy . levels ;
70+
71+ // Select all levels of this hierarchy that are currently in the levels array
72+ const availableLevels = hierarchyLevels . filter ( hl => levels . some ( l => l . name === hl . name ) ) ;
73+
74+ if ( availableLevels . length > 0 ) {
75+ // Find the shallowest selected level
76+ const timeCompleteLevel = availableLevels . reduce ( ( prev , curr ) =>
77+ curr . depth < prev . depth ? curr : prev
78+ ) ;
79+
80+ // Find the deepest level in the definition
81+ const deepestLevel = hierarchyLevels . reduce ( ( prev , curr ) =>
82+ curr . depth > prev . depth ? curr : prev
83+ ) ;
84+
85+ // Check if the deepest level is among the selected levels
86+ const deepestLevelSelected = availableLevels . some ( l => l . depth === deepestLevel . depth ) ;
87+
88+ if ( timeCompleteLevel . depth < deepestLevel . depth && ! deepestLevelSelected ) {
89+ timeComplete = timeCompleteLevel . name ;
90+ }
91+ }
92+ }
93+ }
94+
7495 // Calculate the total member count
7596 let totalCount = calcMaxMemberCount ( levels . map ( l => l . count ) ) ;
7697
0 commit comments