Skip to content

Commit

Permalink
Refactor to useShellHooks for improved context integration across com…
Browse files Browse the repository at this point in the history
…ponents
  • Loading branch information
hervedombya committed Nov 26, 2024
1 parent a11398f commit b2beec4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ui/src/FederableApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { setHistory as setReduxHistory } from './ducks/history';
import { setApiConfigAction } from './ducks/config';
import { authErrorAction } from './ducks/app/authError';
import { AuthError } from './services/errorhandler';
import { ShellHooksProvider } from './ShellHooksContext';
import { ShellHooksProvider, useShellHooks } from './ShellHooksContext';
const composeEnhancers =
// @ts-expect-error - FIXME when you are working on it
typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
Expand Down Expand Up @@ -88,7 +88,8 @@ type Config = {
};
export const useConfig = () => {
const { name } = useCurrentApp();
const runtimeConfiguration = window.shellHooks.useConfig<Config>({
const { useConfig } = useShellHooks();
const runtimeConfiguration = useConfig({
configType: 'run',
name,
});
Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/DashboardInventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const DashboardInventory = () => {
getNodesCountQuery(config || '', getToken),
);
const history = useHistory();

return (
<InventoryContainer>
<PageSubtitle aria-label="inventory">
Expand Down Expand Up @@ -108,7 +109,7 @@ const DashboardInventory = () => {
</StatusWrapper>
</InventoryIcon>
<InventoryValue aria-label={`${nodesCount} nodes`}>
{nodesCount}
{nodesCount as number}
</InventoryValue>
</Card.Body>
</Card.BodyContainer>
Expand Down Expand Up @@ -143,7 +144,7 @@ const DashboardInventory = () => {
</StatusWrapper>
</InventoryIcon>
<InventoryValue aria-label={`${volumesCount} volumes`}>
{volumesCount}
{volumesCount as number}
</InventoryValue>
</Card.Body>
</Card.BodyContainer>
Expand Down
9 changes: 5 additions & 4 deletions ui/src/containers/AlertProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const useHighestSeverityAlerts = (filters: FilterLabels) => {
return alertHooks.useHighestSeverityAlerts(filters);
};
export const useAlertLibrary = () => {
const { alertHooks } = useShellAlerts();
return alertHooks.alertSelectors;
const { alertSelectors } = useShellAlerts();
return alertSelectors;
};

export const highestAlertToStatus = (alerts?: Alert[]): Status => {
Expand All @@ -38,10 +38,11 @@ export const highestAlertToStatus = (alerts?: Alert[]): Status => {

const AlertProvider = ({ children }: { children: React.ReactNode }) => {
const { url_alertmanager } = useConfig();
const alerts = useShellAlerts();
return (
<window.shellAlerts.AlertsProvider alertManagerUrl={url_alertmanager}>
<alerts.AlertsProvider alertManagerUrl={url_alertmanager}>
{children}
</window.shellAlerts.AlertsProvider>
</alerts.AlertsProvider>
);
};

Expand Down
8 changes: 6 additions & 2 deletions ui/src/containers/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useShellHooks } from '../ShellHooksContext';

export function useLinkOpener() {
return window.shellHooks.useLinkOpener();
const { useLinkOpener } = useShellHooks();
return useLinkOpener();
}
export function useDiscoveredViews() {
return window.shellHooks.useDiscoveredViews();
const { useDiscoveredViews } = useShellHooks();
return useDiscoveredViews();
}
4 changes: 3 additions & 1 deletion ui/src/containers/IntlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from 'react';
import { IntlProvider } from 'react-intl';
import translations_en from '../translations/en.json';
import translations_fr from '../translations/fr.json';
import { useShellHooks } from '../ShellHooksContext';
const messages = {
EN: translations_en,
FR: translations_fr,
};

const FederatedIntlProvider = ({ children }: { children: React.ReactNode }) => {
const { language } = window.shellHooks.useLanguage();
const { useLanguage } = useShellHooks();
const { language } = useLanguage();
return (
<IntlProvider locale={language} messages={messages[language.toUpperCase()]}>
{children}
Expand Down
1 change: 0 additions & 1 deletion ui/src/containers/NodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useTypedSelector } from '../hooks';

const NodePage = (props) => {
useRefreshEffect(refreshNodesAction, stopRefreshNodesAction);
// @ts-expect-error - FIXME when you are working on it
const { alerts } = useAlerts();
const theme = useTheme();
const nodeTableData = useSelector(
Expand Down
3 changes: 2 additions & 1 deletion ui/src/containers/PrivateRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const PrivateRoute = ({ component, ...rest }: PrivateRouteProps) => {
(left, right) => left.isAuthError === right.isAuthError,
);
const url_support = api?.url_support;
const { userData } = window.shellHooks.useAuth();
const { useAuth } = useShellHooks();
const { userData } = useAuth();

const dispatch = useDispatch();
const history = useHistory();
Expand Down

0 comments on commit b2beec4

Please sign in to comment.