Skip to content

Commit 221e215

Browse files
authored
Implement Excludes and Sum Platform Costs api call (#1852)
1 parent ba139b5 commit 221e215

3 files changed

Lines changed: 64 additions & 21 deletions

File tree

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization-common/src/clients/optimizations/OptimizationsClient.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class OptimizationsClient implements OptimizationsApi {
191191
this.appendDynamicParams(queryParams, request, 'group_by[');
192192
this.appendDynamicParams(queryParams, request, 'order_by[');
193193
this.appendDynamicFilterParams(queryParams, request);
194+
this.appendDynamicExcludeParams(queryParams, request);
194195
return queryParams;
195196
}
196197

@@ -208,6 +209,7 @@ export class OptimizationsClient implements OptimizationsApi {
208209
}> = [
209210
{ key: 'currency', paramName: 'currency' },
210211
{ key: 'delta', paramName: 'delta' },
212+
{ key: 'category', paramName: 'category' },
211213
{
212214
key: 'filter[limit]',
213215
paramName: 'filter[limit]',
@@ -288,6 +290,23 @@ export class OptimizationsClient implements OptimizationsApi {
288290
}
289291
}
290292

293+
/**
294+
* Appends dynamic exclude parameters (e.g., exclude[project], exclude[cluster], exclude[tag:key])
295+
*/
296+
private appendDynamicExcludeParams(
297+
queryParams: URLSearchParams,
298+
request: GetCostManagementRequest,
299+
): void {
300+
for (const key of Object.keys(request.query)) {
301+
if (key.startsWith('exclude[') && key.endsWith(']')) {
302+
const value = request.query[key as keyof typeof request.query];
303+
if (value) {
304+
queryParams.append(key, String(value));
305+
}
306+
}
307+
}
308+
}
309+
291310
/**
292311
* Search OpenShift projects
293312
* @param search - Search term to filter projects

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization/src/pages/openshift/OpenShiftPage.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,28 @@ export function OpenShiftPage() {
125125
'filter[time_scope_value]': timeScopeValue,
126126
};
127127

128+
// Add category parameter when showPlatformSum is enabled
129+
if (showPlatformSum) {
130+
queryParams.category = 'Platform';
131+
}
132+
128133
queryParams[groupByParam] = '*';
129134

130-
// Handle tag filtering differently
135+
// Handle filtering based on operation (includes/excludes)
131136
if (filterBy === 'tag' && selectedTagKey && selectedTagValue) {
132-
queryParams[`filter[tag:${selectedTagKey}]`] = selectedTagValue;
137+
// Tag filtering uses filter[tag:key] or exclude[tag:key]
138+
if (filterOperation === 'excludes') {
139+
queryParams[`exclude[tag:${selectedTagKey}]`] = selectedTagValue;
140+
} else {
141+
queryParams[`filter[tag:${selectedTagKey}]`] = selectedTagValue;
142+
}
133143
} else if (filterValue) {
134-
queryParams[`filter[${filterBy}]`] = filterValue;
144+
// Regular filtering uses filter[field] or exclude[field]
145+
if (filterOperation === 'excludes') {
146+
queryParams[`exclude[${filterBy}]`] = filterValue;
147+
} else {
148+
queryParams[`filter[${filterBy}]`] = filterValue;
149+
}
135150
}
136151

137152
if (sortField) {
@@ -164,13 +179,14 @@ export function OpenShiftPage() {
164179
groupBy,
165180
filterBy,
166181
filterValue,
182+
filterOperation,
183+
showPlatformSum,
167184
api,
168185
currentPage,
169186
pageSize,
170187
sortField,
171188
sortDirection,
172189
selectedTag,
173-
filterBy,
174190
selectedTagKey,
175191
selectedTagValue,
176192
]);
@@ -532,6 +548,10 @@ export function OpenShiftPage() {
532548
if (value !== 'tag') {
533549
setSelectedTag('');
534550
}
551+
// Reset showPlatformSum when groupBy changes away from 'project'
552+
if (value !== 'project') {
553+
setShowPlatformSum(false);
554+
}
535555
}}
536556
selectedTag={selectedTag}
537557
onSelectedTagChange={value => {
@@ -592,6 +612,7 @@ export function OpenShiftPage() {
592612
showPlatformSum={showPlatformSum}
593613
setShowPlatformSum={setShowPlatformSum}
594614
projectsCount={displayData?.projects?.length || 0}
615+
groupBy={groupBy}
595616
/>
596617
),
597618
}}

workspaces/redhat-resource-optimization/plugins/redhat-resource-optimization/src/pages/openshift/components/TableToolbar.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ type TableToolbarProps = {
3535
showPlatformSum: boolean;
3636
setShowPlatformSum: (showPlatformSum: boolean) => void;
3737
projectsCount: number;
38+
groupBy: string;
3839
};
3940

4041
/** @public */
4142
export function TableToolbar(props: TableToolbarProps) {
42-
const { showPlatformSum, setShowPlatformSum, projectsCount } = props;
43+
const { showPlatformSum, setShowPlatformSum, projectsCount, groupBy } = props;
4344
const classes = useStyles();
4445

4546
return (
@@ -63,22 +64,24 @@ export function TableToolbar(props: TableToolbarProps) {
6364
Projects ({projectsCount})
6465
</Typography>
6566

66-
<div
67-
style={{
68-
display: 'flex',
69-
alignItems: 'center',
70-
gap: '8px',
71-
}}
72-
>
73-
<Switch
74-
checked={showPlatformSum}
75-
onChange={e => setShowPlatformSum(e.target.checked)}
76-
className={classes.switchOff}
77-
/>
78-
<Typography variant="body2" style={{ color: '#6A6E73' }}>
79-
Sum platform costs
80-
</Typography>
81-
</div>
67+
{groupBy === 'project' && (
68+
<div
69+
style={{
70+
display: 'flex',
71+
alignItems: 'center',
72+
gap: '8px',
73+
}}
74+
>
75+
<Switch
76+
checked={showPlatformSum}
77+
onChange={e => setShowPlatformSum(e.target.checked)}
78+
className={classes.switchOff}
79+
/>
80+
<Typography variant="body2" style={{ color: '#6A6E73' }}>
81+
Sum platform costs
82+
</Typography>
83+
</div>
84+
)}
8285

8386
<div
8487
style={{

0 commit comments

Comments
 (0)