Skip to content

Commit a2d731f

Browse files
authored
Merge pull request #1234 from scottsut/fix
refactor: date level naming improvement
2 parents 8f4ca2c + 5fca2ee commit a2d731f

38 files changed

+233
-221
lines changed

frontend/src/app/components/ChartDrill/ChartDrillContextMenu.tsx

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import { Dropdown, Menu } from 'antd';
2121
import {
2222
ChartDataSectionType,
2323
ChartDataViewFieldCategory,
24-
interimDateAggregatedKey,
24+
RUNTIME_DATE_LEVEL_KEY,
2525
} from 'app/constants';
2626
import useI18NPrefix from 'app/hooks/useI18NPrefix';
2727
import { DrillMode } from 'app/models/ChartDrillOption';
28-
import DateMeunItem from 'app/pages/ChartWorkbenchPage/components/ChartOperationPanel/components/ChartFieldAction/DateAggregationAction/DateMeunItem';
28+
import DateLevelMenuItems from 'app/pages/ChartWorkbenchPage/components/ChartOperationPanel/components/ChartFieldAction/DateLevelAction/DateLevelMenuItems';
2929
import ChartDrillContext from 'app/pages/ChartWorkbenchPage/contexts/ChartDrillContext';
3030
import { ChartConfig, ChartDataSectionField } from 'app/types/ChartConfig';
31-
import { getInterimDateAggregateRows } from 'app/utils/chartHelper';
31+
import { getRuntimeDateLevelFields } from 'app/utils/chartHelper';
3232
import { updateBy } from 'app/utils/mutation';
3333
import classnames from 'classnames';
3434
import { FC, memo, useCallback, useContext, useMemo } from 'react';
@@ -41,17 +41,18 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
4141
const {
4242
drillOption,
4343
onDrillOptionChange,
44-
sourceSupportDateField,
45-
onChartDrillDataAggregationChange,
44+
availableSourceFunctions,
45+
onDateLevelChange,
4646
} = useContext(ChartDrillContext);
47-
const currentFields = drillOption?.getCurrentFields();
47+
4848
const currentDrillLevel = drillOption?.getCurrentDrillLevel();
4949

50-
const currentDrillField = useMemo(() => {
50+
const runtimeDateLevelFields = useMemo(() => {
5151
if (!drillOption) {
5252
return;
5353
}
5454
const allFields = drillOption.getAllFields();
55+
const currentFields = drillOption.getCurrentFields();
5556
const groupSection = chartConfig?.datas?.find(
5657
v => v.type === ChartDataSectionType.GROUP,
5758
);
@@ -64,10 +65,10 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
6465
} else {
6566
rows = groupSection?.rows?.filter(v => v.uid === allFields[0].uid);
6667
}
67-
return getInterimDateAggregateRows(rows);
68-
}, [currentFields, drillOption, chartConfig?.datas]);
68+
return getRuntimeDateLevelFields(rows);
69+
}, [drillOption, chartConfig?.datas]);
6970

