mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
* Fix: logs data disapearing causing crashes (#2566) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Refactor helm-chart.api and improve kube validation and error handling (#2265) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix: HPA's not sortable by age (#2565) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Conditionally render status icon for kube meta (#2298) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Fix custom resource loading spinner appears above extensions' cluster menus (#2344) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Lens should point to the release docs (#2268) Signed-off-by: Sebastian Malton <sebastian@malton.name> * Refactor the Extensions settings page (#2221) Signed-off-by: Sebastian Malton <sebastian@malton.name> * try and get jest to not core dump Signed-off-by: Sebastian Malton <sebastian@malton.name>
83 lines
2.0 KiB
TypeScript
83 lines
2.0 KiB
TypeScript
import semver from "semver";
|
|
import { observable } from "mobx";
|
|
import { autobind } from "../../utils";
|
|
import { getChartDetails, HelmChart, listCharts } from "../../api/endpoints/helm-charts.api";
|
|
import { ItemStore } from "../../item.store";
|
|
import flatten from "lodash/flatten";
|
|
|
|
export interface IChartVersion {
|
|
repo: string;
|
|
version: string;
|
|
}
|
|
|
|
@autobind()
|
|
export class HelmChartStore extends ItemStore<HelmChart> {
|
|
@observable versions = observable.map<string, IChartVersion[]>();
|
|
|
|
async loadAll() {
|
|
try {
|
|
const res = await this.loadItems(() => listCharts());
|
|
|
|
this.failedLoading = false;
|
|
|
|
return res;
|
|
} catch (error) {
|
|
this.failedLoading = true;
|
|
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
getByName(name: string, repo: string) {
|
|
return this.items.find(chart => chart.getName() === name && chart.getRepository() === repo);
|
|
}
|
|
|
|
protected sortVersions = (versions: IChartVersion[]) => {
|
|
return versions.sort((first, second) => {
|
|
const firstVersion = semver.coerce(first.version || 0);
|
|
const secondVersion = semver.coerce(second.version || 0);
|
|
|
|
return semver.compare(secondVersion, firstVersion);
|
|
});
|
|
};
|
|
|
|
async getVersions(chartName: string, force?: boolean): Promise<IChartVersion[]> {
|
|
let versions = this.versions.get(chartName);
|
|
|
|
if (versions && !force) {
|
|
return versions;
|
|
}
|
|
|
|
const loadVersions = async (repo: string) => {
|
|
const { versions } = await getChartDetails(repo, chartName);
|
|
|
|
return versions.map(chart => ({
|
|
repo,
|
|
version: chart.getVersion()
|
|
}));
|
|
};
|
|
|
|
if (!this.isLoaded) {
|
|
await this.loadAll();
|
|
}
|
|
const repos = this.items
|
|
.filter(chart => chart.getName() === chartName)
|
|
.map(chart => chart.getRepository());
|
|
|
|
versions = await Promise.all(repos.map(loadVersions))
|
|
.then(flatten)
|
|
.then(this.sortVersions);
|
|
|
|
this.versions.set(chartName, versions);
|
|
|
|
return versions;
|
|
}
|
|
|
|
reset() {
|
|
super.reset();
|
|
this.versions.clear();
|
|
}
|
|
}
|
|
|
|
export const helmChartStore = new HelmChartStore();
|