Skip to content

Commit da4c657

Browse files
committed
Merge remote-tracking branch 'official/main'
2 parents d8a931b + 0f5a1f6 commit da4c657

File tree

9 files changed

+230
-153
lines changed

9 files changed

+230
-153
lines changed

plugin-catalog/src/components/plugins/List.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { PluginCard } from './PluginCard';
99
import { Switch } from '@mui/material';
1010
import { FormControlLabel } from '@mui/material';
1111
import { isEqual } from 'lodash';
12+
import semver from 'semver';
1213

1314
const PAGE_SIZE = 60; // Maximum allowed by the API
1415
const ARTIFACTHUB_HEADLAMP_PLUGIN_KIND = '21';
@@ -49,6 +50,7 @@ export interface PluginPackage {
4950
organization_name: string;
5051
};
5152
isInstalled: boolean;
53+
isUpdateAvailable: boolean;
5254
}
5355

5456
async function fetchPlugins(offset: number, org?: string) {
@@ -126,7 +128,15 @@ async function processPlugins() {
126128
} catch (err) {
127129
console.log('plugin-catalog: Failed to list plugins', err);
128130
}
129-
const installedPlugins = pluginData.map((plugin: any) => plugin.folderName);
131+
const installedVersions: Record<string, string> = pluginData.reduce(
132+
(acc, plugin: any) => {
133+
if (plugin.folderName && plugin.artifacthubVersion) {
134+
acc[plugin.folderName] = plugin.artifacthubVersion;
135+
}
136+
return acc;
137+
},
138+
{}
139+
);
130140

131141
// Merge all plugins and org-specific plugins, removing duplicates
132142
const mergedPlugins = [...allPlugins, ...orgPlugins];
@@ -135,10 +145,24 @@ async function processPlugins() {
135145
);
136146

137147
const pluginsWithInstallStatus = uniquePlugins
138-
.map((pkg: PluginPackage) => ({
139-
...pkg,
140-
isInstalled: installedPlugins.includes(pkg.name),
141-
}))
148+
.map((pkg: PluginPackage) => {
149+
const installedVersion = installedVersions[pkg.name];
150+
let isInstalled = false;
151+
let isUpdateAvailable = false;
152+
153+
if (installedVersion) {
154+
isInstalled = true;
155+
if (semver.valid(pkg.version) && semver.valid(installedVersion)) {
156+
isUpdateAvailable = semver.gt(pkg.version, installedVersion);
157+
}
158+
}
159+
160+
return {
161+
...pkg,
162+
isInstalled,
163+
isUpdateAvailable,
164+
};
165+
})
142166
// Reorder so plugins with logos show first.
143167
.sort((a, b) => (!!b.logo_image_id ? 1 : 0) - (!!a.logo_image_id ? 1 : 0));
144168

plugin-catalog/src/components/plugins/PluginCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ export function PluginCard(props: PluginCardProps) {
151151
}}
152152
>
153153
<span></span>
154-
{plugin.isInstalled && <Typography>Installed</Typography>}
154+
{plugin.isInstalled && (
155+
<Typography>{plugin.isUpdateAvailable ? 'Update available' : 'Installed'}</Typography>
156+
)}
155157
</CardActions>
156158
</Card>
157159
</Box>

