@@ -5,30 +5,27 @@ import { useState } from 'react';
55import { useTranslations } from 'use-intl' ;
66import { encodeBase64 } from 'lib/util/Base64Util' ;
77import { useEnv } from 'app/EnvProvider' ;
8- import { SubmodelOrIdReference , useCurrentAasContext } from 'components/contexts/CurrentAasContext' ;
8+ import { SubmodelOrIdReference } from 'components/contexts/CurrentAasContext' ;
99import { useShowError } from 'lib/hooks/UseShowError' ;
1010import { AssetAdministrationShell } from 'lib/api/aas/models' ;
11- import {
12- checkIfInfrastructureHasSerializationEndpoints ,
13- serializeAasFromInfrastructure ,
14- } from 'lib/services/serialization-service/serializationActions' ;
15- import { useAsyncEffect } from 'lib/hooks/UseAsyncEffect' ;
11+ import { serializeAasFromInfrastructure } from 'lib/services/serialization-service/serializationActions' ;
12+ import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner' ;
1613
1714type ActionMenuProps = {
1815 readonly aas : AssetAdministrationShell | null ;
16+ readonly repositoryUrl ?: string ;
17+ readonly infrastructureName ?: string ;
1918 readonly submodels : SubmodelOrIdReference [ ] | null ;
20- readonly repositoryURL ?: string ;
2119 readonly className ?: string ;
2220} ;
2321
24- export function ActionMenu ( { aas, submodels, repositoryURL , className } : ActionMenuProps ) {
22+ export function ActionMenu ( { aas, submodels, className , infrastructureName , repositoryUrl } : ActionMenuProps ) {
2523 const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
2624 const navigate = useRouter ( ) ;
2725 const t = useTranslations ( 'pages' ) ;
2826 const env = useEnv ( ) ;
27+ const { spawn } = useNotificationSpawner ( ) ;
2928 const { showError } = useShowError ( ) ;
30- const currentAASContext = useCurrentAasContext ( ) ;
31- const [ showDownloadButton , setShowDownloadButton ] = useState ( false ) ;
3229
3330 const handleMenuOpen = ( event : React . MouseEvent < HTMLElement > ) => {
3431 setAnchorEl ( event . currentTarget ) ;
@@ -47,55 +44,49 @@ export function ActionMenu({ aas, submodels, repositoryURL, className }: ActionM
4744
4845 const goToAASView = ( ) => {
4946 if ( aas ?. id ) {
50- navigate . push ( `/viewer/${ encodeBase64 ( aas ?. id ) } ` ) ;
47+ navigate . push (
48+ `/viewer/${ encodeBase64 ( aas ?. id ) } ?repoUrl=${ encodeURIComponent ( repositoryUrl || '' ) } &infrastructure=${ infrastructureName || '' } ` ,
49+ ) ;
5150 }
5251 handleMenuClose ( ) ;
5352 } ;
5453
5554 async function downloadAAS ( ) {
56- if ( ! aas ?. id || ! currentAASContext . infrastructureName ) {
57- handleMenuClose ( ) ;
58- return ;
59- }
60- if ( ! repositoryURL ) {
61- showError ( t ( 'productViewer.actions.downloadErrorNoRepo' ) ) ;
62- handleMenuClose ( ) ;
55+ if ( ! aas ?. id || ! infrastructureName ) {
56+ showError ( t ( 'aasViewer.errors.downloadError' ) ) ;
6357 return ;
6458 }
6559 const submodelIds = Array . isArray ( submodels ) ? submodels . map ( ( s ) => s . id ) : [ ] ;
6660 try {
67- const response = await serializeAasFromInfrastructure (
68- aas ?. id ,
69- submodelIds ,
70- currentAASContext . infrastructureName ,
71- ) ;
61+ const response = await serializeAasFromInfrastructure ( aas ?. id , submodelIds , infrastructureName ) ;
7262 if ( response . isSuccess && response . result ) {
73- const url = window . URL . createObjectURL ( response . result . blob ) ;
63+ const { blob, endpointUrl, infrastructureName : infra } = response . result ;
64+ const url = window . URL . createObjectURL ( blob ) ;
7465 const link = document . createElement ( 'a' ) ;
7566 link . href = url ;
7667 link . setAttribute ( 'download' , `${ aas ?. idShort } .aasx` ) ;
7768 document . body . appendChild ( link ) ;
7869 link . click ( ) ;
7970 link . parentNode ?. removeChild ( link ) ;
8071 window . URL . revokeObjectURL ( url ) ;
72+
73+ // Show success message with endpoint information
74+ spawn ( {
75+ title : t ( 'aasViewer.actions.download' ) ,
76+ message : t ( 'aasViewer.messages.downloadSuccess' , {
77+ endpoint : endpointUrl ,
78+ infrastructure : infra ,
79+ } ) ,
80+ severity : 'success' ,
81+ } ) ;
8182 } else if ( ! response . isSuccess ) {
8283 showError ( response . message ) ;
8384 }
8485 } catch {
85- showError ( t ( 'productViewer.actions .downloadError' ) ) ;
86+ showError ( t ( 'aasViewer.errors .downloadError' ) ) ;
8687 }
87- handleMenuClose ( ) ;
8888 }
8989
90- useAsyncEffect ( async ( ) => {
91- if ( currentAASContext && currentAASContext . infrastructureName ) {
92- const serializationEndpointAvailable = await checkIfInfrastructureHasSerializationEndpoints (
93- currentAASContext . infrastructureName ,
94- ) ;
95- setShowDownloadButton ( serializationEndpointAvailable . isSuccess ) ;
96- }
97- } , [ ] ) ;
98-
9990 return (
10091 < >
10192 < IconButton
@@ -114,16 +105,14 @@ export function ActionMenu({ aas, submodels, repositoryURL, className }: ActionM
114105 { t ( 'productViewer.actions.compareButton' ) }
115106 </ MenuItem >
116107 ) }
117- { env . PRODUCT_VIEW_FEATURE_FLAG && (
108+ { env . EXPERIMENTAL_PRODUCT_VIEW_FEATURE_FLAG && (
118109 < MenuItem onClick = { goToAASView } data-testid = "detail-aas-view-button" >
119110 { t ( 'productViewer.actions.toAasView' ) }
120111 </ MenuItem >
121112 ) }
122- { showDownloadButton && (
123- < MenuItem onClick = { downloadAAS } data-testid = "detail-download-button" >
124- { t ( 'productViewer.actions.download' ) }
125- </ MenuItem >
126- ) }
113+ < MenuItem onClick = { downloadAAS } data-testid = "detail-download-button" >
114+ { t ( 'productViewer.actions.download' ) }
115+ </ MenuItem >
127116 </ Menu >
128117 </ >
129118 ) ;
0 commit comments