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

V2 - Backports #1343

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
74 changes: 74 additions & 0 deletions .github/workflows/run-tests-pcov-pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: run-tests-pcov-pull

on: [pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2]
laravel: [10]
stability: [prefer-dist]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo
tools: phpunit:latest
ini-values: memory_limit=512M
coverage: pcov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Get composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-

- name: Add token
run: |
composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update

- name: Update dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --${{ matrix.stability }} --no-interaction

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run Unit Tests
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
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODE_COV_TOKEN }}
files: ./coverage.xml
verbose: true


74 changes: 74 additions & 0 deletions .github/workflows/run-tests-pcov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: run-tests-pcov

on: [push]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2]
laravel: [10]
stability: [prefer-dist]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, iconv, fileinfo
tools: phpunit:latest
ini-values: memory_limit=512M
coverage: pcov
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Get composer cache directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-PHP${{ matrix.php }}-Laravel${{ matrix.laravel }}-composer-

- name: Add token
run: |
composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update

- name: Update dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --${{ matrix.stability }} --no-interaction

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run Unit Tests
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
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODE_COV_TOKEN }}
files: ./coverage.xml
verbose: true


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ phpunit.xml.dist.bak
phpunit.xml.dist.dev
.github/workflows/code-cov.yml
.history/*
.env
phpunit.xml.bak
phpstan.txt
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
All notable changes to `laravel-livewire-tables` will be documented in this file

## [Unreleased]
- Enhancements
- Add customisable Search Placeholder - setSearchPlaceholder()
- Add CodeCov workflows

## [2.15.0] - 2023-07-15

Expand Down
11 changes: 11 additions & 0 deletions docs/search/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public function configure(): void
}
```

## setSearchPlaceholder

Set a custom placeholder for the search box

```php
public function configure(): void
{
$this->setSearchPlaceholder('Enter Search Term');
}
```

---

You can only set one of the follow search modifiers:
Expand Down
28 changes: 22 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" cacheResult="false" colors="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" >
<testsuites>
<testsuite name="Laravel Livewire Tables Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="false"
cacheResult="false"
executionOrder="random"
failOnWarning="false"
failOnRisky="false"
failOnEmptyTestSuite="false"
beStrictAboutOutputDuringTests="true" >
<testsuites>
<testsuite name="Laravel Livewire Tables Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>config</directory>
<directory>database</directory>
<directory>src</directory>
</include>
</source>
</phpunit>
12 changes: 6 additions & 6 deletions resources/lang/tk.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"All": "Hemmesi",
"All Columns": "Colhli sütünler",
"All Columns": "Ähli sütünler",
"Applied Filters": "Ulanylýan Süzgüçler",
"Applied Sorting": "Ulanylýan Tertipleşdirme",
"Bulk Actions": "Köpçülikleýin Hereketler",
Expand All @@ -10,22 +10,22 @@
"Deselect All": "Hemmesini Aýyr",
"Done Reordering": "Täzeden Tertiplendi",
"Filters": "Süzgüçler",
"No": "Hayir",
"No": "Ýok",
"No items found. Try to broaden your search.": "Hiç zat tapylmady. Gözlegiňizi giňeltmäge synanyşyň.",
"of": "aralygy",
"Remove filter option": "Süzgüç görnüşini aýyryň",
"Remove sort option": "Tertiplemek görnüşini aýyryň",
"Reorder": "Tertibe salmak",
"results": "netijeler",
"row": "hatarlar",
"row": "hatar",
"rows": "hatarlar",
"rows, do you want to select all": "hatarlar, hemmesini saýlamak isleýärsiňizmi?",
"Search": "Gözlemek",
"Select All": "Hepsini seç",
"Select All": "Hemmesini saýla",
"Showing": "Görkezmek",
"to": "-",
"Yes": "Evet",
"Yes": "Hawa",
"You are currently selecting all": "Häzirki wagtda hemmesini saýlap alýarsyňyz",
"You are not connected to the internet.": "Siz internete birikmediksiňiz.",
"You have selected": "Saýladyňyz"
}
}
9 changes: 6 additions & 3 deletions resources/views/components/tools/toolbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class="inline-flex justify-center items-center w-full md:w-auto px-4 py-2 border
@if ($component->searchIsEnabled() && $component->searchVisibilityIsEnabled())
<div class="flex rounded-md shadow-sm">
<input wire:model{{ $component->getSearchOptions() }}="{{ $component->getTableName() }}.search"
placeholder="{{ __('Search') }}" type="text"
placeholder="{{ $component->getSearchPlaceholder() }}"
type="text"
class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 dark:bg-gray-700 dark:text-white dark:border-gray-600 @if ($component->hasSearch()) rounded-none rounded-l-md focus:ring-0 focus:border-gray-300 @else focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md @endif" />

@if ($component->hasSearch())
Expand Down Expand Up @@ -327,7 +328,8 @@ class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150
@if ($component->searchIsEnabled() && $component->searchVisibilityIsEnabled())
<div class="mb-3 mb-md-0 input-group">
<input wire:model{{ $component->getSearchOptions() }}="{{ $component->getTableName() }}.search"
placeholder="{{ __('Search') }}" type="text" class="form-control">
placeholder="{{ $component->getSearchPlaceholder() }}"
type="text" class="form-control">

@if ($component->hasSearch())
<div class="input-group-append">
Expand Down Expand Up @@ -556,7 +558,8 @@ class="px-2 {{ $loop->last ? 'mb-0' : 'mb-1' }}">
@if ($component->searchIsEnabled() && $component->searchVisibilityIsEnabled())
<div class="mb-3 mb-md-0 input-group">
<input wire:model{{ $component->getSearchOptions() }}="{{ $component->getTableName() }}.search"
placeholder="{{ __('Search') }}" type="text" class="form-control">
placeholder="{{ $component->getSearchPlaceholder() }}"
type="text" class="form-control">

@if ($component->hasSearch())
<button wire:click.prevent="clearSearch" class="btn btn-outline-secondary" type="button">
Expand Down
2 changes: 1 addition & 1 deletion src/DataTableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ abstract class DataTableComponent extends Component
WithEvents,
WithFilters,
WithFooter,
WithSecondaryHeader,
WithPagination,
WithRefresh,
WithReordering,
WithSearch,
WithSecondaryHeader,
WithSorting;

protected $listeners = [
Expand Down
7 changes: 7 additions & 0 deletions src/Traits/Configuration/SearchConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@ public function setSearchLazy(): self

return $this;
}

public function setSearchPlaceholder(string $placeholder): self
{
$this->searchPlaceholder = $placeholder;

return $this;
}
}
10 changes: 10 additions & 0 deletions src/Traits/Helpers/SearchHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,14 @@ public function getSearchOptions(): string

return '';
}

public function getSearchPlaceholder(): string
{
return $this->hasSearchPlaceholder() ? $this->searchPlaceholder : __('Search');
}

public function hasSearchPlaceholder(): bool
{
return $this->searchPlaceholder !== null;
}
}
2 changes: 2 additions & 0 deletions src/Traits/WithSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ trait WithSearch

public ?bool $searchFilterLazy = null;

public ?string $searchPlaceholder = null;

// TODO
public function applySearch(): Builder
{
Expand Down
4 changes: 2 additions & 2 deletions src/Views/Columns/ComponentColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

class ComponentColumn extends Column
{
use ComponentColumnHelpers,
ComponentColumnConfiguration;
use ComponentColumnConfiguration,
ComponentColumnHelpers;

protected string $componentView;

Expand Down
4 changes: 2 additions & 2 deletions src/Views/Columns/ImageColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class ImageColumn extends Column
{
use ImageColumnHelpers,
ImageColumnConfiguration;
use ImageColumnConfiguration,
ImageColumnHelpers;

protected string $view = 'livewire-tables::includes.columns.image';

Expand Down
4 changes: 2 additions & 2 deletions src/Views/Columns/LinkColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class LinkColumn extends Column
{
use LinkColumnHelpers,
LinkColumnConfiguration;
use LinkColumnConfiguration,
LinkColumnHelpers;

protected string $view = 'livewire-tables::includes.columns.link';

Expand Down
11 changes: 11 additions & 0 deletions tests/Traits/Configuration/SearchConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,15 @@ public function cant_set_search_lazy_with_other_search_modifiers(): void
$this->basicTable->setSearchLazy();
$this->basicTable->setSearchDebounce(1000);
}

/** @test */
public function can_set_search_placeholder(): void
{
$this->assertSame(__('Search'), $this->basicTable->getSearchPlaceholder());

$this->basicTable->setSearchPlaceholder('Anthony');

$this->assertSame('Anthony', $this->basicTable->getSearchPlaceholder());

}
}
10 changes: 10 additions & 0 deletions tests/Traits/Helpers/ComponentHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public function can_get_additional_selects(): void
$this->assertEquals(['id', 'name'], $this->basicTable->getAdditionalSelects());
}

/** @test */
public function can_get_additional_selects_nonarray(): void
{
$this->assertEquals([], $this->basicTable->getAdditionalSelects());

$this->basicTable->setAdditionalSelects('name');

$this->assertEquals(['name'], $this->basicTable->getAdditionalSelects());
}

/** @test */
public function can_get_configurable_areas(): void
{
Expand Down
Loading