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
6 changes: 3 additions & 3 deletions demo/app/Sharp/Posts/PostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ public function buildFormLayout(FormLayout $formLayout): void

public function buildFormConfig(): void
{
$this->configureDisplayShowPageAfterCreation();
// TODO handle configureEditTitle('Edit post')
// TODO handle configureCreateTitle('New post')
$this->configureDisplayShowPageAfterCreation()
->configureEditTitle('Edit post')
->configureCreateTitle('New post');
}

public function find($id): array
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/EntityList/EntityList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
>
<template #card-header>
<CardTitle>
{{ breadcrumb.items[0].label }}
{{ entityList.title }}
</CardTitle>
</template>
</EntityListComponent>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Form/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
@submit="submit"
>
<template #title>
{{ breadcrumb.items.at(-1).documentTitleLabel }}
{{ form.title }}
</template>
<template #footer>
<div class="flex gap-4">
Expand Down
1 change: 1 addition & 0 deletions resources/js/entity-list/EntityList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class EntityList implements EntityListData {
pageAlert: EntityListData['pageAlert'];
query: EntityListData['query'];
filterValues: EntityListData['filterValues'];
title: EntityListData['title'];

entityKey: string;
hiddenFilters?: Record<string, FilterData['value']>;
Expand Down
1 change: 1 addition & 0 deletions resources/js/form/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class Form implements FormData, CommandFormData {
layout: FormData['layout'];
locales: FormData['locales'];
pageAlert: FormData['pageAlert'];
title: FormData['title'];

state = reactive<{
data: FormData['data'],
Expand Down
14 changes: 5 additions & 9 deletions resources/js/show/Show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Show implements ShowData {
layout: ShowData['layout'];
locales: ShowData['locales'];
pageAlert: ShowData['pageAlert'];
title: ShowData['title'];

entityKey: string;
instanceId?: string;
Expand Down Expand Up @@ -65,15 +66,10 @@ export class Show implements ShowData {
}

getTitle(locale: string): string | null {
if(!this.config.titleAttribute) {
return null;
}
if(this.fields[this.config.titleAttribute]) {
const field = this.fields[this.config.titleAttribute] as ShowTextFieldData;
const value = this.data[this.config.titleAttribute] as ShowTextFieldData['value'];
return field.localized && typeof value?.text === 'object'
? value?.text?.[locale]
: value?.text as string;
if(this.title) {
return typeof this.title === 'object'
? this.title?.[locale]
: this.title;
}
return null;
}
Expand Down
7 changes: 3 additions & 4 deletions resources/js/types/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export type EntityListData = {
data: Array<{ [key: string]: any }>;
filterValues: FilterValuesData;
query: EntityListQueryParamsData | null;
title: string | null;
forms: { [key: string]: EntityListMultiformData } | null;
meta: PaginatorMetaData | null;
pageAlert: PageAlertData | null;
Expand Down Expand Up @@ -274,9 +275,7 @@ export type FormConditionalDisplayData = {
fields: Array<{ key: string; values: string | boolean | Array<string> }>;
};
export type FormConfigData = {
hasShowPage: boolean;
isSingle: boolean;
breadcrumbAttribute: string | null;
};
export type FormCustomFieldData = {
value?: any;
Expand All @@ -295,6 +294,7 @@ export type FormData = {
fields: { [key: string]: FormFieldData };
layout: FormLayoutData;
locales: Array<string>;
title: string | null;
pageAlert: PageAlertData | null;
};
export type FormDateFieldData = {
Expand Down Expand Up @@ -575,8 +575,6 @@ export type FormUploadFieldData = {
allowedExtensions: Array<string> | null;
maxFileSize: number | null;
validationRule: Array<string> | null;
storageBasePath: string | null;
storageDisk: string | null;
label: string | null;
readOnly: boolean | null;
conditionalDisplay: FormConditionalDisplayData | null;
Expand Down Expand Up @@ -764,6 +762,7 @@ export type ShowData = {
fields: { [key: string]: ShowFieldData };
layout: ShowLayoutData;
locales: Array<string> | null;
title: string | { [locale: string]: string } | null;
pageAlert: PageAlertData | null;
};
export type ShowEntityListFieldData = {
Expand Down
2 changes: 2 additions & 0 deletions src/Data/EntityList/EntityListData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
final class EntityListData extends Data
{
public function __construct(
public ?string $title,
public EntityListAuthorizationsData $authorizations,
public EntityListConfigData $config,
/** @var EntityListFieldData[] */
Expand All @@ -32,6 +33,7 @@ public function __construct(
public static function from(array $entityList): self
{
return new self(
title: $entityList['title'] ?? null,
authorizations: new EntityListAuthorizationsData(...$entityList['authorizations']),
config: EntityListConfigData::from($entityList['config']),
fields: EntityListFieldData::collection($entityList['fields']),
Expand Down
2 changes: 0 additions & 2 deletions src/Data/Form/FormConfigData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
final class FormConfigData extends Data
{
public function __construct(
public bool $hasShowPage,
public bool $isSingle = false,
public ?string $breadcrumbAttribute = null,
) {}

public static function from(array $config): self
Expand Down
2 changes: 2 additions & 0 deletions src/Data/Form/FormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
final class FormData extends Data
{
public function __construct(
public ?string $title,
public InstanceAuthorizationsData $authorizations,
public FormConfigData $config,
#[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')]
Expand All @@ -29,6 +30,7 @@ public function __construct(
public static function from(array $form): self
{
return new self(
title: $form['title'],
authorizations: InstanceAuthorizationsData::from($form['authorizations']),
config: FormConfigData::from($form['config']),
data: $form['data'],
Expand Down
3 changes: 3 additions & 0 deletions src/Data/Show/ShowData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
final class ShowData extends Data
{
public function __construct(
#[LiteralTypeScriptType('string | { [locale:string]: string } | null')]
public string|array|null $title,
public InstanceAuthorizationsData $authorizations,
public ShowConfigData $config,
#[LiteralTypeScriptType('{ [key:string]: ShowFieldData["value"] }')]
Expand All @@ -29,6 +31,7 @@ public function __construct(
public static function from(array $show): self
{
return new self(
title: $show['title'],
authorizations: InstanceAuthorizationsData::from($show['authorizations']),
config: ShowConfigData::from($show['config']),
data: $show['data'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function execute(array $data = []): array
? $this->link(sprintf(
'%s/s-show/%s/%s',
$currentUrl,
sharp_normalize_entity_key($this->entityKey)[0],
$this->entityKey,
$instanceId
))
: $this->reload();
Expand Down
22 changes: 11 additions & 11 deletions src/Form/SharpForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ final public function formLayout(): array

public function formConfig(): array
{
return tap(
[
'hasShowPage' => $this->displayShowPageAfterCreation,
// 'title' => sharp()->context()->isCreation()
// ? $this->createFormTitle
// : $this->editFormTitle,
],
function (&$config) {
$this->appendBreadcrumbCustomLabelAttribute($config);
},
);
return [];
}

final public function instance($id): array
Expand Down Expand Up @@ -106,6 +96,16 @@ protected function configureCreateTitle(string $createFormTitle): self

return $this;
}

final public function getCreateTitle(): ?string
{
return $this->createFormTitle;
}

final public function getEditTitle(): ?string
{
return $this->editFormTitle;
}

public function isDisplayShowPageAfterCreation(): bool
{
Expand Down
20 changes: 12 additions & 8 deletions src/Http/Context/SharpBreadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Code16\Sharp\Http\Context\Util\BreadcrumbItem;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Menu\SharpMenuManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
Expand Down Expand Up @@ -203,6 +204,13 @@ private function getDocumentTitleLabelFor(BreadcrumbItem $item, bool $isLeaf): ?
default => null
};
}

public function getParentShowCachedBreadcrumbLabel(): ?string
{
$item = $this->breadcrumbItems()->last();

return Cache::get("sharp.breadcrumb.{$item->key}.s-show.{$item->instance}");
}

/**
* Only for Shows and Forms.
Expand All @@ -211,7 +219,7 @@ private function getEntityLabelForInstance(BreadcrumbItem $item, bool $isLeaf):
{
$cacheKey = "sharp.breadcrumb.{$item->key}.{$item->type}.{$item->instance}";

if ($item->isForm() && ($cached = Cache::get("sharp.breadcrumb.{$item->key}.s-show.{$item->instance}"))) {
if ($item->isForm() && ($cached = $this->getParentShowCachedBreadcrumbLabel())) {
return $cached;
}

Expand All @@ -228,13 +236,9 @@ private function getEntityLabelForInstance(BreadcrumbItem $item, bool $isLeaf):
}
}

$entity = app(SharpEntityManager::class)->entityFor($item->key);

if (str_contains($item->key, ':')) {
return $entity->getMultiforms()[Str::after($item->key, ':')][1] ?? $entity->getLabel();
}

return $entity->getLabel();
return app(SharpEntityManager::class)
->entityFor($item->key)
->getLabel((new EntityKey($item->key))->subEntity());
}

private function isSameEntityKeys(string $key1, string $key2, bool $compareBaseEntities): bool
Expand Down
5 changes: 0 additions & 5 deletions src/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ protected function getShowInstance(string $entityKey): SharpShow
return $this->entityManager->entityFor($entityKey)->getShowOrFail();
}

protected function getFormInstance(string $entityKey): SharpForm
{
return $this->entityManager->entityFor($entityKey)->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
}

protected function getDashboardInstance(string $dashboardKey): ?SharpDashboard
{
return $this->entityManager->entityFor($dashboardKey)->getViewOrFail();
Expand Down
7 changes: 4 additions & 3 deletions src/Http/Controllers/Api/ApiFormAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesEntityCommand;
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesInstanceCommand;
use Code16\Sharp\Http\Controllers\Api\Embeds\HandlesEmbed;
use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Transformers\ArrayConverter;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
Expand All @@ -21,7 +22,7 @@ class ApiFormAutocompleteController extends ApiController
use HandlesEntityCommand;
use HandlesInstanceCommand;

public function index(string $entityKey, string $autocompleteFieldKey)
public function index(EntityKey $entityKey, string $autocompleteFieldKey)
{
$fieldContainer = $this->getFieldContainer($entityKey);
$field = $fieldContainer->findFieldByKey($autocompleteFieldKey);
Expand Down Expand Up @@ -86,7 +87,7 @@ public function index(string $entityKey, string $autocompleteFieldKey)
]);
}

private function getFieldContainer(string $entityKey): SharpFormEditorEmbed|Command|SharpForm
private function getFieldContainer(EntityKey $entityKey): SharpFormEditorEmbed|Command|SharpForm
{
if (request()->input('embed_key')) {
return $this->getEmbedFromKey(request()->input('embed_key'));
Expand Down Expand Up @@ -117,7 +118,7 @@ private function getFieldContainer(string $entityKey): SharpFormEditorEmbed|Comm
);
}

return $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
return $entity->getFormOrFail($entityKey->subEntity());
}

private function normalizeEndpoint(string $input): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Code16\Sharp\Data\Commands\CommandFormData;
use Code16\Sharp\Http\Controllers\Api\ApiController;
use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Uploads\SharpUploadManager;
use Illuminate\Support\Str;

class ApiEntityListQuickCreationCommandController extends ApiController
{
Expand All @@ -17,7 +17,7 @@ public function __construct(private readonly SharpUploadManager $uploadManager)
parent::__construct();
}

public function create(string $entityKey)
public function create(EntityKey $entityKey)
{
$entity = $this->entityManager->entityFor($entityKey);

Expand All @@ -29,16 +29,14 @@ public function create(string $entityKey)
403
);

$form = $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
$form = $entity->getFormOrFail($entityKey->subEntity());
$form->buildFormConfig();

$quickCreationHandler
->setEntityKey($entityKey)
->setFormInstance($form)
->setTitle(__('sharp::breadcrumb.form.create_entity', [
'entity' => str_contains($entityKey, ':')
? $entity->getMultiforms()[Str::after($entityKey, ':')][1] ?? $entity->getLabel()
: $entity->getLabel(),
'entity' => $entity->getLabel($entityKey->subEntity()),
]));

$quickCreationHandler->buildCommandConfig();
Expand All @@ -50,7 +48,7 @@ public function create(string $entityKey)
);
}

public function store(string $entityKey)
public function store(EntityKey $entityKey)
{
$list = $this->getListInstance($entityKey);
$list->buildListConfig();
Expand All @@ -60,7 +58,7 @@ public function store(string $entityKey)
403
);

$form = $this->entityManager->entityFor($entityKey)->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
$form = $this->entityManager->entityFor($entityKey)->getFormOrFail($entityKey->subEntity());
$form->buildFormConfig();

$quickCreationHandler
Expand Down
8 changes: 7 additions & 1 deletion src/Http/Controllers/EntityListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Code16\Sharp\Data\NotificationData;
use Code16\Sharp\Exceptions\SharpInvalidConfigException;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
use Code16\Sharp\Utils\Menu\SharpMenuManager;
use Inertia\Inertia;

class EntityListController extends SharpProtectedController
Expand Down Expand Up @@ -58,7 +59,12 @@ public function show(string $entityKey)
}

return Inertia::render('EntityList/EntityList', [
'entityList' => EntityListData::from($data),
'entityList' => EntityListData::from([
...$data,
'title' => app(SharpMenuManager::class)
->getEntityMenuItem($entityKey)
?->getLabel() ?: trans('sharp::breadcrumb.entityList'),
]),
'breadcrumb' => BreadcrumbData::from([
'items' => sharp()->context()->breadcrumb()->allSegments(),
]),
Expand Down
Loading
Loading