From 2c03a0091e354d93169f03e2392df01f5ad7725b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 20:55:42 +0200 Subject: [PATCH] =?UTF-8?q?Criar=20Hotel:=20a=20mudan=C3=A7a=20de=20sector?= =?UTF-8?q?=20feita=20pelo=20investidor=20no=20editor=20continua=20directa?= =?UTF-8?q?=20(C10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O sector escolhido pelo próprio investidor no editor do dossier substitui a actividade, como aprovado em C10; o que chega de outra referência ou da página de entrada continua a ser só proposta. Retirar a actividade também passa a exigir a escolha explícita. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM --- app/Services/InvestorContext.php | 4 +++- resources/js/pages/investor-path/context.tsx | 20 ++++++++++++++++--- .../InvestmentContextContinuityTest.php | 7 ++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/Services/InvestorContext.php b/app/Services/InvestorContext.php index 591525ef..0bf3d878 100644 --- a/app/Services/InvestorContext.php +++ b/app/Services/InvestorContext.php @@ -690,7 +690,9 @@ final class InvestorContext } // Remove inherited subordinate geography only when its source was actually replaced. foreach ($fields as $key => $value) { - if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) { + // The activity is only removed when the investor asks for it explicitly. + $explicitIntention = in_array($key, self::INTENTION_FIELDS, true) && in_array($key, $data['replace_fields'] ?? [], true); + if (! array_key_exists($key, $proposed) && ($explicitIntention || in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true)) && isset($provenance[$key]['key'])) { unset($fields[$key],$provenance[$key]); } } diff --git a/resources/js/pages/investor-path/context.tsx b/resources/js/pages/investor-path/context.tsx index c91deab4..33b818ea 100644 --- a/resources/js/pages/investor-path/context.tsx +++ b/resources/js/pages/investor-path/context.tsx @@ -969,9 +969,23 @@ function ScopedContextEditor({ className={input + ' max-w-full min-w-0'} disabled={busy} value={selected('sector')} - onChange={(e) => - change('sector', e.target.value) - } + onChange={(e) => { + change('sector', e.target.value); + // A sector chosen here is the investor's own + // decision (C10): it replaces the activity. + // One arriving from another reference or + // from the entry page stays a proposal. + if (view.context.fields.sector) + setReplace((current) => [ + ...current.filter( + (key) => + key !== 'sector_id' && + key !== 'sector', + ), + 'sector_id', + 'sector', + ]); + }} > {view.context.selection.sector && diff --git a/tests/Feature/InvestmentContextContinuityTest.php b/tests/Feature/InvestmentContextContinuityTest.php index ea0bbb41..aed60688 100644 --- a/tests/Feature/InvestmentContextContinuityTest.php +++ b/tests/Feature/InvestmentContextContinuityTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature; use App\Models\Sector; use App\Models\User; use App\Services\InvestmentZones; +use App\Services\InvestorPath; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; @@ -128,11 +129,15 @@ class InvestmentContextContinuityTest extends TestCase $apply(['sector' => null]); $this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $tourism->id); // The dossier choice shows each dossier's activity. - $listed = collect(app(\App\Services\InvestorPath::class)->contexts($owner))->firstWhere('id', $id); + $listed = collect(app(InvestorPath::class)->contexts($owner))->firstWhere('id', $id); $this->assertSame([(string) $tourism->id, $tourism->name], [$listed['sector_id'], $listed['sector']]); $apply(['sector' => 'sector:'.$agro->id], ['sector_id', 'sector']); $this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $agro->id)->assertJsonPath('context.fields.sector', $agro->name); + + // Removing the activity is also an explicit decision (C10 explicit changes keep working). + $apply(['sector' => null], ['sector_id', 'sector']); + $this->assertArrayNotHasKey('sector_id', $this->getJson('/investimentos/'.$id.'/contexto')->json('context.fields')); } public function test_the_business_plan_executive_summary_fields_are_saved_in_the_draft(): void