Files
klz-cables.com/.pnpm-store/v10/files/f5/720ceac2c5eb9fbabb4790050a4d33f6ae98ebdde946df58a39d62122186d3a8daf714a9bbfe6fe21f6f3ac07697c617276793e42c60312b78ca09903e3714
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

65 lines
2.1 KiB
Plaintext

const globalLockDurationDefault = 300;
export async function getGlobalData(req) {
const {
payload: {
config
},
payload
} = req;
// Query locked global documents only if there are globals in the config
// This type is repeated from DashboardViewServerPropsOnly['globalData'].
// I thought about moving it to a payload to share it, but we're already
// exporting all the views props from the next package.
let globalData = [];
if (config.globals.length > 0) {
if (payload.collections?.['payload-locked-documents']) {
const lockedDocuments = await payload.find({
collection: 'payload-locked-documents',
depth: 1,
overrideAccess: false,
pagination: false,
req,
select: {
globalSlug: true,
updatedAt: true,
user: true
},
where: {
globalSlug: {
exists: true
}
}
});
// Map over globals to include `lockDuration` and lock data for each global slug
globalData = config.globals.map(global => {
const lockDuration = typeof global.lockDocuments === 'object' ? global.lockDocuments.duration : globalLockDurationDefault;
const lockedDoc = lockedDocuments.docs.find(doc => doc.globalSlug === global.slug);
return {
slug: global.slug,
data: {
_isLocked: !!lockedDoc,
_lastEditedAt: lockedDoc?.updatedAt ?? null,
_userEditing: lockedDoc?.user?.value ?? null
},
lockDuration
};
});
} else {
// If locked-documents collection doesn't exist, return globals without lock data
globalData = config.globals.map(global => {
const lockDuration = typeof global.lockDocuments === 'object' ? global.lockDocuments.duration : globalLockDurationDefault;
return {
slug: global.slug,
data: {
_isLocked: false,
_lastEditedAt: null,
_userEditing: null
},
lockDuration
};
});
}
}
return globalData;
}
//# sourceMappingURL=getGlobalData.js.map