Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI translations #4531

Merged
merged 18 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/api/article-patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const patchArticle = (
if (dangerousOptions?.patchDirectlyAndOverwriteAuthoringValues === true) {
dispatchInternalEvent(
'dangerouslyOverwriteAuthoringData',
{...patch, _etag: res._etag, _id: res._id},
{item: {...patch, _etag: res._etag, _id: res._id}},
);
}
});
Expand Down
4 changes: 2 additions & 2 deletions scripts/apps/authoring-react/authoring-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ export class AuthoringReact<T extends IBaseRestApiResponse> extends React.PureCo
addInternalEventListener(
'dangerouslyOverwriteAuthoringData',
(event) => {
if (event.detail._id === this.props.itemId) {
const patch = event.detail;
if (event.detail.item._id === this.props.itemId) {
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
const patch = event.detail.item;

const {state} = this;

Expand Down
16 changes: 12 additions & 4 deletions scripts/apps/authoring/authoring/directives/AuthoringDirective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,18 @@ export function AuthoringDirective(
const removeListener = addInternalEventListener(
'dangerouslyOverwriteAuthoringData',
(event) => {
if (event.detail._id === $scope.item._id) {
angular.extend($scope.item, event.detail);
angular.extend($scope.origItem, event.detail);
$scope.$apply();
if (event.detail.item._id === $scope.item._id) {
angular.extend($scope.item, event.detail.item);

if (event.detail.setDirty == false) {
angular.extend($scope.origItem, event.detail.item);
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
}

if (event.detail.setDirty === true) {
$scope.dirty = true;
}

$scope.$applyAsync();
$scope.refresh();
}
},
Expand Down
3 changes: 3 additions & 0 deletions scripts/core/get-superdesk-api-implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ export function getSuperdeskApiImplementation(
addImage: (field: string, image: IArticle) => {
dispatchInternalEvent('addImage', {field, image});
},
applyChangesToEditor: (item: IArticle, setDirty?: boolean) => {
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
dispatchInternalEvent('dangerouslyOverwriteAuthoringData', {item, setDirty});
},
save: () => {
dispatchInternalEvent('saveArticleInEditMode', null);
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/core/internal-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IInternalEvents {
image: IArticle;
};
saveArticleInEditMode: void;
dangerouslyOverwriteAuthoringData: Partial<IArticle>;
dangerouslyOverwriteAuthoringData: {item: Partial<IArticle>; setDirty?: boolean};
replaceAuthoringDataWithChanges: Partial<unknown>;

/**
Expand Down
4 changes: 2 additions & 2 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ declare module 'superdesk-api' {
onPublish?(item: IArticle): Promise<onPublishMiddlewareResult>;
onRewriteAfter?(item: IArticle): Promise<IArticle>;
onSendBefore?(items: Array<IArticle>, desk: IDesk): Promise<void>;
onTranslateAfter(original: IArticle, translation: IArticle): void;
onTranslateAfter?(original: IArticle, translation: IArticle): void;
};
ingest?: {
ruleHandlers?: {[key: string]: IIngestRuleHandlerExtension};
Expand Down Expand Up @@ -2767,7 +2767,7 @@ declare module 'superdesk-api' {
): void;
// This isn't implemented for all fields accepting images.
addImage(field: string, image: IArticle): void;

applyChangesToEditor(item: IArticle, setDirty?: boolean): void;
tomaskikutis marked this conversation as resolved.
Show resolved Hide resolved
/**
* Programmatically triggers saving of an article in edit mode.
* Runs the same code as if "save" button was clicked manually.
Expand Down
6 changes: 1 addition & 5 deletions scripts/extensions/ai-widget/src/headlines/headlines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ export default class HeadlinesBody extends React.Component<IProps> {
),
));
} else {
superdesk.entities.article.patch(
article,
{headline},
{patchDirectlyAndOverwriteAuthoringValues: true},
);
superdesk.ui.article.applyChangesToEditor({...article, headline}, true);
}
}}
type="default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ export default class TranslationsBody extends React.Component<IProps, IState> {
),
));
} else {
superdesk.entities.article.patch(
article,
{body_html: translation},
{patchDirectlyAndOverwriteAuthoringValues: true},
);
superdesk.ui.article.applyChangesToEditor({...article, body_html: translation}, true);
}
}}
size="small"
Expand Down
Loading