@@ -16,7 +16,9 @@ interface AnalyticsLibraryProps {
1616 onAddFormulaMetric : ( ) => void ;
1717 onMoveMetric : ( metricId : string , direction : 'up' | 'down' ) => void ;
1818 onAddStreak : ( ) => void ;
19+ onMoveStreak : ( streakId : string , direction : 'up' | 'down' ) => void ;
1920 onAddChart : ( ) => void ;
21+ onMoveChart : ( chartId : string , direction : 'up' | 'down' ) => void ;
2022}
2123
2224function LibrarySection ( {
@@ -122,7 +124,9 @@ export function AnalyticsLibrary({
122124 onAddFormulaMetric,
123125 onMoveMetric,
124126 onAddStreak,
125- onAddChart
127+ onMoveStreak,
128+ onAddChart,
129+ onMoveChart
126130} : AnalyticsLibraryProps ) {
127131 const baseMetrics = metrics . filter ( ( metric ) => metric . kind === 'base' ) ;
128132 const formulaMetrics = metrics . filter ( ( metric ) => metric . kind === 'formula' ) ;
@@ -137,19 +141,16 @@ export function AnalyticsLibrary({
137141 { baseMetrics . length === 0 ? (
138142 < p className = "text-xs text-muted" > No custom metrics yet.</ p >
139143 ) : (
140- baseMetrics . map ( ( metric ) => (
144+ baseMetrics . map ( ( metric , index ) => (
141145 < LibraryItem
142146 key = { metric . id }
143147 label = { metric . name }
144148 sublabel = { metric . base ?. measure }
145149 active = { selectedItem ?. kind === 'metric' && selectedItem . id === metric . id }
146150 onClick = { ( ) => onSelect ( { kind : 'metric' , id : metric . id } ) }
147151 showMoveControls = { showActions }
148- canMoveUp = { baseMetrics . findIndex ( ( candidate ) => candidate . id === metric . id ) > 0 }
149- canMoveDown = {
150- baseMetrics . findIndex ( ( candidate ) => candidate . id === metric . id ) <
151- baseMetrics . length - 1
152- }
152+ canMoveUp = { index > 0 }
153+ canMoveDown = { index < baseMetrics . length - 1 }
153154 onMoveUp = { ( ) => onMoveMetric ( metric . id , 'up' ) }
154155 onMoveDown = { ( ) => onMoveMetric ( metric . id , 'down' ) }
155156 />
@@ -165,19 +166,16 @@ export function AnalyticsLibrary({
165166 { formulaMetrics . length === 0 ? (
166167 < p className = "text-xs text-muted" > No formula metrics yet.</ p >
167168 ) : (
168- formulaMetrics . map ( ( metric ) => (
169+ formulaMetrics . map ( ( metric , index ) => (
169170 < LibraryItem
170171 key = { metric . id }
171172 label = { metric . name }
172173 sublabel = { metric . formula ?. operator }
173174 active = { selectedItem ?. kind === 'metric' && selectedItem . id === metric . id }
174175 onClick = { ( ) => onSelect ( { kind : 'metric' , id : metric . id } ) }
175176 showMoveControls = { showActions }
176- canMoveUp = { formulaMetrics . findIndex ( ( candidate ) => candidate . id === metric . id ) > 0 }
177- canMoveDown = {
178- formulaMetrics . findIndex ( ( candidate ) => candidate . id === metric . id ) <
179- formulaMetrics . length - 1
180- }
177+ canMoveUp = { index > 0 }
178+ canMoveDown = { index < formulaMetrics . length - 1 }
181179 onMoveUp = { ( ) => onMoveMetric ( metric . id , 'up' ) }
182180 onMoveDown = { ( ) => onMoveMetric ( metric . id , 'down' ) }
183181 />
@@ -193,18 +191,23 @@ export function AnalyticsLibrary({
193191 { streaks . length === 0 ? (
194192 < p className = "text-xs text-muted" > No streaks yet.</ p >
195193 ) : (
196- streaks . map ( ( streak ) => {
194+ streaks . map ( ( streak , index ) => {
197195 const requiredMetricCount = 1 + ( streak . additionalMetricIds ?. length ?? 0 ) ;
198196 return (
199- < LibraryItem
200- key = { streak . id }
201- label = { streak . name }
202- sublabel = { `${ streak . period } ${ streak . thresholdOperator } ${ streak . thresholdValue } ${
203- requiredMetricCount > 1 ? ` · ${ requiredMetricCount } metrics (AND)` : ''
204- } `}
205- active = { selectedItem ?. kind === 'streak' && selectedItem . id === streak . id }
206- onClick = { ( ) => onSelect ( { kind : 'streak' , id : streak . id } ) }
207- />
197+ < LibraryItem
198+ key = { streak . id }
199+ label = { streak . name }
200+ sublabel = { `${ streak . period } ${ streak . thresholdOperator } ${ streak . thresholdValue } ${
201+ requiredMetricCount > 1 ? ` · ${ requiredMetricCount } metrics (AND)` : ''
202+ } `}
203+ active = { selectedItem ?. kind === 'streak' && selectedItem . id === streak . id }
204+ onClick = { ( ) => onSelect ( { kind : 'streak' , id : streak . id } ) }
205+ showMoveControls = { showActions }
206+ canMoveUp = { index > 0 }
207+ canMoveDown = { index < streaks . length - 1 }
208+ onMoveUp = { ( ) => onMoveStreak ( streak . id , 'up' ) }
209+ onMoveDown = { ( ) => onMoveStreak ( streak . id , 'down' ) }
210+ />
208211 ) ;
209212 } )
210213 ) }
@@ -218,13 +221,18 @@ export function AnalyticsLibrary({
218221 { charts . length === 0 ? (
219222 < p className = "text-xs text-muted" > No chart views yet.</ p >
220223 ) : (
221- charts . map ( ( chart ) => (
224+ charts . map ( ( chart , index ) => (
222225 < LibraryItem
223226 key = { chart . id }
224227 label = { chart . name }
225228 sublabel = { `${ chart . chartType } · ${ chart . granularity } ` }
226229 active = { selectedItem ?. kind === 'chart' && selectedItem . id === chart . id }
227230 onClick = { ( ) => onSelect ( { kind : 'chart' , id : chart . id } ) }
231+ showMoveControls = { showActions }
232+ canMoveUp = { index > 0 }
233+ canMoveDown = { index < charts . length - 1 }
234+ onMoveUp = { ( ) => onMoveChart ( chart . id , 'up' ) }
235+ onMoveDown = { ( ) => onMoveChart ( chart . id , 'down' ) }
228236 />
229237 ) )
230238 ) }
0 commit comments