Skip to content

Commit 2c07a9d

Browse files
mgkmgk
authored andcommitted
feat: Component Style
1 parent 2329ea2 commit 2c07a9d

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/frontend/platform/src/pages/Dashboard/components/charts/QueryFilter.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { DashboardComponent, QueryConfig } from "../../types/dataConfig"
1111
interface QueryFilterProps {
1212
component: DashboardComponent // Query the ID of the component, which is used to trigger the refresh of the associated chart
1313
isPreviewMode?: boolean
14+
onQuery?: (filter: any, hasQuery: boolean) => void
1415
}
1516

16-
export function QueryFilter({ component, isPreviewMode = false }: QueryFilterProps) {
17+
export function QueryFilter({ component, isPreviewMode = false, onQuery }: QueryFilterProps) {
1718
const { refreshChartsByQuery } = useEditorDashboardStore()
1819
const [date, setDate] = useState<Date | undefined>(undefined)
1920

@@ -23,6 +24,7 @@ export function QueryFilter({ component, isPreviewMode = false }: QueryFilterPro
2324

2425
const handleQuery = () => {
2526
console.log("查询日期:", date)
27+
onQuery?.(filter, true)
2628
// Refresh the associated chart based on the query component ID
2729
refreshChartsByQuery(component.id, filter)
2830
}
@@ -49,7 +51,11 @@ export function QueryFilter({ component, isPreviewMode = false }: QueryFilterPro
4951

5052
{/* 查询按钮 - 固定在右下角 */}
5153
<div className="absolute bottom-4 right-4">
52-
<Button onClick={handleQuery} size="sm" className="gap-1">
54+
<Button onClick={(e) => {
55+
e.stopPropagation()
56+
e.preventDefault()
57+
handleQuery()
58+
}} size="sm" className="gap-1">
5359
<Search className="h-4 w-4" />
5460
查询
5561
</Button>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const CHART_TYPES: {
4040
{ label: "查询组件", value: ChartType.Query, hasStack: false }
4141
];
4242

43-
export function ComponentConfigDrawer() {
43+
export function ComponentConfigDrawer({showChartSelector}: {showChartSelector:boolean}) {
4444
const { editingComponent, updateEditingComponent } = useComponentEditorStore();
4545
const { refreshChart } = useEditorDashboardStore();
4646

@@ -258,9 +258,8 @@ export function ComponentConfigDrawer() {
258258
}
259259

260260
return (
261-
<div className="fixed right-0 top-14 bottom-0 flex bg-background border-l border-border">
262-
263-
{false ? (
261+
<div className="h-full flex bg-background border-l border-border">
262+
{showChartSelector? (
264263
<ChartSelector
265264
charts={[
266265
{ id: '1', name: '堆叠条形图-图表名称', dataset: '会话500-数据集' },
@@ -272,7 +271,7 @@ export function ComponentConfigDrawer() {
272271
/>
273272
) : (
274273
<>
275-
<div className={`border-r flex flex-col h-full transition-all duration-300 ${configCollapsed.basic ? "w-12" : "w-[400px]"} shrink-0`}>
274+
<div className={`border-r flex flex-col h-full transition-all duration-300 ${configCollapsed.basic ? "w-12" : "w-[300px]"} shrink-0`}>
276275
{configCollapsed.basic ? (
277276
<CollapseLabel
278277
label="基础配置"
@@ -503,7 +502,7 @@ export function ComponentConfigDrawer() {
503502
</div>
504503
)}
505504
</div>
506-
<div className={`flex flex-col h-full transition-all duration-300 ${configCollapsed.data ? "w-12 shrink-0" : "w-[400px]"}`}>
505+
<div className={`flex flex-col h-full transition-all duration-300 ${configCollapsed.data ? "w-12 shrink-0" : "w-[300px]"}`}>
507506
{configCollapsed.data ? (
508507
<CollapseLabel label="数据集配置" onClick={() => toggleCollapse('data')} icon={<ChevronLeft />} />
509508
) : (

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ interface ComponentWrapperProps {
2020
onDuplicate: (componentId: string) => void
2121
onCopyTo: (componentId: string, targetDashboardId: string) => void
2222
onDelete: (componentId: string) => void
23+
onQuery?: (componentId: string, filter: any, hasQuery: boolean) => void
2324
}
2425

2526
// 组件包装器,用于处理选中状态
2627
export function ComponentWrapper({
2728
dashboards, component, isPreviewMode, isDark,
28-
onDuplicate, onCopyTo, onDelete
29+
onDuplicate, onCopyTo, onDelete,onQuery
2930
}: ComponentWrapperProps) {
3031
const [isHovered, setIsHovered] = useState(false)
3132
const [isEditing, setIsEditing] = useState(false)
@@ -45,6 +46,7 @@ export function ComponentWrapper({
4546

4647
const handleClick = (e: React.MouseEvent) => {
4748
e.stopPropagation()
49+
onQuery(component.id, null, false)
4850
if (isPreviewMode) return
4951
if (editingComponent?.id === component.id) return
5052
copyFromDashboard(component.id)
@@ -213,7 +215,10 @@ export function ComponentWrapper({
213215
{/* Component content */}
214216
<div className={['query', 'metric'].includes(component.type) ? 'h-full overflow-hidden' : 'h-[calc(100%-2.5rem)] overflow-hidden'}>
215217
{component.type === 'query' ? (
216-
<QueryFilter isDark={isDark} component={componentData} isPreviewMode={isPreviewMode} />
218+
<QueryFilter isDark={isDark} component={componentData} isPreviewMode={isPreviewMode} onQuery={(filter, hasQuery) => {
219+
onQuery?.(component.id, filter, hasQuery)
220+
}}
221+
/>
217222
) : (
218223
<ChartContainer isDark={isDark} component={componentData} />
219224
)}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function DashboardConfigPanel({ collapsed = false, onCollapse }: Dashboar
5858
)
5959

6060
return (
61-
<div className="fixed right-0 top-14 bottom-0 flex bg-background border-l border-border">
61+
<div className="h-full flex bg-background border-l border-border">
6262
<div className={`border-r flex flex-col h-full transition-all duration-300 ${collapsed ? "w-12" : "w-[400px]"} shrink-0`}>
6363
{collapsed ? (
6464
<CollapseLabel

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
4343
queryFn: getDashboards,
4444
// enabled: isHovered // Only fetch when hovered
4545
})
46-
46+
const [showChartSelector, setShowChartSelector] = useState<boolean>(false)
4747
// Mutation for copying component to another dashboard
4848
const copyToMutation = useMutation({
4949
mutationFn: ({ componentId, targetId }: { componentId: string; targetId: string }) =>
@@ -137,7 +137,10 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
137137
},
138138
})
139139
}
140-
140+
const handleQuery = (componentId: string, filter: any, shouldShow: boolean) => {
141+
console.log(`组件 ${componentId} 触发了查询:`, filter, shouldShow)
142+
setShowChartSelector(shouldShow)
143+
}
141144
const gridBackgroundStyle = useMemo(() => {
142145
if (isPreviewMode || !width || !mounted) return {};
143146

@@ -213,6 +216,7 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
213216

214217
return (
215218
<>
219+
<div className="flex h-full">
216220
<div
217221
id="edit-charts-panne"
218222
ref={containerRef}
@@ -223,7 +227,7 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
223227
onClick={handleCanvasClick}
224228
>
225229
<div className="mx-auto relative" style={{
226-
...gridBackgroundStyle, // 应用动态生成的网格背景
230+
...gridBackgroundStyle,
227231
}}>
228232
{mounted && (
229233
<ReactGridLayout
@@ -256,6 +260,7 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
256260
onDuplicate={handleDuplicate}
257261
onCopyTo={handleCopyTo}
258262
onDelete={handleDelete}
263+
onQuery={handleQuery}
259264
/>
260265
</div>
261266
))}
@@ -264,7 +269,8 @@ export function EditorCanvas({ isPreviewMode, dashboard }: EditorCanvasProps) {
264269
</div>
265270
</div>
266271
{/* 配置抽屉 */}
267-
<ComponentConfigDrawer />
272+
<ComponentConfigDrawer showChartSelector={showChartSelector}/>
273+
</div>
268274
</>
269275
)
270276
}

0 commit comments

Comments
 (0)