Skip to content

Commit

Permalink
Toolbar refactoring improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Aug 14, 2023
1 parent a66075e commit 22ccb6d
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
9 changes: 6 additions & 3 deletions scripts/api/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {IPublishingDateOptions} from 'core/interactive-article-actions-panel/sub
import {notify} from 'core/notify/notify';
import ng from 'core/services/ng';
import {gettext} from 'core/utils';
import {flatMap, keys, pick, trim, union} from 'lodash';
import {flatMap, keys, pick, trim} from 'lodash';
import {IArticle, IDangerousArticlePatchingOptions, IDesk, IStage, onPublishMiddlewareResult} from 'superdesk-api';
import {duplicateItems} from './article-duplicate';
import {fetchItems, fetchItemsToCurrentDesk} from './article-fetch';
Expand Down Expand Up @@ -426,7 +426,10 @@ function edit(
function getItemPatchWithKillOrTakedownTemplate(item: IArticle, action: IArticleAction): Promise<IArticle> {
const itemForTemplate = {
template_name: action,
item: pick(item, union(keys(CONTENT_FIELDS_DEFAULTS), ['_id', 'versioncreated', 'task'])),
item: pick(
item,
[...(keys(CONTENT_FIELDS_DEFAULTS)), '_id', 'versioncreated', 'task'],
),
};

return httpRequestJsonLocal({
Expand All @@ -436,7 +439,7 @@ function getItemPatchWithKillOrTakedownTemplate(item: IArticle, action: IArticle
}).then((result: IArticle) => {
return {
...result,
...(action === 'kill' && {operation: 'kill'}),
...(action === 'kill' ? {operation: 'kill'} : {}),
state: ITEM_STATE.PUBLISHED,
};
});
Expand Down
20 changes: 9 additions & 11 deletions scripts/apps/authoring-react/authoring-angular-integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function getInlineToolbarActions(
priority: 0.1,
component: () => (
<Button
tooltip={gettext('CORRECT')}
tooltip={gettext('Correct')}
text={gettext('C')}
style="filled"
type="primary"
Expand Down Expand Up @@ -271,7 +271,7 @@ function getInlineToolbarActions(
style="filled"
type="primary"
onClick={() => {
ng.get('authoringWorkspace').authoringOpen(item._id, 'kill');
ng.get('authoringWorkspace').authoringOpen(item._id, 'takedown');
}}
/>
),
Expand All @@ -283,7 +283,7 @@ function getInlineToolbarActions(
priority: 0.1,
component: () => (
<Button
tooltip={gettext('UNPUBLISH')}
tooltip={gettext('Unpublish')}
text={'UP'}
style="filled"
type="primary"
Expand Down Expand Up @@ -318,7 +318,7 @@ function getInlineToolbarActions(
</Spacer>
)}
>
Are you sure you want to unpublish item &quot;{getItemLabel(item)}&quot;?
{gettext('Are you sure you want to unpublish item "{{label}}"?', {label: getItemLabel(item)})}
</Modal>
));
}}
Expand Down Expand Up @@ -370,13 +370,11 @@ function getInlineToolbarActions(
style="filled"
type="primary"
onClick={() => {
sdApi.article.get(item._id).then((originalArticle) => {
handleUnsavedChanges()
.then(() => {
sdApi.article.publishItem(item, {...entity, _etag: originalArticle._etag}, 'kill');
})
.then(() => initiateClosing());
});
handleUnsavedChanges()
.then(() => {
sdApi.article.publishItem(item, {...entity}, 'kill');
})
.then(() => initiateClosing());
}}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion scripts/apps/authoring-react/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export const getAuthoringStorageIArticleKillOrTakedown = (action: IArticleAction
return {
saved: {
...updated,
original_creator: saved.original_creator,
...saved, // updated is missing original_creator property so we get it from the saved article
},
autosaved: autosaved,
};
Expand Down
4 changes: 2 additions & 2 deletions scripts/apps/authoring-react/field-adapters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function storeEditor3ValueBase(
article: IArticle,
value: any, // IEditor3ValueStorage
config: IEditor3Config,
planeTextInMultiLineMode?: boolean,
plainTextInMultiLineMode?: boolean,
)
: {article: IArticle; stringValue: string; annotations: Array<any>} {
const rawContentState = value.rawContentState;
Expand All @@ -156,7 +156,7 @@ export function storeEditor3ValueBase(
rawContentState,
config,
article.language,
planeTextInMultiLineMode,
plainTextInMultiLineMode,
);

const articleUpdated: IArticle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export function computeEditor3Output(
rawContentState: RawDraftContentState,
config: IEditor3Config,
language: string,
planeTextInMultiLineMode?: boolean,

// return multi line text for fields with '\n'
plainTextInMultiLineMode?: boolean,
): IEditor3Output {
const contentState: ContentState = createEditorStore(
{
Expand All @@ -21,7 +23,7 @@ export function computeEditor3Output(
).getState().editorState.getCurrentContent();

const generatedValue = (() => {
if (config.singleLine || planeTextInMultiLineMode) {
if (config.singleLine || plainTextInMultiLineMode) {
return contentState.getPlainText();
} else {
return editor3StateToHtml(contentState);
Expand Down
2 changes: 1 addition & 1 deletion scripts/apps/authoring-react/fields/linked-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getLinkedItemsField(): ILinkedItemsField {
contributions: {
authoring: {
onCloseAfter: (item) => {
const itemId = item?._id;
const itemId = item._id;
const storedItemId = sdApi.localStorage.getItem(`open-item-after-related-closed--${itemId}`);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ export class PublishTab extends React.PureComponent<IProps, IState> {
cloneDeep(itemToPublish),
'publish',
this.props.onError,
)
.then(() => {
ng.get('authoringWorkspace').close();
notify.success('Item published.');
});
);
});
})
.catch(() => {
Expand Down

0 comments on commit 22ccb6d

Please sign in to comment.