Skip to content

Commit 9bad657

Browse files
committed
Fix bugs in Helm Chart browser
- Fix bug where sometimes the charts don't load sometimes on Linux - Fix bug where view is stuck loading when there are no repos or charts - Clean up some of the code Fixes #4083 Signed-off-by: David Thompson <[email protected]>
1 parent d7db511 commit 9bad657

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

src/webview/helm-chart/app/helmSearch.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
import React from 'react';
7-
import { Checkbox, Divider, FormControlLabel, FormGroup, IconButton, InputAdornment, Modal, Pagination, Stack, TextField, Tooltip, Typography } from '@mui/material';
7+
import { Alert, Checkbox, Divider, FormControlLabel, FormGroup, IconButton, InputAdornment, Modal, Pagination, Stack, TextField, Tooltip, Typography } from '@mui/material';
88
import { Close, Search } from '@mui/icons-material';
99
import { HelmListItem } from './helmListItem';
1010
import { ChartResponse, HelmRepo } from '../../../helm/helmChartType';
@@ -163,6 +163,7 @@ function SearchBar(props: {
163163

164164
export function HelmSearch() {
165165
const ITEMS_PER_PAGE = 18;
166+
const [isSomeHelmChartsRetrieved, setSomeHelmChartsRetrieved] = React.useState(false);
166167
const [helmRepos, setHelmRepos] = React.useState<HelmRepo[]>([]);
167168
const [helmCharts, sethelmCharts] = React.useState<ChartResponse[]>([]);
168169
const [helmChartEnabled, setHelmChartEnabled] = React.useState<
@@ -196,6 +197,7 @@ export function HelmSearch() {
196197
case 'getHelmCharts': {
197198
sethelmCharts((_helmCharts) => message.data.helmCharts as ChartResponse[]);
198199
VSCodeMessage.postMessage({ action: 'getProviderTypes' });
200+
setSomeHelmChartsRetrieved(_unused => true);
199201
break;
200202
}
201203
default:
@@ -277,7 +279,7 @@ export function HelmSearch() {
277279
<>
278280
<Stack direction='column' height='100%' spacing={0.5}>
279281
{
280-
helmCharts.length === 0 ?
282+
!isSomeHelmChartsRetrieved ?
281283
<LoadScreen title='Retrieving Helm Charts' /> :
282284
<Stack direction="row" spacing={1} width={'100%'}>
283285
{
@@ -328,8 +330,11 @@ export function HelmSearch() {
328330
(getFilteredCharts().length % ITEMS_PER_PAGE > 0.0001 ? 1 : 0)}
329331
perPageCount={ITEMS_PER_PAGE}
330332
chartsLength={getFilteredCharts().length} />
331-
{/* 320px is the approximate combined height of the top bar and bottom bar in the devfile search view */}
332-
{/* 5em is the padding at the top of the page */}
333+
{helmRepos.length === 0 ?
334+
<Stack direction='row' justifyContent='center' alignItems='center' paddingTop='2rem'>
335+
<Alert severity='info'>No Helm repos are configured. Please configure a Helm repo to view its charts.</Alert>
336+
</Stack>
337+
:
333338
<Stack
334339
id='devfileList'
335340
direction='column'
@@ -353,7 +358,7 @@ export function HelmSearch() {
353358
}} />
354359
);
355360
})}
356-
</Stack>
361+
</Stack>}
357362
</Stack>
358363
</Stack>
359364
}

src/webview/helm-chart/helmChartLoader.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ function helmChartMessageListener(event: any): void {
7777
void panel.webview.postMessage({
7878
action: 'setTheme',
7979
themeValue: vscode.window.activeColorTheme.kind,
80-
})
80+
});
81+
void HelmChartLoader.getHelmCharts();
8182
break;
8283
case 'install': {
8384
void vscode.commands.executeCommand('openshift.helm.install', event);
@@ -159,7 +160,6 @@ export default class HelmChartLoader {
159160
panel = undefined;
160161
});
161162
}
162-
await HelmChartLoader.getHelmCharts();
163163
return panel;
164164
}
165165

@@ -181,33 +181,37 @@ export default class HelmChartLoader {
181181
}
182182
}
183183
);
184-
helmRepos.forEach((helmRepo: HelmRepo) => {
184+
await Promise.all(helmRepos.map((helmRepo: HelmRepo) => {
185185
let url = helmRepo.url;
186186
url = url.endsWith('/') ? url : url.concat('/');
187187
url = url.concat('index.yaml');
188-
void HelmChartLoader.fetchURL(helmRepo, url);
189-
});
188+
return HelmChartLoader.fetchURL(helmRepo, url);
189+
}));
190+
void panel?.webview.postMessage(
191+
{
192+
action: 'getHelmCharts',
193+
data: {
194+
helmCharts
195+
}
196+
}
197+
);
190198
}
191199
}
192200

193201
private static async fetchURL(repo: HelmRepo, url: string) {
194-
const signupResponse = await fetch(url, {
195-
method: 'GET'
196-
});
197-
const yamlResponse = JSYAML.load(await signupResponse.text()) as any;
202+
const helmRepoContent = await fetch(url);
203+
const yamlResponse = JSYAML.load(await helmRepoContent.text()) as {
204+
entries: { [key: string]: Chart[] };
205+
};
198206
const entries = yamlResponse.entries;
199207
Object.keys(entries).forEach((key) => {
200208
const res: ChartResponse = {
201-
repoName: '',
202-
repoURL: '',
203-
chartName: '',
204-
chartVersions: [],
209+
repoName: repo.name,
210+
repoURL: repo.url,
211+
chartName: key,
212+
chartVersions: entries[key].sort(HelmChartLoader.descOrder),
205213
displayName: ''
206214
};
207-
res.repoName = repo.name;
208-
res.repoURL = repo.url;
209-
res.chartName = key;
210-
res.chartVersions = entries[key].sort(HelmChartLoader.descOrder);
211215
res.displayName = res.chartVersions[0].annotations ? res.chartVersions[0].annotations['charts.openshift.io/name'] : res.chartVersions[0].name;
212216
helmCharts.push(res);
213217
});
@@ -222,8 +226,8 @@ export default class HelmChartLoader {
222226
}
223227

224228
private static descOrder(oldChart: Chart, newChart: Chart): number {
225-
const oldVersion = parseInt(oldChart.version, 10);
226-
const newVersion = parseInt(newChart.version, 10);
227-
return newVersion - oldVersion;
228-
}
229+
const oldVersion = parseInt(oldChart.version, 10);
230+
const newVersion = parseInt(newChart.version, 10);
231+
return newVersion - oldVersion;
232+
}
229233
}

0 commit comments

Comments
 (0)