Skip to content

Commit 2535a29

Browse files
Mohammed AbdiMohammed Abdi
authored andcommitted
update types frontend
Signed-off-by: Mohammed Abdi <[email protected]>
1 parent 1a2648b commit 2535a29

File tree

10 files changed

+47
-38
lines changed

10 files changed

+47
-38
lines changed

frontend/src/pages/MCADashboard/DropDowns/refresh-rate-drop-down.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const RefreshRateDropDown: React.FunctionComponent<RefreshRateDropDownProps> = (
1515
setIsOpen(!isOpen);
1616
};
1717

18-
function convertDurationToMilliseconds(durationString) {
18+
function convertDurationToMilliseconds(durationString: string) {
1919
const parts = durationString.split(' ');
2020
const numericValue = parseInt(parts[0], 10);
2121
let conversionFactor;
@@ -48,7 +48,8 @@ const RefreshRateDropDown: React.FunctionComponent<RefreshRateDropDownProps> = (
4848
const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: string | number | undefined) => {
4949
// eslint-disable-next-line no-console
5050
console.log('selected', itemId);
51-
onSelected(convertDurationToMilliseconds(itemId));
51+
if(itemId === 'string')
52+
onSelected(convertDurationToMilliseconds(itemId));
5253
setSelected(itemId as string);
5354
setIsOpen(false);
5455
};

frontend/src/pages/MCADashboard/Metrics/McadMetricGraph.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { formatUnitStringOnAxis, timeStringToSeconds, filterData } from './metri
2727

2828
const LegendContainer = ({ children }: { children?: React.ReactNode }) => {
2929
// The first child should be a <rect> with a `width` prop giving the legend's content width
30-
const width = children?.[0]?.[0]?.props?.width ?? '100%';
30+
const width = (React.Children.toArray(children)[0] as React.ReactElement)?.props?.width ?? '100%';
3131
return (
3232
<foreignObject height={75} width="100%" y={245}>
3333
<div className="monitoring-dashboards__legend-wrap horizontal-scroll">
@@ -199,21 +199,19 @@ const Graph: React.FC<GraphProps> = ({
199199
<Spinner />
200200
</div>
201201
);
202-
} else {
203-
console.log("metric to legend", metricData, legendData);
204202
}
205203

206204
const [maxVal, setMaxVal] = React.useState<number>(0);
207205

208206
const domain: any = { x: xDomain, y: undefined };
209-
const getMaxVal = (metricData) => {
207+
const getMaxVal = (metricData: MetricData[]) => {
210208
let maxDataVal;
211209
let maxVal = 0;
212210
for (const data of metricData) {
213211
maxDataVal = _.maxBy(data.values, (item) => {
214212
return parseInt(item[1]);
215-
})[1];
216-
maxVal = Math.max(maxVal, maxDataVal);
213+
})?.[1];
214+
maxVal = Math.max(maxVal, Number(maxDataVal));
217215
}
218216
return maxVal;
219217
};

frontend/src/pages/MCADashboard/Metrics/MetricGraph.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { formatUnitStringOnAxis, timeStringToSeconds, filterData } from './metri
2727

2828
const LegendContainer = ({ children }: { children?: React.ReactNode }) => {
2929
// The first child should be a <rect> with a `width` prop giving the legend's content width
30-
const width = children?.[0]?.[0]?.props?.width ?? '100%';
30+
const width = (React.Children.toArray(children)[0] as React.ReactElement)?.props?.width ?? '100%';
3131
return (
3232
<foreignObject height={75} width="100%" y={245}>
3333
<div className="monitoring-dashboards__legend-wrap horizontal-scroll">
@@ -188,16 +188,15 @@ const Graph: React.FC<GraphProps> = ({
188188
}
189189

190190
const [maxVal, setMaxVal] = React.useState<number>(0);
191-
192191
const domain: any = { x: xDomain, y: undefined };
193-
const getMaxVal = (metricData) => {
192+
const getMaxVal = (metricData: MetricData[]) => {
194193
let maxDataVal;
195194
let maxVal = 0;
196195
for (const data of metricData) {
197196
maxDataVal = _.maxBy(data.values, (item) => {
198197
return parseInt(item[1]);
199-
})[1];
200-
maxVal = Math.max(maxVal, maxDataVal);
198+
})?.[1];
199+
maxVal = Math.max(maxVal, Number(maxDataVal));
201200
}
202201
return maxVal;
203202
};

frontend/src/pages/MCADashboard/Metrics/metrics-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const timeStringToSeconds = (timeString: string) => {
4545
}
4646
};
4747

48-
export const getNamespacesFromAppwrappers = (data): string[] => {
48+
export const getNamespacesFromAppwrappers = (data: { appwrappers: any; }): string[] => {
4949
const namespaces = new Set<string>();
5050
const appwrapperData = data.appwrappers;
5151
for (const key in appwrapperData) {
@@ -101,7 +101,7 @@ export const formatUnitStringOnAxis = (value: number, maxVal: number, unit?: Uni
101101
}
102102
};
103103

104-
export const filterData = (data, validNamespaces) => {
104+
export const filterData = (data: any[], validNamespaces: Set<string> | undefined) => {
105105
if (data && validNamespaces) {
106106
const filteredData = data.filter((dataPoint) => {
107107
return validNamespaces.has(dataPoint.metric.namespace);

frontend/src/pages/MCADashboard/Tables/SearchFieldAppwrappers.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const SearchFieldAppwrappers: React.FC<SearchFieldProps> = ({
3333
selections={searchType}
3434
onSelect={(e, key) => {
3535
if (typeof key === 'string') {
36-
onSearchTypeChange(SearchType[key]);
36+
onSearchTypeChange(SearchType[key as keyof typeof SearchType]);
3737
setTypeOpen(false);
3838
}
3939
}}
4040
>
4141
{types.map((key) => (
4242
<SelectOption key={key} value={key}>
43-
{SearchType[key]}
43+
{SearchType[key as keyof typeof SearchType]}
4444
</SelectOption>
4545
))}
4646
</Select>

frontend/src/pages/MCADashboard/Tables/SearchFieldNamespaces.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ const SearchFieldNamespaces: React.FC<SearchFieldProps> = ({
3131
selections={searchType}
3232
onSelect={(e, key) => {
3333
if (typeof key === 'string') {
34-
onSearchTypeChange(SearchType[key]);
34+
onSearchTypeChange(SearchType[key as keyof typeof SearchType]);
3535
setTypeOpen(false);
3636
}
3737
}}
3838
>
3939
{types.map((key) => (
4040
<SelectOption key={key} value={key}>
41-
{SearchType[key]}
41+
{SearchType[key as keyof typeof SearchType]}
4242
</SelectOption>
4343
))}
4444
</Select>

frontend/src/pages/MCADashboard/Tables/quota-table.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface QuotaData {
2929
memorylimits?: number;
3030
gpu?: number;
3131
gpumemory?: number;
32+
[key: string]: number | string | undefined; // Index signature
3233
}
3334

3435
interface NameSpaceCount {
@@ -46,7 +47,7 @@ enum SearchTypeQuotaTable {
4647
}
4748

4849
type kv_pair = {
49-
key?: number;
50+
[key: string]: number | undefined;
5051
};
5152

5253
type TableData = {
@@ -60,6 +61,13 @@ type TableData = {
6061
gpumemory?: kv_pair;
6162
};
6263

64+
interface DataPoint {
65+
metric: {
66+
namespace: string; // Adjust this type accordingly
67+
};
68+
value: [number, string]; // Adjust this type accordingly
69+
}
70+
6371
export const QuotaTable: React.FunctionComponent<QuotaViewProps> = ({
6472
data: Data,
6573
validNamespaces,
@@ -81,17 +89,19 @@ export const QuotaTable: React.FunctionComponent<QuotaViewProps> = ({
8189
setTableData(initialTableData);
8290
}, []);
8391

84-
const sortFunction = (a: QuotaData, b: QuotaData, keyfield: string) => {
85-
if (a[keyfield] === undefined && b[keyfield] === undefined) {
92+
const sortFunction = (a: QuotaData, b: QuotaData, keyfield: keyof QuotaData) => {
93+
const aValue = a[keyfield] as number | undefined;
94+
const bValue = b[keyfield] as number | undefined;
95+
if (aValue === undefined && bValue === undefined) {
8696
return 0;
8797
}
88-
if (a[keyfield] === undefined) {
98+
if (aValue === undefined) {
8999
return -1;
90100
}
91-
if (b[keyfield] === undefined) {
101+
if (bValue === undefined) {
92102
return 1;
93103
}
94-
return a[keyfield] - b[keyfield];
104+
return aValue - bValue;
95105
};
96106

97107
const columns: SortableData<QuotaData>[] = [
@@ -165,12 +175,8 @@ export const QuotaTable: React.FunctionComponent<QuotaViewProps> = ({
165175
}
166176

167177
React.useEffect(() => {
168-
console.log(tableData);
169-
}, [tableData]);
170-
171-
React.useEffect(() => {
172-
const formatData = (data) => {
173-
const formattedData = {};
178+
const formatData = (data: DataPoint[]) => {
179+
const formattedData: { [key: string]: number } = {};
174180
for (const dataPoint of data) {
175181
formattedData[dataPoint.metric.namespace] =
176182
Math.round(parseFloat(dataPoint.value[1]) * 100) / 100;
@@ -182,8 +188,11 @@ export const QuotaTable: React.FunctionComponent<QuotaViewProps> = ({
182188
const promises = tableQueries.map(async (query) => {
183189
const data = await getMetricTableData(query.query);
184190
const filteredData = filterData(data, validNamespaces);
185-
const formattedData = formatData(filteredData);
186-
return { [query.name]: formattedData };
191+
if (filteredData) {
192+
const formattedData = formatData(filteredData);
193+
return { [query.name]: formattedData };
194+
}
195+
return null;
187196
});
188197
const results = await Promise.all(promises);
189198
const tableDataUpdate = Object.assign({}, ...results);

frontend/src/pages/MCADashboard/Tables/status-summary-table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { Td, Tr } from '@patternfly/react-table';
1010
import { SortableData } from '../components/table/useTableColumnSort';
1111
import Table from '../components/table/Table';
12-
import { Data } from '../types';
12+
import { Data, StatusKey } from '../types';
1313
import { ChartDonut, ChartThemeColor } from '@patternfly/react-charts';
1414
import MCADashboard from '../MCADashboard.css';
1515

@@ -52,8 +52,8 @@ export const StatusSummaryTable: React.FunctionComponent<{ data: Data }> = ({ da
5252

5353
let totalAppWrappers = 0;
5454
for (const key in data.stats.statusCounts) {
55-
if (typeof data.stats.statusCounts[key] === 'number') {
56-
totalAppWrappers += data.stats.statusCounts[key] as number;
55+
if (typeof data.stats.statusCounts[key as StatusKey] === 'number') {
56+
totalAppWrappers += data.stats.statusCounts[key as StatusKey] as number;
5757
}
5858
}
5959

frontend/src/pages/MCADashboard/components/table/useTableColumnSort.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ const useTableColumnSort = <T>(
5858
return 0;
5959
}
6060

61-
const dataValueA = a[columnField.field];
62-
const dataValueB = b[columnField.field];
61+
const dataValueA = a[columnField.field as keyof T];
62+
const dataValueB = b[columnField.field as keyof T];
6363
if (typeof dataValueA === 'string' && typeof dataValueB === 'string') {
6464
return dataValueA.localeCompare(dataValueB);
6565
}

frontend/src/pages/MCADashboard/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ export interface Data {
2626
};
2727
};
2828
}
29+
30+
export type StatusKey = keyof Data['stats']['statusCounts'];

0 commit comments

Comments
 (0)