Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CountColumn, simpler adding of WithCounts, With #1761

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
ff9dfd1
Initial Commit
lrljoe Jul 5, 2024
be1b208
Fix styling
lrljoe Jul 5, 2024
f1faef6
Adjust CountColumn
lrljoe Jul 5, 2024
2e3fdf8
Fix buildedr
lrljoe Jul 5, 2024
474d7d1
Fix styling
lrljoe Jul 5, 2024
fc20d5f
Fixes
lrljoe Jul 5, 2024
d8a03a3
Fix styling
lrljoe Jul 5, 2024
1621829
Add ExtraWiths
lrljoe Jul 5, 2024
baf668e
Fix styling
lrljoe Jul 5, 2024
5ebf022
Add AggregateColumn
lrljoe Jul 5, 2024
6b39025
Fix styling
lrljoe Jul 5, 2024
9d3b2bd
Add SumColumn
lrljoe Jul 5, 2024
87f7b2f
Fix styling
lrljoe Jul 5, 2024
02b4f6f
Standardise to setDataSource
lrljoe Jul 5, 2024
775d760
Fix styling
lrljoe Jul 5, 2024
cd2ad2c
Adjustments
lrljoe Jul 5, 2024
8e26603
Fix styling
lrljoe Jul 5, 2024
c242a94
Adjust SumColumn
lrljoe Jul 5, 2024
f717b4f
Add fixes
lrljoe Jul 5, 2024
c776bdb
Change CountColumn to extend AggregateColumn
lrljoe Jul 5, 2024
91c8b44
Clean up Helpers
lrljoe Jul 5, 2024
a191aa4
Fix styling
lrljoe Jul 5, 2024
9a5dbe4
AvgCol
lrljoe Jul 5, 2024
b64e527
Fix styling
lrljoe Jul 5, 2024
0e500f1
Adjust Avg/Sum
lrljoe Jul 5, 2024
27eb561
Fix styling
lrljoe Jul 5, 2024
d31fdf0
Start docs
lrljoe Jul 5, 2024
31120f2
Update Docs - Add Column Types Section
lrljoe Jul 5, 2024
8c73630
Migrating Column Docs
lrljoe Jul 5, 2024
a079af2
D
lrljoe Jul 5, 2024
288dee8
Test
lrljoe Jul 5, 2024
fd4f614
Revert Docs Change
lrljoe Jul 5, 2024
5f02d70
Add start of docs for new columns
lrljoe Jul 5, 2024
49ee968
Add Array Column doc
lrljoe Jul 5, 2024
9f0c5b0
Add Livewire Component Column
lrljoe Jul 5, 2024
5629981
Add weights
lrljoe Jul 5, 2024
aaf94e5
Adjust Col Docs
lrljoe Jul 5, 2024
fa9d677
Adding Docs
lrljoe Jul 5, 2024
62f6d62
Add more docs for Agg cols
lrljoe Jul 5, 2024
7c445dc
Add exceptions for empty data source, add standard tests
lrljoe Jul 10, 2024
fb85218
Fix styling
lrljoe Jul 10, 2024
dbdb365
Add additional tests
lrljoe Jul 10, 2024
10044b0
Fix styling
lrljoe Jul 10, 2024
8dc312a
Ensure pcov runs on push to master/development/develop
lrljoe Jul 10, 2024
d5cb666
Add extra tests
lrljoe Jul 10, 2024
ef62fb1
Fix styling
lrljoe Jul 10, 2024
7e7fad5
Update to use codecov v4
lrljoe Jul 10, 2024
5a2ce74
Add Count Render Test
lrljoe Jul 10, 2024
435558c
Fix styling
lrljoe Jul 10, 2024
6d3e83b
Add setForeignColumn tests
lrljoe Jul 10, 2024
c7017f6
Fix styling
lrljoe Jul 10, 2024
e58c1ec
Add ExtraWithAvgs tests
lrljoe Jul 10, 2024
efc4521
Fix styling
lrljoe Jul 10, 2024
08de9bd
Update ChangeLog
lrljoe Jul 10, 2024
351b2a7
Update Tests for AvgColumn and SumColumn
lrljoe Jul 10, 2024
bf6e12f
Fix styling
lrljoe Jul 10, 2024
994aecd
Add ArrayColumnTest
lrljoe Jul 10, 2024
dc9b099
Fix styling
lrljoe Jul 10, 2024
0bc1c01
Add ArrayColumnTest
lrljoe Jul 10, 2024
308358a
Fix styling
lrljoe Jul 10, 2024
fa128df
Add emptyValue option
lrljoe Jul 10, 2024
1a846bc
Fix styling
lrljoe Jul 10, 2024
df7de52
Move getContent to Helper method
lrljoe Jul 10, 2024
94a15f8
Fix styling
lrljoe Jul 10, 2024
1e4a25a
Add IsAggregateColumn trait
lrljoe Jul 10, 2024
680e6c8
Fix styling
lrljoe Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/run-tests-pcov-pull.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: run-tests-pcov-pull

