Skip to content

Commit c4a217b

Browse files
Use friendly labels for aggregate functions and column header
Rename functions to Count/Sum/Average/Minimum/Maximum. Change 'Aggregate Column' label to 'Value Column'. Use human-readable column header like 'Sum of Salary' instead of 'SUM(payroll.salary)'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f4f6ada commit c4a217b

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/ReportBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function rowsQuery()
2828
return $query;
2929
}
3030

31-
if (! in_array($this->aggregateFunction, $this->aggregateFunctions(), true)) {
31+
if (! array_key_exists($this->aggregateFunction, $this->aggregateFunctions())) {
3232
return $query;
3333
}
3434

src/Support/Concerns/WithReportBuilder.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ public function hasGroupBy(): bool
8383

8484
public function aggregateFunctions(): array
8585
{
86-
return ['COUNT', 'SUM', 'AVG', 'MIN', 'MAX'];
86+
return [
87+
'COUNT' => 'Count',
88+
'SUM' => 'Sum',
89+
'AVG' => 'Average',
90+
'MIN' => 'Minimum',
91+
'MAX' => 'Maximum',
92+
];
8793
}
8894

8995
public function availableGroupByColumns(): array
@@ -199,20 +205,22 @@ public function buildColumns(): array
199205
$groupColumn->reformatUsing(fn ($value) => $options[$value] ?? $value);
200206
}
201207

208+
$functionLabel = $this->aggregateFunctions()[$this->aggregateFunction] ?? $this->aggregateFunction;
209+
$aggregateConfig = $this->aggregateFunction !== 'COUNT'
210+
? $this->findElementByKey($this->availableColumns(), $this->aggregateColumn)
211+
: null;
212+
$aggregateColumnLabel = $aggregateConfig['label'] ?? $this->aggregateColumn;
213+
202214
$aggregateLabel = $this->aggregateFunction === 'COUNT'
203-
? 'Count'
204-
: "{$this->aggregateFunction}({$this->aggregateColumn})";
215+
? $functionLabel
216+
: "{$functionLabel} of {$aggregateColumnLabel}";
205217

206218
$aggregateCol = Column::make($aggregateLabel, 'aggregate')
207219
->justify('right')
208220
->sortable();
209221

210-
if ($this->aggregateFunction !== 'COUNT') {
211-
$aggregateConfig = $this->findElementByKey($this->availableColumns(), $this->aggregateColumn);
212-
213-
if (! empty($aggregateConfig['view'])) {
214-
$aggregateCol->component($aggregateConfig['view']);
215-
}
222+
if ($aggregateConfig && ! empty($aggregateConfig['view'])) {
223+
$aggregateCol->component($aggregateConfig['view']);
216224
}
217225

218226
return [

0 commit comments

Comments
 (0)