Skip to content

Commit 3d17ceb

Browse files
committed
Fix remote autocomplete in dashboard command form
1 parent 1196f88 commit 3d17ceb

4 files changed

Lines changed: 37 additions & 19 deletions

File tree

resources/js/form/components/fields/Autocomplete.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
embed_key: form.embedKey,
5555
entity_list_command_key: parentCommands?.commandContainer === 'entityList' ? form.commandKey : null,
5656
show_command_key: parentCommands?.commandContainer === 'show' ? form.commandKey : null,
57+
dashboard_command_key: parentCommands?.commandContainer === 'dashboard' ? form.commandKey : null,
5758
instance_id: form.instanceId,
5859
endpoint: field.remoteEndpoint,
5960
search: query,

src/Http/Controllers/Api/Commands/ApiDashboardCommandController.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
namespace Code16\Sharp\Http\Controllers\Api\Commands;
44

5-
use Code16\Sharp\Dashboard\Commands\DashboardWizardCommand;
6-
use Code16\Sharp\Dashboard\SharpDashboard;
75
use Code16\Sharp\Data\Commands\CommandFormData;
8-
use Code16\Sharp\Exceptions\Auth\SharpAuthorizationException;
96
use Code16\Sharp\Http\Controllers\Api\ApiController;
107
use Code16\Sharp\Utils\Uploads\SharpUploadManager;
118

129
class ApiDashboardCommandController extends ApiController
1310
{
1411
use HandlesCommandForm;
1512
use HandlesCommandResult;
13+
use HandlesDashboardCommand;
1614

1715
public function __construct(
1816
private readonly SharpUploadManager $uploadManager,
@@ -49,20 +47,4 @@ public function update(string $globalFilter, string $entityKey, string $commandK
4947

5048
return $result;
5149
}
52-
53-
protected function getDashboardCommandHandler(SharpDashboard $dashboard, string $commandKey)
54-
{
55-
$commandHandler = $dashboard->findDashboardCommandHandler($commandKey);
56-
$commandHandler->buildCommandConfig();
57-
58-
$authorized = $commandHandler instanceof DashboardWizardCommand && ($step = $commandHandler->extractStepFromRequest())
59-
? $commandHandler->authorizeForStep($step)
60-
: $commandHandler->authorize();
61-
62-
if (! $authorized) {
63-
throw new SharpAuthorizationException();
64-
}
65-
66-
return $commandHandler;
67-
}
6850
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Code16\Sharp\Http\Controllers\Api\Commands;
4+
5+
use Code16\Sharp\Dashboard\Commands\DashboardWizardCommand;
6+
use Code16\Sharp\Dashboard\SharpDashboard;
7+
use Code16\Sharp\Exceptions\Auth\SharpAuthorizationException;
8+
9+
trait HandlesDashboardCommand
10+
{
11+
protected function getDashboardCommandHandler(SharpDashboard $dashboard, string $commandKey)
12+
{
13+
$commandHandler = $dashboard->findDashboardCommandHandler($commandKey);
14+
$commandHandler->buildCommandConfig();
15+
16+
$authorized = $commandHandler instanceof DashboardWizardCommand && ($step = $commandHandler->extractStepFromRequest())
17+
? $commandHandler->authorizeForStep($step)
18+
: $commandHandler->authorize();
19+
20+
if (! $authorized) {
21+
throw new SharpAuthorizationException();
22+
}
23+
24+
return $commandHandler;
25+
}
26+
}

src/Http/Controllers/Api/HandlesFieldContainer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
use Code16\Sharp\EntityList\Commands\Command;
66
use Code16\Sharp\Form\Fields\Embeds\SharpFormEditorEmbed;
77
use Code16\Sharp\Form\SharpForm;
8+
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesDashboardCommand;
89
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesEntityCommand;
910
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesInstanceCommand;
1011
use Code16\Sharp\Http\Controllers\Api\Embeds\HandlesEmbed;
1112
use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
1213

1314
trait HandlesFieldContainer
1415
{
16+
use HandlesDashboardCommand;
1517
use HandlesEmbed;
1618
use HandlesEntityCommand;
1719
use HandlesInstanceCommand;
@@ -47,6 +49,13 @@ private function getFieldContainer(EntityKey $entityKey): SharpFormEditorEmbed|C
4749
);
4850
}
4951

52+
if ($commandKey = request()->input('dashboard_command_key')) {
53+
return $this->getDashboardCommandHandler(
54+
$entity->getViewOrFail(),
55+
$commandKey
56+
);
57+
}
58+
5059
return $entity->getFormOrFail($entityKey->multiformKey());
5160
}
5261
}

0 commit comments

Comments
 (0)