Skip to content

Commit 2a94cc1

Browse files
committed
chore: stash
1 parent ac96cf9 commit 2a94cc1

File tree

8 files changed

+120
-49
lines changed

8 files changed

+120
-49
lines changed

builder.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version": null}
148 KB
Loading

src/components/GridLayout.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type TransferData = {
135135
w: number;
136136
h: number;
137137
};
138-
templateId: string;
138+
component: string;
139139
[key: string]: any
140140
}
141141

@@ -183,7 +183,7 @@ export const DragAndDropProvider: FC<PropsWithChildren> = ({ children }) => {
183183
interface DraggableProps<T = {}> {
184184
dropData?: {
185185
layout: { w: number; h: number; minW?: number; maxW?: number; minH?: number; maxH?: number };
186-
templateId: string;
186+
component: string;
187187
} & T;
188188
}
189189

@@ -424,7 +424,7 @@ const LayoutItemComponent: FC<LayoutItemComponentProps> = ({
424424
};
425425

426426
export interface Layout {
427-
templateId: string;
427+
component: string;
428428
id: string;
429429
x: number;
430430
y: number;
@@ -553,8 +553,8 @@ export const GridLayout: FC<GridLayoutProps> = ({
553553
onLayoutsChange([
554554
...layouts,
555555
{
556-
id: `${data.templateId}-${Math.random()}`, // TODO: need redesign the computation?
557-
templateId: data.templateId,
556+
id: `${data.component}-${Math.random()}`, // TODO: need redesign the computation?
557+
component: data.component,
558558
...data.layout,
559559
...dropPositionRef.current,
560560
},
31.2 KB
Loading
68.2 KB
Loading

src/components/TicketStatusOverview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const TicketOverview = (props: SystemProps) => {
3333

3434
return (
3535
<RefreshWrapper
36-
{...props}
3736
maxWidth="448px"
37+
{...props}
3838
title="Ticket Status"
3939
onRefresh={fetchData}
4040
refreshIntervalSeconds={ticketStatusConfig.refreshIntervalSeconds}

src/pages/api/builder.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import { NextApiHandler } from 'next';
4+
5+
const postBuilder: NextApiHandler = (req, res) => {
6+
fs.writeFileSync(filePath, JSON.stringify(req.body), 'utf8');
7+
return res.status(200).json({ success: true })
8+
}
9+
10+
const filePath = path.join(process.cwd(), 'builder.json');
11+
12+
const getBuilder: NextApiHandler = (_, res) => {
13+
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'))
14+
return res.status(200).json(data.version ? data : null)
15+
}
16+
17+
const handler: NextApiHandler = (req, res) => {
18+
if (req.method === 'POST') return postBuilder(req, res)
19+
20+
return getBuilder(req, res)
21+
}
22+
23+
export default handler

src/pages/builder.tsx

Lines changed: 90 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,81 @@
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';
34
import { GridLayout, DragAndDropProvider, Draggable, Layout } from '@/components/GridLayout';
45
import ProjectTimeline from '@/components/ProjectTimeline';
56
import 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

2080
const 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

Comments
 (0)