-
Notifications
You must be signed in to change notification settings - Fork 593
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 #9774 from invincibleJai/bz-1991977
Bug 1991977: fetch kamelets form both current namespace and global namespace where operator is installed
- Loading branch information
Showing
5 changed files
with
68 additions
and
16 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
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,2 +1,3 @@ | ||
export * from './useEventSourceModelsWithAccess'; | ||
export * from './useEventSourceStatus'; | ||
export * from './useKameletsData'; |
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
49 changes: 49 additions & 0 deletions
49
frontend/packages/knative-plugin/src/hooks/useKameletsData.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,49 @@ | ||
import * as React from 'react'; | ||
import { useK8sWatchResources } from '@console/internal/components/utils/k8s-watch-hook'; | ||
import { K8sResourceKind, referenceForModel } from '@console/internal/module/k8s'; | ||
import { GLOBAL_OPERATOR_NS } from '../const'; | ||
import { CamelKameletModel } from '../models'; | ||
|
||
export const useKameletsData = (namespace: string): [K8sResourceKind[], boolean, any] => { | ||
const [kamelets, setKamelets] = React.useState<K8sResourceKind[]>([]); | ||
const [kameletsLoaded, setKameletsLoaded] = React.useState(false); | ||
const [kameletsLoadError, setKameletsLoadError] = React.useState(null); | ||
|
||
const watchedResources = React.useMemo( | ||
() => ({ | ||
kamelets: { | ||
isList: true, | ||
kind: referenceForModel(CamelKameletModel), | ||
namespace, | ||
optional: true, | ||
}, | ||
kameletsGlobalNs: { | ||
isList: true, | ||
kind: referenceForModel(CamelKameletModel), | ||
namespace: GLOBAL_OPERATOR_NS, | ||
optional: true, | ||
}, | ||
}), | ||
[namespace], | ||
); | ||
|
||
const extraResources = useK8sWatchResources<{ | ||
[key: string]: K8sResourceKind[]; | ||
}>(watchedResources); | ||
|
||
React.useEffect(() => { | ||
const resDataLoaded = Object.keys(extraResources).every((key) => extraResources[key].loaded); | ||
const resDataloadError = Object.keys(extraResources).every( | ||
(key) => extraResources[key].loadError, | ||
); | ||
const { kamelets: kameletsData, kameletsGlobalNs } = extraResources; | ||
if (resDataLoaded) { | ||
setKamelets(kameletsData.data.length > 0 ? kameletsData.data : kameletsGlobalNs.data); | ||
setKameletsLoaded(kameletsData.loaded || kameletsGlobalNs.loaded); | ||
} else if (resDataloadError) { | ||
setKameletsLoadError(kameletsGlobalNs.loadError || kameletsGlobalNs.loadError); | ||
} | ||
}, [extraResources]); | ||
|
||
return [kamelets, kameletsLoaded, kameletsLoadError]; | ||
}; |