Skip to content
Open
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: 6 additions & 0 deletions src/components/menus/MenuEditor/SortableItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ChevronRight, ChevronDown, GripVertical, Plus, Trash2 } from "lucide-re
import { IconButton } from "../../ui/Button";
import Tooltip from "../../ui/Tooltip";
import MenuCombobox from "./MenuCombobox";
import { MENU_DEFAULT_LABEL_NEW_ITEM, MENU_DEFAULT_LABEL_NEW_CHILD } from "./utils/menuUtils";

// SortableItem component - memoized
const SortableItem = memo(function SortableItem({
Expand Down Expand Up @@ -81,11 +82,16 @@ const SortableItem = memo(function SortableItem({
const page = pages.find((p) => p.value === value);

if (page) {

const trimmedLabel = String(item.label ?? "").trim();
const isDefaultLabel = !trimmedLabel || trimmedLabel === MENU_DEFAULT_LABEL_NEW_ITEM || trimmedLabel === MENU_DEFAULT_LABEL_NEW_CHILD;

// User selected an internal page - store pageUuid and derive link from current slug
onEdit(item.id, {
...item,
pageUuid: page.value,
link: `${page.slug}.html`,
label: isDefaultLabel ? page.label : item.label
});
} else {
// Custom URL - explicitly clear pageUuid because menu item updates are merged.
Expand Down
6 changes: 3 additions & 3 deletions src/components/menus/MenuEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { debounce, isEqual } from "lodash";
import Button from "../../ui/Button";
import SortableList from "./SortableList";
import DragOverlayComponent from "./DragOverlay";
import { ensureIds, findItemById, getItemAtPath, generateId } from "./utils/menuUtils";
import { ensureIds, findItemById, getItemAtPath, generateId, MENU_DEFAULT_LABEL_NEW_ITEM, MENU_DEFAULT_LABEL_NEW_CHILD } from "./utils/menuUtils";
import {
flattenTree,
getProjection,
Expand Down Expand Up @@ -307,7 +307,7 @@ function MenuEditor({ initialItems = [], onChange, onDeleteItem }) {
...prevItems,
{
id: generateId(),
label: "New Item",
label: MENU_DEFAULT_LABEL_NEW_ITEM,
link: "",
items: [],
},
Expand Down Expand Up @@ -412,7 +412,7 @@ function MenuEditor({ initialItems = [], onChange, onDeleteItem }) {
// Add the new child
parentItem.items.push({
id: generateId(),
label: "New Child",
label: MENU_DEFAULT_LABEL_NEW_CHILD,
link: "",
items: [],
});
Expand Down
3 changes: 3 additions & 0 deletions src/components/menus/MenuEditor/utils/menuUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { v4 as uuidv4 } from "uuid";

export const MENU_DEFAULT_LABEL_NEW_ITEM = "New Item";
export const MENU_DEFAULT_LABEL_NEW_CHILD = "New Child";

// Generate a unique ID
export const generateId = () => `item-${uuidv4()}`;

Expand Down