Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4565 from openshift-cherrypick-robot/cherry-pick-…
…4558-to-release-4.4 [release-4.4] Bug 1808611: Fix for sort/filter on helm details resources page
- Loading branch information
Showing
3 changed files
with
69 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 58 additions & 10 deletions
68
frontend/packages/dev-console/src/components/helm/HelmReleaseResources.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,69 @@ | ||
import * as React from 'react'; | ||
import { safeLoadAll } from 'js-yaml'; | ||
import { MultiListPage } from '@console/internal/components/factory'; | ||
import { FirehoseResource } from '@console/internal/components/utils'; | ||
import { coFetchJSON } from '@console/internal/co-fetch'; | ||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { flattenResources } from './helm-release-resources-utils'; | ||
import HelmResourcesListComponent from './HelmResourcesListComponent'; | ||
import { HelmRelease } from './helm-types'; | ||
import { match as RMatch } from 'react-router'; | ||
|
||
export interface HelmReleaseResourcesProps { | ||
helmManifestResources: FirehoseResource[]; | ||
match: RMatch<{ | ||
ns?: string; | ||
name?: string; | ||
}>; | ||
} | ||
|
||
const HelmReleaseResources: React.FC<HelmReleaseResourcesProps> = ({ helmManifestResources }) => ( | ||
<MultiListPage | ||
filterLabel="Resources by name" | ||
resources={helmManifestResources} | ||
flatten={flattenResources} | ||
label="Resources" | ||
ListComponent={HelmResourcesListComponent} | ||
/> | ||
); | ||
const HelmReleaseResources: React.FC<HelmReleaseResourcesProps> = ({ match }) => { | ||
const namespace = match.params.ns; | ||
const helmReleaseName = match.params.name; | ||
const [helmManifestResources, setHelmManifestResources] = React.useState<FirehoseResource[]>([]); | ||
|
||
React.useEffect(() => { | ||
let ignore = false; | ||
|
||
const fetchHelmReleases = async () => { | ||
let res: HelmRelease[]; | ||
try { | ||
res = await coFetchJSON(`/api/helm/releases?ns=${namespace}`); | ||
} catch { | ||
return; | ||
} | ||
if (ignore) return; | ||
|
||
const releaseData = res?.filter((rel) => rel.name === helmReleaseName); | ||
const helmManifest = safeLoadAll(releaseData[0].manifest); | ||
|
||
const resources: FirehoseResource[] = helmManifest.map((resource: K8sResourceKind) => ({ | ||
kind: resource.kind, | ||
name: resource.metadata.name, | ||
namespace, | ||
prop: `${resource.metadata.name}-${resource.kind.toLowerCase()}`, | ||
isList: false, | ||
optional: true, | ||
})); | ||
|
||
setHelmManifestResources(resources); | ||
}; | ||
|
||
fetchHelmReleases(); | ||
|
||
return () => { | ||
ignore = true; | ||
}; | ||
}, [helmReleaseName, namespace]); | ||
|
||
return ( | ||
<MultiListPage | ||
filterLabel="Resources by name" | ||
resources={helmManifestResources} | ||
flatten={flattenResources} | ||
label="Resources" | ||
ListComponent={HelmResourcesListComponent} | ||
/> | ||
); | ||
}; | ||
|
||
export default HelmReleaseResources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters