Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Oct 16, 2024
2 parents f706bed + bcdf22e commit 5b0e380
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/api/entities.v2/model/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class Entity {
);
}

changePropertyValue(property: Property, value: string) {
if (property.type === 'text') {
setPropertyValue(property: Property, value: string) {
if (property.type === 'text' || property.type === 'markdown') {
const isTitleProperty = property instanceof CommonProperty && property.name === 'title';
const { metadata } = this;
if (!(property instanceof CommonProperty)) {
Expand All @@ -80,17 +80,17 @@ export class Entity {
);
}

throw new Error('types other than string are not implemented yet');
throw new Error('types other than string/markdown are not implemented yet');
}

getPropertyValue(property: Property): string {
if (property.type === 'text') {
if (property.type === 'text' || property.type === 'markdown') {
const isTitleProperty = property instanceof CommonProperty && property.name === 'title';
if (isTitleProperty) return this.title;
return this.metadata[property.name][0].value as string;
}

throw new Error('types other than string are not implemented yet');
throw new Error('types other than string/markdown are not implemented yet');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class RequestEntityTranslation {
await entities.forEach(async fetchedEntity => {
if (languagesTo.includes(fetchedEntity.language as LanguageISO6391)) {
await this.entitiesDS.updateEntity(
fetchedEntity.changePropertyValue(property, pendingText)
fetchedEntity.setPropertyValue(property, pendingText)
);
this.logger.info(
`[AT] - Pending translation saved on DB - ${property.name}: ${pendingText}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SaveEntityTranslations {
}
if (translation?.success && property) {
const textTranslated = `${SaveEntityTranslations.AITranslatedText} ${translation.text}`;
await this.entitiesDS.updateEntity(entity.changePropertyValue(property, textTranslated));
await this.entitiesDS.updateEntity(entity.setPropertyValue(property, textTranslated));

this.logger.info(
`[AT] - Property saved on DB - ${JSON.stringify({ entityId: entity._id, language: entity.language, [property.name]: translation.text })}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ import { ATTaskMessage, RequestEntityTranslation } from '../RequestEntityTransla
const factory = getFixturesFactory();
const fixtures: DBFixture = {
templates: [
factory.template('template1', [factory.property('text1'), factory.property('empty_text')]),
factory.template('template1', [
factory.property('text1'),
factory.property('text2', 'markdown'),
factory.property('empty_text'),
]),
],
entities: [
...factory.entityInMultipleLanguages(['en', 'es', 'pt'], 'entity1', 'template1', {
text1: [{ value: 'original text1' }],
text2: [{ value: 'markdown text' }],
empty_text: [{ value: '' }],
}),
],
Expand All @@ -39,7 +44,11 @@ const fixtures: DBFixture = {
templates: [
{
template: factory.idString('template1'),
properties: [factory.idString('text1'), factory.idString('empty_text')],
properties: [
factory.idString('text1'),
factory.idString('text2'),
factory.idString('empty_text'),
],
commonProperties: [factory.commonPropertiesTitleId('template1')],
},
],
Expand Down Expand Up @@ -112,7 +121,7 @@ describe('RequestEntityTranslation', () => {
});

it('should send a task to the automatic translation service queue', () => {
expect(taskManager.startTask).toHaveBeenCalledTimes(2);
expect(taskManager.startTask).toHaveBeenCalledTimes(3);

expect(taskManager.startTask).toHaveBeenCalledWith({
key: ['tenant', 'entity1', factory.commonPropertiesTitleId('template1').toString()],
Expand All @@ -127,6 +136,13 @@ describe('RequestEntityTranslation', () => {
language_from: 'en',
languages_to: ['es', 'pt'],
});

expect(taskManager.startTask).toHaveBeenCalledWith({
key: ['tenant', 'entity1', factory.property('text2')._id?.toString()],
text: 'markdown text',
language_from: 'en',
languages_to: ['es', 'pt'],
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uwazi",
"version": "1.189.0-rc3",
"version": "1.189.0-rc4",
"description": "Uwazi is a free, open-source solution for organising, analysing and publishing your documents.",
"keywords": [
"react"
Expand Down

0 comments on commit 5b0e380

Please sign in to comment.