Skip to content

Commit

Permalink
Merge pull request #3705 from openequella/hotfix/2020.2.1
Browse files Browse the repository at this point in the history
Hotfix/2020.2.1
  • Loading branch information
PenghaiZhang authored Jan 10, 2022
2 parents 753a3ab + a0696cf commit e812365
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import * as OEQ from "@openequella/rest-api-client";
import Axios from "axios";
import { isEqual } from "lodash";
import * as React from "react";
import { v4 } from "uuid";
import {
Expand Down Expand Up @@ -114,6 +115,21 @@ export interface LegacyContentProps {
children?: never;
}

interface LegacyContentSubmission {
/**
* Indicate whether there is a request submitted to `LegacyContentApi` already but not completed yet.
*/
submitting: boolean;
/**
* Where to send the form data.
*/
action?: string;
/**
* Payload of the submission.
*/
payload?: StateData;
}

export type SubmitResponse =
| ExternalRedirect
| LegacyContentResponse
Expand Down Expand Up @@ -149,6 +165,9 @@ export const LegacyContent = React.memo(function LegacyContent({
userUpdated,
}: LegacyContentProps) {
const [content, setContent] = React.useState<PageContent>();
const submittingForm = React.useRef<LegacyContentSubmission>({
submitting: false,
});
const baseUrl = document.getElementsByTagName("base")[0].href;

function toRelativeUrl(url: string) {
Expand Down Expand Up @@ -186,6 +205,24 @@ export const LegacyContent = React.memo(function LegacyContent({
submitValues: StateData,
callback?: (response: SubmitResponse) => void
) {
if (formAction) {
const { submitting, action, payload } = submittingForm.current;
if (
submitting &&
formAction === action &&
isEqual(submitValues, payload)
) {
console.error(`ignore redundant submission to ${formAction}`);
return;
}

submittingForm.current = {
submitting: true,
action: formAction,
payload: submitValues,
};
}

submitRequest(toRelativeUrl(formAction || pathname), submitValues)
.then((content) => {
if (callback) {
Expand All @@ -207,6 +244,11 @@ export const LegacyContent = React.memo(function LegacyContent({
? fromAxiosResponse(error.response)
: generateFromError(error);
onError({ error: errorResponse, fullScreen });
})
.finally(() => {
if (formAction) {
submittingForm.current = { submitting: false };
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

$.datepicker.setDefaults({
showOn : 'both',
yearRange : "c-50:c+10",
yearRange : "1970:c+10",
changeYear : true,
changeMonth : true,
constrainInput : true,
Expand All @@ -32,7 +32,7 @@ function disablePicker($jelem, disabled)
}

/**
*
*
* @param $jelem
* @param $hiddenElem
* @param timezoneOffset
Expand All @@ -56,7 +56,7 @@ function setupPicker($jelem, $hiddenElem, timezoneOffset, changeFunc, $otherCale
showButtonPanel : false,
buttonText : buttonText
};

$jelem.datepicker(settings);
$jelem.data('$hiddenElem', $hiddenElem);

Expand Down Expand Up @@ -175,7 +175,7 @@ function stripExtras($dp)
}

/**
*
*
* @param $elem
* @param timezoneOffset
* @returns A UTC date which is Midnight *our* time
Expand All @@ -189,13 +189,13 @@ function getPickerUiValue($elem, timezoneOffset)
// Convert to midnight our time
// var toff2 = new Date(dtUtc).getTimezoneOffset() * 60000;
return dtUtc; /* - toff2 */
;

}
return null;
}

/**
*
*
* @param $elem
* @param utcDate
* A UTC date which is Midnight *our* time
Expand Down Expand Up @@ -238,4 +238,4 @@ function setPickerHiddenValue($elem, utcDate)
{
$elem.data('$hiddenElem').val('');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testViewCount() {
public void testAttachmentViewCount() {
final String linkAttachment = "https://archive.org/";

final String archiveOrgPreambleString = "div.preamble-whoweare";
final By title = By.xpath("//title[contains(text(),'Internet Archive')]");
logon(AUTOTEST_LOGON, AUTOTEST_PASSWD);

final WizardPageTab wizard = new ContributePage(context).load().openWizard(COLLECTION3);
Expand All @@ -145,9 +145,7 @@ public void testAttachmentViewCount() {
checkViews(summary, 1, linkAttachment, 0);

// view the attachment and go back
summary
.attachments()
.viewLinkAttachment(linkAttachment, By.cssSelector(archiveOrgPreambleString));
summary.attachments().viewLinkAttachment(linkAttachment, title);
final WebDriver.Navigation navigate = context.getDriver().navigate();
navigate.back();
// navigate.refresh();
Expand All @@ -157,9 +155,7 @@ public void testAttachmentViewCount() {
checkViews(summary, 2, linkAttachment, 1);

// view the attachment again and go back
summary
.attachments()
.viewLinkAttachment(linkAttachment, By.cssSelector(archiveOrgPreambleString));
summary.attachments().viewLinkAttachment(linkAttachment, title);
navigate.back();
// navigate.refresh();

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ name := "Equella"

equellaMajor in ThisBuild := 2020
equellaMinor in ThisBuild := 2
equellaPatch in ThisBuild := 0
equellaPatch in ThisBuild := 1
equellaStream in ThisBuild := "Stable"
equellaBuild in ThisBuild := buildConfig.value.getString("build.buildname")

Expand Down
2 changes: 1 addition & 1 deletion buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ phases:
commands:
- env | sort | grep -vi -e key -e secret -e password
- setupBuild
- . $NVM_DIR/nvm.sh && nvm install # version from nvmrc
- . $NVM_DIR/nvm.sh && set +a && nvm install # version from nvmrc
- npm config set unsafe-perm true
install:
commands:
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.4.0")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.2")

addSbtPlugin("de.johoop" % "sbt-testng-plugin" % "3.1.1")

Expand Down

0 comments on commit e812365

Please sign in to comment.