Skip to content

Commit 9d2de9a

Browse files
authored
Merge pull request #4178 from dlabrecq/COST-5831
Details page export doesn't always reflect date range selection
2 parents 861d799 + 0f9353f commit 9d2de9a

21 files changed

+47
-132
lines changed

locales/data.json

-49
Original file line numberDiff line numberDiff line change
@@ -7392,55 +7392,6 @@
73927392
"value": "groupBy"
73937393
}
73947394
],
7395-
"exportTimeScope": [
7396-
{
7397-
"options": {
7398-
"current": {
7399-
"value": [
7400-
{
7401-
"type": 0,
7402-
"value": "Current ("
7403-
},
7404-
{
7405-
"type": 1,
7406-
"value": "date"
7407-
},
7408-
{
7409-
"type": 0,
7410-
"value": ")"
7411-
}
7412-
]
7413-
},
7414-
"other": {
7415-
"value": []
7416-
},
7417-
"previous": {
7418-
"value": [
7419-
{
7420-
"type": 0,
7421-
"value": "Previous ("
7422-
},
7423-
{
7424-
"type": 1,
7425-
"value": "date"
7426-
},
7427-
{
7428-
"type": 0,
7429-
"value": ")"
7430-
}
7431-
]
7432-
}
7433-
},
7434-
"type": 5,
7435-
"value": "value"
7436-
}
7437-
],
7438-
"exportTimeScopeTitle": [
7439-
{
7440-
"type": 0,
7441-
"value": "Month"
7442-
}
7443-
],
74447395
"exportTitle": [
74457396
{
74467397
"type": 0,

locales/translations.json

-2
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,6 @@
325325
"exportNameTooLong": "Should not exceed 255 characters",
326326
"exportResolution": "{value, select, daily {Daily} monthly {Monthly} other {}}",
327327
"exportSelected": "{groupBy, select, account {Selected accounts ({count})} aws_category {Selected cost categories ({count})} cluster {Selected clusters ({count})} gcp_project {Selected GCP projects ({count})} instance {Selected instances ({count})} node {Selected nodes ({count})} org_unit_id {Selected organizational units ({count})} payer_tenant_id {Selected accounts ({count})} product_service {Selected services ({count})} project {Selected projects ({count})} region {Selected regions ({count})} resource_location {Selected regions ({count})} service {Selected services ({count})} service_name {Selected services ({count})} subscription_guid {Selected accounts ({count})} tag {Selected tags ({count})} vm_name {Selected virtual machines ({count})}other {}}",
328-
"exportTimeScope": "{value, select, current {Current ({date})} previous {Previous ({date})} other {}}",
329-
"exportTimeScopeTitle": "Month",
330328
"exportTitle": "Export",
331329
"exportsDesc": "Exports are available for download from the time that they are generated up to 7 days later. After 7 days, the export file will be removed.",
332330
"exportsEmptyState": "To get started, close this view and select rows in the table you want to export and click the export button to start the journey.",

src/locales/messages.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1980,16 +1980,6 @@ export default defineMessages({
19801980
description: 'Selected items for export',
19811981
id: 'exportSelected',
19821982
},
1983-
exportTimeScope: {
1984-
defaultMessage: '{value, select, current {Current ({date})} previous {Previous ({date})} other {}}',
1985-
description: 'Export time scope',
1986-
id: 'exportTimeScope',
1987-
},
1988-
exportTimeScopeTitle: {
1989-
defaultMessage: 'Month',
1990-
description: 'Month',
1991-
id: 'exportTimeScopeTitle',
1992-
},
19931983
exportTitle: {
19941984
defaultMessage: 'Export',
19951985
description: 'Export title',

src/routes/components/export/exportModal.tsx

+4-58
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '@patternfly/react-core';
1616
import type { ReportPathsType, ReportType } from 'api/reports/report';
1717
import type { AxiosError } from 'axios';
18-
import { format } from 'date-fns';
1918
import messages from 'locales/messages';
2019
import { orderBy } from 'lodash';
2120
import React from 'react';
@@ -35,7 +34,7 @@ export interface ExportModalOwnProps {
3534
groupBy?: string;
3635
isAllItems?: boolean;
3736
isOpen: boolean;
38-
isTimeScoped?: boolean;
37+
isTimeScoped?: boolean; // Indicates API should use time_scope_value or start and end date parameters
3938
items?: ComputedReportItem[];
4039
onClose(isOpen: boolean);
4140
reportPathsType: ReportPathsType;
@@ -44,7 +43,6 @@ export interface ExportModalOwnProps {
4443
resolution?: 'daily' | 'monthly'; // Default resolution
4544
showAggregateType?: boolean; // Monthly resolution filters are not valid with date range
4645
showFormatType?: boolean; // Format type; CVS / JSON
47-
showTimeScope?: boolean; // timeScope filters are not valid with date range
4846
timeScopeValue?: number;
4947
}
5048

@@ -79,31 +77,14 @@ const resolutionOptions: {
7977
{ label: messages.exportResolution, value: 'monthly' },
8078
];
8179

82-
const timeScopeOptions: {
83-
label: MessageDescriptor;
84-
value: string;
85-
}[] = [
86-
{ label: messages.exportTimeScope, value: 'current' },
87-
{ label: messages.exportTimeScope, value: 'previous' },
88-
];
89-
9080
export class ExportModalBase extends React.Component<ExportModalProps, ExportModalState> {
9181
protected defaultState: ExportModalState = {
9282
error: undefined,
9383
formatType: 'csv',
9484
resolution: this.props.resolution || 'monthly',
95-
timeScope: this.props.timeScopeValue === -2 ? 'previous' : 'current',
9685
};
9786
public state: ExportModalState = { ...this.defaultState };
9887

99-
public componentDidUpdate(prevProps: ExportModalProps) {
100-
const { timeScopeValue } = this.props;
101-
102-
if (timeScopeValue !== prevProps.timeScopeValue) {
103-
this.setState({ timeScope: timeScopeValue === -2 ? 'previous' : 'current' });
104-
}
105-
}
106-
10788
// Reset default state upon close -- see https://issues.redhat.com/browse/COST-1134
10889
private handleOnClose = () => {
10990
this.setState({ ...this.defaultState }, () => {
@@ -115,10 +96,6 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
11596
this.setState({ error });
11697
};
11798

118-
private handleOnMonthChange = event => {
119-
this.setState({ timeScope: event.currentTarget.value });
120-
};
121-
12299
private handleOnNameChange = event => {
123100
this.setState({ name: event.currentTarget.value });
124101
};
@@ -148,7 +125,6 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
148125
groupBy,
149126
intl,
150127
isAllItems,
151-
isDetailsDateRangeToggleEnabled,
152128
isExportsToggleEnabled,
153129
isTimeScoped,
154130
items,
@@ -157,9 +133,9 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
157133
reportType,
158134
showAggregateType = true,
159135
showFormatType = true,
160-
showTimeScope = isDetailsDateRangeToggleEnabled ? false : true,
136+
timeScopeValue,
161137
} = this.props;
162-
const { error, formatType, name, resolution, timeScope } = this.state;
138+
const { error, formatType, name, resolution } = this.state;
163139

164140
let sortedItems = [...items];
165141
if (this.props.isOpen) {
@@ -179,11 +155,6 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
179155
selectedLabel = intl.formatMessage(messages.exportSelected, { groupBy: 'tag', count });
180156
}
181157

182-
const thisMonth = new Date();
183-
const lastMonth = new Date().setMonth(thisMonth.getMonth() - 1);
184-
const currentMonth = format(thisMonth, 'MMMM yyyy');
185-
const previousMonth = format(lastMonth - 1, 'MMMM yyyy');
186-
187158
const defaultName =
188159
name !== undefined
189160
? name
@@ -211,14 +182,14 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
211182
isTimeScoped={isTimeScoped}
212183
items={items}
213184
key="confirm"
214-
timeScope={timeScope}
215185
onClose={this.handleOnClose}
216186
onError={this.handleOnError}
217187
name={defaultName}
218188
reportPathsType={reportPathsType}
219189
reportQueryString={reportQueryString}
220190
reportType={reportType}
221191
resolution={resolution}
192+
timeScopeValue={timeScopeValue}
222193
/>,
223194
<Button ouiaId="cancel-btn" key="cancel" onClick={this.handleOnClose} variant={ButtonVariant.link}>
224195
{intl.formatMessage(messages.cancel)}
@@ -276,31 +247,6 @@ export class ExportModalBase extends React.Component<ExportModalProps, ExportMod
276247
</React.Fragment>
277248
</FormGroup>
278249
)}
279-
{showTimeScope && (
280-
<FormGroup fieldId="timeScope" label={intl.formatMessage(messages.exportTimeScopeTitle)} isRequired>
281-
<React.Fragment>
282-
{timeScopeOptions.map((option, index) => (
283-
<Radio
284-
key={index}
285-
id={`timeScope-${index}`}
286-
isValid={option.value !== undefined}
287-
label={intl.formatMessage(option.label, {
288-
date: option.value === 'previous' ? previousMonth : currentMonth,
289-
value: option.value,
290-
})}
291-
value={option.value}
292-
isChecked={timeScope === option.value}
293-
name="timeScope"
294-
onChange={this.handleOnMonthChange}
295-
aria-label={intl.formatMessage(option.label, {
296-
date: option.value === 'previous' ? previousMonth : currentMonth,
297-
value: option.value,
298-
})}
299-
/>
300-
))}
301-
</React.Fragment>
302-
</FormGroup>
303-
)}
304250
{showFormatType && isExportsToggleEnabled && (
305251
<GridItem span={12}>
306252
<FormGroup fieldId="formatType" label={intl.formatMessage(messages.exportFormatTypeTitle)} isRequired>

src/routes/components/export/exportSubmit.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ExportSubmitOwnProps extends RouterComponentProps, WrappedCompo
3737
reportQueryString: string;
3838
reportType: ReportType;
3939
resolution: string;
40-
timeScope: 'current' | 'previous';
40+
timeScopeValue?: number;
4141
}
4242

4343
interface ExportSubmitDispatchProps {
@@ -159,10 +159,10 @@ const mapStateToProps = createMapStateToProps<ExportSubmitOwnProps, ExportSubmit
159159
reportType,
160160
resolution,
161161
router,
162-
timeScope,
162+
timeScopeValue,
163163
} = props;
164164

165-
const isPrevious = timeScope === 'previous';
165+
const isPrevious = timeScopeValue === -2;
166166
const queryFromRoute = parseQuery<Query>(router.location.search);
167167
const getDateRange = () => {
168168
if (queryFromRoute.dateRangeType) {

src/routes/details/awsDetails/awsDetails.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class AwsDetails extends React.Component<AwsDetailsProps, AwsDetailsState> {
178178
: groupById
179179
}
180180
isOpen={isExportModalOpen}
181+
isTimeScoped
181182
items={items}
182183
onClose={this.handleOnExportModalClose}
183184
reportPathsType={reportPathsType}

src/routes/details/awsDetails/detailsTable.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,18 @@ class DetailsTableBase extends React.Component<DetailsTableProps, DetailsTableSt
227227
};
228228

229229
private getActions = (item: ComputedReportItem, isDisabled: boolean = false) => {
230-
const { groupBy, reportQueryString } = this.props;
230+
const { groupBy, reportQueryString, timeScopeValue } = this.props;
231231

232232
return (
233233
<Actions
234234
groupBy={groupBy}
235235
isDisabled={isDisabled}
236+
isTimeScoped
236237
item={item}
237238
reportPathsType={reportPathsType}
238239
reportQueryString={reportQueryString}
239240
reportType={ReportType.cost}
241+
timeScopeValue={timeScopeValue}
240242
/>
241243
);
242244
};

src/routes/details/azureDetails/azureDetails.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class AzureDetails extends React.Component<AzureDetailsProps, AzureDetailsState>
165165
isAllItems={(isAllSelected || selectedItems.length === itemsTotal) && computedItems.length > 0}
166166
groupBy={groupByTagKey ? `${tagPrefix}${groupByTagKey}` : groupById}
167167
isOpen={isExportModalOpen}
168+
isTimeScoped
168169
items={items}
169170
onClose={this.handleOnExportModalClose}
170171
reportPathsType={reportPathsType}

src/routes/details/azureDetails/detailsTable.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,18 @@ class DetailsTableBase extends React.Component<DetailsTableProps, DetailsTableSt
199199
};
200200

201201
private getActions = (item: ComputedReportItem, isDisabled) => {
202-
const { groupBy, reportQueryString } = this.props;
202+
const { groupBy, reportQueryString, timeScopeValue } = this.props;
203203

204204
return (
205205
<Actions
206206
groupBy={groupBy}
207207
isDisabled={isDisabled}
208+
isTimeScoped
208209
item={item}
209210
reportPathsType={reportPathsType}
210211
reportQueryString={reportQueryString}
211212
reportType={ReportType.cost}
213+
timeScopeValue={timeScopeValue}
212214
/>
213215
);
214216
};

src/routes/details/components/actions/actions.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface DetailsActionsOwnProps extends WrappedComponentProps, RouterComponentP
2424
reportType: ReportType;
2525
showAggregateType?: boolean;
2626
showPriceListOption?: boolean;
27+
timeScopeValue?: number;
2728
}
2829

2930
interface DetailsActionsStateProps {
@@ -53,8 +54,16 @@ class DetailsActionsBase extends React.Component<DetailsActionsProps, DetailsAct
5354
}
5455

5556
private getExportModal = () => {
56-
const { groupBy, isTimeScoped, item, reportPathsType, reportQueryString, reportType, showAggregateType } =
57-
this.props;
57+
const {
58+
groupBy,
59+
isTimeScoped,
60+
item,
61+
timeScopeValue,
62+
reportPathsType,
63+
reportQueryString,
64+
reportType,
65+
showAggregateType,
66+
} = this.props;
5867
const { isExportModalOpen } = this.state;
5968

6069
return (
@@ -69,6 +78,7 @@ class DetailsActionsBase extends React.Component<DetailsActionsProps, DetailsAct
6978
reportQueryString={reportQueryString}
7079
reportType={reportType}
7180
showAggregateType={showAggregateType}
81+
timeScopeValue={timeScopeValue}
7282
/>
7383
);
7484
};

src/routes/details/gcpDetails/detailsTable.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,18 @@ class DetailsTableBase extends React.Component<DetailsTableProps, DetailsTableSt
197197
};
198198

199199
private getActions = (item: ComputedReportItem, isDisabled) => {
200-
const { groupBy, reportQueryString } = this.props;
200+
const { groupBy, reportQueryString, timeScopeValue } = this.props;
201201

202202
return (
203203
<Actions
204204
groupBy={groupBy}
205205
isDisabled={isDisabled}
206+
isTimeScoped
206207
item={item}
207208
reportPathsType={reportPathsType}
208209
reportQueryString={reportQueryString}
209210
reportType={ReportType.cost}
211+
timeScopeValue={timeScopeValue}
210212
/>
211213
);
212214
};

src/routes/details/gcpDetails/gcpDetails.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class GcpDetails extends React.Component<GcpDetailsProps, GcpDetailsState> {
165165
isAllItems={(isAllSelected || selectedItems.length === itemsTotal) && computedItems.length > 0}
166166
groupBy={groupByTagKey ? `${tagPrefix}${groupByTagKey}` : groupById}
167167
isOpen={isExportModalOpen}
168+
isTimeScoped
168169
items={items}
169170
onClose={this.handleOnExportModalClose}
170171
reportPathsType={reportPathsType}

src/routes/details/ibmDetails/detailsTable.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,18 @@ class DetailsTableBase extends React.Component<DetailsTableProps, DetailsTableSt
197197
};
198198

199199
private getActions = (item: ComputedReportItem, isDisabled) => {
200-
const { groupBy, reportQueryString } = this.props;
200+
const { groupBy, reportQueryString, timeScopeValue } = this.props;
201201

202202
return (
203203
<Actions
204204
groupBy={groupBy}
205205
isDisabled={isDisabled}
206+
isTimeScoped
206207
item={item}
207208
reportPathsType={reportPathsType}
208209
reportQueryString={reportQueryString}
209210
reportType={ReportType.cost}
211+
timeScopeValue={timeScopeValue}
210212
/>
211213
);
212214
};

src/routes/details/ibmDetails/ibmDetails.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class IbmDetails extends React.Component<IbmDetailsProps, IbmDetailsState> {
166166
isAllItems={(isAllSelected || selectedItems.length === itemsTotal) && computedItems.length > 0}
167167
groupBy={groupByTagKey ? `${tagPrefix}${groupByTagKey}` : groupById}
168168
isOpen={isExportModalOpen}
169+
isTimeScoped
169170
items={items}
170171
onClose={this.handleOnExportModalClose}
171172
reportPathsType={reportPathsType}

0 commit comments

Comments
 (0)