fix: 🚑 resolve bug in the menu node data component when a resource is moving part.2

This commit is contained in:
Alexis Gousseau 2024-10-09 16:22:17 +02:00
parent 17b7a7dfd6
commit 2d75247534
4 changed files with 15 additions and 10 deletions

View file

@ -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;

View file

@ -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(),

View file

@ -29,7 +29,7 @@
<div class="list-group">
<Draggable
:list="nodeList"
item-key="type"
item-key="id"
>
<!-- LIST ITEM -->
<template #item="{ element, index } : {element: MenuNodeInterface, index: number}">
@ -168,6 +168,7 @@ onMounted(() => {
/** Add a new link node to the menu */
function addLinkNode(): void {
const newNode = {
id: Math.max(...nodeList.value.map(o => o.id)) + 1,
type: MenuNodeTypeEnum.link,
title: trans.methods.__("Lien"),
published: false,

View file

@ -1,8 +1,8 @@
import type { MenuNodeTypeEnum } from "resources/ts";
import type { LinkInterface } from "resources/ts/types/models/Link";
export interface MenuNodeInterface {
id: number,
type: MenuNodeTypeEnum,
published: boolean,
title: string,