1- import { ComponentType , FC , useState } from 'react' ;
2- import Image , { StaticImageData } from 'next/image' ;
1+ import { FC , useState , ComponentProps } from 'react' ;
2+ import Image from 'next/image' ;
3+ import styled from '@emotion/styled' ;
34import { GridLayout , DragAndDropProvider , Draggable , Layout } from '@/components/GridLayout' ;
45import ProjectTimeline from '@/components/ProjectTimeline' ;
56import ProjectTimelinePreview from '@/components/ProjectTimeline.preview.png' ;
7+ import TicketStatusOverview from '@/components/TicketStatusOverview' ;
8+ import TicketStatusOverviewPreview from '@/components/TicketStatusOverview.preview.png' ;
9+ import BuildStatusOverview from '@/components/BuildStatusOverview' ;
10+ import BuildStatusOverviewPreview from '@/components/BuildStatusOverview.preview.png' ;
11+ import OwnerRotationOverview from '@/components/OwnerRotationOverview' ;
12+ import OwnerRotationOverviewPreview from '@/components/OwnerRotationOverview.preview.png' ;
613
7- const COMPONENTS : Record <
8- string ,
14+ const COMPONENTS = [
915 {
10- Component : ComponentType ;
11- preview : StaticImageData ;
12- }
13- > = {
14- ProjectTimeline : {
15- Component : ProjectTimeline ,
16+ name : 'ProjectTimeline' ,
17+ Component : ( props : ComponentProps < typeof ProjectTimeline > ) => (
18+ < ProjectTimeline h = "100%" { ...props } />
19+ ) ,
1620 preview : ProjectTimelinePreview ,
21+ layout : {
22+ w : 8 ,
23+ minW : 2 ,
24+ h : 7 ,
25+ minH : 2 ,
26+ maxH : 9 ,
27+ } ,
1728 } ,
18- } ;
29+ {
30+ name : 'TicketStatusOverview' ,
31+ Component : ( props : ComponentProps < typeof ProjectTimeline > ) => (
32+ < TicketStatusOverview h = "100%" maxWidth = "auto" { ...props } />
33+ ) ,
34+ preview : TicketStatusOverviewPreview ,
35+ layout : {
36+ w : 4 ,
37+ minW : 2 ,
38+ h : 6 ,
39+ minH : 2 ,
40+ maxH : 9 ,
41+ } ,
42+ } ,
43+ {
44+ name : 'BuildStatusOverview' ,
45+ Component : ( props : ComponentProps < typeof ProjectTimeline > ) => (
46+ < BuildStatusOverview h = "100%" maxWidth = "auto" { ...props } />
47+ ) ,
48+ preview : BuildStatusOverviewPreview ,
49+ layout : {
50+ w : 9 ,
51+ minW : 2 ,
52+ h : 6 ,
53+ minH : 2 ,
54+ maxH : 9 ,
55+ } ,
56+ } ,
57+ {
58+ name : 'OwnerRotationOverview' ,
59+ Component : ( props : ComponentProps < typeof ProjectTimeline > ) => (
60+ < OwnerRotationOverview h = "100%" maxWidth = "auto" { ...props } />
61+ ) ,
62+ preview : OwnerRotationOverviewPreview ,
63+ layout : {
64+ w : 2 ,
65+ minW : 2 ,
66+ h : 6 ,
67+ minH : 4 ,
68+ } ,
69+ } ,
70+ ] ;
71+
72+ const ComponentItem = styled ( 'div' ) `
73+ /* TODO: adjust styles */
74+ margin-bottom: 10px;
75+ border-radius: 14px;
76+ padding: 8px;
77+ background: #f3f3f3;
78+ ` ;
1979
2080const PageContainer : FC = ( ) => {
2181 const [ layouts , setLayouts ] = useState < Layout [ ] > ( ( ) => [ ] ) ;
@@ -30,44 +90,31 @@ const PageContainer: FC = () => {
3090 id = "components"
3191 style = { { flex : 'none' , width : 250 , borderRight : '1px solid #eee' , padding : 10 } }
3292 >
33- < Draggable
34- dropData = { {
35- templateId : 'ProjectTimeline' ,
36- layout : {
37- w : 8 ,
38- minW : 2 ,
39- maxW : 10 ,
40- h : 7 ,
41- minH : 2 ,
42- maxH : 9 ,
43- } ,
44- } }
45- >
46- { /* TODO: adjust styles */ }
47- < div
48- style = { {
49- background : '#f3f3f3' ,
50- borderRadius : 14 ,
51- padding : 8 ,
52- } }
53- >
54- < Image
55- src = { ProjectTimelinePreview }
56- alt = "ProjectTimeline preview"
57- draggable = { false }
58- />
59- </ div >
60- </ Draggable >
93+ { COMPONENTS . map ( ( { name, preview, layout } ) => {
94+ return (
95+ < Draggable
96+ key = { name }
97+ dropData = { {
98+ component : name ,
99+ layout,
100+ } }
101+ >
102+ < ComponentItem >
103+ < Image src = { preview } alt = "ProjectTimeline preview" draggable = { false } />
104+ </ ComponentItem >
105+ </ Draggable >
106+ ) ;
107+ } ) }
61108 </ aside >
62- < main style = { { flex : 1 } } >
109+ < main style = { { flex : 1 , padding : 10 } } >
63110 < GridLayout
64111 cols = { 12 }
65112 rows = { 12 }
66113 layouts = { layouts }
67114 onLayoutsChange = { ( newLayouts ) => setLayouts ( newLayouts ) }
68- itemRender = { ( layout ) => {
69- const { Component } = COMPONENTS [ layout . templateId ] ;
70- return < Component /> ;
115+ itemRender = { ( { component } ) => {
116+ const { Component } = COMPONENTS . find ( ( { name } ) => name === component ) ! ;
117+ return < Component w = "100%" h = "100%" /> ;
71118 } }
72119 droppable
73120 draggable
0 commit comments