Skip to content

Commit

Permalink
Merge pull request #2741 from dlabrecq/3283-category-filter
Browse files Browse the repository at this point in the history
Refactor platform costs to use category filter
  • Loading branch information
dlabrecq committed Dec 1, 2022
2 parents e9a6dcf + ab0310c commit 1d5e3f6
Show file tree
Hide file tree
Showing 15 changed files with 1,155 additions and 22,676 deletions.
23,780 changes: 1,122 additions & 22,658 deletions locales/data.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/api/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const unallocatedPlatformCapacity = 'Platform Unallocated Capacity'; // U
export const unallocatedWorkersCapacity = 'Workers Unallocated Capacity'; // Unallocated workers costs

export interface Filters {
category?: string;
limit?: number;
offset?: number;
resolution?: 'daily' | 'monthly';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class BreakdownHeader extends React.Component<BreakdownHeaderProps> {
// Don't want these params when returning to the details page
if (newQuery.filter) {
newQuery.filter.account = undefined;
newQuery.filter.category = undefined;
newQuery[breakdownDescKey] = undefined;
newQuery[orgUnitIdKey] = undefined;
newQuery[breakdownTitleKey] = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const mapStateToProps = createMapStateToProps<HistoricalDataCostChartOwnProps, H
filter_by: {
// Add filters here to apply logical OR/AND
...(queryFromRoute && queryFromRoute.filter_by && queryFromRoute.filter_by),
...(queryFromRoute && queryFromRoute.filter && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
},
exclude: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataTrendChartOwnProps,
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
},
exclude: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ const mapStateToProps = createMapStateToProps<HistoricalDataUsageChartOwnProps,
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
...(groupByOrgValue && useFilter && { [orgUnitIdKey]: groupByOrgValue }),
},
Expand Down
3 changes: 3 additions & 0 deletions src/routes/views/details/components/summary/summaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ const mapStateToProps = createMapStateToProps<SummaryOwnProps, SummaryStateProps
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
...(groupBy && { [groupBy]: groupByValue }), // group bys must appear in filter to show costs by region, account, etc
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ const mapStateToProps = createMapStateToProps<SummaryModalContentOwnProps, Summa
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
...(groupBy && { [groupBy]: groupByValue }), // group bys must appear in filter to show costs by regions, accounts, etc
},
Expand Down
2 changes: 2 additions & 0 deletions src/routes/views/details/components/tag/tagLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const mapStateToProps = createMapStateToProps<TagLinkOwnProps, TagLinkStateProps
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
// Todo: enable when tags API is ready
// ...(queryFromRoute && queryFromRoute.filter && queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && groupBy.indexOf(tagPrefix) === -1 && { [groupBy]: groupByValue }), // Note: Cannot use group_by with tags
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/routes/views/details/components/tag/tagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const mapStateToProps = createMapStateToProps<TagModalOwnProps, TagModalStatePro
...(queryFromRoute &&
queryFromRoute.filter &&
queryFromRoute.filter.account && { [`${logicalAndPrefix}account`]: queryFromRoute.filter.account }),
// Todo: enable when tags API is ready
// ...(queryFromRoute && queryFromRoute.filter && queryFromRoute.filter.category && { category: queryFromRoute.filter.category }),
...(groupBy && groupBy.indexOf(tagPrefix) === -1 && { [groupBy]: groupByValue }), // Note: Cannot use group_by with tags
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ const mapStateToProps = createMapStateToProps<UsageChartOwnProps, UsageChartStat
filter_by: {
// Add filters here to apply logical OR/AND
...(queryFromRoute && queryFromRoute.filter_by && queryFromRoute.filter_by),
...(queryFromRoute && queryFromRoute.filter && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
},
exclude: {
Expand Down
2 changes: 2 additions & 0 deletions src/routes/views/details/ocpBreakdown/ocpBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const mapStateToProps = createMapStateToProps<OcpBreakdownOwnProps, OcpBreakdown
filter_by: {
// Add filters here to apply logical OR/AND
...(queryFromRoute && queryFromRoute.filter_by && queryFromRoute.filter_by),
...(queryFromRoute && queryFromRoute.filter && { category: queryFromRoute.filter.category }),
...(groupBy && { [groupBy]: undefined }), // Omit filters associated with the current group_by -- see https://issues.redhat.com/browse/COST-1131
},
exclude: {
Expand All @@ -81,6 +82,7 @@ const mapStateToProps = createMapStateToProps<OcpBreakdownOwnProps, OcpBreakdown
const reportQueryString = getQuery({
...newQuery,
currency,
category: undefined,
});
const report = reportSelectors.selectReport(state, reportPathsType, reportType, reportQueryString);
const reportError = reportSelectors.selectReportError(state, reportPathsType, reportType, reportQueryString);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/views/details/ocpDetails/detailsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DetailsTableBase extends React.Component<DetailsTableProps> {
item.label === unallocatedPlatformCapacity || item.label === unallocatedWorkersCapacity;
const desc = item.id && item.id !== item.label ? <div style={styles.infoDescription}>{item.id}</div> : null;
const isDisabled = label === `no-${groupBy}` || label === `no-${groupByTagKey}` || isUnallocatedCosts;
const actions = this.getActions(item, isDisabled || isPlatformCosts);
const actions = this.getActions(item, isDisabled);

const name = isDisabled ? (
(label as any)
Expand Down Expand Up @@ -231,7 +231,7 @@ class DetailsTableBase extends React.Component<DetailsTableProps> {
],
item,
selected: isAllSelected || (selectedItems && selectedItems.find(val => val.id === item.id) !== undefined),
selectionDisabled: isDisabled || isPlatformCosts,
selectionDisabled: isDisabled,
});
});

Expand Down
23 changes: 8 additions & 15 deletions src/routes/views/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ export const getBreakdownPath = ({
...(description && description !== label && { [breakdownDescKey]: description }),
...(isPlatformCosts && { [breakdownTitleKey]: label }),
group_by: {
[groupBy]: label,
[groupBy]: isPlatformCosts ? '*' : label,
},
...(isPlatformCosts && {
group_by: {
[groupBy]: ['kube-', 'openshift-'],
},
}),
};
if (isPlatformCosts) {
if (!newQuery.filter) {
newQuery.filter = {};
}
newQuery.filter.category = platformCategory;
}
return `${basePath}?${getQueryRoute(newQuery)}`;
};

Expand Down Expand Up @@ -77,13 +78,5 @@ export const getOrgBreakdownPath = ({
};

export const isPlatformCosts = (queryFromRoute: Query) => {
let result = false;

// Note that "kube-" and "openshift-" are provided only when users select the 'platform' project.
// The category below is mainly used to restore state for the previous page
if (Array.isArray(queryFromRoute.group_by.project)) {
result =
queryFromRoute.group_by.project.includes('kube-') && queryFromRoute.group_by.project.includes('openshift-');
}
return result && queryFromRoute.category === platformCategory;
return queryFromRoute.filter.category === platformCategory;
};
2 changes: 1 addition & 1 deletion src/utils/computedReport/getComputedReportItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function getComputedReportItems<R extends Report, T extends ReportItem>({
);
}

// For multiple group_by's (platform costs; 'kube-' and 'openshift-'), all clusters are listed in the breakdown page
// For filter[categpry]=platform, all clusters are listed in the breakdown page
function getClusters(val, item?: any) {
const clusters = val.clusters ? val.clusters : [];
if (item && item.clusters) {
Expand Down

0 comments on commit 1d5e3f6

Please sign in to comment.