Repository: statamic-rad-pack/runway (php)

Issue:
Save erased data
### Description

I had a published model with this data:
![CleanShot 2024-06-28 at 11 23 09@2x](https://github.com/statamic-rad-pack/runway/assets/6069653/e2fb457a-5918-44a4-9746-c762a0b51a27)

Then I changed one field and when I hit save (cmd+s), a working copy was created that was empty and my existing data disappeared:
![CleanShot 2024-06-28 at 11 24 12@2x](https://github.com/statamic-rad-pack/runway/assets/6069653/dea28863-0b19-4452-b633-9e6188197bd6)

![CleanShot 2024-06-28 at 11 24 37@2x](https://github.com/statamic-rad-pack/runway/assets/6069653/b5a1a570-f63f-41cf-8f80-e4f0a79eca0c)



### Steps to reproduce

1. have published model, with data in a json column
2. edit that data
3. save

### Environment


Environment
Application Name: Zakat Foundation of America
Laravel Version: 11.13.0
PHP Version: 8.3.8
Composer Version: 2.7.6
Environment: local
Debug Mode: ENABLED
URL: zakat.test
Maintenance Mode: OFF
Timezone: America/Los_Angeles
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: null
Cache: file
Database: mysql
Logs: stack / daily
Mail: smtp
Queue: sync
Session: file

Livewire
Livewire: v3.5.1

Statamic
Addons: 13
Sites: 3 (zakat.org (EN), zakat.org (AR), zfinstitute.com (ZFI))
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.11.0 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.12.0
edalzell/forma: 3.0.1
jacksleight/statamic-bard-mutator: 2.3.1
jacksleight/statamic-distill: 0.7.1
jonassiewertsen/statamic-livewire: 3.6.0
statamic-rad-pack/runway: 7.5.1
statamic/seo-pro: 6.0.3
transformstudios/events: 5.4.3
transformstudios/front: 3.0.1
transformstudios/github: dev-main
transformstudios/neon: dev-feature/enable-revisions
transformstudios/review: 5.0
transformstudios/simple: 5.1.7


Pull request:
[7.x] Handle json data in revisions
Fixes #541 

Patch:
diff --git a/composer.json b/composer.json
index 7e1a51f..6059dd2 100644
--- a/composer.json
+++ b/composer.json
@@ -20,7 +20,10 @@
             "StatamicRadPack\\Runway\\Tests\\": "tests",
             "StatamicRadPack\\Runway\\Tests\\Fixtures\\": "tests/__fixtures__/app",
             "StatamicRadPack\\Runway\\Tests\\Fixtures\\Database\\Factories\\": "tests/__fixtures__/database/factories"
-        }
+        },
+        "classmap": [
+            "tests/__fixtures__/database"
+        ]
     },
     "extra": {
         "statamic": {
diff --git a/resources/js/components/Publish/PublishForm.vue b/resources/js/components/Publish/PublishForm.vue
index c7489c9..f8d0034 100644
--- a/resources/js/components/Publish/PublishForm.vue
+++ b/resources/js/components/Publish/PublishForm.vue
@@ -5,7 +5,7 @@
         <div class="flex items-center mb-6">
             <h1 class="flex-1">
                 <div class="flex items-center">
-                    <span v-html="$options.filters.striptags(__(title))" />
+                    <span v-html="$options.filters.striptags(title)" />
                 </div>
             </h1>
 
@@ -116,11 +116,11 @@
                                 <label class="publish-field-label font-medium mb-2" v-text="__('Revisions')"/>
                                 <div class="mb-1 flex items-center" v-if="published">
                                     <span class="text-green-600 w-6 text-center">&check;</span>
-                                    <span class="text-2xs" v-text="__('Entry has a published version')"></span>
+                                    <span class="text-2xs" v-text="__('Model has a published version')"></span>
                                 </div>
                                 <div class="mb-1 flex items-center" v-else>
                                     <span class="text-orange w-6 text-center">!</span>
-                                    <span class="text-2xs" v-text="__('Entry has not been published')"></span>
+                                    <span class="text-2xs" v-text="__('Model has not been published')"></span>
                                 </div>
                                 <div class="mb-1 flex items-center" v-if="!isWorkingCopy && published">
                                     <span class="text-green-600 w-6 text-center">&check;</span>
@@ -330,6 +330,8 @@ export default {
 
         saveText() {
             switch(true) {
+                case this.revisionsEnabled:
+                    return __('Save Changes');
                 case this.isUnpublishing:
                     return __('Save & Unpublish');
                 case this.publishStatesEnabled && this.isDraft:
diff --git a/src/Actions/Publish.php b/src/Actions/Publish.php
index d6bbacd..9bcafdb 100644
--- a/src/Actions/Publish.php
+++ b/src/Actions/Publish.php
@@ -22,11 +22,7 @@ class Publish extends Action
 
     public function visibleToBulk($items)
     {
-        if ($items->filter(fn ($item) => $item->published())->count() > 0) {
-            return false;
-        }
-
-        return true;
+        return $items->every(fn ($item) => $this->visibleTo($item));
     }
 
     public function authorize($user, $item)
diff --git a/src/Actions/Unpublish.php b/src/Actions/Unpublish.php
index a731a50..3fa1d67 100644
--- a/src/Actions/Unpublish.php
+++ b/src/Actions/Unpublish.php
@@ -22,11 +22,7 @@ class Unpublish extends Action
 
     public function visibleToBulk($items)
     {
-        if ($items->reject(fn ($item) => $item->published())->count() > 0) {
-            return false;
-        }
-
-        return true;
+        return $items->every(fn ($item) => $this->visibleTo($item));
     }
 
     public function authorize($user, $item)
diff --git a/src/Traits/HasRunwayResource.php b/src/Traits/HasRunwayResource.php
index 6fe8ff8..729d3ed 100644
--- a/src/Traits/HasRunwayResource.php
+++ b/src/Traits/HasRunwayResource.php
@@ -10,6 +10,7 @@ use Statamic\Fieldtypes\Hidden;
 use Statamic\Fieldtypes\Section;
 use Statamic\GraphQL\ResolvesValues;
 use Statamic\Revisions\Revisable;
+use Statamic\Support\Str;
 use Statamic\Support\Traits\FluentlyGetsAndSets;
 use StatamicRadPack\Runway\Data\AugmentedModel;
 use StatamicRadPack\Runway\Data\HasAugmentedInstance;
@@ -182,8 +183,9 @@ trait HasRunwayResource
             ->reject(fn (Field $field) => $field->fieldtype() instanceof Section)
             ->reject(fn (Field $field) => $field->visibility() === 'computed')
             ->reject(fn (Field $field) => $field->get('save', true) === false)
-            ->map->handle()
+            ->map(fn (Field $field) => Str::before($field->handle(), '->'))
             ->values()
+            ->unique()
             ->all();
 
         return [


Test patch:
diff --git a/tests/Actions/PublishTest.php b/tests/Actions/PublishTest.php
index ae709c1..27aac13 100644
--- a/tests/Actions/PublishTest.php
+++ b/tests/Actions/PublishTest.php
@@ -72,6 +72,18 @@ class PublishTest extends TestCase
         $this->assertTrue($visibleToBulk);
     }
 
+    /** @test */
+    public function is_not_visible_in_bulk_to_entry()
+    {
+        Collection::make('posts')->save();
+
+        Entry::make()->collection('posts')->slug('hello-world')->save();
+
+        $visibleTo = (new Publish())->context([])->visibleToBulk(Entry::all());
+
+        $this->assertFalse($visibleTo);
+    }
+
     /** @test */
     public function is_not_visible_to_eloquent_models_in_bulk_when_not_all_models_are_unpublished()
     {
diff --git a/tests/Actions/UnpublishTest.php b/tests/Actions/UnpublishTest.php
index db2eb42..e056217 100644
--- a/tests/Actions/UnpublishTest.php
+++ b/tests/Actions/UnpublishTest.php
@@ -62,6 +62,18 @@ class UnpublishTest extends TestCase
         $this->assertFalse($visibleTo);
     }
 
+    /** @test */
+    public function is_not_visible_in_bulk_to_entry()
+    {
+        Collection::make('posts')->save();
+
+        Entry::make()->collection('posts')->slug('hello-world')->save();
+
+        $visibleTo = (new Unpublish())->context([])->visibleToBulk(Entry::all());
+
+        $this->assertFalse($visibleTo);
+    }
+
     /** @test */
     public function is_visible_to_eloquent_models_in_bulk()
     {
diff --git a/tests/Http/Controllers/CP/ModelRevisionsControllerTest.php b/tests/Http/Controllers/CP/ModelRevisionsControllerTest.php
index 9866038..603caa7 100644
--- a/tests/Http/Controllers/CP/ModelRevisionsControllerTest.php
+++ b/tests/Http/Controllers/CP/ModelRevisionsControllerTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Http\Controllers\CP;
+namespace StatamicRadPack\Runway\Tests\Http\Controllers\CP;
 
 use Illuminate\Support\Carbon;
 use Statamic\Facades\Folder;
diff --git a/tests/Http/Controllers/CP/PublishedModelsControllerTest.php b/tests/Http/Controllers/CP/PublishedModelsControllerTest.php
index 832957d..98afa38 100644
--- a/tests/Http/Controllers/CP/PublishedModelsControllerTest.php
+++ b/tests/Http/Controllers/CP/PublishedModelsControllerTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Http\Controllers\CP;
+namespace StatamicRadPack\Runway\Tests\Http\Controllers\CP;
 
 use Statamic\Facades\Folder;
 use Statamic\Facades\User;
diff --git a/tests/Http/Controllers/CP/RestoreModelRevisionController.php b/tests/Http/Controllers/CP/RestoreModelRevisionController.php
index 07676e0..233cedb 100644
--- a/tests/Http/Controllers/CP/RestoreModelRevisionController.php
+++ b/tests/Http/Controllers/CP/RestoreModelRevisionController.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Http\Controllers\CP;
+namespace StatamicRadPack\Runway\Tests\Http\Controllers\CP;
 
 use Statamic\Facades\Folder;
 use Statamic\Facades\User;