Skip to content

Commit

Permalink
Authoring-react keybindings (#4196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonidoo authored Feb 7, 2023
1 parent 36736f1 commit af644e4
Show file tree
Hide file tree
Showing 16 changed files with 469 additions and 288 deletions.
21 changes: 20 additions & 1 deletion scripts/apps/authoring-react/authoring-angular-integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ function getInlineToolbarActions(options: IExposedFromAuthoring<IArticle>): IAut
/>
),
availableOffline: true,
keyBindings: {
'ctrl+shift+s': () => {
if (hasUnsavedChanges()) {
save();
}
},
},
};

const closeButton: ITopBarWidget<IArticle> = {
Expand All @@ -72,6 +79,11 @@ function getInlineToolbarActions(options: IExposedFromAuthoring<IArticle>): IAut
/>
),
availableOffline: true,
keyBindings: {
'ctrl+shift+e': () => {
initiateClosing();
},
},
};

const minimizeButton: ITopBarWidget<IArticle> = {
Expand Down Expand Up @@ -146,7 +158,6 @@ function getInlineToolbarActions(options: IExposedFromAuthoring<IArticle>): IAut
actions.push(getManageHighlights());
}


// eslint-disable-next-line no-case-declarations
const manageDesksButton: ITopBarWidget<IArticle> = ({
group: 'start',
Expand Down Expand Up @@ -196,8 +207,16 @@ function getInlineToolbarActions(options: IExposedFromAuthoring<IArticle>): IAut
unlock={() => {
stealLock();
}}
isLockedInOtherSession={(article) => sdApi.article.isLockedInOtherSession(article)}
/>
),
keyBindings: {
'ctrl+shift+u': () => {
if (sdApi.article.isLockedInOtherSession(item)) {
stealLock();
}
},
},
availableOffline: false,
});

Expand Down
83 changes: 46 additions & 37 deletions scripts/apps/authoring-react/authoring-integration-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,23 @@ import {CompareArticleVersionsModal} from './toolbar/compare-article-versions';
import {httpRequestJsonLocal} from 'core/helpers/network';
import {getArticleAdapter} from './article-adapter';
import {ui} from 'core/ui-utils';
import TranslateModal from './toolbar/translate-modal';
import {MarkForDesksModal} from './toolbar/mark-for-desks/mark-for-desks-modal';

function getAuthoringActionsFromExtensions(
item: IArticle,
contentProfile: IContentProfileV2,
fieldsData: Map<string, unknown>,
): Promise<Array<IAuthoringAction>> {
): Array<IAuthoringAction> {
const actionGetters
: Array<IExtensionActivationResult['contributions']['getAuthoringActions']>
= flatMap(
Object.values(extensions),
(extension) => extension.activationResult.contributions?.getAuthoringActions ?? [],
);

return Promise.all(actionGetters.map((getPromise) => getPromise(item, contentProfile, fieldsData)))
.then((res) => {
return flatMap(res);
});
return flatMap(
actionGetters.map((getPromise) => getPromise(item, contentProfile, fieldsData)),
);
}

const defaultToolbarItems: Array<React.ComponentType<{article: IArticle}>> = [CreatedModifiedInfo];
Expand Down Expand Up @@ -183,18 +181,27 @@ const getExportModal = (
});

const getHighlightsAction = (getItem: () => IArticle): IAuthoringAction => {
const showHighlightsModal = () => {
showModal(({closeModal}) => {
return (
<HighlightsModal
article={getItem()}
closeModal={closeModal}
/>
);
});
};

return {
label: gettext('Highlights'),
onTrigger: () => (
showModal(({closeModal}) => {
return (
<HighlightsModal
article={getItem()}
closeModal={closeModal}
/>
);
})
showHighlightsModal()
),
keyBindings: {
'ctrl+shift+h': () => {
showHighlightsModal();
},
},
};
};

Expand All @@ -212,7 +219,6 @@ const getSaveAsTemplate = (getItem: () => IArticle): IAuthoringAction => ({
),
});


const getTranslateModal = (getItem: () => IArticle): IAuthoringAction => ({
label: gettext('Translate'),
onTrigger: () => {
Expand Down Expand Up @@ -375,28 +381,28 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
fieldsAdapter,
storageAdapter,
}) => {
return Promise.all([
getAuthoringActionsFromExtensions(item, contentProfile, fieldsData),
getArticleActionsFromExtensions(item),
]).then((res) => {
const [authoringActionsFromExtensions, articleActionsFromExtensions] = res;

return [
getSaveAsTemplate(getLatestItem),
getCompareVersionsModal(
getLatestItem,
authoringStorage,
fieldsAdapter,
storageAdapter,
),
getHighlightsAction(getLatestItem),
getMarkedForDesksModal(getLatestItem),
getExportModal(getLatestItem, handleUnsavedChanges, hasUnsavedChanges),
getTranslateModal(getLatestItem),
...authoringActionsFromExtensions,
...articleActionsFromExtensions,
];
});
const authoringActionsFromExtensions = getAuthoringActionsFromExtensions(
item,
contentProfile,
fieldsData,
);
const articleActionsFromExtensions = getArticleActionsFromExtensions(item);

return [
getSaveAsTemplate(getLatestItem),
getCompareVersionsModal(
getLatestItem,
authoringStorage,
fieldsAdapter,
storageAdapter,
),
getHighlightsAction(getLatestItem),
getMarkedForDesksModal(getLatestItem),
getExportModal(getLatestItem, handleUnsavedChanges, hasUnsavedChanges),
getTranslateModal(getLatestItem),
...authoringActionsFromExtensions,
...articleActionsFromExtensions,
];
}}
getInlineToolbarActions={this.props.getInlineToolbarActions}
getAuthoringTopBarWidgets={
Expand Down Expand Up @@ -473,6 +479,9 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
getSidebar={this.state.isSidebarCollapsed ? null : getSidebar}
topBar2Widgets={topbar2WidgetsReady}
validateBeforeSaving={false}
getSideWidgetNameAtIndex={(article, index) => {
return getWidgetsFromExtensions(article)[index].label;
}}
/>
);
}}
Expand Down
Loading

0 comments on commit af644e4

Please sign in to comment.