Skip to content

Commit d5e5643

Browse files
committed
fix:fix bug
1 parent ee571e7 commit d5e5643

4 files changed

Lines changed: 122 additions & 30 deletions

File tree

src/frontend/platform/public/locales/en-US/dashboard.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"dialog": {
7777
"editDisplayName": "Edit Name",
7878
"originalName": "Original Name",
79+
"displayRequired": "Name cannot be empty",
7980
"displayName": "Display Name",
8081
"displayNameRequired": "Display Name *",
8182
"enterDisplayName": "Enter display name",

src/frontend/platform/public/locales/ja/dashboard.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@
4646
"customStyle": "カスタムスタイル",
4747
"basicConfigTab": "基本設定",
4848
"styleConfigTab": "カスタムスタイル",
49-
49+
"validation": {
50+
"validationFailed": "検証に失敗しました",
51+
"chartTypeRequired": "グラフタイプを選択してください",
52+
"categoryRequired": "少なくとも1つのカテゴリーディメンションを追加してください",
53+
"metricRequired": "少なくとも1つのメトリックを追加してください",
54+
"datasetRequired": "データセットを選択してください",
55+
"stackRequired": "積み上げグラフにはスタックディメンションが必要です",
56+
"invalidCategoryFields": "カテゴリーディメンションに無効なフィールドがあります",
57+
"invalidMetricFields": "メトリックに無効なフィールドがあります"
58+
},
5059
"chartType": "グラフタイプ",
5160
"selectChartType": "グラフタイプを選択",
5261

@@ -76,6 +85,7 @@
7685
"dialog": {
7786
"editDisplayName": "表示名を編集",
7887
"originalName": "元の名前",
88+
"displayRequired": "名前を入力してください",
7989
"displayName": "表示名",
8090
"displayNameRequired": "表示名 *",
8191
"enterDisplayName": "表示名を入力してください",
@@ -98,16 +108,7 @@
98108
"value": "メトリックエリア"
99109
}
100110
},
101-
"validation": {
102-
"validationFailed": "検証に失敗しました",
103-
"chartTypeRequired": "グラフタイプを選択してください",
104-
"categoryRequired": "少なくとも1つのカテゴリーディメンションを追加してください",
105-
"metricRequired": "少なくとも1つのメトリックを追加してください",
106-
"datasetRequired": "データセットを選択してください",
107-
"stackRequired": "積み上げグラフにはスタックディメンションが必要です",
108-
"invalidCategoryFields": "カテゴリーディメンションに無効なフィールドがあります",
109-
"invalidMetricFields": "メトリックに無効なフィールドがあります"
110-
},
111+
111112
"configPanel": {
112113
"title": "ダッシュボード設定",
113114
"dashboardStyle": "ダッシュボードスタイル",

src/frontend/platform/public/locales/zh-Hans/dashboard.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"dialog": {
7171
"chartUpdated": "图表已更新",
7272
"editDisplayName": "编辑显示名称",
73+
"displayRequired":"名称不能为空",
7374
"originalName": "原始名称",
7475
"displayName": "显示名称",
7576
"displayNameRequired": "显示名称 *",

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

Lines changed: 108 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export function ComponentConfigDrawer() {
6060
// 使用自定义Hook管理所有图表状态
6161
const chartState = useChartState(editingComponent)
6262
const [isMetricCard, setIsMetricCard] = useState(true)
63-
console.log(editingComponent, 3434343434);
6463

6564
// 从Hook中解构状态和方法
6665
const {
@@ -118,8 +117,20 @@ export function ComponentConfigDrawer() {
118117
return false
119118
}
120119
}
121-
120+
const isFieldInCategoryOrStack = (fieldId: string) => {
121+
return (
122+
categoryDimensions.some(dim => dim.fieldId === fieldId) ||
123+
stackDimensions.some(dim => dim.fieldId === fieldId)
124+
)
125+
}
122126
if (field.role === 'dimension') {
127+
if (isFieldInCategoryOrStack(safeFieldId)) {
128+
toast({
129+
description: t("useChartState.warn.fieldExists"),
130+
variant: "warning"
131+
})
132+
return
133+
}
123134
if (categoryDimensions.length < 2 && isMetricCard) {
124135
if (isFieldAlreadyAdded(safeFieldId, 'category')) {
125136
toast({
@@ -141,6 +152,13 @@ export function ComponentConfigDrawer() {
141152
}
142153
chartState.setCategoryDimensions(prev => [...prev, newDimension])
143154
} else if (currentChartHasStack && stackDimensions.length === 0 && isMetricCard) {
155+
if (isFieldInCategoryOrStack(safeFieldId)) {
156+
toast({
157+
description: t("useChartState.warn.fieldExists"),
158+
variant: "warning"
159+
})
160+
return
161+
}
144162
if (isFieldAlreadyAdded(safeFieldId, 'stack')) {
145163
toast({
146164
description: t("componentConfigDrawer.toast.fieldAlreadyExists", {
@@ -190,21 +208,21 @@ export function ComponentConfigDrawer() {
190208
}
191209

192210
if (valueDimensions.length > 0) {
193-
if (currentIsVirtual && !hasVirtualMetric) {
194-
toast({
195-
description: t("componentConfigDrawer.toast.virtualMetricConflict"),
196-
variant: "warning"
197-
})
198-
return
199-
}
211+
// if (currentIsVirtual && !hasVirtualMetric) {
212+
// toast({
213+
// description: t("componentConfigDrawer.toast.virtualMetricConflict"),
214+
// variant: "warning"
215+
// })
216+
// return
217+
// }
200218

201-
if (!currentIsVirtual && hasVirtualMetric) {
202-
toast({
203-
description: t("componentConfigDrawer.toast.virtualMetricConflict"),
204-
variant: "warning"
205-
})
206-
return
207-
}
219+
// if (!currentIsVirtual && hasVirtualMetric) {
220+
// toast({
221+
// description: t("componentConfigDrawer.toast.virtualMetricConflict"),
222+
// variant: "warning"
223+
// })
224+
// return
225+
// }
208226

209227
// 多个虚拟指标
210228
// if (currentIsVirtual && hasVirtualMetric) {
@@ -293,6 +311,14 @@ export function ComponentConfigDrawer() {
293311

294312
const saveDisplayName = useCallback(() => {
295313
if (editingDimension) {
314+
const trimmedName = editingDimension.displayName?.trim();
315+
if (!trimmedName) {
316+
toast({
317+
description: t("componentConfigDrawer.dialog.displayRequired"),
318+
variant: "error"
319+
});
320+
return;
321+
}
296322
// 更新对应的维度显示名称
297323
const updateDimensions = (prev: any[]) =>
298324
prev.map(d => d.id === editingDimension.id ? { ...d, displayName: editingDimension.displayName } : d)
@@ -608,8 +634,71 @@ export function ComponentConfigDrawer() {
608634
const chartLabel = ChartGroupItems
609635
.flatMap(item => item.data)
610636
.find(item => item.type === data.type)?.label;
611-
if (chartLabel) {
612-
setTitle(t(`chart.${chartLabel}`));
637+
638+
// 判断用户是否自定义过标题
639+
const userCustomizedTitle = editingComponent.title !== styleConfig.title;
640+
const newTitle = userCustomizedTitle ? editingComponent.title : (chartLabel ? t(`chart.${chartLabel}`) : title);
641+
642+
if (!userCustomizedTitle && chartLabel) {
643+
setTitle(newTitle);
644+
}
645+
646+
// 立即触发图表更新
647+
if (editingComponent) {
648+
// 使用当前实际的限制配置
649+
const currentLimitType = limitType;
650+
const currentLimitValue = limitValue;
651+
652+
// 获取当前数据配置
653+
const dataConfig = getDataConfig(currentLimitType, currentLimitValue, editingComponent.data_config?.timeFilter);
654+
655+
// 根据新图表类型调整配置
656+
const STACKED_CHART_TYPES = new Set<ChartType>([
657+
ChartType.StackedBar,
658+
ChartType.StackedHorizontalBar,
659+
ChartType.StackedLine
660+
]);
661+
662+
const isNewChartStacked = STACKED_CHART_TYPES.has(data.type);
663+
const isCurrentChartStacked = currentChartHasStack;
664+
665+
let updatedDataConfig = { ...dataConfig };
666+
667+
// 处理堆叠维度
668+
if (isCurrentChartStacked && !isNewChartStacked) {
669+
// 从堆叠图切换到非堆叠图:移除堆叠维度配置
670+
updatedDataConfig = {
671+
...updatedDataConfig,
672+
stackDimension: undefined,
673+
// 保持其他维度不变
674+
dimensions: updatedDataConfig.dimensions || [],
675+
metrics: updatedDataConfig.metrics || []
676+
};
677+
} else if (!isCurrentChartStacked && isNewChartStacked) {
678+
// 从非堆叠图切换到堆叠图:清空堆叠维度(用户需要手动添加)
679+
updatedDataConfig = {
680+
...updatedDataConfig,
681+
stackDimension: undefined, // 清空堆叠维度
682+
// 保持其他维度不变
683+
dimensions: updatedDataConfig.dimensions || [],
684+
metrics: updatedDataConfig.metrics || []
685+
};
686+
}
687+
688+
// 更新组件配置
689+
updateEditingComponent({
690+
type: data.type,
691+
data_config: updatedDataConfig,
692+
title: newTitle,
693+
style_config: {
694+
...styleConfig,
695+
title: newTitle // 同时更新styleConfig中的标题
696+
},
697+
dataset_code: editingComponent.dataset_code
698+
});
699+
700+
// 刷新图表
701+
refreshChart(editingComponent.id);
613702
}
614703
}} maxHeight={500}>
615704
<div className="relative w-full group">
@@ -730,7 +819,7 @@ export function ComponentConfigDrawer() {
730819
<div
731820
key={field.id}
732821
draggable
733-
onMouseDown={() => setDraggingId(field.id)}
822+
onMouseDown={() => { }}
734823
onDragStart={(e) => {
735824
setDraggingId(field.id)
736825
e.dataTransfer.effectAllowed = 'move'

0 commit comments

Comments
 (0)