From 2d75247534a1d7d0696e9b3d6be3bdca6b7e8dec Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Wed, 9 Oct 2024 16:22:17 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=9A=91=20resolve=20bug=20in=20the?= =?UTF-8?q?=20menu=20node=20data=20component=20when=20a=20resource=20is=20?= =?UTF-8?q?moving=20part.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Lib/Definitions/MenuNode.php | 17 ++++++++++------- app/Models/GeneralSetting.php | 3 ++- resources/ts/bo/components/MainMenu.vue | 3 ++- resources/ts/types/models/MenuNode.d.ts | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/Lib/Definitions/MenuNode.php b/app/Lib/Definitions/MenuNode.php index 036353bd..5eb5614a 100644 --- a/app/Lib/Definitions/MenuNode.php +++ b/app/Lib/Definitions/MenuNode.php @@ -6,11 +6,11 @@ use App\Enums\Settings\MenuNodeType; use App\Lib\Link; /** - * @property-read integer $id The node menu id. - * @property-read \App\Enums\Settings\MenuNodeType $type The node menu type. - * @property-read string $title The node menu title. - * @property-read \App\Lib\Link $link The node menu link. - * @property-read boolean $published The node menu publish status. + * @property-read integer $id The node menu id. + * @property-read \App\Enums\Settings\MenuNodeType $type The node menu type. + * @property-read string $title The node menu title. + * @property-read \App\Lib\Link $link The node menu link. + * @property-read boolean $published The node menu publish status. * @package App\Lib\Definitions */ class MenuNode extends \stdClass @@ -24,7 +24,7 @@ class MenuNode extends \stdClass */ public function __get(string $name): mixed { - if (in_array($name, ['type', 'title', 'link', 'published'])) { + if (in_array($name, ['id', 'type', 'title', 'link', 'published'])) { return $this->{$name}; } throw new \TypeError("undefined property {$name}"); @@ -33,6 +33,7 @@ class MenuNode extends \stdClass /** * Make and instance * + * @param integer $id The node menu id. * @param integer $type The node menu type. * @param boolean $published The node menu published. * @param string $title The node menu title. @@ -40,12 +41,14 @@ class MenuNode extends \stdClass * @return \App\Lib\Definitions\MenuNode * @throws \RuntimeException If $type or $data is wrong. */ - public static function make(int $type, bool $published, string $title, array $link): self + public static function make(int $id, int $type, bool $published, string $title, array $link): self { self::assertTypeIsCorrect($type); $menuNode = new self(); // @phpstan-ignore-next-line + $menuNode->id = $id; + // @phpstan-ignore-next-line $menuNode->type = MenuNodeType::make($type); // @phpstan-ignore-next-line $menuNode->published = $published; diff --git a/app/Models/GeneralSetting.php b/app/Models/GeneralSetting.php index a3c4f2dc..d273a4a9 100644 --- a/app/Models/GeneralSetting.php +++ b/app/Models/GeneralSetting.php @@ -142,7 +142,8 @@ class GeneralSetting extends Model return match ($type) { SettingsType::mainMenu => collect(MenuNodeType::all()) ->filter(fn(MenuNodeType $menuNodeType) => $menuNodeType !== MenuNodeType::link) - ->map(fn(MenuNodeType $nodeType) => MenuNode::make( + ->map(fn(MenuNodeType $nodeType, int $key) => MenuNode::make( + $key + 1, $nodeType->value(), true, $nodeType->label(), diff --git a/resources/ts/bo/components/MainMenu.vue b/resources/ts/bo/components/MainMenu.vue index ddebb2ce..0067e029 100644 --- a/resources/ts/bo/components/MainMenu.vue +++ b/resources/ts/bo/components/MainMenu.vue @@ -29,7 +29,7 @@