diff --git a/src/Data/BreadcrumbData.php b/src/Data/BreadcrumbData.php index 0a3f0c393..189135062 100644 --- a/src/Data/BreadcrumbData.php +++ b/src/Data/BreadcrumbData.php @@ -8,8 +8,8 @@ final class BreadcrumbData extends Data { public function __construct( - /** @var DataCollection */ - public DataCollection $items, + /** @var BreadcrumbItemData[] */ + public array $items, ) {} public static function from(array $breadcrumb): self diff --git a/src/Data/Commands/CommandFormData.php b/src/Data/Commands/CommandFormData.php index 9a737dd7d..fd5540b2c 100644 --- a/src/Data/Commands/CommandFormData.php +++ b/src/Data/Commands/CommandFormData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Commands; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\FormFieldData; use Code16\Sharp\Data\Form\FormLayoutData; use Code16\Sharp\Data\PageAlertData; @@ -18,8 +17,8 @@ public function __construct( #[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')] public ?array $data, public CommandFormConfigData $config, - /** @var DataCollection */ - public ?DataCollection $fields = null, + /** @var array */ + public ?array $fields = null, public ?FormLayoutData $layout = null, /** @var array */ public ?array $locales = null, diff --git a/src/Data/Dashboard/DashboardData.php b/src/Data/Dashboard/DashboardData.php index baa82a3ac..444a7a622 100644 --- a/src/Data/Dashboard/DashboardData.php +++ b/src/Data/Dashboard/DashboardData.php @@ -4,7 +4,6 @@ use Code16\Sharp\Data\Dashboard\Widgets\WidgetData; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Filters\FilterValuesData; use Code16\Sharp\Data\PageAlertData; @@ -14,8 +13,8 @@ final class DashboardData extends Data { public function __construct( - /** @var DataCollection */ - public DataCollection $widgets, + /** @var WidgetData[] */ + public array $widgets, public DashboardConfigData $config, public DashboardLayoutData $layout, /** @var array */ diff --git a/src/Data/Dashboard/DashboardLayoutData.php b/src/Data/Dashboard/DashboardLayoutData.php index 8d7fff330..bb746feea 100644 --- a/src/Data/Dashboard/DashboardLayoutData.php +++ b/src/Data/Dashboard/DashboardLayoutData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Dashboard; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -11,8 +10,8 @@ final class DashboardLayoutData extends Data { public function __construct( - /** @var DataCollection */ - public DataCollection $sections, + /** @var DashboardLayoutSectionData[] */ + public array $sections, ) {} public static function from(array $layout): self diff --git a/src/Data/Dashboard/DashboardLayoutSectionData.php b/src/Data/Dashboard/DashboardLayoutSectionData.php index caf32f2bc..5754d718c 100644 --- a/src/Data/Dashboard/DashboardLayoutSectionData.php +++ b/src/Data/Dashboard/DashboardLayoutSectionData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Dashboard; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -13,7 +12,7 @@ final class DashboardLayoutSectionData extends Data public function __construct( public ?string $key, public string $title, - /** @var array> */ + /** @var array */ public array $rows, ) {} diff --git a/src/Data/Data.php b/src/Data/Data.php index 45984e483..bfff231ee 100644 --- a/src/Data/Data.php +++ b/src/Data/Data.php @@ -6,6 +6,9 @@ use ReflectionClass; use ReflectionParameter; +/** + * @internal + */ abstract class Data implements Arrayable { /** @var ReflectionParameter[][] */ @@ -13,9 +16,9 @@ abstract class Data implements Arrayable protected array $additionalAttributes = []; - public static function collection($payload): DataCollection + public static function collection($payload): array { - return DataCollection::make($payload) + return collect($payload) ->map(function ($item) { if (is_array($item)) { if (method_exists(static::class, 'from')) { @@ -26,7 +29,8 @@ public static function collection($payload): DataCollection } return $item; - }); + }) + ->all(); } public static function optional(mixed $payload): ?static @@ -86,6 +90,10 @@ protected function transformValues(array $values): array return $value->value; } + if (is_array($value)) { + return collect($value)->toArray(); + } + return $value; }) ->toArray(); diff --git a/src/Data/DataCollection.php b/src/Data/DataCollection.php deleted file mode 100644 index ba9a1c9b0..000000000 --- a/src/Data/DataCollection.php +++ /dev/null @@ -1,7 +0,0 @@ - */ - public DataCollection $fields, + /** @var array */ + public array $fields, ) {} public static function from(array $embed): self diff --git a/src/Data/Embeds/EmbedFormData.php b/src/Data/Embeds/EmbedFormData.php index 93e3d3b19..c8124f844 100644 --- a/src/Data/Embeds/EmbedFormData.php +++ b/src/Data/Embeds/EmbedFormData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Embeds; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\FormFieldData; use Code16\Sharp\Data\Form\FormLayoutData; use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType; @@ -16,8 +15,8 @@ final class EmbedFormData extends Data public function __construct( #[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')] public ?array $data, - /** @var DataCollection */ - public DataCollection $fields, + /** @var array */ + public array $fields, public ?FormLayoutData $layout, ) {} diff --git a/src/Data/EntityList/EntityListData.php b/src/Data/EntityList/EntityListData.php index 74c138593..eb3e2445e 100644 --- a/src/Data/EntityList/EntityListData.php +++ b/src/Data/EntityList/EntityListData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\EntityList; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\EntityListAuthorizationsData; use Code16\Sharp\Data\Filters\FilterValuesData; use Code16\Sharp\Data\PageAlertData; @@ -18,14 +17,14 @@ final class EntityListData extends Data public function __construct( public EntityListAuthorizationsData $authorizations, public EntityListConfigData $config, - /** @var DataCollection */ - public DataCollection $fields, + /** @var EntityListFieldData[] */ + public array $fields, #[LiteralTypeScriptType('Array<{ [key: string]: any }>')] public array $data, public FilterValuesData $filterValues, public ?EntityListQueryParamsData $query, - /** @var DataCollection */ - public ?DataCollection $forms = null, + /** @var array|null */ + public ?array $forms = null, public ?PaginatorMetaData $meta = null, public ?PageAlertData $pageAlert = null, ) {} diff --git a/src/Data/EntityStateData.php b/src/Data/EntityStateData.php index 3a28358cb..2674b2a55 100644 --- a/src/Data/EntityStateData.php +++ b/src/Data/EntityStateData.php @@ -9,8 +9,8 @@ final class EntityStateData extends Data { public function __construct( public string $attribute, - /** @var DataCollection */ - public DataCollection $values, + /** @var EntityStateValueData[] */ + public array $values, /** @var bool|array */ public mixed $authorization, ) {} diff --git a/src/Data/Form/Fields/FormAutocompleteLocalFieldData.php b/src/Data/Form/Fields/FormAutocompleteLocalFieldData.php index 1020af267..7c11e28de 100644 --- a/src/Data/Form/Fields/FormAutocompleteLocalFieldData.php +++ b/src/Data/Form/Fields/FormAutocompleteLocalFieldData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form\Fields; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData; use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData; use Code16\Sharp\Enums\FormFieldType; @@ -36,8 +35,8 @@ public function __construct( /** @var array */ public ?array $searchKeys = null, public ?bool $localized = null, - /** @var DataCollection */ - public ?DataCollection $dynamicAttributes = null, + /** @var FormDynamicAttributeData[]|null */ + public ?array $dynamicAttributes = null, public ?string $label = null, public ?bool $readOnly = null, public ?FormConditionalDisplayData $conditionalDisplay = null, diff --git a/src/Data/Form/Fields/FormAutocompleteRemoteFieldData.php b/src/Data/Form/Fields/FormAutocompleteRemoteFieldData.php index 45c4f8339..56daedc03 100644 --- a/src/Data/Form/Fields/FormAutocompleteRemoteFieldData.php +++ b/src/Data/Form/Fields/FormAutocompleteRemoteFieldData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form\Fields; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData; use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData; use Code16\Sharp\Enums\FormFieldType; @@ -32,8 +31,8 @@ public function __construct( /** @var string[]|null */ public ?array $callbackLinkedFields = null, public ?string $placeholder = null, - /** @var DataCollection */ - public ?DataCollection $dynamicAttributes = null, + /** @var FormDynamicAttributeData[]|null */ + public ?array $dynamicAttributes = null, public ?string $label = null, public ?bool $readOnly = null, public ?FormConditionalDisplayData $conditionalDisplay = null, diff --git a/src/Data/Form/Fields/FormSelectFieldData.php b/src/Data/Form/Fields/FormSelectFieldData.php index 30515ad66..a0b37a4b3 100644 --- a/src/Data/Form/Fields/FormSelectFieldData.php +++ b/src/Data/Form/Fields/FormSelectFieldData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form\Fields; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData; use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData; use Code16\Sharp\Enums\FormFieldType; @@ -31,8 +30,8 @@ public function __construct( #[LiteralTypeScriptType('"list" | "dropdown"')] public string $display, public bool $inline, - /** @var DataCollection */ - public ?DataCollection $dynamicAttributes = null, + /** @var FormDynamicAttributeData[]|null */ + public ?array $dynamicAttributes = null, public ?int $maxSelected = null, public ?bool $localized = null, public ?string $label = null, diff --git a/src/Data/Form/FormData.php b/src/Data/Form/FormData.php index ba49ca2af..2c40569bb 100644 --- a/src/Data/Form/FormData.php +++ b/src/Data/Form/FormData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Form\Fields\FormFieldData; use Code16\Sharp\Data\InstanceAuthorizationsData; use Code16\Sharp\Data\PageAlertData; @@ -19,8 +18,8 @@ public function __construct( public FormConfigData $config, #[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')] public ?array $data, - /** @var DataCollection */ - public DataCollection $fields, + /** @var array */ + public array $fields, public FormLayoutData $layout, /** @var array */ public array $locales, diff --git a/src/Data/Form/FormLayoutData.php b/src/Data/Form/FormLayoutData.php index de5310f4f..2230da3cf 100644 --- a/src/Data/Form/FormLayoutData.php +++ b/src/Data/Form/FormLayoutData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -12,8 +11,8 @@ final class FormLayoutData extends Data { public function __construct( public bool $tabbed, - /** @var DataCollection */ - public DataCollection $tabs, + /** @var FormLayoutTabData[] */ + public array $tabs, ) {} public static function from(array $config): self diff --git a/src/Data/Form/FormLayoutTabData.php b/src/Data/Form/FormLayoutTabData.php index 97bb29133..c6954196c 100644 --- a/src/Data/Form/FormLayoutTabData.php +++ b/src/Data/Form/FormLayoutTabData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Form; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -12,8 +11,8 @@ final class FormLayoutTabData extends Data { public function __construct( public string $title, - /** @var DataCollection */ - public DataCollection $columns, + /** @var FormLayoutColumnData[] */ + public array $columns, ) {} public static function from(array $tab): self diff --git a/src/Data/MenuData.php b/src/Data/MenuData.php index 101aa5c67..4fd31df81 100644 --- a/src/Data/MenuData.php +++ b/src/Data/MenuData.php @@ -11,8 +11,8 @@ final class MenuData extends Data { public function __construct( - /** @var DataCollection */ - public DataCollection $items, + /** @var MenuItemData[] */ + public array $items, public UserMenuData $userMenu, public bool $isVisible, ) {} diff --git a/src/Data/MenuItemData.php b/src/Data/MenuItemData.php index 448c50a58..f79e7348e 100644 --- a/src/Data/MenuItemData.php +++ b/src/Data/MenuItemData.php @@ -19,8 +19,8 @@ public function __construct( public ?string $entityKey = null, public bool $isSeparator = false, public bool $current = false, - /** @var DataCollection */ - public ?DataCollection $children = null, + /** @var MenuItemData[]|null */ + public ?array $children = null, public bool $isCollapsible = false, ) {} diff --git a/src/Data/SearchResultSetData.php b/src/Data/SearchResultSetData.php index 3b6a080d6..6c400290c 100644 --- a/src/Data/SearchResultSetData.php +++ b/src/Data/SearchResultSetData.php @@ -10,7 +10,7 @@ final class SearchResultSetData extends Data public function __construct( public string $label, /** @var SearchResultLinkData[] */ - public DataCollection $resultLinks, + public array $resultLinks, public ?IconData $icon, public ?string $emptyStateLabel = null, /** @var string[] */ diff --git a/src/Data/Show/Fields/ShowListFieldData.php b/src/Data/Show/Fields/ShowListFieldData.php index 78147b5d5..f1fa22b76 100644 --- a/src/Data/Show/Fields/ShowListFieldData.php +++ b/src/Data/Show/Fields/ShowListFieldData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Show\Fields; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Enums\ShowFieldType; use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType; use Spatie\TypeScriptTransformer\Attributes\Optional; @@ -23,8 +22,8 @@ public function __construct( public ShowFieldType $type, public bool $emptyVisible, public ?string $label, - /** @var DataCollection */ - public DataCollection $itemFields, + /** @var array */ + public array $itemFields, ) {} public static function from(array $list): self diff --git a/src/Data/Show/Fields/ShowTextFieldData.php b/src/Data/Show/Fields/ShowTextFieldData.php index 55d415006..a35c3ec9f 100644 --- a/src/Data/Show/Fields/ShowTextFieldData.php +++ b/src/Data/Show/Fields/ShowTextFieldData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Show\Fields; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\Embeds\EmbedData; use Code16\Sharp\Data\Form\Fields\FormEditorFieldData; use Code16\Sharp\Enums\ShowFieldType; @@ -27,8 +26,8 @@ public function __construct( public bool $html, public ?bool $localized = null, public ?int $collapseToWordCount = null, - /** @var DataCollection */ - public ?DataCollection $embeds = null, + /** @var array */ + public ?array $embeds = null, public ?string $label = null, ) {} diff --git a/src/Data/Show/ShowData.php b/src/Data/Show/ShowData.php index b7266f8d2..2b757d744 100644 --- a/src/Data/Show/ShowData.php +++ b/src/Data/Show/ShowData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Show; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; use Code16\Sharp\Data\InstanceAuthorizationsData; use Code16\Sharp\Data\PageAlertData; use Code16\Sharp\Data\Show\Fields\ShowFieldData; @@ -19,8 +18,8 @@ public function __construct( public ShowConfigData $config, #[LiteralTypeScriptType('{ [key:string]: ShowFieldData["value"] }')] public ?array $data, - /** @var DataCollection */ - public DataCollection $fields, + /** @var array */ + public array $fields, public ShowLayoutData $layout, /** @var string[] */ public ?array $locales, diff --git a/src/Data/Show/ShowLayoutData.php b/src/Data/Show/ShowLayoutData.php index d900ee103..28016927e 100644 --- a/src/Data/Show/ShowLayoutData.php +++ b/src/Data/Show/ShowLayoutData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Show; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -12,7 +11,7 @@ final class ShowLayoutData extends Data { public function __construct( /** @var ShowLayoutSectionData[] */ - public DataCollection $sections, + public array $sections, ) {} public static function from(array $layout): self diff --git a/src/Data/Show/ShowLayoutSectionData.php b/src/Data/Show/ShowLayoutSectionData.php index 8801fe898..c43453e8c 100644 --- a/src/Data/Show/ShowLayoutSectionData.php +++ b/src/Data/Show/ShowLayoutSectionData.php @@ -3,7 +3,6 @@ namespace Code16\Sharp\Data\Show; use Code16\Sharp\Data\Data; -use Code16\Sharp\Data\DataCollection; /** * @internal @@ -15,7 +14,7 @@ public function __construct( public string $title, public bool $collapsable, /** @var ShowLayoutColumnData[] */ - public DataCollection $columns + public array $columns ) {} public static function from(array $section): self diff --git a/src/Data/UserMenuData.php b/src/Data/UserMenuData.php index 4209aff9a..11eb1575a 100644 --- a/src/Data/UserMenuData.php +++ b/src/Data/UserMenuData.php @@ -8,7 +8,7 @@ final class UserMenuData extends Data { public function __construct( - /** @var DataCollection */ - public DataCollection $items, + /** @var MenuItemData[] */ + public array $items, ) {} } diff --git a/src/Http/Controllers/PreloadsShowEntityLists.php b/src/Http/Controllers/PreloadsShowEntityLists.php index 07e3f0a19..f70131d92 100644 --- a/src/Http/Controllers/PreloadsShowEntityLists.php +++ b/src/Http/Controllers/PreloadsShowEntityLists.php @@ -12,15 +12,18 @@ trait PreloadsShowEntityLists { protected function addPreloadHeadersForShowEntityLists(ShowData $payload): void { - $payload->fields->whereInstanceOf(ShowEntityListFieldData::class) - ->each(function (ShowEntityListFieldData $entityListField) use ($payload) { - $section = $payload->layout->sections->firstWhere(fn (ShowLayoutSectionData $section) => collect($section->columns->map(fn (ShowLayoutColumnData $column) => $column->fields)) - ->flatten(2) - ->firstWhere('key', $entityListField->key) - ); + collect($payload->fields)->each(function ($field) use ($payload) { + if ($field instanceof ShowEntityListFieldData) { + $section = collect($payload->layout->sections) + ->firstWhere(fn (ShowLayoutSectionData $section) => collect($section->columns) + ->map(fn (ShowLayoutColumnData $column) => $column->fields) + ->flatten(2) + ->firstWhere('key', $field->key) + ); if ($section && ! $section->collapsable) { - app(AddLinkHeadersForPreloadedRequests::class)->preload($entityListField->endpointUrl); + app(AddLinkHeadersForPreloadedRequests::class)->preload($field->endpointUrl); } - }); + } + }); } }