Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions resources/js/show/Show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@ export class Show implements ShowData {
}

get formUrl(): string {
const multiformKey = this.config.multiformAttribute
? this.data[this.config.multiformAttribute]
: null;

if(route().params.instanceId) {
return route('code16.sharp.form.edit', {
parentUri: getAppendableParentUri(),
entityKey: multiformKey ? `${this.entityKey}:${multiformKey}` : this.entityKey,
entityKey: this.entityKey,
instanceId: this.instanceId,
});
}

return route('code16.sharp.form.create', {
parentUri: getAppendableParentUri(),
entityKey: multiformKey ? `${this.entityKey}:${multiformKey}` : this.entityKey,
entityKey: this.entityKey,
});
}

Expand Down
1 change: 0 additions & 1 deletion resources/js/types/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ export type ShowConfigData = {
deleteConfirmationText: string;
isSingle: boolean;
commands: ConfigCommandsData | null;
multiformAttribute: string | null;
titleAttribute: string | null;
breadcrumbAttribute: string | null;
editButtonLabel: string | null;
Expand Down
1 change: 0 additions & 1 deletion src/Data/Show/ShowConfigData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function __construct(
public string $deleteConfirmationText,
public bool $isSingle = false,
public ?ConfigCommandsData $commands = null,
public ?string $multiformAttribute = null,
public ?string $titleAttribute = null,
public ?string $breadcrumbAttribute = null,
public ?string $editButtonLabel = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ShowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function show(string $parentUri, EntityKey $entityKey, string $instanceId
abort_if($show instanceof SharpSingleShow, 404);

$show->buildShowConfig();

$showData = $show->instance($instanceId);
$payload = ShowData::from([
'title' => $showData[$show->titleAttribute()] ?? $entity->getLabel($entityKey->subEntity()),
Expand Down
10 changes: 3 additions & 7 deletions src/Show/SharpShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ abstract class SharpShow
use WithCustomTransformers;

protected ?ShowLayout $showLayout = null;
protected ?string $multiformAttribute = null;
protected ?SharpShowTextField $pageTitleField = null;
protected ?string $deleteConfirmationText = null;
protected ?string $editButtonLabel = null;
Expand All @@ -51,7 +50,6 @@ final public function instance(mixed $id): array
->merge(array_keys($this->transformers))
->when($this->breadcrumbAttribute, fn ($collect) => $collect->push($this->breadcrumbAttribute))
->when($this->entityStateAttribute, fn ($collect) => $collect->push($this->entityStateAttribute))
->when($this->multiformAttribute, fn ($collect) => $collect->push($this->multiformAttribute))
->unique()
->values()
->toArray()
Expand All @@ -66,9 +64,6 @@ public function showConfig(mixed $instanceId, array $config = []): array
'deleteConfirmationText' => $this->deleteConfirmationText ?: trans('sharp::show.delete_confirmation_text'),
'editButtonLabel' => $this->editButtonLabel,
])
->when($this->multiformAttribute, fn ($collection) => $collection->merge([
'multiformAttribute' => $this->multiformAttribute,
]))
->when($this->pageTitleField, fn ($collection) => $collection->merge([
'titleAttribute' => $this->pageTitleField->key,
]))
Expand All @@ -81,10 +76,11 @@ public function showConfig(mixed $instanceId, array $config = []): array
});
}

/**
* @deprecated to be deleted, no more useful
*/
final protected function configureMultiformAttribute(string $attribute): self
{
$this->multiformAttribute = $attribute;

return $this;
}

Expand Down
34 changes: 0 additions & 34 deletions tests/Http/ShowControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Code16\Sharp\Show\Layout\ShowLayoutSection;
use Code16\Sharp\Tests\Fixtures\Entities\PersonEntity;
use Code16\Sharp\Tests\Fixtures\Entities\SinglePersonEntity;
use Code16\Sharp\Tests\Fixtures\Sharp\PersonForm;
use Code16\Sharp\Tests\Fixtures\Sharp\PersonShow;
use Code16\Sharp\Tests\Fixtures\Sharp\PersonSingleShow;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
Expand Down Expand Up @@ -285,39 +284,6 @@ public function authorizeFor(mixed $instanceId): bool
);
});

it('returns the valuated multiform attribute if configured', function () {
fakeShowFor('person', new class() extends PersonShow
{
public function buildShowConfig(): void
{
$this->configureMultiformAttribute('nobel');
}

public function find($id): array
{
return [
'id' => 1,
'name' => 'Marie Curie',
'nobel' => 'nobelized',
];
}
});

app(SharpEntityManager::class)
->entityFor('person')
->setMultiforms([
'nobelized' => [PersonForm::class, 'With Nobel prize'],
'nope' => [PersonForm::class, 'No Nobel prize'],
]);

$this->get('/sharp/s-list/person/s-show/person/1')
->assertOk()
->assertInertia(fn (Assert $page) => $page
->where('show.config.multiformAttribute', 'nobel')
->where('show.data.nobel', 'nobelized')
);
});

it('allows to configure a page alert', function () {
fakeShowFor('person', new class() extends PersonShow
{
Expand Down
Loading