Skip to content

Commit bea1d8f

Browse files
committed
feat: add query component
1 parent ed50e06 commit bea1d8f

5 files changed

Lines changed: 61 additions & 59 deletions

File tree

src/frontend/platform/src/pages/Dashboard/components/editor/ComponentPicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cn } from '@/utils';
33
import React, { useState } from 'react';
44
import { ChartType } from '../../types/dataConfig';
55

6-
export const ChartItems = [
6+
export const ChartGroupItems = [
77
{
88
label: '柱状图',
99
data: [
@@ -43,6 +43,7 @@ export const ChartItems = [
4343
]
4444
}
4545
];
46+
export const ChartItems = ChartGroupItems.flatMap(item => item.data);
4647

4748
// 定义数据项结构
4849
export interface PickerItem {
@@ -91,7 +92,7 @@ const ComponentPicker = ({ children, className, onSelect }: ComponentPickerProps
9192
<PopoverContent align="start" className={cn("w-[332px] p-4 shadow-xl", className)}>
9293
<div className="space-y-2">
9394
{
94-
ChartItems.map(item => (
95+
ChartGroupItems.map(item => (
9596
<div>
9697
<h4 className="text-sm font-medium mb-2 px-1">{item.label}</h4>
9798
<ItemGrid list={item.data} />

src/frontend/platform/src/pages/Dashboard/components/editor/ComponentWrapper.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import "./index.css"
1212

1313
interface ComponentWrapperProps {
1414
component: DashboardComponent
15-
isSelected: boolean
1615
isPreviewMode: boolean
17-
dashboards: Dashboard[],
16+
dashboards: Dashboard[]
1817
isDark: boolean
19-
onClick: () => void
2018
onDuplicate: (componentId: string) => void
2119
onCopyTo: (componentId: string, targetDashboardId: string) => void
2220
onDelete: (componentId: string) => void

src/frontend/platform/src/pages/Dashboard/components/editor/EditorCanvas.tsx

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -206,59 +206,59 @@ export function EditorCanvas({ isLoading, isPreviewMode, dashboard }: EditorCanv
206206

207207
return (
208208
<>
209-
<div className="flex h-full">
210-
<div
211-
id="edit-charts-panne"
212-
ref={containerRef}
213-
className="flex-1 p-2 overflow-auto"
214-
style={{
215-
backgroundColor: currentDashboard.style_config.theme === 'dark' ? '#1a1a1a' : '#f5f5f5',
216-
}}
217-
onClick={handleCanvasClick}
218-
>
219-
<div className="mx-auto relative" style={{
220-
...gridBackgroundStyle,
221-
}}>
222-
{mounted && (
223-
<ReactGridLayout
224-
className="layout"
225-
layout={layouts}
226-
width={width}
227-
gridConfig={{
228-
cols: 24,
229-
rowHeight: 32
230-
}}
231-
dragConfig={{ enabled: !isPreviewMode }}
232-
resizeConfig={
233-
{
234-
enabled: !isPreviewMode,
235-
handles: ["sw", "nw", "se", "ne"]
209+
<div className="flex h-full">
210+
<div
211+
id="edit-charts-panne"
212+
ref={containerRef}
213+
className="flex-1 p-2 overflow-auto"
214+
style={{
215+
backgroundColor: currentDashboard.style_config.theme === 'dark' ? '#1a1a1a' : '#f5f5f5',
216+
}}
217+
onClick={handleCanvasClick}
218+
>
219+
<div className="mx-auto relative" style={{
220+
...gridBackgroundStyle,
221+
}}>
222+
{mounted && (
223+
<ReactGridLayout
224+
className="layout"
225+
layout={layouts}
226+
width={width}
227+
gridConfig={{
228+
cols: 24,
229+
rowHeight: 32
236230
}}
237-
onLayoutChange={handleLayoutChange}
238-
draggableHandle=".drag-handle"
239-
margin={[16, 16]}
240-
containerPadding={[0, 0]}
241-
compactor={verticalCompactor}
242-
>
243-
{currentDashboard.components.map((component) => (
244-
<div key={component.id} className="drag-handle">
245-
<ComponentWrapper
246-
dashboards={dashboards}
247-
component={component}
248-
isDark={currentDashboard.style_config.theme === 'dark'}
249-
isPreviewMode={isPreviewMode}
250-
onDuplicate={handleDuplicate}
251-
onCopyTo={handleCopyTo}
252-
onDelete={handleDelete}
253-
/>
254-
</div>
255-
))}
256-
</ReactGridLayout>
257-
)}
231+
dragConfig={{ enabled: !isPreviewMode }}
232+
resizeConfig={
233+
{
234+
enabled: !isPreviewMode,
235+
handles: ["sw", "nw", "se", "ne"]
236+
}}
237+
onLayoutChange={handleLayoutChange}
238+
draggableHandle=".drag-handle"
239+
margin={[16, 16]}
240+
containerPadding={[0, 0]}
241+
compactor={verticalCompactor}
242+
>
243+
{currentDashboard.components.map((component) => (
244+
<div key={component.id} className="drag-handle">
245+
<ComponentWrapper
246+
dashboards={dashboards}
247+
component={component}
248+
isDark={currentDashboard.style_config.theme === 'dark'}
249+
isPreviewMode={isPreviewMode}
250+
onDuplicate={handleDuplicate}
251+
onCopyTo={handleCopyTo}
252+
onDelete={handleDelete}
253+
/>
254+
</div>
255+
))}
256+
</ReactGridLayout>
257+
)}
258+
</div>
258259
</div>
259-
</div>
260-
{/* 配置抽屉 */}
261-
<ComponentConfigDrawer />
260+
{/* 配置抽屉 */}
261+
{!isPreviewMode && <ComponentConfigDrawer />}
262262
</div>
263263
</>
264264
)

src/frontend/platform/src/pages/Dashboard/components/editor/EditorHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useNavigate } from "react-router-dom"
1717
import { usePublishDashboard } from "../../hook"
1818
import ComponentPicker from "./ComponentPicker"
1919
import ThemePicker from "./ThemePicker"
20-
import { Dashboard } from "../../types/dataConfig"
20+
import { ChartType, Dashboard } from "../../types/dataConfig"
2121
import { Separator } from "@/components/bs-ui/separator"
2222
import { Badge } from "@/components/bs-ui/badge"
2323

@@ -270,7 +270,10 @@ export function EditorHeader({
270270
添加图表
271271
</Button>
272272
</ComponentPicker>
273-
<Button variant="outline" size="sm" className="gap-2">
273+
<Button variant="outline" size="sm" className="gap-2" onClick={() => addComponentToLayout({
274+
title: "",
275+
type: ChartType.Query
276+
})}>
274277
<FunnelIcon size="14" />
275278
添加查询组件
276279
</Button>

src/frontend/platform/src/pages/Dashboard/components/editor/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function Home() {
2323

2424
{/* Chart Grid */}
2525
<div className="flex justify-center flex-wrap gap-4">
26-
{ChartItems.flatMap(e => e.data).map((item) => (
26+
{ChartItems.map((item) => (
2727
<div
2828
key={item.type}
2929
onClick={() => handleItemClick(item)}

0 commit comments

Comments
 (0)