Skip to content
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

[PCC 1699] Deprecate injected preview bar #324

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/plenty-rice-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pantheon-systems/pcc-react-sdk": patch
a11rew marked this conversation as resolved.
Show resolved Hide resolved
---

The injected preview bar is deprecated in favor of the integrated preview bar in
the dashboard preview interface
4 changes: 0 additions & 4 deletions packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@pantheon-systems/pcc-sdk-core": "workspace:*",
"framer-motion": "^10.18.0",
"goober": "^2.1.14",
"graphql": "^16.8.1",
"lodash": "^4.17.21",
"query-string": "^8.2.0",
"react-laag": "^2.0.5",
"react-markdown": "^8.0.7",
"rehype-raw": "^6.1.1",
"remark-heading-id": "^1.0.1",
Expand Down
50 changes: 0 additions & 50 deletions packages/react-sdk/src/components/ArticleRenderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
} from "@pantheon-systems/pcc-sdk-core/types";
import { Element } from "hast";
import React, { useEffect } from "react";
import { createPortal } from "react-dom";
import { getTextContent } from "../../utils/react-element";
import { PreviewBar, PreviewBarExternalProps } from "../Preview/Preview";
import MarkdownRenderer from "./Markdown";
import PantheonTreeRenderer from "./PantheonTreeRenderer";
import PantheonTreeV2Renderer from "./PantheonTreeV2Renderer";
Expand Down Expand Up @@ -52,7 +50,6 @@ interface Props {
content: string,
) => React.ReactNode;
smartComponentMap?: SmartComponentMap;
previewBarProps?: PreviewBarExternalProps;
componentMap?: ComponentMap;
renderBody?: (bodyElement: React.ReactElement) => React.ReactNode;
__experimentalFlags?: {
Expand All @@ -63,36 +60,17 @@ interface Props {
};
}

function getOrCreatePortalTarget(
targetOverride: globalThis.Element | null | undefined,
) {
const pccGeneratedPortalTargetKey = "__pcc-portal-target__";
let portalTarget =
targetOverride || document.getElementById(pccGeneratedPortalTargetKey);

if (!portalTarget) {
portalTarget = document.createElement("div");
portalTarget.id = pccGeneratedPortalTargetKey;
document.body.prepend(portalTarget);
}

return portalTarget;
}

const ArticleRenderer = ({
article,
bodyClassName,
containerClassName,
headerClassName,
renderTitle,
smartComponentMap,
previewBarProps,
componentMap,
renderBody,
__experimentalFlags,
}: Props) => {
const [renderCSR, setRenderCSR] = React.useState(false);

useEffect(() => {
if (__experimentalFlags?.useUnintrusiveTitleRendering !== true) {
console.warn(
Expand All @@ -101,33 +79,15 @@ const ArticleRenderer = ({
}
}, [__experimentalFlags]);

useEffect(() => {
setRenderCSR(true);
}, []);

if (!article?.content) {
return null;
}

const portalTarget =
renderCSR && typeof document !== "undefined"
? getOrCreatePortalTarget(previewBarProps?.portalTarget)
: null;
const contentType = article?.contentType;

if (contentType === "TEXT_MARKDOWN") {
return (
<div className={containerClassName}>
{renderCSR &&
article != null &&
portalTarget != null &&
article.publishingLevel === "REALTIME"
? createPortal(
<PreviewBar {...previewBarProps} article={article} />,
portalTarget,
)
: null}

{article?.content ? (
<MarkdownRenderer
smartComponentMap={smartComponentMap}
Expand Down Expand Up @@ -202,16 +162,6 @@ const ArticleRenderer = ({

return (
<div className={containerClassName}>
{renderCSR &&
article != null &&
portalTarget != null &&
article.publishingLevel === "REALTIME"
? createPortal(
<PreviewBar {...previewBarProps} article={article} />,
portalTarget,
)
: null}

{titleElement != null ? (
<div className={headerClassName}>
{renderTitle
Expand Down
106 changes: 0 additions & 106 deletions packages/react-sdk/src/components/Preview/LivePreviewIndicator.tsx

This file was deleted.

Loading