-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2293] feat: pages version history #5417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6c1818c
chore: project page version
NarayanBavisetti 861756c
feat: page version history implemented
aaryan610 2ea7220
chore: hide save button when version history overlay is active
aaryan610 146a508
refactor: updated navigation logic
aaryan610 125a640
chore: added error states
aaryan610 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,23 @@ | ||
| import { useRef, useState } from "react"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { observer } from "mobx-react"; | ||
| import { useSearchParams } from "next/navigation"; | ||
| // plane editor | ||
| import { EditorRefApi, useEditorMarkings } from "@plane/editor"; | ||
| // plane types | ||
| import { TPage } from "@plane/types"; | ||
| // plane ui | ||
| import { setToast, TOAST_TYPE } from "@plane/ui"; | ||
| import { PageEditorHeaderRoot, PageEditorBody } from "@/components/pages"; | ||
| // components | ||
| import { PageEditorHeaderRoot, PageEditorBody, PageVersionsOverlay } from "@/components/pages"; | ||
| // hooks | ||
| import { useProjectPages } from "@/hooks/store"; | ||
| import { useAppRouter } from "@/hooks/use-app-router"; | ||
| import { usePageDescription } from "@/hooks/use-page-description"; | ||
| import { useQueryParams } from "@/hooks/use-query-params"; | ||
| // services | ||
| import { ProjectPageVersionService } from "@/services/page"; | ||
| const projectPageVersionService = new ProjectPageVersionService(); | ||
| // store | ||
| import { IPage } from "@/store/pages/page"; | ||
|
|
||
| type TPageRootProps = { | ||
|
|
@@ -16,34 +27,40 @@ type TPageRootProps = { | |
| }; | ||
|
|
||
| export const PageRoot = observer((props: TPageRootProps) => { | ||
| // router | ||
| const router = useAppRouter(); | ||
| const { projectId, workspaceSlug, page } = props; | ||
| const { createPage } = useProjectPages(); | ||
| const { access, description_html, name } = page; | ||
|
|
||
| // states | ||
| const [editorReady, setEditorReady] = useState(false); | ||
| const [readOnlyEditorReady, setReadOnlyEditorReady] = useState(false); | ||
|
|
||
| const [sidePeekVisible, setSidePeekVisible] = useState(window.innerWidth >= 768); | ||
| const [isVersionsOverlayOpen, setIsVersionsOverlayOpen] = useState(false); | ||
| // refs | ||
| const editorRef = useRef<EditorRefApi>(null); | ||
| const readOnlyEditorRef = useRef<EditorRefApi>(null); | ||
|
|
||
| // router | ||
| const router = useAppRouter(); | ||
| // search params | ||
| const searchParams = useSearchParams(); | ||
| // store hooks | ||
| const { createPage } = useProjectPages(); | ||
| // derived values | ||
| const { access, description_html, name } = page; | ||
| // editor markings hook | ||
| const { markings, updateMarkings } = useEditorMarkings(); | ||
|
|
||
| const [sidePeekVisible, setSidePeekVisible] = useState(window.innerWidth >= 768 ? true : false); | ||
|
|
||
| // project-description | ||
| const { handleDescriptionChange, isDescriptionReady, pageDescriptionYJS, handleSaveDescription } = usePageDescription( | ||
| { | ||
| editorRef, | ||
| page, | ||
| projectId, | ||
| workspaceSlug, | ||
| } | ||
| ); | ||
| const { | ||
| handleDescriptionChange, | ||
| isDescriptionReady, | ||
| pageDescriptionYJS, | ||
| handleSaveDescription, | ||
| manuallyUpdateDescription, | ||
| } = usePageDescription({ | ||
| editorRef, | ||
| page, | ||
| projectId, | ||
| workspaceSlug, | ||
| }); | ||
| // update query params | ||
| const { updateQueryParams } = useQueryParams(); | ||
|
|
||
| const handleCreatePage = async (payload: Partial<TPage>) => await createPage(payload); | ||
|
|
||
|
|
@@ -65,8 +82,48 @@ export const PageRoot = observer((props: TPageRootProps) => { | |
| ); | ||
| }; | ||
|
|
||
| const version = searchParams.get("version"); | ||
| useEffect(() => { | ||
| if (!version) { | ||
| setIsVersionsOverlayOpen(false); | ||
| return; | ||
| } | ||
| setIsVersionsOverlayOpen(true); | ||
| }, [version]); | ||
|
|
||
| const handleCloseVersionsOverlay = () => { | ||
| const updatedRoute = updateQueryParams({ | ||
| paramsToRemove: ["version"], | ||
| }); | ||
| router.push(updatedRoute); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <PageVersionsOverlay | ||
| activeVersion={version} | ||
| fetchAllVersions={async (pageId) => { | ||
| if (!workspaceSlug || !projectId) return; | ||
| return await projectPageVersionService.fetchAllVersions( | ||
| workspaceSlug.toString(), | ||
| projectId.toString(), | ||
| pageId | ||
| ); | ||
| }} | ||
| fetchVersionDetails={async (pageId, versionId) => { | ||
| if (!workspaceSlug || !projectId) return; | ||
| return await projectPageVersionService.fetchVersionById( | ||
| workspaceSlug.toString(), | ||
| projectId.toString(), | ||
| pageId, | ||
| versionId | ||
| ); | ||
| }} | ||
| handleRestore={manuallyUpdateDescription} | ||
| isOpen={isVersionsOverlayOpen} | ||
| onClose={handleCloseVersionsOverlay} | ||
| pageId={page.id ?? ""} | ||
| /> | ||
|
Comment on lines
+103
to
+126
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize asynchronous functions. Consider extracting the asynchronous functions |
||
| <PageEditorHeaderRoot | ||
| editorRef={editorRef} | ||
| readOnlyEditorRef={readOnlyEditorRef} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.