Fix: Remove active columns when field removed
This commit is contained in:
parent
eaa880127d
commit
3d270ce9a4
|
@ -7,6 +7,7 @@ use Cviebrock\EloquentSluggable\Sluggable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Laravel\Scout\Searchable;
|
use Laravel\Scout\Searchable;
|
||||||
use Spatie\Image\Manipulations;
|
use Spatie\Image\Manipulations;
|
||||||
|
@ -144,6 +145,13 @@ class Form extends Model implements HasMedia
|
||||||
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()['key'], 'asc'] : null,
|
'sorting' => $model->getFields()->count() ? [$model->getFields()->first()['key'], 'asc'] : null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array(data_get($model->meta, 'active_columns'))) {
|
||||||
|
$model->setAttribute('meta', [
|
||||||
|
...$model->meta,
|
||||||
|
'active_columns' => array_diff($model->getFields()->pluck('key')->toArray(), $model->meta['active_columns']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,24 @@ class FormUpdateActionTest extends FormTestCase
|
||||||
|
|
||||||
$this->assertTrue(data_get($form->config, 'sections.0.fields.0.max_today'));
|
$this->assertTrue(data_get($form->config, 'sections.0.fields.0.max_today'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItUpdatesActiveColumnsWhenFieldRemoved(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami()->withoutExceptionHandling();
|
||||||
|
$form = Form::factory()
|
||||||
|
->sections([FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->textField('firstname'),
|
||||||
|
$this->textField('geb'),
|
||||||
|
$this->textField('lastname'),
|
||||||
|
])])
|
||||||
|
->create();
|
||||||
|
$payload = FormRequest::new()->sections([
|
||||||
|
FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->textField('firstname'),
|
||||||
|
])
|
||||||
|
])->create();
|
||||||
|
|
||||||
|
$this->patchJson(route('form.update', ['form' => $form]), $payload)->assertSessionDoesntHaveErrors()->assertOk();
|
||||||
|
$this->assertEquals(['firstname'], $form->fresh()->meta['active_columns']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue