Skip to content

Commit 2b11ecf

Browse files
committed
Date range menu appears blank after change of perspective
https://issues.redhat.com/browse/COST-5586
1 parent eb3c8c4 commit 2b11ecf

File tree

3 files changed

+23
-46
lines changed

3 files changed

+23
-46
lines changed

src/routes/explorer/explorer.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,18 @@ class Explorer extends React.Component<ExplorerProps, ExplorerState> {
375375
}
376376
};
377377

378+
private handleOnDateRangeSelect = (dateRangeType: string) => {
379+
const { query, router } = this.props;
380+
381+
const newQuery = {
382+
...JSON.parse(JSON.stringify(query)),
383+
dateRangeType,
384+
start_date: undefined,
385+
end_date: undefined,
386+
};
387+
router.navigate(getRouteForQuery(newQuery, router.location, true), { replace: true });
388+
};
389+
378390
private handleOnExportModalClose = (isOpen: boolean) => {
379391
this.setState({ isExportModalOpen: isOpen });
380392
};
@@ -569,6 +581,7 @@ class Explorer extends React.Component<ExplorerProps, ExplorerState> {
569581
onCostDistributionSelect={() => handleOnCostDistributionSelect(query, router)}
570582
onCostTypeSelect={() => handleOnCostTypeSelect(query, router)}
571583
onCurrencySelect={() => handleOnCurrencySelect(query, router)}
584+
onDateRangeSelect={this.handleOnDateRangeSelect}
572585
onFilterAdded={filter => handleOnFilterAdded(query, router, filter)}
573586
onFilterRemoved={filter => handleOnFilterRemoved(query, router, filter)}
574587
onGroupBySelect={this.handleOnGroupBySelect}

src/routes/explorer/explorerDatePicker.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ExplorerDatePickerOwnProps extends RouterComponentProps, WrappedCompon
1616
dateRangeType?: DateRangeType;
1717
endDate?: string;
1818
onSelect(startDate: Date, endDate: Date);
19-
startDate?: Date;
19+
startDate?: string;
2020
}
2121

2222
interface ExplorerDatePickerState {
@@ -39,11 +39,6 @@ class ExplorerDatePickerBase extends React.Component<ExplorerDatePickerProps, Ex
3939

4040
public componentDidMount() {
4141
const { dateRangeType, endDate, startDate } = this.props;
42-
// const queryFromRoute = parseQuery<Query>(router.location.search);
43-
//
44-
// // Query dates are undefined until a selection is made
45-
// const end_date = queryFromRoute.end_date;
46-
// const start_date = queryFromRoute.start_date;
4742

4843
if (this.startDateRef?.current) {
4944
this.startDateRef.current.setCalendarOpen(dateRangeType !== DateRangeType.custom);

src/routes/explorer/explorerFilter.tsx

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343

4444
interface ExplorerFilterOwnProps extends RouterComponentProps, WrappedComponentProps {
4545
dateRangeType: DateRangeType;
46-
endDate?: boolean;
46+
endDate?: string;
4747
groupBy: string;
4848
isCurrentMonthData?: boolean;
4949
isDisabled?: boolean;
@@ -53,7 +53,7 @@ interface ExplorerFilterOwnProps extends RouterComponentProps, WrappedComponentP
5353
perspective: PerspectiveType;
5454
pagination?: React.ReactNode;
5555
query?: Query;
56-
startDate?: boolean;
56+
startDate?: string;
5757
}
5858

5959
interface ExplorerFilterStateProps {
@@ -80,7 +80,6 @@ interface ExplorerFilterDispatchProps {
8080

8181
interface ExplorerFilterState {
8282
categoryOptions?: ToolbarChipGroup[];
83-
currentDateRange: DateRangeType;
8483
showDatePicker?: boolean;
8584
}
8685

@@ -92,24 +91,20 @@ const tagType = TagType.tag;
9291

9392
export class ExplorerFilterBase extends React.Component<ExplorerFilterProps, ExplorerFilterState> {
9493
protected defaultState: ExplorerFilterState = {
95-
currentDateRange: this.props.dateRangeType,
9694
showDatePicker: false,
9795
};
9896
public state: ExplorerFilterState = { ...this.defaultState };
9997

10098
public componentDidMount() {
101-
const { dateRangeType } = this.props;
102-
10399
this.updateReport();
104100
this.setState({
105-
currentDateRange: dateRangeType,
106101
categoryOptions: this.getCategoryOptions(),
107-
showDatePicker: dateRangeType === DateRangeType.custom,
102+
showDatePicker: this.props.dateRangeType === DateRangeType.custom,
108103
});
109104
}
110105

111106
public componentDidUpdate(prevProps: ExplorerFilterProps) {
112-
const { dateRangeType, orgReport, perspective, query, tagReport } = this.props;
107+
const { dateRangeType, orgReport, query, tagReport } = this.props;
113108

114109
if (query && !isEqual(query, prevProps.query)) {
115110
this.updateReport();
@@ -120,18 +115,10 @@ export class ExplorerFilterBase extends React.Component<ExplorerFilterProps, Exp
120115
prevProps.dateRangeType !== dateRangeType
121116
) {
122117
this.setState({
123-
currentDateRange: dateRangeType,
124118
categoryOptions: this.getCategoryOptions(),
125119
showDatePicker: dateRangeType === DateRangeType.custom,
126120
});
127121
}
128-
// Preserve filter -- see https://issues.redhat.com/browse/COST-1090
129-
if (prevProps.perspective !== perspective) {
130-
const currentDateRange = undefined;
131-
this.setState({ currentDateRange }, () => {
132-
this.updateDateRange(currentDateRange);
133-
});
134-
}
135122
}
136123

137124
private getCategoryOptions = (): ToolbarChipGroup[] => {
@@ -172,12 +159,11 @@ export class ExplorerFilterBase extends React.Component<ExplorerFilterProps, Exp
172159
};
173160

174161
private getDateRangeComponent = () => {
175-
const { isCurrentMonthData, isDisabled } = this.props;
176-
const { currentDateRange } = this.state;
162+
const { dateRangeType, isCurrentMonthData, isDisabled } = this.props;
177163

178164
return (
179165
<DateRange
180-
dateRangeType={currentDateRange}
166+
dateRangeType={dateRangeType}
181167
isCurrentMonthData={isCurrentMonthData}
182168
isDisabled={isDisabled}
183169
isExplorer
@@ -219,30 +205,13 @@ export class ExplorerFilterBase extends React.Component<ExplorerFilterProps, Exp
219205

220206
const currentDateRange = getDateRangeById(value);
221207
const showDatePicker = value === DateRangeType.custom;
222-
this.setState({ currentDateRange, showDatePicker }, () => {
223-
if (!showDatePicker) {
224-
this.updateDateRange(currentDateRange);
225-
226-
// Clear inline alert
227-
if (onDateRangeSelect) {
228-
onDateRangeSelect(currentDateRange);
229-
}
208+
this.setState({ showDatePicker }, () => {
209+
if (onDateRangeSelect && !showDatePicker) {
210+
onDateRangeSelect(currentDateRange);
230211
}
231212
});
232213
};
233214

234-
private updateDateRange = (value: string) => {
235-
const { query, router } = this.props;
236-
237-
const newQuery = {
238-
...JSON.parse(JSON.stringify(query)),
239-
dateRangeType: value,
240-
start_date: undefined,
241-
end_date: undefined,
242-
};
243-
router.navigate(getRouteForQuery(newQuery, router.location, true), { replace: true });
244-
};
245-
246215
private updateReport = () => {
247216
const {
248217
fetchOrg,

0 commit comments

Comments
 (0)