Skip to content

Commit

Permalink
Merge pull request #3703 from openequella/hotfix/2021.2.1
Browse files Browse the repository at this point in the history
Hotfix/2021.2.1
  • Loading branch information
edalex-ian authored Jan 7, 2022
2 parents f08bb1d + f1a27a6 commit d8fd69f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ name := "Equella"

(ThisBuild / equellaMajor) := 2021
(ThisBuild / equellaMinor) := 2
(ThisBuild / equellaPatch) := 0
(ThisBuild / equellaPatch) := 1
(ThisBuild / equellaStream) := "Stable"
(ThisBuild / equellaBuild) := buildConfig.value.getString("build.buildname")
(ThisBuild / buildTimestamp) := Instant.now().getEpochSecond
Expand Down
42 changes: 42 additions & 0 deletions react-front-end/tsrc/legacycontent/LegacyContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import { CircularProgress, Grid } from "@material-ui/core";
import Axios from "axios";
import { isEqual } from "lodash";
import * as React from "react";
import { useContext } from "react";
import { v4 } from "uuid";
Expand Down Expand Up @@ -104,6 +105,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 @@ -146,6 +162,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 { appErrorHandler } = useContext(AppRenderErrorContext);

const baseUrl = document.getElementsByTagName("base")[0].href;
Expand Down Expand Up @@ -225,6 +244,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) => {
// Clear raw mode saved in local storage after a login request is resolved.
Expand All @@ -251,6 +288,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

0 comments on commit d8fd69f

Please sign in to comment.