diff --git a/apps/router/src/context/AppContext.tsx b/apps/router/src/context/AppContext.tsx index ee5c5ea90..9d8c2d9bd 100644 --- a/apps/router/src/context/AppContext.tsx +++ b/apps/router/src/context/AppContext.tsx @@ -148,10 +148,9 @@ export const AppContextProvider: React.FC = ({ const [state, dispatch] = useReducer(reducer, makeInitialState()); useEffect(() => { - const addService = (service: Service) => { + const addService = (service: Service, index: number) => { const kind = isGuardian(service) ? 'guardian' : 'gateway'; - const stateKey = `${kind}s` as 'guardians' | 'gateways'; - const id = (Object.keys(state[stateKey]).length + 1).toString(); + const id = (index + 1).toString(); if (kind === 'guardian') { dispatch({ @@ -173,12 +172,13 @@ export const AppContextProvider: React.FC = ({ const handleConfig = (data: Service | Service[]) => { const services = Array.isArray(data) ? data : [data]; - services.forEach((service) => { + services.forEach((service, index) => { if (isGuardian(service) || isGateway(service)) { - addService(service); + addService(service, index); } }); }; + fetch('/config.json') .then((response) => { if (!response.ok) { @@ -202,7 +202,7 @@ export const AppContextProvider: React.FC = ({ .catch((error) => { console.error('Error fetching or processing config:', error); }); - }, [state]); + }, []); return ( diff --git a/apps/router/src/home/HomePage.tsx b/apps/router/src/home/HomePage.tsx index b07c14d93..8ff1393c0 100644 --- a/apps/router/src/home/HomePage.tsx +++ b/apps/router/src/home/HomePage.tsx @@ -52,23 +52,25 @@ export const HomePage: React.FC = () => { - + - {Object.keys(guardians).map((guardianIndex) => ( - - - - - ))} + {Object.entries(guardians).map( + ([guardianIndex, guardian]) => ( + + + + + ) + )}
{t('home.guardianId', 'Guardian ID')}{t('home.guardianUrl', 'Guardian URL')} {t('home.actions', 'Actions')}
{guardianIndex} - - - -
{guardian.config.fm_config_api} + + + +
@@ -84,14 +86,14 @@ export const HomePage: React.FC = () => { - + - {Object.keys(gateways).map((gatewayIndex) => ( + {Object.entries(gateways).map(([gatewayIndex, gateway]) => ( - +
{t('home.gatewayId', 'Gateway ID')}{t('home.gatewayUrl', 'Gateway URL')} {t('home.actions', 'Actions')}
{gatewayIndex}{gateway.config.baseUrl}