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

CLDR-17560 Overall Errors #3743

Merged
merged 5 commits into from
May 24, 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
496 changes: 251 additions & 245 deletions tools/cldr-apps/js/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion tools/cldr-apps/js/src/esm/cldrClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SURVEY_TOOL_SESSION_HEADER } from "./cldrAjax.mjs";

const OAS3_ROOT = "/openapi"; // Path to the 'openapi' (sibling to cldr-apps). Needs to be a host-relative URL.

const RESOLVED_ROOT = new URL(OAS3_ROOT, document.baseURI);

/**
* Create a promise to a swagger client for ST operations.
*
Expand All @@ -16,7 +18,8 @@ const OAS3_ROOT = "/openapi"; // Path to the 'openapi' (sibling to cldr-apps). N
* @returns Promise<SwaggerClient>
*/
function getClient() {
return new SwaggerClient(OAS3_ROOT, {
return new SwaggerClient({
url: RESOLVED_ROOT,
requestInterceptor: (obj) => {
// add the session header to each request
obj.headers[SURVEY_TOOL_SESSION_HEADER] = getSessionId();
Expand Down
12 changes: 10 additions & 2 deletions tools/cldr-apps/js/src/esm/cldrComponents.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import { App } from "vue";
*/

// local components
import CldrError from "../views/CldrError.vue";
import CldrValue from "../views/CldrValue.vue";
import LoginButton from "../views/LoginButton.vue";
import OverallErrors from "../views/OverallErrors.vue";
import ReportResponse from "../views/ReportResponse.vue";
import SearchButton from "../views/SearchButton.vue";

Expand All @@ -19,6 +21,7 @@ import {
Alert,
Avatar,
Button,
Card,
Checkbox,
Collapse,
CollapsePanel,
Expand All @@ -31,9 +34,10 @@ import {
Select,
Spin,
Steps,
Tag,
Textarea,
Tooltip,
Timeline,
Tooltip,
UploadDragger,
} from "ant-design-vue";
// Note: 'notification' is a function and is imported as a function in cldrVue.mjs,
Expand All @@ -52,9 +56,10 @@ function setup(app) {
app.component("a-alert", Alert);
app.component("a-avatar", Avatar);
app.component("a-button", Button);
app.component("a-card", Card);
app.component("a-checkbox", Checkbox);
app.component("a-collapse", Collapse);
app.component("a-collapse-panel", CollapsePanel);
app.component("a-collapse", Collapse);
app.component("a-form-item", Form.Item);
app.component("a-form", Form);
app.component("a-input-password", Input.Password);
Expand All @@ -71,12 +76,15 @@ function setup(app) {
app.component("a-spin", Spin);
app.component("a-step", Steps.Step);
app.component("a-steps", Steps);
app.component("a-tag", Tag);
app.component("a-textarea", Textarea);
app.component("a-timeline-item", Timeline.Item);
app.component("a-timeline", Timeline);
app.component("a-tooltip", Tooltip);
app.component("a-upload-dragger", UploadDragger);
app.component("cldr-error", CldrError);
app.component("cldr-loginbutton", LoginButton);
app.component("cldr-overall-errors", OverallErrors);
app.component("cldr-report-response", ReportResponse);
app.component("cldr-searchbutton", SearchButton);
app.component("cldr-value", CldrValue);
Expand Down
13 changes: 12 additions & 1 deletion tools/cldr-apps/js/src/esm/cldrDash.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* cldrDash: encapsulate dashboard data.
*/
import * as cldrAjax from "./cldrAjax.mjs";
import * as cldrClient from "./cldrClient.mjs";
import * as cldrCoverage from "./cldrCoverage.mjs";
import * as cldrNotify from "./cldrNotify.mjs";
import * as cldrProgress from "./cldrProgress.mjs";
Expand Down Expand Up @@ -469,11 +470,21 @@ async function downloadXlsx(data, locale, cb) {
cb(null);
}

/**
* @param {string} locale locale to list for
* @returns {Array<CheckStatusSummary>}
*/
async function getLocaleErrors(locale) {
const client = await cldrClient.getClient();
return await client.apis.voting.getLocaleErrors({ locale });
}

export {
doFetch,
downloadXlsx,
getFetchError,
getLocaleErrors,
saveEntryCheckmark,
setData,
updatePath,
downloadXlsx,
};
9 changes: 1 addition & 8 deletions tools/cldr-apps/js/src/esm/cldrSurvey.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,12 @@ function testsToHtml(tests) {
if (!tests) {
return newHtml;
}
var hadEntireLocale = false;

for (var i = 0; i < tests.length; i++) {
var testItem = tests[i];
const { entireLocale } = testItem;
if (entireLocale) {
hadEntireLocale = true;
continue;
continue; // skip entireLocale errors
}
newHtml += "<p class='trInfo tr_" + testItem.type;
if (testItem.type == "Warning") {
Expand Down Expand Up @@ -788,11 +786,6 @@ function testsToHtml(tests) {

newHtml += "</p>\n";
}
if (hadEntireLocale) {
Copy link
Member

Choose a reason for hiding this comment

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

this makes hadEntireLocale unused (dead code), so it should be removed above

Copy link
Member Author

Choose a reason for hiding this comment

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

true.

newHtml += `<p class='trInfo tr_Warning alert alert-warning fix-popover-help'>See also <a href='#r_supplemental/${cldrStatus.getCurrentLocale()}//'>${cldrText.get(
"special_r_supplemental"
)}</a></p>\n`;
}
return newHtml;
}

Expand Down
66 changes: 66 additions & 0 deletions tools/cldr-apps/js/src/views/CldrError.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<div style="background: #ffffff; padding: 30px">
<a-card hoverable :title="subtypeString">
<!-- TODO: Error details are commented out temporarily, see discussion at CLDR-17664 -->
<template #extra
><a-tag
:title="status.subtype"
:color="'error' || status.type.toLowerCase()"
>{{ "error" || status.type }}</a-tag
></template
>
<!-- <p>
{{ status.message }}
</p> -->
<p>Information on how to fix this is forthcoming.</p>
<!--
<template v-if="status.subtypeUrl" #actions>
<a class="warningReference" :href="status.subtypeUrl">How to Fix…</a>
</template>
-->
</a-card>
</div>
</template>

<script>
export default {
computed: {
myClass() {
return `cldrError tr_${this.status.type} `;
},
subtypeString() {
return this.status.subtype.split(/(?=[A-Z])/).join(" ");
},
},
props: {
/**
* 'status' is a VoteAPI.CheckStatusSummary with these properties:
*
* public String message;
* public Type type;
* public Subtype subtype;
* public String subtypeUrl;
* public Phase phase;
* public String cause;
* public boolean entireLocale;
*
* */
status: Object,
},
};
</script>

<style scoped>
.subtype {
font-size: larger;
font-weight: bold;
color: black;
}

.cldrError {
border: 1px solid gray;
padding: 1em;
margin-bottom: 2em;
margin-right: 1em;
}
</style>
2 changes: 2 additions & 0 deletions tools/cldr-apps/js/src/views/GeneralInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
>
Open Dashboard
</button>

<cldr-overall-errors />
</div>
</template>

Expand Down
46 changes: 46 additions & 0 deletions tools/cldr-apps/js/src/views/OverallErrors.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<a-spin v-if="!loaded" />
<div v-if="loaded && errors">
<h2>Overall Errors</h2>
<p>
Check the following errors carefully. These issues often require a ticket
to be filed with CLDR to fix.
</p>

<cldr-error v-for="test of errors" :key="test.subtype" :status="test" />
</div>
</template>

<script setup>
import { ref } from "vue";
import { getLocaleErrors } from "../esm/cldrDash.mjs";
import { getCurrentLocale } from "../esm/cldrStatus.mjs";
import * as cldrNotify from "../esm/cldrNotify.mjs";

const loaded = ref(false);
const errors = ref(null);
const locale = ref(getCurrentLocale());

async function loadData() {
const resp = await getLocaleErrors(locale.value);
if (!resp || !resp.body) {
errors.value = null;
} else {
const { body } = resp;
const { tests } = body;
errors.value = tests;
}
loaded.value = true;
}

loadData().then(
() => {},
(err) => {
console.error(err);
cldrNotify.exception(
err,
"Loading overall errors for " + getCurrentLocale()
);
}
);
</script>
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.unicode.cldr.web.api;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -136,6 +140,34 @@ public Response getPage(
return VoteAPIHelper.handleGetOnePage(loc, session, page, xpstrid);
}

/** Array of status items. Only stores one example entry per subtype. */
public static final class EntireLocaleStatusResponse {
public EntireLocaleStatusResponse() {}

void addAll(Collection<CheckStatus> list) {
for (final CheckStatus c : list) {
add(c);
}
}

void add(CheckStatus c) {
if (!allSubtypes.contains(c.getSubtype())) {
tests.add(new CheckStatusSummary(c));
allSubtypes.add(c.getSubtype());
}
}

@Schema(description = "list of test results")
public List<CheckStatusSummary> tests = new ArrayList<>();

// we only want to store one example for each subtype.
private Set<CheckStatus.Subtype> allSubtypes = new HashSet<>();

boolean isEmpty() {
return tests.isEmpty();
}
}

public static final class RowResponse {

public static final class Row {
Expand Down Expand Up @@ -372,4 +404,40 @@ public CheckStatusSummary(CheckStatus checkStatus) {
this.entireLocale = checkStatus.getEntireLocale();
}
}

@GET
@Path("/{locale}/errors")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get overall errors", description = "Get overall errors for a locale")
@APIResponses(
value = {
@APIResponse(
responseCode = "200",
description = "Error results",
content =
@Content(
mediaType = "application/json",
schema =
@Schema(
implementation =
EntireLocaleStatusResponse.class))),
@APIResponse(responseCode = "204", description = "No errors in this locale"),
@APIResponse(
responseCode = "403",
description = "Forbidden, no access to this data"),
@APIResponse(responseCode = "404", description = "Locale does not exist"),
@APIResponse(
responseCode = "500",
description = "Internal Server Error",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = STError.class))),
})
public Response getLocaleErrors(
@Parameter(required = true, example = "br", schema = @Schema(type = SchemaType.STRING))
@PathParam("locale")
String loc) {
return VoteAPIHelper.handleGetLocaleErrors(loc);
}
}
Loading
Loading