Skip to content

A free open source IT asset/license management system

Ported companies to new blade components

snipe9efbc33e1ba1
diff --git a/resources/views/blade/input/company-select.blade.php b/resources/views/blade/input/company-select.blade.php
index c9200c76c4..179277f0c5 100644
--- a/resources/views/blade/input/company-select.blade.php
+++ b/resources/views/blade/input/company-select.blade.php
@@ -1,6 +1,12 @@
@use('App\Models\Company', 'Company')
@use('Illuminate\Support\Arr', 'Arr')
+{{-- onlyTopLevel / excludeId power the parent-company picker: the first
+ disables sub-companies (they can't themselves become parents), the
+ second hides the company being edited (so it can't be selected as its
+ own parent). Both are read as data-* attributes by the js-data-ajax
+ initializer in snipeit.js and forwarded to the
+ /api/v1/companies/selectlist endpoint. --}}
@props([
'label',
'name',
@@ -8,6 +14,8 @@
'required' => false,
'multiple' => false,
'hideNewButton' => false,
+ 'onlyTopLevel' => false,
+ 'excludeId' => null,
])
<div
@@ -22,6 +30,8 @@
class="js-data-ajax"
data-endpoint="companies"
data-placeholder="{{ trans('general.select_company') }}"
+ @if ($onlyTopLevel) data-only-top-level="true" @endif
+ @if ($excludeId) data-exclude-id="{{ $excludeId }}" @endif
name="{{ $name }}{{ $multiple ? '[]' : '' }}"
id="{{ $name }}"
style="width: 100%"
diff --git a/resources/views/companies/edit.blade.php b/resources/views/companies/edit.blade.php
index 867d071d11..16643b5610 100644
--- a/resources/views/companies/edit.blade.php
+++ b/resources/views/companies/edit.blade.php
@@ -28,12 +28,14 @@
name="name"
/>
- @include('partials.forms.edit.company-select', [
- 'translated_name' => trans('admin/companies/table.parent'),
- 'fieldname' => 'parent_id',
- 'only_top_level' => true,
- 'exclude_id' => $item->id ?? null,
- ])
+ <x-input.company-select
+ :label="trans('admin/companies/table.parent')"
+ name="parent_id"
+ :selected="old('parent_id', $item->parent_id)"
+ :onlyTopLevel="true"
+ :excludeId="$item->id ?? null"
+ hideNewButton
+ />
<x-form.row
:label="trans('admin/suppliers/table.phone')"
diff --git a/tests/Feature/Companies/Ui/EditCompanyTest.php b/tests/Feature/Companies/Ui/EditCompanyTest.php
index c15b1e73a6..b7b1275f68 100644
--- a/tests/Feature/Companies/Ui/EditCompanyTest.php
+++ b/tests/Feature/Companies/Ui/EditCompanyTest.php
@@ -14,4 +14,23 @@ class EditCompanyTest extends TestCase
->get(route('companies.edit', Company::factory()->create()))
->assertOk();
}
+
+ public function test_parent_company_picker_ships_only_top_level_and_exclude_id_data_attrs()
+ {
+ // Regression guard for the migration off @include('partials.forms
+ // .edit.company-select'). The parent-company picker relies on two
+ // data-* hooks read by the js-data-ajax initializer in snipeit.js:
+ // data-only-top-level="true" so sub-companies get greyed out (they
+ // can't themselves become parents), and data-exclude-id="{id}" so
+ // the company being edited never appears in its own parent list.
+ $company = Company::factory()->create();
+
+ $response = $this->actingAs(User::factory()->superuser()->create())
+ ->get(route('companies.edit', $company))
+ ->assertOk();
+
+ $response->assertSee('data-only-top-level="true"', false);
+ $response->assertSee('data-exclude-id="'.$company->id.'"', false);
+ $response->assertSee('id="submit_button"', false);
+ }
}