Skip to content

Commit

Permalink
Fix bug 1518820: Add errors and warnings (#1266)
Browse files Browse the repository at this point in the history
Also:
- Re-run checks on approval: reviewers should also see ignored checks
- Disable all checks for the tutorial project (not just TTK)
- Simplification: All User instances have a corresponding UserProfile instance
  • Loading branch information
mathjazz committed Apr 23, 2019
1 parent db63c40 commit f1ea6a2
Show file tree
Hide file tree
Showing 19 changed files with 816 additions and 113 deletions.
11 changes: 11 additions & 0 deletions frontend/public/static/locale/en-US/translate.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ editor-editor-button-save = Save
editor-editor-button-suggest = Suggest
## Failed Checks
## Renders the failed checks popup

editor-settings-toolkit-checks = ×
.aria-label = Close failed checks popup
editor-FailedChecks--title = The following checks have failed
editor-FailedChecks--save-anyway = Save anyway
editor-FailedChecks--suggest-anyway = Suggest anyway
editor-FailedChecks--approve-anyway = Approve anyway
## EditorSettings
## Shows options to update user settings regarding the editor.

Expand Down
16 changes: 13 additions & 3 deletions frontend/src/core/api/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class TranslationAPI extends APIBase {
pluralForm: number,
original: string,
forceSuggestions: boolean,
ignoreWarnings: ?boolean,
) {
const csrfToken = this.getCSRFToken();

Expand All @@ -27,6 +28,11 @@ export default class TranslationAPI extends APIBase {
payload.append('plural_form', pluralForm.toString());
payload.append('original', original);
payload.append('force_suggestions', forceSuggestions.toString());

if (ignoreWarnings) {
payload.append('ignore_warnings', ignoreWarnings.toString());
}

payload.append('csrfmiddlewaretoken', csrfToken);

const headers = new Headers();
Expand All @@ -37,7 +43,7 @@ export default class TranslationAPI extends APIBase {
return this.fetch('/update/', 'POST', payload, headers);
}

_changeStatus(url: string, id: number, resource: string) {
_changeStatus(url: string, id: number, resource: string, ignoreWarnings: ?boolean) {
const csrfToken = this.getCSRFToken();

const payload = new URLSearchParams();
Expand All @@ -47,15 +53,19 @@ export default class TranslationAPI extends APIBase {
payload.append('paths[]', resource);
}

if (ignoreWarnings) {
payload.append('ignore_warnings', ignoreWarnings.toString());
}

const headers = new Headers();
headers.append('X-Requested-With', 'XMLHttpRequest');
headers.append('X-CSRFToken', csrfToken);

return this.fetch(url, 'POST', payload, headers);
}

approve(id: number, resource: string) {
return this._changeStatus('/approve-translation/', id, resource);
approve(id: number, resource: string, ignoreWarnings: ?boolean) {
return this._changeStatus('/approve-translation/', id, resource, ignoreWarnings);
}

unapprove(id: number, resource: string) {
Expand Down
54 changes: 51 additions & 3 deletions frontend/src/modules/editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { actions as entitiesActions } from 'modules/entitieslist';
import type { DbEntity } from 'modules/entitieslist';


export const RESET_FAILED_CHECKS: 'editor/RESET_FAILED_CHECKS' = 'editor/RESET_FAILED_CHECKS';
export const RESET_SELECTION: 'editor/RESET_SELECTION' = 'editor/RESET_SELECTION';
export const UPDATE: 'editor/UPDATE' = 'editor/UPDATE';
export const UPDATE_FAILED_CHECKS: 'editor/UPDATE_FAILED_CHECKS' = 'editor/UPDATE_FAILED_CHECKS';
export const UPDATE_SELECTION: 'editor/UPDATE_SELECTION' = 'editor/UPDATE_SELECTION';


Expand Down Expand Up @@ -47,8 +49,34 @@ export function updateSelection(content: string): UpdateSelectionAction {


/**
* Update the content that should replace the currently selected text in the
* active editor.
* Update failed checks in the active editor.
*/
export type FailedChecks = {|
+clErrors: Array<string>,
+pErrors: Array<string>,
+clWarnings: Array<string>,
+pndbWarnings: Array<string>,
+ttWarnings: Array<string>,
|};
export type UpdateFailedChecksAction = {|
+type: typeof UPDATE_FAILED_CHECKS,
+failedChecks: FailedChecks,
+source: '' | 'stored' | 'submitted' | number,
|};
export function updateFailedChecks(
failedChecks: FailedChecks,
source: '' | 'stored' | 'submitted' | number,
): UpdateFailedChecksAction {
return {
type: UPDATE_FAILED_CHECKS,
failedChecks,
source,
};
}
/**
* Reset content to default value.
*/
export type ResetSelectionAction = {|
+type: typeof RESET_SELECTION,
Expand All @@ -60,6 +88,19 @@ export function resetSelection(): ResetSelectionAction {
}
/**
* Reset failed checks to default value.
*/
export type ResetFailedChecksAction = {|
+type: typeof RESET_FAILED_CHECKS,
|};
export function resetFailedChecks(): ResetFailedChecksAction {
return {
type: RESET_FAILED_CHECKS,
};
}
/**
* Save the current translation.
*/
Expand All @@ -72,6 +113,7 @@ export function sendTranslation(
forceSuggestions: boolean,
nextEntity: ?DbEntity,
router: Object,
ignoreWarnings: ?boolean,
): Function {
return async dispatch => {
const content = await api.translation.updateTranslation(
Expand All @@ -81,9 +123,13 @@ export function sendTranslation(
pluralForm,
original,
forceSuggestions,
ignoreWarnings,
);
if (content.same) {
if (content.failedChecks) {
dispatch(updateFailedChecks(content.failedChecks, 'submitted'));
}
else if (content.same) {
// The translation that was provided is the same as an existing
// translation for that entity.
// Show an error.
Expand Down Expand Up @@ -112,8 +158,10 @@ export function sendTranslation(


export default {
resetFailedChecks,
resetSelection,
sendTranslation,
update,
updateFailedChecks,
updateSelection,
};
Loading

0 comments on commit f1ea6a2

Please sign in to comment.