Skip to content

Commit

Permalink
Fix the conflicting content logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Nov 12, 2024
1 parent 138bdbb commit d6a042f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
18 changes: 10 additions & 8 deletions ui/ui-app/src/app/pages/editor/EditorPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { CSSProperties, FunctionComponent, useEffect, useState } from "react";
import { PageSection, PageSectionVariants } from "@patternfly/react-core";
import { PageSection, PageSectionVariants, useInterval } from "@patternfly/react-core";
import { ArtifactTypes, ContentTypes } from "@models/common";
import { DownloadService, useDownloadService } from "@services/useDownloadService.ts";
import {
Expand Down Expand Up @@ -61,6 +61,7 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
labels: {},
modifiedBy: "",
modifiedOn: new Date(),
contentId: 0,
name: "",
type: "",
version: ""
Expand All @@ -76,23 +77,24 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
const [isPleaseWaitModalOpen, setPleaseWaitModalOpen] = useState(false);
const [isConfirmOverwriteModalOpen, setConfirmOverwriteModalOpen] = useState(false);
const [pleaseWaitMessage, setPleaseWaitMessage] = useState("");
const [intervalId, setIntervalId] = useState<any>();
const [isContentConflicting, setIsContentConflicting] = useState(false);

const { groupId, draftId, version } = useParams();

const drafts: DraftsService = useDraftsService();
const downloadSvc: DownloadService = useDownloadService();

// Poll the server for new content every 60s. If the content has been updated on
// the server then we have a conflict that we need to report to the user.
useInterval(() => {
detectContentConflict();
}, 30000);

const createLoaders = (): Promise<any>[] => {
return [
drafts.getDraft(groupId as string, draftId as string, version as string)
.then(d => {
setDraft(d);

// Poll the server for new content every 60s. If the content has been updated on
// the server then we have a conflict that we need to report to the user.
setIntervalId(setInterval(detectContentConflict, 60000));
})
.catch(error => {
setPageError(toPageError(error, "Error loading page data."));
Expand All @@ -110,7 +112,6 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
// Cleanup any possible event listener we might still have registered
return () => {
window.removeEventListener("beforeunload", onBeforeUnload);
clearInterval(intervalId);
};
}, []);

Expand Down Expand Up @@ -145,8 +146,9 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {

const detectContentConflict = (): void => {
drafts.getDraft(groupId as string, draftId as string, version as string).then(currentDraft => {
console.info(`[EditorPage] Detecting conflicting content. Latest contentId: ${currentDraft.contentId} Editor contentId: ${draft.contentId}`);
if (currentDraft.contentId !== draft.contentId) {
console.debug(`[EditorPage] Detected Draft content conflict. Expected '${draft.contentId}' but found '${currentDraft.contentId}'.'`);
console.debug(`[EditorPage] Detected Draft content conflict. Expected '${draft.contentId}' but found '${currentDraft.contentId}'`);
setIsContentConflicting(true);
}
});
Expand Down
10 changes: 5 additions & 5 deletions ui/ui-app/src/app/pages/editor/components/EditorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const EditorContext: FunctionComponent<EditorContextProps> = (props: Edit

return (
<div className="editor-context">
<div className="editor-context-breadcrumbs" children={breadcrumbs} />
<div key="editor-context-breadcrumbs" className="editor-context-breadcrumbs" children={breadcrumbs} />
<If condition={props.contentConflict}>
<div className="editor-context-conflict">
<div key="editor-context-conflict" className="editor-context-conflict">
<Icon status="warning">
<Popover
triggerAction="hover"
Expand All @@ -99,12 +99,12 @@ export const EditorContext: FunctionComponent<EditorContextProps> = (props: Edit
</div>
</If>
<If condition={props.draft.modifiedOn !== undefined}>
<div className="editor-context-last-modified">
<div key="editor-context-last-modified" className="editor-context-last-modified">
<span>Last modified:</span>
<FromNow date={props.draft.modifiedOn}/>
</div>
</If>
<div className="editor-context-actions">
<div key="editor-context-actions" className="editor-context-actions">
<ObjectDropdown
label="Actions"
items={menuItems}
Expand All @@ -117,7 +117,7 @@ export const EditorContext: FunctionComponent<EditorContextProps> = (props: Edit
itemIsDisabled={item => item.isDisabled === undefined ? false : item.isDisabled()}
itemToString={item => item.label} />
</div>
<div className="editor-context-save">
<div key="editor-context-save" className="editor-context-save">
<Button className="btn-save" variant="primary" onClick={() => props.onSave()} isDisabled={!props.dirty}>Save</Button>
</div>
</div>
Expand Down

0 comments on commit d6a042f

Please sign in to comment.