11import {
22 Button ,
33 Chip ,
4+ Popover ,
5+ PopoverContent ,
6+ PopoverTrigger ,
47 Skeleton ,
58 tv ,
69 useCheckbox ,
@@ -10,11 +13,12 @@ import Icon from "../misc/icon";
1013import { ContextMenuState , Extension , PlatformEnum } from "@/lib/types" ;
1114import useExtensionManager from "@/lib/hooks/use-extension-manager" ;
1215import toast from "react-hot-toast" ;
13- import { useContext , useEffect , useState } from "react" ;
16+ import { use , useContext , useEffect , useState } from "react" ;
1417import ContextMenu from "../interface/context-menu" ;
1518import { EditorContext } from "../providers/editor-context-provider" ;
1619import { getPlatform } from "@/lib/platform-api/platform-checker" ;
1720import { getRemoteClientBaseURL } from "@/lib/module-federation/remote" ;
21+ import { getHostMFVersion } from "@/lib/module-federation/version" ;
1822
1923export default function ExtensionPreview ( {
2024 extension,
@@ -43,6 +47,15 @@ export default function ExtensionPreview({
4347
4448 const [ isShowInfo , setIsShowInfo ] = useState ( false ) ;
4549
50+ const [ hostMFVersion , setHostMFVersion ] = useState < string > ( "unknown" ) ;
51+ const [ showMFVersionInfo , setShowMFVersionInfo ] = useState ( false ) ;
52+
53+ useEffect ( ( ) => {
54+ getHostMFVersion ( ) . then ( ( version ) => {
55+ setHostMFVersion ( version ) ;
56+ } ) ;
57+ } , [ ] ) ;
58+
4659 useEffect ( ( ) => {
4760 setIsLoaded ( true ) ;
4861
@@ -99,8 +112,110 @@ export default function ExtensionPreview({
99112 { isInstalled && (
100113 < EnableCheckBox isActive = { isEnabled } onPress = { toggleExtension } />
101114 ) }
115+
116+ { extension . config . mfVersion === "unknown" ? (
117+ < Popover
118+ isOpen = { showMFVersionInfo }
119+ onOpenChange = { setShowMFVersionInfo }
120+ >
121+ < PopoverTrigger >
122+ < Button
123+ isIconOnly
124+ variant = "light"
125+ radius = "full"
126+ size = "sm"
127+ onMouseEnter = { ( e ) => {
128+ e . stopPropagation ( ) ;
129+ setShowMFVersionInfo ( true ) ;
130+ } }
131+ onMouseLeave = { ( e ) => {
132+ e . stopPropagation ( ) ;
133+ setShowMFVersionInfo ( false ) ;
134+ } }
135+ >
136+ < Icon name = "warning" className = "text-danger!" />
137+ </ Button >
138+ </ PopoverTrigger >
139+ < PopoverContent >
140+ < div className = "max-w-xs" >
141+ < p >
142+ This app is outdated and no longer a valid module
143+ federation app. Please update the app to the latest
144+ version.
145+ </ p >
146+ </ div >
147+ </ PopoverContent >
148+ </ Popover >
149+ ) : extension . config . mfVersion !== hostMFVersion ? (
150+ < Popover
151+ isOpen = { showMFVersionInfo }
152+ onOpenChange = { setShowMFVersionInfo }
153+ >
154+ < PopoverTrigger >
155+ < Button
156+ isIconOnly
157+ variant = "light"
158+ radius = "full"
159+ size = "sm"
160+ onMouseEnter = { ( e ) => {
161+ e . stopPropagation ( ) ;
162+ setShowMFVersionInfo ( true ) ;
163+ } }
164+ onMouseLeave = { ( e ) => {
165+ e . stopPropagation ( ) ;
166+ setShowMFVersionInfo ( false ) ;
167+ } }
168+ >
169+ < Icon name = "warning" className = "text-warning!" />
170+ </ Button >
171+ </ PopoverTrigger >
172+ < PopoverContent >
173+ < div className = "max-w-xs" >
174+ < p >
175+ This app's module federation version (
176+ { extension . config . mfVersion } ) does not match the host
177+ version ({ hostMFVersion } ). This may cause issues when
178+ using the app. Please update the app to the latest
179+ version.
180+ </ p >
181+ </ div >
182+ </ PopoverContent >
183+ </ Popover >
184+ ) : (
185+ < Popover
186+ isOpen = { showMFVersionInfo }
187+ onOpenChange = { setShowMFVersionInfo }
188+ >
189+ < PopoverTrigger >
190+ < Chip
191+ variant = "faded"
192+ color = "success"
193+ onMouseEnter = { ( e ) => {
194+ e . stopPropagation ( ) ;
195+ setShowMFVersionInfo ( true ) ;
196+ } }
197+ onMouseLeave = { ( e ) => {
198+ e . stopPropagation ( ) ;
199+ setShowMFVersionInfo ( false ) ;
200+ } }
201+ >
202+ Compatible
203+ </ Chip >
204+ </ PopoverTrigger >
205+ < PopoverContent >
206+ < div className = "max-w-xs" >
207+ < p >
208+ This app's module federation version (
209+ { extension . config . mfVersion } ) matches the host version (
210+ { hostMFVersion } ). The app should work correctly.
211+ </ p >
212+ </ div >
213+ </ PopoverContent >
214+ </ Popover >
215+ ) }
102216 </ div >
103217 </ div >
218+
104219 < Button
105220 className = "relative m-0 h-full w-full rounded-md p-0"
106221 onPress = { ( ) => {
0 commit comments