chore: update normalize funnel steps

Signed-off-by: Shivanshu Raj Shrivastava <shivanshu1333@gmail.com>
This commit is contained in:
Shivanshu Raj Shrivastava 2025-04-29 17:24:00 +05:30
parent 9a96817a88
commit 77cd490e48
No known key found for this signature in database
GPG Key ID: D34D26C62AC3E9AE

View File

@ -48,17 +48,28 @@ func ValidateFunnelSteps(steps []tracefunnel.FunnelStep) error {
return nil return nil
} }
// NormalizeFunnelSteps normalizes step orders to be sequential // NormalizeFunnelSteps normalizes step orders to be sequential starting from 1.
// Returns a new slice with normalized step orders, leaving the input slice unchanged.
func NormalizeFunnelSteps(steps []tracefunnel.FunnelStep) []tracefunnel.FunnelStep { func NormalizeFunnelSteps(steps []tracefunnel.FunnelStep) []tracefunnel.FunnelStep {
sort.Slice(steps, func(i, j int) bool { if len(steps) == 0 {
return steps[i].Order < steps[j].Order return nil
})
for i := range steps {
steps[i].Order = int64(i + 1)
} }
return steps // Create a copy of the input slice
newSteps := make([]tracefunnel.FunnelStep, len(steps))
copy(newSteps, steps)
// Sort the copy
sort.Slice(newSteps, func(i, j int) bool {
return newSteps[i].Order < newSteps[j].Order
})
// Update orders in the copy
for i := range newSteps {
newSteps[i].Order = int64(i + 1)
}
return newSteps
} }
func GetClaims(r *http.Request) (*authtypes.Claims, error) { func GetClaims(r *http.Request) (*authtypes.Claims, error) {