Files
klz-cables.com/.pnpm-store/v10/files/1c/a9520e9f7662b1c80be236add88d3f8d91fbe82b1484c5e57cdb3991ffea92a4d1408e422ab88b88ad28b7b1a7228eea33f8d5685671eb8ed18aad1d0a82db
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

64 lines
1.7 KiB
Plaintext

import { RenderServerComponent } from '@payloadcms/ui/elements/RenderServerComponent';
/**
* Server function to get the default dashboard layout on-demand.
* Used when resetting the dashboard to its default configuration.
*/
export const getDefaultLayoutHandler = async ({
cookies,
locale,
permissions,
req
}) => {
if (!req.user) {
throw new Error('Unauthorized');
}
const {
defaultLayout = [],
widgets = []
} = req.payload.config.admin.dashboard || {};
const {
importMap
} = req.payload;
const layoutItems = await getItemsFromConfig(defaultLayout, req, widgets);
const layout = layoutItems.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
};
});
return {
layout
};
};
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(w => w.slug === widgetInstance.widgetSlug);
return {
id: `${widgetInstance.widgetSlug}-${index}`,
maxWidth: widget?.maxWidth ?? 'full',
minWidth: widget?.minWidth ?? 'x-small',
width: widgetInstance.width || 'x-small'
};
});
}
//# sourceMappingURL=getDefaultLayoutServerFn.js.map