-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to authoring react in broadcasting (#4313)
- Loading branch information
Showing
8 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {authoringReactEnabledUserSelection, extensions, setAuthoringReact} from 'appConfig'; | ||
import {AUTHORING_REACT_FIELDS, registerAuthoringReactFields} from 'apps/authoring-react/fields/register-fields'; | ||
import { | ||
registerAuthoringReactWidgets, | ||
authoringReactWidgetsExtension, | ||
} from 'apps/authoring-react/manage-widget-registration'; | ||
import {unregisterInternalExtension} from 'core/helpers/register-internal-extension'; | ||
import {trimStartExact} from 'core/helpers/utils'; | ||
import {flatMap} from 'lodash'; | ||
import ng from 'core/services/ng'; | ||
|
||
/** | ||
* Enable authoring react in certain conditions | ||
*/ | ||
export const setupAuthoringReact = (url: string) => { | ||
const extensionUrls = flatMap( | ||
Object.values(extensions).map(({activationResult}) => activationResult), | ||
(activationResult) => activationResult.contributions?.pages ?? [], | ||
).map((page) => page.url); | ||
|
||
const parsedPath = new URL(url); | ||
const isNavigatingToAnExtensionPage = extensionUrls.find( | ||
(extensionUrl) => extensionUrl.startsWith(trimStartExact(parsedPath.hash, '#')), | ||
) != null; | ||
|
||
const action: 'register' | 'deregister' = (() => { | ||
if (isNavigatingToAnExtensionPage) { | ||
// regardless of user setting, authoring-react | ||
// must be enabled in extensions | ||
return 'register'; | ||
} else { | ||
// respect user setting | ||
return authoringReactEnabledUserSelection ? 'register' : 'deregister'; | ||
} | ||
})(); | ||
|
||
if (action === 'register') { | ||
setAuthoringReact(true); | ||
registerAuthoringReactWidgets(); | ||
registerAuthoringReactFields(); | ||
} else { | ||
setAuthoringReact(false); | ||
unregisterInternalExtension(authoringReactWidgetsExtension); | ||
unregisterInternalExtension(AUTHORING_REACT_FIELDS); | ||
} | ||
|
||
if (isNavigatingToAnExtensionPage) { | ||
ng.get('authoringWorkspace').close(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters