Skip to content

Commit

Permalink
Merge pull request #3704 from openequella/hotfix/2021.1.3
Browse files Browse the repository at this point in the history
Hotfix/2021.1.3
  • Loading branch information
PenghaiZhang authored Jan 10, 2022
2 parents 25b17cf + 0c65ce3 commit 94de657
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { CircularProgress, Grid } from "@material-ui/core";
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 @@ -123,6 +124,21 @@ export interface LegacyContentProps extends BaseOEQRouteComponentProps {
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 @@ -165,6 +181,9 @@ export const LegacyContent = React.memo(function LegacyContent({
}: LegacyContentProps) {
const [content, setContent] = React.useState<PageContent>();
const [updatingContent, setUpdatingContent] = React.useState<boolean>(true);
const submittingForm = React.useRef<LegacyContentSubmission>({
submitting: false,
});

const baseUrl = document.getElementsByTagName("base")[0].href;

Expand Down Expand Up @@ -242,6 +261,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 @@ -263,6 +300,11 @@ export const LegacyContent = React.memo(function LegacyContent({
? fromAxiosResponse(error.response)
: generateFromError(error);
handleError(fullScreen, errorResponse);
})
.finally(() => {
if (formAction) {
submittingForm.current = { submitting: false };
}
});
}

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 := 2021
equellaMinor in ThisBuild := 1
equellaPatch in ThisBuild := 2
equellaPatch in ThisBuild := 3
equellaStream in ThisBuild := "Stable"
equellaBuild in ThisBuild := buildConfig.value.getString("build.buildname")

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.6.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 94de657

Please sign in to comment.