Skip to content

Commit 6c5d33d

Browse files
Merge pull request #54 from kirschbaum-development/enable-method
New enable method, instead of disable
2 parents 2df066f + aa63af6 commit 6c5d33d

6 files changed

Lines changed: 147 additions & 55 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ All notable changes to `nova-inline-select` will be documented in this file
4141
- Github Actions now doing the heavy lifting for tests. Thanks [@luisdalmolin](https://github.com/luisdalmolin) [#19](https://github.com/kirschbaum-development/nova-inline-select/issues/19).
4242
- Added pretty printing results for PHPUnit tests
4343

44-
## 2.0.0 - 2022-5-22
44+
## 2.0.0 - 2022-4-22
4545

4646
- Upgraded and ready for Nova 4!
47+
48+
## 2.0.1 - 2022-5-23
49+
50+
- Added `enableOneStepOn...()` methods to eventually replace `disableTwoStepOn...()` methods.

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class User extends Resource
5454
}
5555
```
5656

57-
Now you can use the `InlineSelect` field just like Nova's `Select` field. Now for the magic...
57+
Use the `InlineSelect` field just like Nova's `Select` field. But now for the magic...
5858

5959
### Inline editing
6060

@@ -66,22 +66,22 @@ InlineSelect::make('Status')->options($options)
6666
->inlineOnDetail(),
6767
```
6868

69-
Now the above inline select field will show up on both the index and detail views. When making a change to the select field, a button will display next to the field allowing you to commit the change. If you would prefer the field to auto-submit the change, just add `disableTwoStepOnIndex()` or `disableTwoStepOnDetail()`.
69+
The above inline select field will show up on both the index and detail views. When making a change to the select field, a button will display next to the field allowing you to commit the change. If you would rather the field auto-submits the change, simply add `enableOneStepOnIndex()` or `enableOneStepOnDetail()`.
7070

7171
```php
7272
InlineSelect::make('Status')->options($options)
7373
->inlineOnIndex()
74-
->disableTwoStepOnIndex(),
74+
->enableOneStepOnIndex(),
7575
```
7676

77-
Now changing the select field on the index view will auto-submit the changed value.
77+
The inline select field on the index view now will auto-submit the changed value. You can also continue to use the old `disableTwoStepOnIndex()` method if you choose, which just calls `enableOneStepOnIndex()` under the hood.
7878

79-
You can also add the inline select to Lenses. Use the `inlineOnLens()` method. Auto-submitting works the same as well with `disableTwoStepOnLens()`.
79+
You can also add the inline select to Lenses. Use the `inlineOnLens()` method. Auto-submitting works the same as well with `enableOneStepOnLens()`.
8080

8181
```php
8282
InlineSelect::make('Status')->options($options)
8383
->inlineOnLens()
84-
->disableTwoStepOnLens(),
84+
->enableOneStepOnLens(),
8585
```
8686

8787
### Display using labels

src/InlineSelect.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,72 @@ class InlineSelect extends Select
1515

1616
/**
1717
* Allow inline select to auto-update field value on change on detail view.
18-
*
19-
* @return $this
2018
*/
21-
public function disableTwoStepOnDetail()
19+
public function enableOneStepOnDetail(): InlineSelect
2220
{
2321
return $this->withMeta(['detailTwoStepDisabled' => true]);
2422
}
2523

24+
/**
25+
* Allow inline select to auto-update field value on change on detail view.
26+
*/
27+
public function disableTwoStepOnDetail(): InlineSelect
28+
{
29+
return $this->enableOneStepOnDetail();
30+
}
31+
2632
/**
2733
* Allow inline select to auto-update field value on change on index view.
28-
*
29-
* @return $this
3034
*/
31-
public function disableTwoStepOnIndex()
35+
public function enableOneStepOnIndex(): InlineSelect
3236
{
3337
return $this->withMeta(['indexTwoStepDisabled' => true]);
3438
}
3539

3640
/**
3741
* Allow inline select to auto-update field value on change on index view.
38-
*
39-
* @return $this
4042
*/
41-
public function disableTwoStepOnLens()
43+
public function disableTwoStepOnIndex(): InlineSelect
44+
{
45+
return $this->enableOneStepOnIndex();
46+
}
47+
48+
/**
49+
* Allow inline select to auto-update field value on change on index view.
50+
*/
51+
public function enableOneStepOnLens(): InlineSelect
52+
{
53+
return $this->enableOneStepOnIndex();
54+
}
55+
56+
/**
57+
* Allow inline select to auto-update field value on change on index view.
58+
*/
59+
public function disableTwoStepOnLens(): InlineSelect
4260
{
43-
return $this->disableTwoStepOnIndex();
61+
return $this->enableOneStepOnIndex();
4462
}
4563

4664
/**
4765
* Enable inline editing on detail view.
48-
*
49-
* @return $this
5066
*/
51-
public function inlineOnDetail()
67+
public function inlineOnDetail(): InlineSelect
5268
{
5369
return $this->withMeta(['inlineDetail' => true]);
5470
}
5571

