Skip to content

Commit 83f20ee

Browse files
authored
Merge pull request #772 from lyp000119/dev
fix: Edit charts page does not select default chart
2 parents e53874c + 32bb278 commit 83f20ee

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

frontend/src/app/components/ChartEditor.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ export const ChartEditor: React.FC<ChartEditorProps> = ({
113113

114114
useMount(
115115
() => {
116-
if (!dataChartId && !originChart) {
116+
if (
117+
(container === 'dataChart' && !dataChartId) ||
118+
(container === 'widget' && !originChart)
119+
) {
117120
// Note: add default chart if new to editor
118121
const currentChart = ChartManager.instance().getDefaultChart();
119122
handleChartChange(currentChart);
@@ -135,6 +138,7 @@ export const ChartEditor: React.FC<ChartEditorProps> = ({
135138
backendChart: originChart as ChartDTO,
136139
}),
137140
);
141+
138142
if (!originChart) {
139143
dispatch(actions.updateChartAggregation(true));
140144
}
@@ -201,7 +205,9 @@ export const ChartEditor: React.FC<ChartEditorProps> = ({
201205
);
202206

203207
const clearDataConfig = useCallback(() => {
204-
const currentChart = ChartManager.instance().getById(chart?.meta?.id);
208+
const currentChart = chart?.meta?.id
209+
? ChartManager.instance().getById(chart?.meta?.id)
210+
: ChartManager.instance().getDefaultChart();
205211
let targetChartConfig = CloneValueDeep(currentChart?.config);
206212
registerChartEvents(currentChart);
207213
setChart(currentChart);

0 commit comments

Comments
 (0)