1515 */
1616
1717import { HomePageLayoutBlueprint } from '@backstage/plugin-home-react/alpha' ;
18- import { HomePageLayout } from '../components/HomePageLayout' ;
19- import { HomePageCardConfig } from '../../types' ;
18+ import { z } from 'zod' ;
19+
20+ const breakpointLayoutSchema = z . object ( {
21+ w : z . number ( ) . optional ( ) ,
22+ h : z . number ( ) . optional ( ) ,
23+ x : z . number ( ) . optional ( ) ,
24+ y : z . number ( ) . optional ( ) ,
25+ } ) ;
26+
27+ const widgetLayoutEntrySchema = z . object ( {
28+ priority : z . number ( ) . optional ( ) ,
29+ breakpoints : z . record ( z . string ( ) , breakpointLayoutSchema ) . optional ( ) ,
30+ } ) ;
2031
2132/**
2233 * Custom home page layout extension for the New Frontend System.
@@ -29,63 +40,21 @@ import { HomePageCardConfig } from '../../types';
2940export const homePageLayoutExtension =
3041 HomePageLayoutBlueprint . makeWithOverrides ( {
3142 name : 'dynamic-homepage-layout' ,
32- config : {
33- schema : {
34- customizable : z => z . boolean ( ) . optional ( ) ,
35- widgetLayout : z =>
36- z
37- . record (
38- z . object ( {
39- priority : z . number ( ) . optional ( ) ,
40- breakpoints : z
41- . record (
42- z . object ( {
43- w : z . number ( ) . optional ( ) ,
44- h : z . number ( ) . optional ( ) ,
45- x : z . number ( ) . optional ( ) ,
46- y : z . number ( ) . optional ( ) ,
47- } ) ,
48- )
49- . optional ( ) ,
50- } ) ,
51- )
52- . optional ( ) ,
53- } ,
43+ configSchema : {
44+ customizable : z . boolean ( ) . optional ( ) ,
45+ widgetLayout : z . record ( z . string ( ) , widgetLayoutEntrySchema ) . optional ( ) ,
5446 } ,
5547 factory ( originalFactory , { config } ) {
5648 const customizable = config . customizable ?? true ;
5749 const layoutConfig = config . widgetLayout ?? { } ;
5850
5951 return originalFactory ( {
60- loader : async ( ) =>
61- function CustomHomePageLayout ( { widgets } ) {
62- const processedWidgets : HomePageCardConfig [ ] = widgets
63- . map ( widget => {
64- const widgetConfig = layoutConfig [ widget . name ?? '' ] ;
65- const configBreakpoints = widgetConfig ?. breakpoints ;
66-
67- if ( ! configBreakpoints ) return widget ;
68-
69- return {
70- ...widget ,
71- breakpointLayouts : configBreakpoints ,
72- } ;
73- } )
74- . sort ( ( a , b ) => {
75- if ( customizable ) return 0 ; // keep original order
76-
77- const priorityA = layoutConfig [ a . name ?? '' ] ?. priority ?? 0 ;
78- const priorityB = layoutConfig [ b . name ?? '' ] ?. priority ?? 0 ;
79- return priorityB - priorityA ;
80- } ) ;
81-
82- return (
83- < HomePageLayout
84- widgets = { processedWidgets }
85- customizable = { customizable }
86- />
87- ) ;
88- } ,
52+ loader : async ( ) => {
53+ const { createCustomHomePageLayout } = await import (
54+ '../components/CustomHomePageLayout'
55+ ) ;
56+ return createCustomHomePageLayout ( { customizable, layoutConfig } ) ;
57+ } ,
8958 } ) ;
9059 } ,
9160 } ) ;
0 commit comments