5672
/**
5773
* Enable inline editing on index view.
58-
*
59-
* @return $this
6074
*/
61-
public function inlineOnIndex()
75+
public function inlineOnIndex(): InlineSelect
6276
{
6377
return $this->withMeta(['inlineIndex' => true]);
6478
}
6579

6680
/**
6781
* Enable inline editing on index view.
68-
*
69-
* @return $this
7082
*/
71-
public function inlineOnLens()
83+
public function inlineOnLens(): InlineSelect
7284
{
7385
return $this->inlineOnIndex();
7486
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use KirschbaumDevelopment\Nova\InlineSelect;
8+
9+
class InlineSelectDetailTest extends TestCase
10+
{
11+
use WithFaker;
12+
13+
/**
14+
* @var InlineSelect
15+
*/
16+
protected InlineSelect $inlineSelect;
17+
18+
/**
19+
* @before
20+
*/
21+
public function setUp(): void
22+
{
23+
parent::setUp();
24+
25+
$this->inlineSelect = new InlineSelect('inline-select');
26+
}
27+
28+
public function testThatItInlinesOnDetail()
29+
{
30+
$this->inlineSelect->inlineOnDetail();
31+
32+
$this->assertTrue($this->inlineSelect->meta['inlineDetail']);
33+
}
34+
35+
public function testThatItEnablesOneStepOnDetail()
36+
{
37+
$this->inlineSelect->enableOneStepOnDetail();
38+
39+
$this->assertTrue($this->inlineSelect->meta['detailTwoStepDisabled']);
40+
}
41+
42+
public function testThatItDisablesTwoStepOnDetail()
43+
{
44+
$this->inlineSelect->disableTwoStepOnDetail();
45+
46+
$this->assertTrue($this->inlineSelect->meta['detailTwoStepDisabled']);
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3-
namespace Tests;
3+
namespace Tests\Unit;
44

5+
use Tests\TestCase;
56
use Illuminate\Foundation\Testing\WithFaker;
67
use KirschbaumDevelopment\Nova\InlineSelect;
78

8-
class InlineSelectFieldTest extends TestCase
9+
class InlineSelectIndexTest extends TestCase
910
{
1011
use WithFaker;
1112

@@ -24,45 +25,24 @@ public function setUp(): void
2425
$this->inlineSelect = new InlineSelect('inline-select');
2526
}
2627

27-
public function testThatItDisablesTwoStepOnDetail()
28-
{
29-
$this->inlineSelect->disableTwoStepOnDetail();
30-
31-
$this->assertTrue($this->inlineSelect->meta['detailTwoStepDisabled']);
32-
}
33-
34-
public function testThatItDisablesTwoStepOnIndex()
35-
{
36-
$this->inlineSelect->disableTwoStepOnIndex();
37-
38-
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
39-
}
40-
41-
public function testThatItDisablesTwoStepOnLens()
42-
{
43-
$this->inlineSelect->disableTwoStepOnLens();
44-
45-
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
46-
}
47-
4828
public function testThatItInlinesOnIndex()
4929
{
5030
$this->inlineSelect->inlineOnIndex();
5131

5232
$this->assertTrue($this->inlineSelect->meta['inlineIndex']);
5333
}
5434

55-
public function testThatItInlinesOnLens()
35+
public function testThatItEnablesOneStepOnIndex()
5636
{
57-
$this->inlineSelect->inlineOnIndex();
37+
$this->inlineSelect->enableOneStepOnIndex();
5838

59-
$this->assertTrue($this->inlineSelect->meta['inlineIndex']);
39+
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
6040
}
6141

62-
public function testThatItInlinesOnDetail()
42+
public function testThatItDisablesTwoStepOnIndex()
6343
{
64-
$this->inlineSelect->inlineOnDetail();
44+
$this->inlineSelect->disableTwoStepOnIndex();
6545

66-
$this->assertTrue($this->inlineSelect->meta['inlineDetail']);
46+
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
6747
}
6848
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Tests\TestCase;
6+
use Illuminate\Foundation\Testing\WithFaker;
7+
use KirschbaumDevelopment\Nova\InlineSelect;
8+
9+
class InlineSelectLensTest extends TestCase
10+
{
11+
use WithFaker;
12+
13+
/**
14+
* @var InlineSelect
15+
*/
16+
protected InlineSelect $inlineSelect;
17+
18+
/**
19+
* @before
20+
*/
21+
public function setUp(): void
22+
{
23+
parent::setUp();
24+
25+
$this->inlineSelect = new InlineSelect('inline-select');
26+
}
27+
28+
public function testThatItInlinesOnLens()
29+
{
30+
$this->inlineSelect->inlineOnIndex();
31+
32+
$this->assertTrue($this->inlineSelect->meta['inlineIndex']);
33+
}
34+
35+
public function testThatItEnablesOneStepOnLens()
36+
{
37+
$this->inlineSelect->enableOneStepOnLens();
38+
39+
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
40+
}
41+
42+
public function testThatItDisablesTwoStepOnLens()
43+
{
44+
$this->inlineSelect->disableTwoStepOnLens();
45+
46+
$this->assertTrue($this->inlineSelect->meta['indexTwoStepDisabled']);
47+
}
48+
}

0 commit comments

Comments
 (0)