Files
klz-cables.com/.pnpm-store/v10/files/63/896d41d9dc361ea42c0071d8f4ffe5821fdbd17c187ff197f787d1031cf2fb1be02e8581ce502d10e29bd8b6022215770931a0a9530501d95f1c320664f8f8
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

94 lines
2.8 KiB
Plaintext

import { jsx as _jsx } from "react/jsx-runtime";
import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
import { PREFERENCE_KEYS } from 'payload/shared';
import React from 'react';
import { getPreferences } from '../../../../utilities/getPreferences.js';
import { ModularDashboardClient } from './index.client.js';
export async function ModularDashboard(props) {
const {
defaultLayout = [],
widgets = []
} = props.payload.config.admin.dashboard || {};
const {
importMap
} = props.payload;
const {
user
} = props;
const {
cookies,
locale,
permissions,
req
} = props.initPageResult;
const {
i18n
} = req;
const layout = (await getItemsFromPreferences(props.payload, user)) ?? (await getItemsFromConfig(defaultLayout, req, widgets));
const serverLayout = layout.map(layoutItem => {
const widgetSlug = layoutItem.id.slice(0, layoutItem.id.lastIndexOf('-'));
return {
component: RenderServerComponent({
Component: widgets.find(widget => widget.slug === widgetSlug)?.ComponentPath,
importMap,
serverProps: {
cookies,
locale,
permissions,
req,
widgetSlug
}
}),
item: layoutItem
};
});
// Resolve function labels to static labels for client components
const clientWidgets = widgets.map(widget => {
const {
ComponentPath: _,
label,
...rest
} = widget;
return {
...rest,
label: typeof label === 'function' ? label({
i18n,
t: i18n.t
}) : label
};
});
return /*#__PURE__*/_jsx("div", {
children: /*#__PURE__*/_jsx(ModularDashboardClient, {
clientLayout: serverLayout,
widgets: clientWidgets
})
});
}
async function getItemsFromPreferences(payload, user) {
const savedPreferences = await getPreferences(PREFERENCE_KEYS.DASHBOARD_LAYOUT, payload, user.id, user.collection);
if (!savedPreferences?.value || typeof savedPreferences.value !== 'object' || !('layouts' in savedPreferences.value)) {
return null;
}
return savedPreferences.value.layouts;
}
async function getItemsFromConfig(defaultLayout, req, widgets) {
// Handle function format
let widgetInstances;
if (typeof defaultLayout === 'function') {
widgetInstances = await defaultLayout({
req
});
} else {
widgetInstances = defaultLayout;
}
return widgetInstances.map((widgetInstance, index) => {
const widget = widgets.find(widget => widget.slug === widgetInstance.widgetSlug);
return {
id: `${widgetInstance.widgetSlug}-${index}`,
maxWidth: widget?.maxWidth ?? 'full',
minWidth: widget?.minWidth ?? 'x-small',
width: widgetInstance.width || 'x-small'
};
});
}
//# sourceMappingURL=index.js.map