Skip to content

Commit 208761f

Browse files
authored
CLDR-16819 Change text of one notification; renaming; refactoring (#5099)
1 parent b65fcfb commit 208761f

File tree

4 files changed

+67
-76
lines changed

4 files changed

+67
-76
lines changed

tools/cldr-apps/js/src/esm/cldrVote.mjs

Lines changed: 59 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,8 @@ function handleVoteSubmitted(json, tr, theRow, button, valToShow) {
190190
button.className = "ichoice-o";
191191
button.checked = false;
192192
cldrSurvey.hideLoader();
193-
if (json.testResults && (json.testWarnings || json.testErrors)) {
194-
// Tried to submit, have errs or warnings.
195-
// Caution: even though json is defined, it is NOT used here as the 5th argument
196-
// for showProposedItem, which apparently depends on the 5th argument being
197-
// undefined when called from here (handleVoteSubmitted), and only defined
198-
// when called from handleVoteNotSubmitted.
199-
showProposedItem(tr, theRow, valToShow, json.testResults);
193+
if (json.testResults && (json.hasTestWarnings || json.hasTestErrors)) {
194+
showProposedItem(tr, theRow, valToShow, json);
200195
}
201196
if (CLDR_VOTE_DEBUG) {
202197
console.log(
@@ -217,9 +212,9 @@ function handleVoteSubmitted(json, tr, theRow, button, valToShow) {
217212
function handleVoteNotSubmitted(json, tr, theRow, button, valToShow) {
218213
if (
219214
(json.statusAction && json.statusAction != "ALLOW") ||
220-
(json.testResults && (json.testWarnings || json.testErrors))
215+
(json.testResults && (json.hasTestWarnings || json.hasTestErrors))
221216
) {
222-
showProposedItem(tr, theRow, valToShow, json.testResults, json);
217+
showVoteNotSubmitted(tr, theRow, valToShow, json);
223218
}
224219
button.className = "ichoice-o";
225220
button.checked = false;
@@ -270,67 +265,64 @@ function getSubmitUrl(xpstrid) {
270265
return cldrAjax.makeApiUrl(api, null);
271266
}
272267

273-
/**
274-
* Show an item that's not in the saved data, but has been proposed newly by the user.
275-
* Used for "+" button in table.
276-
*
277-
* Caution: if called from handleVoteSubmitted, the fifth argument (json) is undefined
278-
* (even though there is json from the server response), and that appears to be necessary
279-
* for this function to work right, as it stands. The fifth argument (json) is only defined
280-
* when called from handleVoteNotSubmitted. This function cries out to be thoroughly refactored,
281-
* but that may only be feasible in conjunction with a thorough analysis or refactoring of the
282-
* back end.
283-
*/
284-
function showProposedItem(tr, theRow, value, tests, json) {
268+
function showVoteNotSubmitted(tr, theRow, value, json) {
269+
if (!cldrSurvey.parseStatusAction(json.statusAction).vote) {
270+
showVoteNotAllowed(theRow, value, json);
271+
} else if (json.reasonNotSubmitted) {
272+
const description = "Did not submit this value: " + json.reasonNotSubmitted;
273+
cldrNotify.error("Not submitted", description);
274+
} else {
275+
showProposedItem(tr, theRow, value, json);
276+
}
277+
}
278+
279+
function showVoteNotAllowed(theRow, value, json) {
285280
const ourItem = cldrSurvey.findItemByValue(theRow.items, value);
286-
if (json && !cldrSurvey.parseStatusAction(json.statusAction).vote) {
287-
const replaceErrors =
288-
json.statusAction === "FORBID_PERMANENT_WITHOUT_FORUM";
289-
if (replaceErrors) {
290-
/*
291-
* Special case: for clarity, replace any warnings/errors that may be
292-
* in tests[] with a single error message for this situation.
293-
*/
294-
tests = [
295-
{
296-
type: "Error",
297-
message: cldrText.get("StatusAction_" + json.statusAction),
298-
},
299-
];
300-
}
281+
const replaceErrors = json.statusAction === "FORBID_PERMANENT_WITHOUT_FORUM";
282+
let tests = json.testResults;
283+
if (replaceErrors) {
284+
/*
285+
* Special case: for clarity, replace any warnings/errors that may be
286+
* in tests[] with a single error message for this situation.
287+
*/
288+
tests = [
289+
{
290+
type: "Error",
291+
message: cldrText.get("StatusAction_" + json.statusAction),
292+
},
293+
];
294+
}
301295

302-
const valueMessage = value === "" ? "Abstention" : "Value: " + value;
296+
const valueMessage = value === "" ? "Abstention" : "Value: " + value;
303297

304-
// TODO: modernize to obviate cldrSurvey.testsToHtml
305-
// Reference: https://unicode-org.atlassian.net/browse/CLDR-18013
306-
const testDescription = cldrSurvey.testsToHtml(tests);
307-
if (ourItem || (replaceErrors && value === "") /* Abstain */) {
308-
const statusAction = cldrText.get("StatusAction_" + json.statusAction);
309-
const message = cldrText.sub("StatusAction_msg", [statusAction]);
310-
/*
311-
* This may happen if, for example, the user types a space (" ") in
312-
* the input pop-up window and presses Enter. The value has been rejected
313-
* by the server. Then we show an additional pop-up window with the error message
314-
* from the server like "Input Processor Error: DAIP returned a 0 length string"
315-
*/
316-
const statusMessage = cldrText.sub("StatusAction_popupmsg", [
317-
statusAction,
318-
theRow.code,
319-
]);
320-
const description =
321-
valueMessage + "<br>" + statusMessage + " " + testDescription;
322-
cldrNotify.openWithHtml(message, description);
323-
} else {
324-
const description = valueMessage + "<br>" + testDescription;
325-
cldrNotify.openWithHtml("Response to voting", description);
326-
}
327-
return;
328-
} else if (json?.didNotSubmit) {
329-
const description = "Did not submit this value: " + json.didNotSubmit;
330-
cldrNotify.error("Not submitted", description);
331-
return;
298+
// TODO: modernize to obviate cldrSurvey.testsToHtml
299+
// Reference: https://unicode-org.atlassian.net/browse/CLDR-18013
300+
const testDescription = cldrSurvey.testsToHtml(tests);
301+
if (ourItem || (replaceErrors && value === "") /* Abstain */) {
302+
const statusAction = cldrText.get("StatusAction_" + json.statusAction);
303+
const message = cldrText.sub("StatusAction_msg", [statusAction]);
304+
/*
305+
* This may happen if, for example, the user types a space (" ") in
306+
* the input pop-up window and presses Enter. The value has been rejected
307+
* by the server. Then we show an additional pop-up window with the error message
308+
* from the server like "Input Processor Error: DAIP returned a 0 length string"
309+
*/
310+
const statusMessage = cldrText.sub("StatusAction_popupmsg", [
311+
statusAction,
312+
theRow.code,
313+
]);
314+
const description =
315+
valueMessage + "<br>" + statusMessage + " " + testDescription;
316+
cldrNotify.openWithHtml(message, description);
317+
} else {
318+
const description = valueMessage + "<br>" + testDescription;
319+
cldrNotify.openWithHtml("Vote not allowed", description);
332320
}
333-
// Note: it is possible to arrive here (as of 2025-09), for example, if the vote was accepted but has warnings
321+
}
322+
323+
function showProposedItem(tr, theRow, value, json) {
324+
const tests = json.testResults;
325+
const ourItem = cldrSurvey.findItemByValue(theRow.items, value);
334326
const ourDiv = ourItem ? ourItem.div : document.createElement("div");
335327
const testKind = getTestKind(tests);
336328
cldrTable.setDivClassSelected(ourDiv, testKind);
@@ -345,7 +337,7 @@ function showProposedItem(tr, theRow, value, tests, json) {
345337
const newDiv = document.createElement("div");
346338
div3.appendChild(newDiv);
347339
newDiv.innerHTML = cldrSurvey.testsToHtml(tests);
348-
if (json && !parseStatusAction(json.statusAction).vote) {
340+
if (!json.didVote && !parseStatusAction(json.statusAction).vote) {
349341
const text = cldrText.sub("StatusAction_msg", [
350342
cldrText.get("StatusAction_" + json.statusAction),
351343
]);

tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/VoteAPI.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public static final class RowResponse {
177177
public static final class Row {
178178

179179
public static final class Candidate {
180-
public String displayValue;
181180
public String example;
182181
public String history;
183182
public boolean isBaselineValue;
@@ -418,7 +417,7 @@ public static final class VoteResponse {
418417
public boolean didVote;
419418

420419
@Schema(description = "If set, some other reason why the submission failed.")
421-
public String didNotSubmit;
420+
public String reasonNotSubmitted;
422421

423422
@Schema(description = "If not ALLOW_*, gives reason why the voting was not allowed.")
424423
public StatusAction statusAction = null;
@@ -427,15 +426,15 @@ public static final class VoteResponse {
427426
public CheckStatusSummary[] testResults;
428427

429428
@Schema(description = "True if testResults include warnings.")
430-
public boolean testWarnings;
429+
public boolean hasTestWarnings;
431430

432431
@Schema(description = "True if testResults include errors.")
433-
public boolean testErrors;
432+
public boolean hasTestErrors;
434433

435434
void setTestResults(List<CheckStatus> testResults) {
436435
this.testResults = new CheckStatusSummary[testResults.size()];
437-
this.testWarnings = has(testResults, CheckStatus.warningType);
438-
this.testErrors = has(testResults, CheckStatus.errorType);
436+
this.hasTestWarnings = has(testResults, CheckStatus.warningType);
437+
this.hasTestErrors = has(testResults, CheckStatus.errorType);
439438
for (int i = 0; i < testResults.size(); i++) {
440439
this.testResults[i] = new CheckStatusSummary(testResults.get(i));
441440
}

tools/cldr-apps/src/main/java/org/unicode/cldr/web/api/VoteAPIHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ public static VoteResponse getHandleVoteForMissingResponse(
646646

647647
private static void normalizedToZeroLengthError(VoteResponse r, List<CheckStatus> result) {
648648
final String message = "DAIP returned a 0 length string";
649-
r.didNotSubmit = message;
649+
r.reasonNotSubmitted = message;
650650
r.statusAction = CheckCLDR.StatusAction.FORBID_ERRORS;
651651
String[] list = {message};
652652
result.add(

tools/cldr-apps/src/test/java/org/unicode/cldr/web/DataDrivenSTTestHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,11 @@ private void handleElementApivote(
484484
"exception="
485485
+ needException
486486
+ " but got status "
487-
+ r.didNotSubmit
487+
+ r.reasonNotSubmitted
488488
+ " - "
489489
+ r.toString());
490490
} else {
491-
System.out.println(" status = " + r.didNotSubmit);
491+
System.out.println(" status = " + r.reasonNotSubmitted);
492492
}
493493
} catch (Throwable iae) {
494494
if (needException == true) {

0 commit comments

Comments
 (0)