Skip to content

Commit

Permalink
MNES-1071 Added .env check for submodel registry
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsXitaso committed Jul 11, 2024
1 parent ba85bc9 commit d5dc592
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app/[locale]/viewer/_components/SubmodelsOverviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { MobileModal } from 'components/basics/MobileModal';
import { useApis } from 'components/azureAuthentication/ApiProvider';
import { useRegistryAasState } from 'components/contexts/CurrentAasContext';
import { getSubmodelFromSubmodelDescriptor } from 'lib/searchUtilActions/search';
import { useEnv } from 'app/env/provider';


export type SubmodelsOverviewCardProps = { readonly smReferences?: Reference[]; readonly isLoading?: boolean };

Expand All @@ -28,6 +30,7 @@ export function SubmodelsOverviewCard(props: SubmodelsOverviewCardProps) {
const [open, setOpen] = useState<boolean>(false);
const isMobile = useIsMobile();
const firstSubmodelIdShort = 'Nameplate';
const env = useEnv();

useAsyncEffect(async () => {
if (!props.smReferences) return;
Expand All @@ -45,7 +48,7 @@ export function SubmodelsOverviewCard(props: SubmodelsOverviewCardProps) {
} else {
for (const reference of props.smReferences as Reference[]) {
try {
const submodelFromRegistry = await submodelRegistryServiceClient.getSubmodelDescriptorsById(reference.keys[0].value)
const submodelFromRegistry = env.SUBMODEL_REGISTRY_API_URL ? await submodelRegistryServiceClient.getSubmodelDescriptorsById(reference.keys[0].value) : null
if (submodelFromRegistry) {
submodels.push({
id: submodelFromRegistry.id,
Expand All @@ -62,7 +65,6 @@ export function SubmodelsOverviewCard(props: SubmodelsOverviewCardProps) {
}
}


if (submodels) {
submodels.sort(function (x, y) {
return x.label == firstSubmodelIdShort ? -1 : y.label == firstSubmodelIdShort ? 1 : 0;
Expand All @@ -87,13 +89,14 @@ export function SubmodelsOverviewCard(props: SubmodelsOverviewCardProps) {
if (selectedSubmodel.endpoint) {
try {
fetchedSubmodel = await getSubmodelFromSubmodelDescriptor(selectedSubmodel.endpoint);
} catch(e) {
} catch (e) {
console.error(e);
}
} if (!registryAasData) {
}
if (!registryAasData) {
try {
fetchedSubmodel = await submodelClient.getSubmodelById(selectedSubmodel?.id ?? '');
} catch(e) {
} catch (e) {
console.error(e);
}
}
Expand Down

0 comments on commit d5dc592

Please sign in to comment.