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

I18N-1297 - Temporarily block third-party sync for a Text Unit Variant #165

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public enum Status {

MT_REVIEW,
/** A string that doesn't need any work to be performed on it. */
APPROVED;
APPROVED,
/** It was overridden in Mojito, so it won't be updated during third-party sync */
OVERRIDDEN;
};

@Column(name = "content", length = Integer.MAX_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ public AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
TMTextUnitVariant.Status status,
boolean includedInLocalizedFile,
ZonedDateTime createdDate,
User createdBy) {
User createdBy,
boolean checkOverridden) {

boolean noUpdate = false;

Expand Down Expand Up @@ -604,16 +605,20 @@ public AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
} else {
logger.debug("There is a current text unit variant, check if an update is needed");
TMTextUnitVariant currentTmTextUnitVariant = tmTextUnitCurrentVariant.getTmTextUnitVariant();
boolean overridden =
checkOverridden
&& currentTmTextUnitVariant.getStatus() == TMTextUnitVariant.Status.OVERRIDDEN;
boolean updateNeeded =
isUpdateNeededForTmTextUnitVariant(
currentTmTextUnitVariant.getStatus(),
currentTmTextUnitVariant.getContentMD5(),
currentTmTextUnitVariant.isIncludedInLocalizedFile(),
currentTmTextUnitVariant.getComment(),
status,
DigestUtils.md5Hex(content),
includedInLocalizedFile,
comment);
!overridden
&& isUpdateNeededForTmTextUnitVariant(
currentTmTextUnitVariant.getStatus(),
currentTmTextUnitVariant.getContentMD5(),
currentTmTextUnitVariant.isIncludedInLocalizedFile(),
currentTmTextUnitVariant.getComment(),
status,
DigestUtils.md5Hex(content),
includedInLocalizedFile,
comment);

if (updateNeeded) {
logger.debug(
Expand All @@ -638,14 +643,43 @@ public AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
tmTextUnitCurrentVariantRepository.save(tmTextUnitCurrentVariant);
} else {
logger.debug(
"The current text unit variant has same content, comment and review status, don't add entities and return it instead");
overridden
? "The current text unit variant is kept because it has the OVERRIDDEN status"
: "The current text unit variant has same content, comment and review status, don't add entities and return it instead");
noUpdate = true;
}
}

return new AddTMTextUnitCurrentVariantResult(!noUpdate, tmTextUnitCurrentVariant);
}

public AddTMTextUnitCurrentVariantResult addTMTextUnitCurrentVariantWithResult(
Copy link
Author

@DarKhaos DarKhaos Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method with existing parameters and behavior (checkTranslatedInMojito set to false)

TMTextUnitCurrentVariant tmTextUnitCurrentVariant,
Long tmId,
Long assetId,
Long tmTextUnitId,
Long localeId,
String content,
String comment,
TMTextUnitVariant.Status status,
boolean includedInLocalizedFile,
ZonedDateTime createdDate,
User createdBy) {
return this.addTMTextUnitCurrentVariantWithResult(
tmTextUnitCurrentVariant,
tmId,
assetId,
tmTextUnitId,
localeId,
content,
comment,
status,
includedInLocalizedFile,
createdDate,
createdBy,
false);
}

/**
* Indicates if a {@link TMTextUnitVariant} should be updated by looking at new/old content,
* status, comments, etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void importTextUnitsOfLocaleAndAsset(
textUnitForBatchImport.getStatus(),
textUnitForBatchImport.isIncludedInLocalizedFile(),
importTime,
importedBy);
importedBy,
true);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not update text unit variants with TRANSLATED_IN_MOJITO status


if (addTMTextUnitCurrentVariantResult.isTmTextUnitCurrentVariantUpdated()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ public enum StatusFilter {
* TextUnits that are not rejected, ie {@link TMTextUnitVariant#includedInLocalizedFile} is true.
*/
NOT_REJECTED,
/** TextUnits with status ({@link TMTextUnitVariant.Status#OVERRIDDEN}). */
OVERRIDDEN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ NativeCriteria getCriteriaForSearch(TextUnitSearcherParameters searchParameters)
"tuv.status", TMTextUnitVariant.Status.TRANSLATION_NEEDED.toString()),
new NativeEqExpFix("tuv.included_in_localized_file", Boolean.FALSE))));
break;
case OVERRIDDEN:
conjunction.add(
new NativeEqExpFix("tuv.status", TMTextUnitVariant.Status.OVERRIDDEN.toString()));
break;
default:
throw new RuntimeException("Filter type not implemented");
}
Expand Down
1 change: 0 additions & 1 deletion webapp/src/main/resources/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,3 @@ spring.session.jdbc.table-name=SPRING_SESSION_V2
# l10n.pagerduty.retry.minBackOffDelay=500
# Maximum back off delay in milliseconds
# l10n.pagerduty.retry.maxBackOffDelay=5000

