From 7604ef1081fc6b54f3d1e8408c331bdfdcbc4d54 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Thu, 24 Aug 2023 16:02:16 +0300 Subject: [PATCH] Switch to authoring react in broadcasting (#4313) --- scripts/appConfig.ts | 13 ++++- .../fields/linked-items/index.tsx | 20 ++++---- .../authoring-react/fields/register-fields.ts | 4 +- .../manage-widget-registration.ts | 2 +- .../MetaDataDropdownSingleSelectReact.tsx | 4 +- scripts/core/menu/authoring-switch.ts | 50 +++++++++++++++++++ scripts/core/menu/menu.ts | 11 +++- scripts/extensions/broadcasting/src/page.tsx | 10 ++-- 8 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 scripts/core/menu/authoring-switch.ts diff --git a/scripts/appConfig.ts b/scripts/appConfig.ts index 52482aa1d0..1d0edb842f 100644 --- a/scripts/appConfig.ts +++ b/scripts/appConfig.ts @@ -46,6 +46,15 @@ export const debugInfo = { translationsLoaded: false, }; -// -export const authoringReactViewEnabled = localStorage.getItem('authoring-react-enabled') != null; +export const authoringReactEnabledUserSelection = false; + +/** + * Authoring react has to be enabled in the broadcasting + * module regardless of the user selection. + * */ +export let authoringReactViewEnabled = true; export const uiFrameworkAuthoringPanelTest = false; + +export function setAuthoringReact(enabled: boolean) { + authoringReactViewEnabled = enabled; +} diff --git a/scripts/apps/authoring-react/fields/linked-items/index.tsx b/scripts/apps/authoring-react/fields/linked-items/index.tsx index b2bbb27ac5..1de70676bf 100644 --- a/scripts/apps/authoring-react/fields/linked-items/index.tsx +++ b/scripts/apps/authoring-react/fields/linked-items/index.tsx @@ -37,15 +37,17 @@ export function getLinkedItemsField(): ILinkedItemsField { contributions: { authoring: { onCloseAfter: (item) => { - const itemId = item._id; - const storedItemId = sdApi.localStorage.getItem(`open-item-after-related-closed--${itemId}`); - - /** - * If related item was just created and saved, open the original item - * that triggered the creation of this related item. - */ - if (storedItemId != null) { - openArticle(storedItemId, 'edit'); + if (item?._id != null) { + const itemId = item._id; + const storedItemId = sdApi.localStorage.getItem(`open-item-after-related-closed--${itemId}`); + + /** + * If related item was just created and saved, open the original item + * that triggered the creation of this related item. + */ + if (storedItemId != null) { + openArticle(storedItemId, 'edit'); + } } }, }, diff --git a/scripts/apps/authoring-react/fields/register-fields.ts b/scripts/apps/authoring-react/fields/register-fields.ts index d72f4cf16e..f379ea7166 100644 --- a/scripts/apps/authoring-react/fields/register-fields.ts +++ b/scripts/apps/authoring-react/fields/register-fields.ts @@ -17,6 +17,8 @@ import {getArticlesInPackageField} from './package-items'; import {getTagInputField} from './tag-input'; import {getDatelineField} from './dateline'; +export const AUTHORING_REACT_FIELDS = 'authoring-react--fields'; + export function registerAuthoringReactFields() { const result: IExtensionActivationResult = { contributions: { @@ -57,5 +59,5 @@ export function registerAuthoringReactFields() { }, }; - registerInternalExtension('authoring-react--fields', result); + registerInternalExtension(AUTHORING_REACT_FIELDS, result); } diff --git a/scripts/apps/authoring-react/manage-widget-registration.ts b/scripts/apps/authoring-react/manage-widget-registration.ts index d5bbc5f449..d42e72c4fd 100644 --- a/scripts/apps/authoring-react/manage-widget-registration.ts +++ b/scripts/apps/authoring-react/manage-widget-registration.ts @@ -12,7 +12,7 @@ import {getMacrosWidget} from './macros/macros'; import {getPackagesWidget} from './packages'; import {getMetadataWidget} from './article-widgets/metadata/metadata'; -const authoringReactWidgetsExtension = 'authoring-react-widgets'; +export const authoringReactWidgetsExtension = 'authoring-react-widgets'; export function registerAuthoringReactWidgets() { const sidebarWidgets: IExtensionActivationResult['contributions']['authoringSideWidgets'] = [ diff --git a/scripts/apps/authoring/metadata/views/MetaDataDropdownSingleSelectReact.tsx b/scripts/apps/authoring/metadata/views/MetaDataDropdownSingleSelectReact.tsx index 4e77d80d50..84f72d0cb8 100644 --- a/scripts/apps/authoring/metadata/views/MetaDataDropdownSingleSelectReact.tsx +++ b/scripts/apps/authoring/metadata/views/MetaDataDropdownSingleSelectReact.tsx @@ -25,7 +25,7 @@ export class MetaDataDropdownSingleSelectReact extends React.PureComponent