@@ -14,6 +14,7 @@ import { TransferableContext, buildTransferableContext } from '../common/transfe
1414import { useModal } from '../contexts/modal-context'
1515import { useMutableWeb } from '../contexts/mutable-web-context'
1616import { BuiltInLayoutManagers } from '../../constants'
17+ import { TargetService } from '../services/target/target.service'
1718
1819export const ContextManager : FC = ( ) => {
1920 return < ContextTree children = { ContextHandler } />
@@ -132,10 +133,33 @@ const InsPointHandler: FC<{
132133 const props = {
133134 // ToDo: unify context forwarding
134135 context : transferableContext ,
135- apps : apps . map ( ( app ) => ( {
136- id : app . id ,
137- metadata : app . metadata ,
138- } ) ) ,
136+ apps : apps
137+ . filter ( ( app ) => {
138+ const suitableNonStaticTargets = app . targets . filter (
139+ ( target ) => ! target . static && TargetService . isTargetMet ( target , context )
140+ )
141+
142+ if ( suitableNonStaticTargets . length === 0 ) {
143+ return false
144+ }
145+
146+ if ( suitableNonStaticTargets . some ( ( target ) => ! target . injectOnce ) ) {
147+ return true
148+ }
149+
150+ const injectedWidgets = allUserLinks . filter ( ( link ) => link . appId === app . id )
151+
152+ // ToDo: the similar logic is used in createLink
153+ const isThereInjectedWidgets = suitableNonStaticTargets
154+ . filter ( ( target ) => target . injectOnce )
155+ . some ( ( target ) => injectedWidgets . some ( ( link ) => link . insertionPoint === target . injectTo ) )
156+
157+ return ! isThereInjectedWidgets
158+ } )
159+ . map ( ( app ) => ( {
160+ id : app . id ,
161+ metadata : app . metadata ,
162+ } ) ) ,
139163 widgets : allUserLinks . map ( ( link ) => ( {
140164 linkId : link . id ,
141165 linkAuthorId : link . authorId ,
0 commit comments