Skip to content

Commit

Permalink
Add shell hooks integration and update useAlerts function to accept o…
Browse files Browse the repository at this point in the history
…ptional filters
  • Loading branch information
hervedombya committed Nov 26, 2024
1 parent 533f14e commit e908e64
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 9 deletions.
2 changes: 1 addition & 1 deletion shell-ui/src/alerts/alertHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const useHighestSeverityAlerts = (filters: FilterLabels): Alert[] => {
*
* @returns react query result
*/
export function useAlerts(filters: FilterLabels) {
export function useAlerts(filters?: FilterLabels) {
const query = useContext(AlertContext);

if (!query) {
Expand Down
102 changes: 102 additions & 0 deletions shell-ui/src/hooks/useShellHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
useAlerts,
getPlatformAlertSelectors,
getNodesAlertSelectors,
getVolumesAlertSelectors,
getNetworksAlertSelectors,
getServicesAlertSelectors,
getK8SMasterAlertSelectors,
getBootstrapAlertSelectors,
getMonitoringAlertSelectors,
getAlertingAlertSelectors,
getLoggingAlertSelectors,
getDashboardingAlertSelectors,
getIngressControllerAlertSelectors,
getAuthenticationAlertSelectors,
useHighestSeverityAlerts,
} from '../alerts';
import AlertProvider from '../alerts/AlertProvider';
import { useAuthConfig } from '../auth/AuthConfigProvider';
import { useAuth } from '../auth/AuthProvider';
import {
useConfig,
useConfigRetriever,
useDiscoveredViews,
useLinkOpener,
} from '../initFederation/ConfigurationProviders';
import { useShellConfig } from '../initFederation/ShellConfigProvider';
import { useShellThemeSelector } from '../initFederation/ShellThemeSelectorProvider';
import { useDeployedApps } from '../initFederation/UIListProvider';
import { useLanguage } from '../navbar/lang';

type ShellHooks = {
useAuthConfig: typeof useAuthConfig;
useAuth: typeof useAuth;
useConfigRetriever: typeof useConfigRetriever;
useDiscoveredViews: typeof useDiscoveredViews;
useShellConfig: typeof useShellConfig;
useLanguage: typeof useLanguage;
useConfig: typeof useConfig;
useLinkOpener: typeof useLinkOpener;
useDeployedApps: typeof useDeployedApps;
useShellThemeSelector: typeof useShellThemeSelector;
};

type ShellAlerts = {
AlertsProvider: typeof AlertProvider;
alertHooks: {
useAlerts: typeof useAlerts;
useHighestSeverityAlerts: typeof useHighestSeverityAlerts;
};
alertSelectors: {
getPlatformAlertSelectors: typeof getPlatformAlertSelectors;
getNodesAlertSelectors: typeof getNodesAlertSelectors;
getVolumesAlertSelectors: typeof getVolumesAlertSelectors;
getNetworksAlertSelectors: typeof getNetworksAlertSelectors;
getServicesAlertSelectors: typeof getServicesAlertSelectors;
getK8SMasterAlertSelectors: typeof getK8SMasterAlertSelectors;
getBootstrapAlertSelectors: typeof getBootstrapAlertSelectors;
getMonitoringAlertSelectors: typeof getMonitoringAlertSelectors;
getAlertingAlertSelectors: typeof getAlertingAlertSelectors;
getLoggingAlertSelectors: typeof getLoggingAlertSelectors;
getDashboardingAlertSelectors: typeof getDashboardingAlertSelectors;
getIngressControllerAlertSelectors: typeof getIngressControllerAlertSelectors;
getAuthenticationAlertSelectors: typeof getAuthenticationAlertSelectors;
};
};

export const shellHooks: ShellHooks = {
useAuthConfig,
useAuth,
useConfigRetriever,
useDiscoveredViews,
useShellConfig,
useLanguage,
useConfig,
useLinkOpener,
useDeployedApps,
useShellThemeSelector,
};

export const shellAlerts: ShellAlerts = {
AlertsProvider: AlertProvider,
alertHooks: {
useAlerts,
useHighestSeverityAlerts,
},
alertSelectors: {
getPlatformAlertSelectors,
getNodesAlertSelectors,
getVolumesAlertSelectors,
getNetworksAlertSelectors,
getServicesAlertSelectors,
getK8SMasterAlertSelectors,
getBootstrapAlertSelectors,
getMonitoringAlertSelectors,
getAlertingAlertSelectors,
getLoggingAlertSelectors,
getDashboardingAlertSelectors,
getIngressControllerAlertSelectors,
getAuthenticationAlertSelectors,
},
};
15 changes: 7 additions & 8 deletions shell-ui/src/initFederation/ShellConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ export const useShellConfig = () => {
export const ShellConfigProvider = ({ shellConfigUrl, children }) => {
const { data: config, status } = useQuery<ShellJSONFileConfig>(
'getShellJSONConfigFile',
() => {
return fetch(shellConfigUrl).then((r) => {
if (r.ok) {
return r.json();
} else {
return Promise.reject();
}
});
async () => {
const r = await fetch(shellConfigUrl);
if (r.ok) {
return r.json();
} else {
return Promise.reject();
}
},
{
refetchOnWindowFocus: false,
Expand Down

0 comments on commit e908e64

Please sign in to comment.