Skip to content

Commit

Permalink
Minor tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Mar 3, 2025
1 parent 3e394a2 commit 3794165
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export function RevenueEventsSettings(): JSX.Element {
</LemonButton>
</div>

<Query
query={eventsQuery}
context={{
showOpenEditorButton: true,
extraDataTableQueryFeatures: [QueryFeature.highlightExceptionEventRows],
}}
/>
{eventsQuery ? (
<Query
query={eventsQuery}
context={{
showOpenEditorButton: true,
extraDataTableQueryFeatures: [QueryFeature.highlightExceptionEventRows],
}}
/>
) : null}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const revenueEventsSettingsLogic = kea<revenueEventsSettingsLogicType>([
],
eventsQuery: [
(s) => [s.revenueTrackingConfig],
(revenueTrackingConfig: RevenueTrackingConfig) => {
(revenueTrackingConfig: RevenueTrackingConfig | null) => {
if (!revenueTrackingConfig) {
return null
}
Expand Down
69 changes: 35 additions & 34 deletions posthog/hogql_queries/utils/revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ def revenue_sum_expression(config: Union[RevenueTrackingConfig, dict, None]) ->
if isinstance(config, dict):
config = RevenueTrackingConfig.model_validate(config)

if not config or not config.events:
return ast.Constant(value=None)

exprs: list[ast.Expr] = []
if config:
for event in config.events:
exprs.append(
ast.Call(
name="sumIf",
args=[
ast.Call(
name="ifNull",
args=[
ast.Call(
name="toFloat",
args=[ast.Field(chain=["events", "properties", event.revenueProperty])],
),
ast.Constant(value=0),
],
),
ast.CompareOperation(
left=ast.Field(chain=["event"]),
op=ast.CompareOperationOp.Eq,
right=ast.Constant(value=event.eventName),
),
],
)
for event in config.events:
exprs.append(
ast.Call(
name="sumIf",
args=[
ast.Call(
name="ifNull",
args=[
ast.Call(
name="toFloat",
args=[ast.Field(chain=["events", "properties", event.revenueProperty])],
),
ast.Constant(value=0),
],
),
ast.CompareOperation(
left=ast.Field(chain=["event"]),
op=ast.CompareOperationOp.Eq,
right=ast.Constant(value=event.eventName),
),
],
)
if not exprs:
return ast.Constant(value=None)
)
if len(exprs) == 1:
return exprs[0]
return ast.Call(name="plus", args=exprs)
Expand All @@ -71,17 +71,18 @@ def revenue_events_exprs(config: Union[RevenueTrackingConfig, dict, None]) -> li
if isinstance(config, dict):
config = RevenueTrackingConfig.model_validate(config)

if not config or not config.events:
return []

exprs: list[ast.Expr] = []
if config:
for event in config.events:
exprs.append(
ast.CompareOperation(
left=ast.Field(chain=["event"]),
op=ast.CompareOperationOp.Eq,
right=ast.Constant(value=event.eventName),
)
for event in config.events:
exprs.append(
ast.CompareOperation(
left=ast.Field(chain=["event"]),
op=ast.CompareOperationOp.Eq,
right=ast.Constant(value=event.eventName),
)

)
return exprs


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def to_query(self) -> ast.SelectQuery:
revenue_events_expr(tracking_config),
ast.CompareOperation(
op=CompareOperationOp.NotEq,
left=revenue_expression(tracking_config),
left=ast.Field(chain=["revenue"]), # refers to the Alias above
right=ast.Constant(value=None),
),
]
Expand Down

0 comments on commit 3794165

Please sign in to comment.