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
48 lines
1.1 KiB
Plaintext
48 lines
1.1 KiB
Plaintext
import { isPathMatchingRoute } from './isPathMatchingRoute.js';
|
|
export const getCustomViewByRoute = ({
|
|
config,
|
|
currentRoute: currentRouteWithAdmin
|
|
}) => {
|
|
const {
|
|
admin: {
|
|
components: {
|
|
views
|
|
}
|
|
},
|
|
routes: {
|
|
admin: adminRoute
|
|
}
|
|
} = config;
|
|
let viewKey;
|
|
const currentRoute = adminRoute === '/' ? currentRouteWithAdmin : currentRouteWithAdmin.replace(adminRoute, '');
|
|
const foundViewConfig = views && typeof views === 'object' && Object.entries(views).find(([key, view]) => {
|
|
const isMatching = isPathMatchingRoute({
|
|
currentRoute,
|
|
exact: view.exact,
|
|
path: view.path,
|
|
sensitive: view.sensitive,
|
|
strict: view.strict
|
|
});
|
|
if (isMatching) {
|
|
viewKey = key;
|
|
}
|
|
return isMatching;
|
|
})?.[1] || undefined;
|
|
if (!foundViewConfig) {
|
|
return {
|
|
view: {
|
|
Component: null
|
|
},
|
|
viewConfig: null,
|
|
viewKey: null
|
|
};
|
|
}
|
|
return {
|
|
view: {
|
|
payloadComponent: foundViewConfig.Component
|
|
},
|
|
viewConfig: foundViewConfig,
|
|
viewKey
|
|
};
|
|
};
|
|
//# sourceMappingURL=getCustomViewByRoute.js.map |