6 changes: 6 additions & 0 deletions webapp/src/main/resources/properties/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ search.statusDropdown.needsReview=Needs Review
# Status filter option to search for text units that need to be translated
search.statusDropdown.forTranslation=Needs Translation

# Status filter option to search for text units that are overridden in Mojito
search.statusDropdown.overridden=Overridden

# Status filter option to search for text units that are rejected (won't be added in localized file)
search.statusDropdown.rejected=Rejected

Expand Down Expand Up @@ -325,6 +328,9 @@ textUnit.reviewModal.rejected=Rejected
# Button label used for primary action "removeReview" on modal dialog
textUnit.reviewModal.accepted=Accepted

# Label for Overridden button on modal dialog
textUnit.reviewModal.overridden=Overridden

# Button label used for the Needs Review button on the textunit review modal
textUnit.reviewModal.needsReview=Needs Review

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ let StatusDropdown = createReactClass({
},

setStateAndCallSearchParamChanged(searchFilterParam, searchFilterParamValue) {

let state = {};

state[searchFilterParam] = searchFilterParamValue;

this.setState(state, function () {
Expand Down Expand Up @@ -170,6 +170,8 @@ let StatusDropdown = createReactClass({
return this.props.intl.formatMessage({ id: "search.statusDropdown.needsReview" });
case SearchParamsStore.STATUS.REJECTED:
return this.props.intl.formatMessage({ id: "search.statusDropdown.rejected" });
case SearchParamsStore.STATUS.OVERRIDDEN:
return this.props.intl.formatMessage({ id: "search.statusDropdown.overridden" });
}
},

Expand Down Expand Up @@ -263,6 +265,7 @@ let StatusDropdown = createReactClass({
{this.renderStatusMenuItem(SearchParamsStore.STATUS.FOR_TRANSLATION)}
{this.renderStatusMenuItem(SearchParamsStore.STATUS.REVIEW_NEEDED)}
{this.renderStatusMenuItem(SearchParamsStore.STATUS.REJECTED)}
{this.renderStatusMenuItem(SearchParamsStore.STATUS.OVERRIDDEN)}

<MenuItem divider />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ let TextUnit = createReactClass({
textUnit.setIncludedInLocalizedFile(true);
textUnit.setStatus(TextUnitSDK.STATUS.TRANSLATION_NEEDED);
break;
case "overridden":
textUnit.setIncludedInLocalizedFile(true);
textUnit.setStatus(TextUnitSDK.STATUS.OVERRIDDEN);
break;
}

WorkbenchActions.saveTextUnit(textUnit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class TextUnitsreviewModal extends React.Component {
this.REVIEW = "review";
this.REJECT = "reject";
this.ACCEPT = "accept";
this.TRANSLATE = "translate";
this.TRANSLATE = "translate"
this.OVERRIDDEN = "overridden";

this.state = {
"currentReviewState": this.getInitialReviewStateOfTextUnits(),
Expand Down Expand Up @@ -99,6 +100,15 @@ class TextUnitsreviewModal extends React.Component {
);
};

getOverriddenButton = () => {
return (
<Button active={this.state.currentReviewState === this.OVERRIDDEN}
onClick={this.optionClicked.bind(this, this.OVERRIDDEN)}>
<FormattedMessage id="textUnit.reviewModal.overridden"/>
</Button>
);
};

/**
* @returns {JSX} The JSX for the translate button with class active set according to the current component state
*/
Expand Down Expand Up @@ -166,6 +176,8 @@ class TextUnitsreviewModal extends React.Component {
currentReviewState = this.REVIEW;
} else if (textUnit.getStatus() === TextUnit.STATUS.TRANSLATION_NEEDED) {
currentReviewState = this.TRANSLATE;
} else if (textUnit.getStatus() === TextUnit.STATUS.OVERRIDDEN) {
currentReviewState = this.OVERRIDDEN;
}

}
Expand Down Expand Up @@ -216,6 +228,7 @@ class TextUnitsreviewModal extends React.Component {
{this.getTranslateButton()}
{this.getReviewButton()}
{this.getAcceptButton()}
{this.getOverriddenButton()}
</ButtonGroup>
</ButtonToolbar>
</Modal.Body>
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/main/resources/public/js/sdk/TextUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,6 @@ TextUnit.STATUS = {
"TRANSLATION_NEEDED": "TRANSLATION_NEEDED",
"REVIEW_NEEDED": "REVIEW_NEEDED",
"APPROVED": "APPROVED",
"REJECTED": "REJECTED"
"REJECTED": "REJECTED",
"OVERRIDDEN": "OVERRIDDEN",
};
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ SearchParamsStore.STATUS = {
* TextUnits that are not rejected, ie includedInLocalizedFile is true.
*/
"NOT_REJECTED": "NOT_REJECTED",

/**
* TextUnits with status OVERRIDDEN.
*/
"OVERRIDDEN": "OVERRIDDEN",
};

export default alt.createStore(SearchParamsStore, 'SearchParamsStore');
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.box.l10n.mojito.service.tm.search.TextUnitDTO;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcher;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParameters;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParametersForTesting;
import com.box.l10n.mojito.test.TestIdWatcher;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
Expand Down Expand Up @@ -4756,4 +4757,55 @@ public void testLocalizeHtmlFilter() throws Exception {
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">", "");
assertEquals(assetContent, localizedAsset);
}

@Test
public void testAddTMTextUnitWithOverriddenStatus() throws RepositoryNameAlreadyUsedException {
createTestData();

Long textUnitId =
addTextUnitAndCheck(
this.tmId,
this.assetId,
"name",
"this is the content",
"some comment",
"3063c39d3cf8ab69bcabbbc5d7187dc9",
"cf8ea6b6848f23345648038bc3abf324");

Locale targetLocale = this.localeService.findByBcp47Tag("fr-FR");

this.tmService.addTMTextUnitCurrentVariant(
textUnitId,
targetLocale.getId(),
"this is the new content",
"some comment",
TMTextUnitVariant.Status.OVERRIDDEN,
true);

TextUnitSearcherParameters textUnitSearcherParameters =
new TextUnitSearcherParametersForTesting();
textUnitSearcherParameters.setRepositoryNames(
Collections.singletonList(this.repository.getName()));
textUnitSearcherParameters.setAssetPath(this.asset.getPath());
textUnitSearcherParameters.setLocaleTags(List.of(targetLocale.getBcp47Tag()));

TextUnitDTO textUnitDTOFromSearch =
this.textUnitSearcher.search(textUnitSearcherParameters).getFirst();

assertEquals("this is the new content", textUnitDTOFromSearch.getTarget());
assertEquals(TMTextUnitVariant.Status.OVERRIDDEN, textUnitDTOFromSearch.getStatus());

this.tmService.addTMTextUnitCurrentVariant(
textUnitId,
targetLocale.getId(),
"this is the newest content",
"some comment",
TMTextUnitVariant.Status.APPROVED,
true);

textUnitDTOFromSearch = this.textUnitSearcher.search(textUnitSearcherParameters).getFirst();

assertEquals("this is the newest content", textUnitDTOFromSearch.getTarget());
assertEquals(TMTextUnitVariant.Status.APPROVED, textUnitDTOFromSearch.getStatus());
}
}
Loading