on:
push:
branches:
- 'develop'
- 'development'
- 'master'
pull_request:
branches:
- 'develop'
Expand All @@ -18,7 +23,7 @@ jobs:
laravel: [10]
stability: [prefer-dist]

name: PCOV-PULL - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
name: PCOV - ${{ matrix.os }} - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
env:
extensionKey: phpextensions-${{ matrix.os }}-P${{ matrix.php }}-withpcov
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pcov,pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
Expand Down Expand Up @@ -86,7 +91,7 @@ jobs:
run: php ./vendor/bin/paratest --cache-directory=".phpunit.cache/code-coverage" --strict-coverage --coverage-clover ./coverage.xml --processes=4

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ phpunit.xml.dist.dev
.history/*
.env
phpunit.xml.bak
phpstan.txt
phpstan.txt
coverage.xml
./tmp/**
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## UNRELEASED
### New Features
- Add new columns (ArrayColumn, AvgColumn, CountColumn, SumColumn) by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1761

## [v3.2.8] - 2024-07-03
### Bug Fixes
- Fix hide bulk actions when empty not reflecting in frontend by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1747
Expand Down
2,894 changes: 0 additions & 2,894 deletions coverage.xml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/bulk-actions/_index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
title: Bulk Actions
weight: 9
weight: 10
---
4 changes: 4 additions & 0 deletions docs/column-types/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Column Types
weight: 5
---
22 changes: 22 additions & 0 deletions docs/column-types/array_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Array Columns (beta)
weight: 1
---

Array columns provide an easy way to work with and display an array of data from a field.

```
ArrayColumn::make('notes', 'name')
->data(fn($value, $row) => ($row->notes))
->outputFormat(fn($index, $value) => "<a href='".$value->id."'>".$value->name."</a>")
->separator('<br />')
->sortable(),
```

### Empty Value
You may define the default/empty value using the "emptyValue" method

```
ArrayColumn::make('notes', 'name')
->emptyValue('Unknown'),
```
14 changes: 14 additions & 0 deletions docs/column-types/avg_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Avg Columns (beta)
weight: 2
---

Avg columns provide an easy way to display the "Average" of a field on a relation.

```
AvgColumn::make('Average Related User Age')
->setDataSource('users','age')
->sortable(),
```

The "sortable()" callback can accept a callback, or you can use the default behaviour, which calculates the correct field to sort on.
81 changes: 81 additions & 0 deletions docs/column-types/boolean_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Boolean Columns
weight: 3
---

Boolean columns are good if you have a column type that is a true/false, or 0/1 value.

For example:

```php
BooleanColumn::make('Active')
```

Would yield:

![Boolean Column](https://imgur.com/LAk6gHY.png)

### Using your own view

If you don't want to use the default view and icons you can set your own:

```php
BooleanColumn::make('Active')
->setView('my.active.view')
```

You will have access to `$component`, `$status`, and `$successValue`.

To help you better understand, this is the Tailwind implementation of BooleanColumn:

```html
@if ($status)
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === true) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
@else
<svg xmlns="http://www.w3.org/2000/svg" class="inline-block h-5 w-5 @if ($successValue === false) text-green-500 @else text-red-500 @endif" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
@endif
```

### Setting the truthy value

If you want the false value to be the green option, you can set:

```php
BooleanColumn::make('Active')
->setSuccessValue(false); // Makes false the 'successful' option
```

That would swap the colors of the icons in the image above.

### Setting the status value

By default, the `$status` is set to:

```php
(bool)$value === true
```

You can override this functionality:

```php
BooleanColumn::make('Active')
// Note: Parameter `$row` available as of v2.4
->setCallback(function(string $value, $row) {
// Figure out what makes $value true
}),
```

### Different types of boolean display

By default, the BooleanColumn displays icons.

If you would like the BooleanColumn to display a plain Yes/No, you can set:

```php
BooleanColumn::make('Active')
->yesNo()
```
34 changes: 34 additions & 0 deletions docs/column-types/button_group_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Button Group Columns
weight: 4
---

Button group columns let you provide an array of LinkColumns to display in a single cell.

```php
ButtonGroupColumn::make('Actions')
->attributes(function($row) {
return [
'class' => 'space-x-2',
];
})
->buttons([
LinkColumn::make('View') // make() has no effect in this case but needs to be set anyway
->title(fn($row) => 'View ' . $row->name)
->location(fn($row) => route('user.show', $row))
->attributes(function($row) {
return [
'class' => 'underline text-blue-500 hover:no-underline',
];
}),
LinkColumn::make('Edit')
->title(fn($row) => 'Edit ' . $row->name)
->location(fn($row) => route('user.edit', $row))
->attributes(function($row) {
return [
'target' => '_blank',
'class' => 'underline text-blue-500 hover:no-underline',
];
}),
]),
```
41 changes: 41 additions & 0 deletions docs/column-types/color_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Color Columns
weight: 5
---

Color columns provide an easy way to a Color in a Column

You may pass either pass a CSS-compliant colour as a field
```php
ColorColumn::make('Favourite Colour', 'favourite_color'),
```

Or you may use a Callback
```php
ColorColumn::make('Favourite Colour')
->color(
function ($row) {
if ($row->success_rate < 40)
{
return '#ff0000';
}
else if ($row->success_rate > 90)
{
return '#008000';
}
else return '#ffa500';

}
),
```

You may also specify attributes to use on the div displaying the color, to adjust the size or appearance, this receives the full row. By default, this will replace the standard classes, to retain them, set "default" to true. To then over-ride, you should prefix your classes with "!" to signify importance.
```php
ColorColumn::make('Favourite Colour')
->attributes(function ($row) {
return [
'class' => '!rounded-lg self-center',
'default' => true,
];
}),
```
28 changes: 28 additions & 0 deletions docs/column-types/component_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Component Columns
weight: 6
---

Component columns let you specify a component name and attributes and provides the column value to the slot.

```php
// Before
Column::make("Email", "email")
->format(function ($value) {
return view('components.alert')
->with('attributes', new ComponentAttributeBag([
'type' => Str::endsWith($value, 'example.org') ? 'success' : 'danger',
'dismissible' => true,
]))
->with('slot', $value);
}),

// After
ComponentColumn::make('E-mail', 'email')
->component('email')
->attributes(fn ($value, $row, Column $column) => [
'type' => Str::endsWith($value, 'example.org') ? 'success' : 'danger',
'dismissible' => true,
]),
```

14 changes: 14 additions & 0 deletions docs/column-types/count_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Count Columns (beta)
weight: 7
---

Count columns provide an easy way to display the "Count" of a relation.

```
CountColumn::make('Related Users')
->setDataSource('users')
->sortable(),
```

The "sortable()" callback can accept a callback, or you can use the default behaviour, which calculates the correct field to sort on.
28 changes: 28 additions & 0 deletions docs/column-types/date_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Date Columns
weight: 8
---

Date columns provide an easy way to display dates in a given format, without having to use repetitive format() methods or partial views.

You may pass either a DateTime object, in which you can define an "outputFormat"
```php
DateColumn::make('Updated At', 'updated_at')
->outputFormat('Y-m-d H:i:s),
```

Or you may pass a string, in which case you can define an "inputFormat" in addition to the outputFormat:
```php
DateColumn::make('Last Charged', 'last_charged_at')
->inputFormat('Y-m-d H:i:s')
->outputFormat('Y-m-d'),
```

You may also set an "emptyValue" to use when there is no value from the database:
```php
DateColumn::make('Last Charged', 'last_charged_at')
->inputFormat('Y-m-d H:i:s')
->outputFormat('Y-m-d')
->emptyValue('Not Found'),
```

26 changes: 26 additions & 0 deletions docs/column-types/image_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: Image Columns
weight: 9
---

Image columns provide a way to display images in your table without having to use `format()` or partial views:

```php
ImageColumn::make('Avatar')
->location(
fn($row) => storage_path('app/public/avatars/' . $row->id . '.jpg')
),
```

You may also pass an array of attributes to apply to the image tag:

```php
ImageColumn::make('Avatar')
->location(
fn($row) => storage_path('app/public/avatars/' . $row->id . '.jpg')
)
->attributes(fn($row) => [
'class' => 'rounded-full',
'alt' => $row->name . ' Avatar',
]),
```
24 changes: 24 additions & 0 deletions docs/column-types/link_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Link Columns
weight: 10
---

Link columns provide a way to display HTML links in your table without having to use `format()` or partial views:

```php
LinkColumn::make('Action')
->title(fn($row) => 'Edit')
->location(fn($row) => route('admin.users.edit', $row)),
```

You may also pass an array of attributes to apply to the `a` tag:

```php
LinkColumn::make('Action')
->title(fn($row) => 'Edit')
->location(fn($row) => route('admin.users.edit', $row))
->attributes(fn($row) => [
'class' => 'rounded-full',
'alt' => $row->name . ' Avatar',
]),
```
5 changes: 5 additions & 0 deletions docs/column-types/livewire_component_column.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Livewire Component (beta)
weight: 11
---

Loading