70-
const handleChangeDataAggregate = useCallback(
71+
const handleDateLevelChange = useCallback(
7172
(config: ChartDataSectionField) => {
7273
const groupData = chartConfig?.datas?.find(
7374
v => v.type === ChartDataSectionType.GROUP,
@@ -77,25 +78,25 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
7778
const _groupData = updateBy(groupData, draft => {
7879
if (draft.rows) {
7980
const index = draft.rows.findIndex(v => v.uid === config.uid);
80-
const interimDateAggregatedValue =
81-
draft.rows[index][interimDateAggregatedKey];
82-
const deleteColName = interimDateAggregatedValue
83-
? interimDateAggregatedValue.colName
81+
const runtimeDateLevel =
82+
draft.rows[index][RUNTIME_DATE_LEVEL_KEY];
83+
const replacedColName = runtimeDateLevel
84+
? runtimeDateLevel.colName
8485
: draft.rows[index].colName;
8586

86-
draft.rows[index][interimDateAggregatedKey] = config;
87-
draft.deleteColName = deleteColName;
87+
draft.rows[index][RUNTIME_DATE_LEVEL_KEY] = config;
88+
draft.replacedColName = replacedColName;
8889
}
8990
});
9091

91-
onChartDrillDataAggregationChange?.('data', {
92+
onDateLevelChange?.('data', {
9293
needRefresh: true,
9394
ancestors: [0],
9495
value: _groupData,
9596
});
9697
}
9798
},
98-
[chartConfig?.datas, onChartDrillDataAggregationChange],
99+
[chartConfig?.datas, onDateLevelChange],
99100
);
100101

101102
const selectDrillStatusMenu = useMemo(() => {
@@ -114,6 +115,7 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
114115
</Menu.Item>
115116
);
116117
}, [drillOption?.isSelectedDrill, t]);
118+
117119
const contextMenu = useMemo(() => {
118120
return (
119121
<StyledChartDrillMenu
@@ -151,16 +153,16 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
151153
)}
152154
{drillOption?.mode !== DrillMode.Expand && selectDrillStatusMenu}
153155

154-
{currentDrillField?.map((v, i) => {
156+
{runtimeDateLevelFields?.map((v, i) => {
155157
if (
156-
v.category === ChartDataViewFieldCategory.DateAggregationField
158+
v.category === ChartDataViewFieldCategory.DateLevelComputedField
157159
) {
158160
return (
159161
<Menu.SubMenu key={i} title={v.colName}>
160-
<DateMeunItem
161-
sourceSupportDateField={sourceSupportDateField}
162-
config={v[interimDateAggregatedKey] || v}
163-
onChange={config => handleChangeDataAggregate(config)}
162+
<DateLevelMenuItems
163+
availableSourceFunctions={availableSourceFunctions}
164+
config={v[RUNTIME_DATE_LEVEL_KEY] || v}
165+
onChange={config => handleDateLevelChange(config)}
164166
/>
165167
</Menu.SubMenu>
166168
);
@@ -174,10 +176,10 @@ const ChartDrillContextMenu: FC<{ chartConfig?: ChartConfig }> = memo(
174176
t,
175177
drillOption,
176178
selectDrillStatusMenu,
179+
runtimeDateLevelFields,
177180
onDrillOptionChange,
178-
currentDrillField,
179-
handleChangeDataAggregate,
180-
sourceSupportDateField,
181+
handleDateLevelChange,
182+
availableSourceFunctions,
181183
]);
182184

183185
return (

frontend/src/app/components/ChartEditor.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ import {
3737
chartConfigSelector,
3838
currentDataViewSelector,
3939
datasetsSelector,
40+
selectAvailableSourceFunctions,
4041
shadowChartConfigSelector,
41-
sourceSupportDateFieldSelector,
4242
} from 'app/pages/ChartWorkbenchPage/slice/selectors';
4343
import {
44-
fetchsourceSupportDateField,
44+
fetchAvailableSourceFunctions,
4545
initWorkbenchAction,
4646
refreshDatasetAction,
4747
updateChartAction,
@@ -58,8 +58,8 @@ import { IChart } from 'app/types/Chart';
5858
import { IChartDrillOption } from 'app/types/ChartDrillOption';
5959
import { ChartDTO } from 'app/types/ChartDTO';
6060
import {
61-
getInterimDateAggregateRows,
62-
handledateAggregaeToComputedFields,
61+
getRuntimeComputedFields,
62+
getRuntimeDateLevelFields,
6363
} from 'app/utils/chartHelper';
6464
import { makeDownloadDataTask } from 'app/utils/fetch';
6565
import {
@@ -132,7 +132,7 @@ export const ChartEditor: FC<ChartEditorProps> = ({
132132
const shadowChartConfig = useSelector(shadowChartConfigSelector);
133133
const backendChart = useSelector(backendChartSelector);
134134
const aggregation = useSelector(aggregationSelector);
135-
const sourceSupportDateField = useSelector(sourceSupportDateFieldSelector);
135+
const availableSourceFunctions = useSelector(selectAvailableSourceFunctions);
136136
const [chart, setChart] = useState<IChart>();
137137
const drillOptionRef = useRef<IChartDrillOption>();
138138

@@ -220,7 +220,7 @@ export const ChartEditor: FC<ChartEditorProps> = ({
220220

221221
useEffect(() => {
222222
if (dataview?.sourceId) {
223-
dispatch(fetchsourceSupportDateField({ sourceId: dataview.sourceId }));
223+
dispatch(fetchAvailableSourceFunctions({ sourceId: dataview.sourceId }));
224224
}
225225
}, [dataview?.sourceId, dispatch]);
226226

@@ -340,20 +340,20 @@ export const ChartEditor: FC<ChartEditorProps> = ({
340340
return true;
341341
}
342342
if (payload.value.type !== ChartDataSectionType.FILTER) {
343-
const dateAggregationField = payload.value.rows.filter(
344-
v => v.category === ChartDataViewFieldCategory.DateAggregationField,
343+
const dateLevelComputedFields = payload.value.rows.filter(
344+
v => v.category === ChartDataViewFieldCategory.DateLevelComputedField,
345345
);
346-
const deleteColName = payload.value.deleteColName;
347-
const computedFields = handledateAggregaeToComputedFields(
348-
dateAggregationField,
349-
deleteColName,
346+
const replacedColName = payload.value.replacedColName;
347+
const computedFields = getRuntimeComputedFields(
348+
dateLevelComputedFields,
349+
replacedColName,
350350
CloneValueDeep(dataview?.computedFields),
351351
chartConfig,
352352
);
353353

354-
if (deleteColName) {
354+
if (replacedColName) {
355355
payload = updateBy(payload, draft => {
356-
delete draft.value.deleteColName;
356+
delete draft.value.replacedColName;
357357
});
358358
}
359359

@@ -588,15 +588,15 @@ export const ChartEditor: FC<ChartEditorProps> = ({
588588
dispatch(refreshDatasetAction({ drillOption: option }));
589589
};
590590

591-
const handleDrillDataAggregationChange = (type, payload) => {
592-
const rows = getInterimDateAggregateRows(payload.value?.rows);
593-
const dateAggregationField = rows.filter(
594-
v => v.category === ChartDataViewFieldCategory.DateAggregationField,
591+
const handleDateLevelChange = (type, payload) => {
592+
const rows = getRuntimeDateLevelFields(payload.value?.rows);
593+
const dateLevelComputedFields = rows.filter(
594+
v => v.category === ChartDataViewFieldCategory.DateLevelComputedField,
595595
);
596-
const deleteColName = payload.value.deleteColName;
597-
const computedFields = handledateAggregaeToComputedFields(
598-
dateAggregationField,
599-
deleteColName,
596+
const replacedColName = payload.value.replacedColName;
597+
const computedFields = getRuntimeComputedFields(
598+
dateLevelComputedFields,
599+
replacedColName,
600600
dataview?.computedFields,
601601
chartConfig,
602602
);
@@ -647,14 +647,14 @@ export const ChartEditor: FC<ChartEditorProps> = ({
647647
defaultViewId={defaultViewId}
648648
expensiveQuery={expensiveQuery}
649649
allowQuery={allowQuery}
650-
sourceSupportDateField={sourceSupportDateField}
650+
availableSourceFunctions={availableSourceFunctions}
651651
onChartChange={handleChartChange}
652652
onChartConfigChange={handleChartConfigChange}
653653
onChartDrillOptionChange={handleDrillOptionChange}
654654
onDataViewChange={handleDataViewChanged}
655655
onRefreshDataset={handleRefreshDataset}
656656
onCreateDownloadDataTask={handleCreateDownloadDataTask}
657-
onChartDrillDataAggregationChange={handleDrillDataAggregationChange}
657+
onDateLevelChange={handleDateLevelChange}
658658
/>
659659
<SaveForm
660660
width={400}

frontend/src/app/components/ChartGraph/BasicBarChart/BasicBarChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import {
3737
getExtraSeriesDataFormat,
3838
getExtraSeriesRowData,
3939
getGridStyle,
40-
getInterimDateAggregateRows,
4140
getReference2,
41+
getRuntimeDateLevelFields,
4242
getSeriesTooltips4Rectangular2,
4343
getStyles,
4444
hadAxisLabelOverflowConfig,
@@ -130,7 +130,7 @@ class BasicBarChart extends Chart {
130130
const dataConfigs: ChartDataConfig[] = config.datas || [];
131131
const settingConfigs: ChartStyleConfig[] = config.settings || [];
132132

133-
const groupConfigs: ChartDataSectionField[] = getInterimDateAggregateRows(
133+
const groupConfigs: ChartDataSectionField[] = getRuntimeDateLevelFields(
134134
getDrillableRows(dataConfigs, drillOption),
135135
);
136136
const aggregateConfigs: ChartDataSectionField[] = dataConfigs

frontend/src/app/constants.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export enum ChartDataViewFieldCategory {
8181
Variable = 'variable',
8282
ComputedField = 'computedField',
8383
AggregateComputedField = 'aggregateComputedField',
84-
DateAggregationField = 'dateAggregationField',
84+
DateLevelComputedField = 'dateLevelComputedField',
8585
}
8686

8787
export enum SortActionType {
@@ -158,7 +158,7 @@ export const ChartDataSectionFieldActionType = {
158158
ColorRange: 'colorRange',
159159
ColorizeSingle: 'colorSingle',
160160
Size: 'size',
161-
DateAggregate: 'dateAggregate',
161+
DateLevel: 'dateLevel',
162162
};
163163

164164
export const FilterRelationType = {
@@ -225,4 +225,4 @@ export enum DownloadFileType {
225225
'Image' = 'IMAGE',
226226
}
227227

228-
export const interimDateAggregatedKey = Symbol('DateAggregated');
228+
export const RUNTIME_DATE_LEVEL_KEY = Symbol('DateLevel');

frontend/src/app/models/ChartDataRequestBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
import { ChartDatasetPageInfo } from 'app/types/ChartDataSet';
3737
import ChartDataView from 'app/types/ChartDataView';
3838
import { IChartDrillOption } from 'app/types/ChartDrillOption';
39-
import { getInterimDateAggregateRows, getValue } from 'app/utils/chartHelper';
39+
import { getRuntimeDateLevelFields, getValue } from 'app/utils/chartHelper';
4040
import { transformToViewConfig } from 'app/utils/internalChartHelper';
4141
import {
4242
formatTime,
@@ -143,7 +143,7 @@ export class ChartDataRequestBuilder {
143143
return acc.concat(cur.rows || []);
144144
}
145145
if (cur.type === ChartDataSectionType.GROUP) {
146-
const rows = getInterimDateAggregateRows(cur.rows);
146+
const rows = getRuntimeDateLevelFields(cur.rows);
147147

148148
if (cur.drillable) {
149149
if (

frontend/src/app/pages/ChartWorkbenchPage/components/ChartOperationPanel/components/ChartDataConfigSection/GroupTypeSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const GroupTypeSection: FC<ChartDataConfigSectionProps> = memo(
4242
[DataViewFieldType.DATE]: [
4343
ChartDataSectionFieldActionType.Alias,
4444
ChartDataSectionFieldActionType.Sortable,
45-
ChartDataSectionFieldActionType.DateAggregate,
45+
ChartDataSectionFieldActionType.DateLevel,
4646
],
4747
},
4848
},

frontend/src/app/pages/ChartWorkbenchPage/components/ChartOperationPanel/components/ChartDataConfigSection/MixedTypeSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const MixedTypeSection: FC<ChartDataConfigSectionProps> = memo(
4444
[DataViewFieldType.DATE]: [
4545
ChartDataSectionFieldActionType.Alias,
4646
ChartDataSectionFieldActionType.Sortable,
47-
ChartDataSectionFieldActionType.DateAggregate,
47+
ChartDataSectionFieldActionType.DateLevel,
4848
],
4949
},
5050
},

frontend/src/app/pages/ChartWorkbenchPage/components/ChartOperationPanel/components/ChartDataViewPanel/ChartDataViewPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const ChartDataViewPanel: FC<{
228228

229229
const sortedMetaFields = useMemo(() => {
230230
const computedFields = dataView?.computedFields?.filter(
231-
v => v.category !== ChartDataViewFieldCategory.DateAggregationField,
231+
v => v.category !== ChartDataViewFieldCategory.DateLevelComputedField,
232232
);
233233
const allFields = (dataView?.meta || []).concat(computedFields || []);
234234
const hierarchyFields = allFields.filter(

0 commit comments

Comments
 (0)