prometheus/src/components/Chart/CPUChart/CPUChart.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { useTheme } from '@mui/material';
1+
import { alpha, useTheme } from '@mui/material';
2+
import { blue } from '@mui/material/colors';
23
import { fetchMetrics } from '../../../request';
34
import { createTickTimestampFormatter, dataProcessor, PrometheusEndpoint } from '../../../util';
45
import Chart from '../Chart/Chart';
@@ -45,7 +46,7 @@ export function CPUChart(props: CPUChartProps) {
4546

4647
const YTickProps = {
4748
domain: ['dataMin', 'auto'],
48-
width: 80,
49+
width: 60,
4950
};
5051

5152
return (
@@ -54,8 +55,8 @@ export function CPUChart(props: CPUChartProps) {
5455
{
5556
query: props.query,
5657
name: 'cpu (cores)',
57-
strokeColor: '#CDC300',
58-
fillColor: '#FFF178',
58+
strokeColor: alpha(blue[400], 0.8),
59+
fillColor: alpha(blue[400], 0.1),
5960
dataProcessor: dataProcessor,
6061
},
6162
]}

prometheus/src/components/Chart/Chart/Chart.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { EmptyContent, Loader } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
22
import { Box, useTheme } from '@mui/material';
33
import { useEffect, useState } from 'react';
4-
import { Area, AreaChart, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
4+
import {
5+
Area,
6+
AreaChart,
7+
CartesianGrid,
8+
Legend,
9+
ResponsiveContainer,
10+
Tooltip,
11+
XAxis,
12+
YAxis,
13+
} from 'recharts';
514
import { getTimeRange, PrometheusEndpoint } from '../../../util';
615

716
/**
@@ -50,10 +59,11 @@ export default function Chart(props: ChartProps) {
5059
SUCCESS,
5160
}
5261
const { fetchMetrics, xAxisProps, yAxisProps } = props;
53-
const [metrics, setMetrics] = useState<object>({});
62+
const [metrics, setMetrics] = useState<Array<any>>([]);
5463
const [state, setState] = useState<ChartState | null>(null);
5564
const [error, setError] = useState<string | null>(null);
5665
const theme = useTheme();
66+
const timeRange = getTimeRange(props.interval);
5767

5868
const fetchMetricsData = async (
5969
plots: Array<{ query: string; name: string; dataProcessor: (data: any) => any }>,
@@ -142,29 +152,38 @@ export default function Chart(props: ChartProps) {
142152
clearInterval(refreshInterval);
143153
};
144154
}
145-
}, [props.autoRefresh, props.plots]);
155+
}, [props.autoRefresh, props.plots, props.interval]);
146156

147157
let chartContent;
148158

149159
if (state === ChartState.SUCCESS) {
150160
chartContent = (
151-
<AreaChart data={metrics}>
152-
<XAxis stroke={theme.palette.chartStyles.labelColor} {...xAxisProps} />
153-
<YAxis stroke={theme.palette.chartStyles.labelColor} {...yAxisProps} />
161+
<AreaChart data={metrics} style={{ fontSize: 14 }}>
162+
<XAxis
163+
stroke={theme.palette.chartStyles.labelColor}
164+
fontSize={12}
165+
{...xAxisProps}
166+
type="number"
167+
domain={[timeRange.from, timeRange.to]}
168+
allowDataOverflow
169+
/>
170+
<YAxis fontSize={14} stroke={theme.palette.chartStyles.labelColor} {...yAxisProps} />
154171
{props.CustomTooltip === undefined ? (
155172
<Tooltip />
156173
) : (
157174
<Tooltip content={props.CustomTooltip} />
158175
)}
159176
<Legend />
177+
<CartesianGrid strokeDasharray="2 4" stroke={theme.palette.divider} vertical={false} />
160178
{props.plots.map(plot => (
161179
<Area
162180
stackId="1"
163-
type="monotone"
181+
type="step"
164182
dataKey={plot.name}
165183
stroke={plot.strokeColor}
184+
strokeWidth={2}
166185
fill={plot.fillColor}
167-
activeDot={{ r: 8 }}
186+
activeDot={{ r: 2 }}
168187
animationDuration={props.autoRefresh ? 0 : 400} // Disable animation when refreshing
169188
/>
170189
))}

prometheus/src/components/Chart/FilesystemChart/FilesystemChart.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { useTheme } from '@mui/material';
1+
import { alpha, useTheme } from '@mui/material';
2+
import { orange, purple } from '@mui/material/colors';
23
import { fetchMetrics } from '../../../request';
34
import { createTickTimestampFormatter, dataProcessor, PrometheusEndpoint } from '../../../util';
45
import { formatBytes } from '../../../util';
@@ -32,15 +33,15 @@ export function FilesystemChart(props: FilesystemChartProps) {
3233
{
3334
query: props.readQuery,
3435
name: 'read',
35-
strokeColor: '#CDC300',
36-
fillColor: '#FFF178',
36+
strokeColor: alpha(orange[400], 0.8),
37+
fillColor: alpha(orange[400], 0.1),
3738
dataProcessor: dataProcessor,
3839
},
3940
{
4041
query: props.writeQuery,
4142
name: 'write',
42-
strokeColor: '#006B58',
43-
fillColor: '#98F6DC',
43+
strokeColor: alpha(purple[400], 0.8),
44+
fillColor: alpha(purple[400], 0.1),
4445
dataProcessor: dataProcessor,
4546
},
4647
]}

0 commit comments

Comments
 (0)