Skip to content

Commit 5ce3e5a

Browse files
authored
Implement Columns Management (#1855)
1 parent e6286b6 commit 5ce3e5a

2 files changed

Lines changed: 330 additions & 67 deletions

File tree

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

Lines changed: 118 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ interface ProjectCost {
5151
monthOverMonthValue: number;
5252
includesOverhead: boolean;
5353
previousPeriodCost: number;
54+
infrastructureCost: number;
55+
infrastructureCostPercentage: number;
56+
supplementaryCost: number;
57+
supplementaryCostPercentage: number;
5458
}
5559

5660
/** @public */
@@ -74,6 +78,10 @@ export function OpenShiftPage() {
7478
const [selectedTag, setSelectedTag] = useState<string>('');
7579
const [selectedTagKey, setSelectedTagKey] = useState<string>('');
7680
const [selectedTagValue, setSelectedTagValue] = useState<string>('');
81+
const [showMonthOverMonthChange, setShowMonthOverMonthChange] =
82+
useState(true);
83+
const [showInfrastructureCost, setShowInfrastructureCost] = useState(false);
84+
const [showSupplementaryCost, setShowSupplementaryCost] = useState(false);
7785

7886
// Fetch tags on first load
7987
useAsync(async () => {
@@ -236,6 +244,12 @@ export function OpenShiftPage() {
236244
platform_distributed?: { value?: number };
237245
storage_unattributed_distributed?: { value?: number };
238246
};
247+
infrastructure?: {
248+
total?: { value?: number };
249+
};
250+
supplementary?: {
251+
total?: { value?: number };
252+
};
239253
delta_percent?: number;
240254
delta_value?: number;
241255
}) || {};
@@ -253,6 +267,9 @@ export function OpenShiftPage() {
253267
const deltaPercent = value?.delta_percent || 0;
254268
const deltaValue = value?.delta_value || 0;
255269

270+
const infrastructureValue = value?.infrastructure?.total?.value || 0;
271+
const supplementaryValue = value?.supplementary?.total?.value || 0;
272+
256273
return {
257274
id: `${index}`,
258275
projectName: itemName,
@@ -266,16 +283,32 @@ export function OpenShiftPage() {
266283
value?.cost?.platform_distributed?.value !== 0 ||
267284
value?.cost?.storage_unattributed_distributed?.value !== 0,
268285
previousPeriodCost: costValue + Math.abs(deltaValue),
286+
infrastructureCost: infrastructureValue,
287+
infrastructureCostPercentage: 0,
288+
supplementaryCost: supplementaryValue,
289+
supplementaryCostPercentage: 0,
269290
};
270291
}) || [];
271292

272-
const totalCost = costData.meta?.total?.cost?.distributed?.value || 0;
293+
const totalCost = costData.meta?.total?.cost?.total?.value || 0;
294+
const totalInfrastructureCost =
295+
costData.meta?.total?.infrastructure?.total?.value || 0;
296+
const totalSupplementaryCost =
297+
costData.meta?.total?.supplementary?.total?.value || 0;
273298

274299
const currencyCode = costData.meta?.currency || currency;
275300

276301
const projectsWithPercentage = projects.map(p => ({
277302
...p,
278303
costPercentage: totalCost > 0 ? (p.cost / totalCost) * 100 : 0,
304+
infrastructureCostPercentage:
305+
totalInfrastructureCost > 0
306+
? (p.infrastructureCost / totalInfrastructureCost) * 100
307+
: 0,
308+
supplementaryCostPercentage:
309+
totalSupplementaryCost > 0
310+
? (p.supplementaryCost / totalSupplementaryCost) * 100
311+
: 0,
279312
}));
280313

281314
let month: string;
@@ -357,8 +390,8 @@ export function OpenShiftPage() {
357390
selectedRows.size > 0 &&
358391
selectedRows.size < displayData.projects.length;
359392

360-
const columns = useMemo<TableColumn<ProjectCost>[]>(
361-
() => [
393+
const columns = useMemo<TableColumn<ProjectCost>[]>(() => {
394+
const cols: TableColumn<ProjectCost>[] = [
362395
{
363396
title: (
364397
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
@@ -425,7 +458,10 @@ export function OpenShiftPage() {
425458
</div>
426459
),
427460
},
428-
{
461+
];
462+
463+
if (showMonthOverMonthChange) {
464+
cols.push({
429465
title: 'Month over month change',
430466
field: 'monthOverMonthChange',
431467
sorting: false,
@@ -448,42 +484,88 @@ export function OpenShiftPage() {
448484
</div>
449485
</div>
450486
),
451-
},
452-
{
453-
title: 'Cost',
454-
field: 'cost',
487+
});
488+
}
489+
490+
cols.push({
491+
title: 'Cost',
492+
field: 'cost',
493+
render: data => (
494+
<div>
495+
<div>
496+
{formatCurrency(data.cost, displayData?.currencyCode || '')}
497+
</div>
498+
<div style={{ fontSize: '0.75rem', color: '#666' }}>
499+
{data.costPercentage.toFixed(2)}% of cost
500+
</div>
501+
</div>
502+
),
503+
});
504+
505+
if (showInfrastructureCost) {
506+
cols.push({
507+
title: 'Infrastructure cost',
508+
field: 'infrastructureCost',
455509
render: data => (
456510
<div>
457511
<div>
458-
{formatCurrency(data.cost, displayData?.currencyCode || '')}
512+
{formatCurrency(
513+
data.infrastructureCost,
514+
displayData?.currencyCode || '',
515+
)}
459516
</div>
460517
<div style={{ fontSize: '0.75rem', color: '#666' }}>
461-
{data.costPercentage.toFixed(2)}% of cost
518+
{data.infrastructureCostPercentage.toFixed(2)}% of cost
462519
</div>
463520
</div>
464521
),
465-
},
466-
{
467-
title: 'Actions',
468-
field: 'actions',
469-
sorting: false,
470-
render: () => (
471-
<div style={{ display: 'flex', gap: '8px' }}>
472-
<img src={BlackSvgIcon} alt="CSV" style={{ cursor: 'pointer' }} />
522+
});
523+
}
524+
525+
if (showSupplementaryCost) {
526+
cols.push({
527+
title: 'Supplementary cost',
528+
field: 'supplementaryCost',
529+
render: data => (
530+
<div>
531+
<div>
532+
{formatCurrency(
533+
data.supplementaryCost,
534+
displayData?.currencyCode || '',
535+
)}
536+
</div>
537+
<div style={{ fontSize: '0.75rem', color: '#666' }}>
538+
{data.supplementaryCostPercentage.toFixed(2)}% of cost
539+
</div>
473540
</div>
474541
),
475-
},
476-
],
477-
[
478-
handleRowSelect,
479-
isAllSelected,
480-
isIndeterminate,
481-
selectedRows,
482-
handleSelectAll,
483-
displayData?.currencyCode,
484-
groupBy,
485-
],
486-
);
542+
});
543+
}
544+
545+
cols.push({
546+
title: 'Actions',
547+
field: 'actions',
548+
sorting: false,
549+
render: () => (
550+
<div style={{ display: 'flex', gap: '8px' }}>
551+
<img src={BlackSvgIcon} alt="CSV" style={{ cursor: 'pointer' }} />
552+
</div>
553+
),
554+
});
555+
556+
return cols;
557+
}, [
558+
handleRowSelect,
559+
isAllSelected,
560+
isIndeterminate,
561+
selectedRows,
562+
handleSelectAll,
563+
displayData?.currencyCode,
564+
groupBy,
565+
showMonthOverMonthChange,
566+
showInfrastructureCost,
567+
showSupplementaryCost,
568+
]);
487569

488570
const handleOrderChange = useCallback(
489571
(orderBy: number, orderDirection: 'asc' | 'desc') => {
@@ -613,6 +695,12 @@ export function OpenShiftPage() {
613695
setShowPlatformSum={setShowPlatformSum}
614696
projectsCount={displayData?.projects?.length || 0}
615697
groupBy={groupBy}
698+
showMonthOverMonthChange={showMonthOverMonthChange}
699+
setShowMonthOverMonthChange={setShowMonthOverMonthChange}
700+
showInfrastructureCost={showInfrastructureCost}
701+
setShowInfrastructureCost={setShowInfrastructureCost}
702+
showSupplementaryCost={showSupplementaryCost}
703+
setShowSupplementaryCost={setShowSupplementaryCost}
616704
/>
617705
),
618706
}}

0 commit comments

Comments
 (0)