Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Topology, fetch build config data when necessary
- Loading branch information
1 parent
eac92a3
commit fb36344
Showing
30 changed files
with
296 additions
and
189 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
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
53 changes: 53 additions & 0 deletions
53
frontend/packages/console-shared/src/hooks/useBuildConfigsWatcher.ts
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as React from 'react'; | ||
import { CronJobKind, K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { useK8sWatchResources } from '@console/internal/components/utils/k8s-watch-hook'; | ||
import { getBuildConfigsForCronJob, getBuildConfigsForResource } from '../utils'; | ||
import { BuildConfigOverviewItem } from '../types'; | ||
|
||
export const useBuildConfigsWatcher = ( | ||
resource: K8sResourceKind, | ||
): { loaded: boolean; loadError: string; buildConfigs: BuildConfigOverviewItem[] } => { | ||
const [loaded, setLoaded] = React.useState<boolean>(false); | ||
const [loadError, setLoadError] = React.useState<string>(''); | ||
const [buildConfigs, setBuildConfigs] = React.useState<BuildConfigOverviewItem[]>(); | ||
const { namespace } = resource.metadata; | ||
const watchedResources = React.useMemo( | ||
() => ({ | ||
buildConfigs: { | ||
isList: true, | ||
kind: 'BuildConfig', | ||
namespace, | ||
}, | ||
builds: { | ||
isList: true, | ||
kind: 'Build', | ||
namespace, | ||
}, | ||
}), | ||
[namespace], | ||
); | ||
|
||
const resources = useK8sWatchResources(watchedResources); | ||
|
||
React.useEffect(() => { | ||
const errorKey = Object.keys(resources).find((key) => resources[key].loadError); | ||
if (errorKey) { | ||
setLoadError(resources[errorKey].loadError); | ||
return; | ||
} | ||
setLoadError(null); | ||
if ( | ||
Object.keys(resources).length > 0 && | ||
Object.keys(resources).every((key) => resources[key].loaded) | ||
) { | ||
const resourceBuildConfigs = | ||
resource.kind === 'CronJob' | ||
? getBuildConfigsForCronJob(resource as CronJobKind, resources) | ||
: getBuildConfigsForResource(resource, resources); | ||
setBuildConfigs(resourceBuildConfigs); | ||
setLoaded(true); | ||
} | ||
}, [resource, resources]); | ||
|
||
return { loaded, loadError, buildConfigs }; | ||
}; |
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
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
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
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 |
---|---|---|
|
@@ -23,7 +23,6 @@ describe('Monitoring Tab', () => { | |
}, | ||
}, | ||
}, | ||
buildConfigs: [], | ||
routes: [], | ||
services: [], | ||
}, | ||
|
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
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
Oops, something went wrong.