Skip to content

Commit

Permalink
Merge pull request #4177 from dlabrecq/COST-5830_2
Browse files Browse the repository at this point in the history
Reset details page date range dropdown
  • Loading branch information
dlabrecq authored Jan 20, 2025
2 parents 6ef1723 + c3b0e9b commit 861d799
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 27 deletions.
19 changes: 16 additions & 3 deletions src/routes/details/awsDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GroupBy } from 'routes/components/groupBy';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedAwsReportItemsParams } from 'routes/utils/computedReport/getComputedAwsReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedAwsReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -83,11 +83,24 @@ const tagPathsType = TagPathsType.aws;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps, any> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnCostTypeSelect = (value: string) => {
const { onCostTypeSelect } = this.props;

Expand Down
19 changes: 16 additions & 3 deletions src/routes/details/azureDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GroupBy } from 'routes/components/groupBy';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedAzureReportItemsParams } from 'routes/utils/computedReport/getComputedAzureReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedAzureReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -76,11 +76,24 @@ const tagPathsType = TagPathsType.azure;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps, any> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
19 changes: 16 additions & 3 deletions src/routes/details/gcpDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GroupBy } from 'routes/components/groupBy';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedGcpReportItemsParams } from 'routes/utils/computedReport/getComputedGcpReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedGcpReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -77,11 +77,24 @@ const tagPathsType = TagPathsType.gcp;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps, any> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
19 changes: 16 additions & 3 deletions src/routes/details/ibmDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GroupBy } from 'routes/components/groupBy';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedIbmReportItemsParams } from 'routes/utils/computedReport/getComputedIbmReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedIbmReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -77,11 +77,24 @@ const tagPathsType = TagPathsType.ibm;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps, any> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
19 changes: 16 additions & 3 deletions src/routes/details/ociDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GroupBy } from 'routes/components/groupBy';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedOciReportItemsParams } from 'routes/utils/computedReport/getComputedOciReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedOciReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -76,11 +76,24 @@ const tagPathsType = TagPathsType.oci;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps, any> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
14 changes: 5 additions & 9 deletions src/routes/details/ocpDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { EmptyValueState } from 'routes/components/state/emptyValueState';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedOcpReportItemsParams } from 'routes/utils/computedReport/getComputedOcpReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedOcpReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -86,23 +86,19 @@ class DetailsHeaderBase extends React.Component<DetailsHeaderProps, DetailsHeade
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
this.setState({ currentDateRangeType: this.getCurrentDateRangeType() });
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: this.getCurrentDateRangeType() });
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private getCurrentDateRangeType = () => {
const { timeScopeValue } = this.props;

return timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate;
};

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
19 changes: 16 additions & 3 deletions src/routes/details/rhelDetails/detailsHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { EmptyValueState } from 'routes/components/state/emptyValueState';
import { ProviderDetailsModal } from 'routes/details/components/providerStatus';
import type { ComputedRhelReportItemsParams } from 'routes/utils/computedReport/getComputedRhelReportItems';
import { getIdKeyForGroupBy } from 'routes/utils/computedReport/getComputedRhelReportItems';
import { DateRangeType } from 'routes/utils/dateRange';
import { DateRangeType, getCurrentDateRangeType } from 'routes/utils/dateRange';
import { filterProviders } from 'routes/utils/providers';
import type { FetchStatus } from 'store/common';
import { createMapStateToProps } from 'store/common';
Expand Down Expand Up @@ -79,11 +79,24 @@ const tagPathsType = TagPathsType.rhel;

class DetailsHeaderBase extends React.Component<DetailsHeaderProps> {
protected defaultState: DetailsHeaderState = {
currentDateRangeType:
this.props.timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate,
currentDateRangeType: DateRangeType.currentMonthToDate,
};
public state: DetailsHeaderState = { ...this.defaultState };

public componentDidMount() {
const { timeScopeValue } = this.props;

this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}

public componentDidUpdate(prevProps: DetailsHeaderProps) {
const { timeScopeValue } = this.props;

if (prevProps.timeScopeValue !== timeScopeValue) {
this.setState({ currentDateRangeType: getCurrentDateRangeType(timeScopeValue) });
}
}

private handleOnDateRangeSelect = (value: string) => {
const { onDateRangeSelect } = this.props;

Expand Down
4 changes: 4 additions & 0 deletions src/routes/utils/dateRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export const getDateRange = (dateRangeType: DateRangeType, isFormatted = true) =
return dateRange;
};

export const getCurrentDateRangeType = (timeScopeValue: number) => {
return timeScopeValue === -2 ? DateRangeType.previousMonth : DateRangeType.currentMonthToDate;
};

export const getDateRangeTypeDefault = (queryFromRoute: Query, defaultToPreviousMonth: boolean): DateRangeType => {
if (queryFromRoute.dateRangeType) {
return queryFromRoute.dateRangeType;
Expand Down

0 comments on commit 861d799

Please sign in to comment.