Skip to content

Commit

Permalink
CLDR-17079 Flag interface: fix some bugs (#3415)
Browse files Browse the repository at this point in the history
-Never show flag icon on a Discuss button since it cannot cause a path to be flagged

-If a Request button is disabled, do not show a flag icon on it or an empty space for a flag icon

-When a forum post is made, update the locale stamp so the front end will request an update

-New STFactory.PerLocaleData.nextStamp to enable SurveyForum to update the locale stamp

-Improve performance of STFactory.localeStamps initialization, do not copy Set as Array just to get its size

-Remove unused method STFactory.getLocaleStamp
  • Loading branch information
btangmu authored Dec 18, 2023
1 parent 2248cdd commit 06a4a2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
13 changes: 9 additions & 4 deletions tools/cldr-apps/js/src/esm/cldrForum.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -872,13 +872,18 @@ function makeOneNewPostButton(
code,
value
) {
const buttonClass = couldFlag
// A "new post" button has type cldrForumType.REQUEST or cldrForumType.DISCUSS.
// REQUEST is only enabled if there is a non-null value (which the user voted for).
const disabled = postType === cldrForumType.REQUEST && value === null;
// Only an enabled REQUEST button can really cause a path to be flagged.
const reallyCanFlag =
couldFlag && postType === cldrForumType.REQUEST && !disabled;
const buttonClass = reallyCanFlag
? "addPostButton forumNewPostFlagButton btn btn-default btn-sm"
: "addPostButton forumNewButton btn btn-default btn-sm";

const newButton = forumCreateChunk(label, "button", buttonClass);
// a "new post" button has type cldrForumType.REQUEST or cldrForumType.DISCUSS
if (postType === cldrForumType.REQUEST && value === null) {
if (disabled) {
newButton.disabled = true;
} else {
cldrDom.listenFor(newButton, "click", function (e) {
Expand All @@ -892,7 +897,7 @@ function makeOneNewPostButton(
if (o.result && o.result.ph) {
subj = xpathMap.formatPathHeader(o.result.ph);
}
if (couldFlag) {
if (reallyCanFlag) {
subj += " (Flag for review)";
}
openPostOrReply({
Expand Down
20 changes: 7 additions & 13 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/STFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public final class PerLocaleData implements Comparable<PerLocaleData>, BallotBox
/** Voting information for each XPath */
private final Map<String, PerXPathData> xpathToData = new HashMap<>();

public void nextStamp() {
stamp.next();
}

/** Per-xpath data. There's one of these per xpath- voting data, etc. */
final class PerXPathData {
/**
Expand Down Expand Up @@ -354,7 +358,7 @@ public Date getLastModDate() {
dataBackedSource =
new BallotBoxXMLSource<User>(diskData.cloneAsThawed(), this);
loadVoteValues(dataBackedSource, VoteLoadingContext.ORDINARY_LOAD_VOTES);
stamp.next();
nextStamp();
dataBackedSource.addListener(gTestCache);
XMLSource resolvedXmlsource = makeResolvingSource();
rFile =
Expand Down Expand Up @@ -1135,7 +1139,7 @@ private void internalSetVoteForValue(
makeSureInPathsForFile(distinguishingXpath, user, value);
getXPathData(distinguishingXpath)
.setVoteForValue(user, value, voteOverride, when, voteType);
stamp.next();
nextStamp();
}

@Override
Expand Down Expand Up @@ -1334,7 +1338,7 @@ public PerLocaleData load(CLDRLocale key) throws Exception {
});

private final Map<CLDRLocale, MutableStamp> localeStamps =
new ConcurrentHashMap<>(SurveyMain.getLocales().length);
new ConcurrentHashMap<>(SurveyMain.getLocalesSet().size());

/**
* Return changetime.
Expand All @@ -1351,16 +1355,6 @@ public MutableStamp mintLocaleStamp(CLDRLocale locale) {
return s;
}

/**
* Get the locale stamp, loading the locale if not loaded.
*
* @param loc
* @return
*/
public Stamp getLocaleStamp(CLDRLocale loc) {
return get(loc).getStamp();
}

/**
* Fetch a locale from the per locale data, create if not there.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,8 @@ private Integer doPostInternal(PostInfo postInfo) throws SurveyException {
if (postInfo.getSendEmail()) {
emailNotify(postInfo, postId);
}
CLDRLocale locale = postInfo.getLocale();
sm.getSTFactory().get(locale).nextStamp();
return postId;
}

Expand Down

0 comments on commit 06a4a2e

Please sign in to comment.