Skip to content

Commit

Permalink
Allow disabling the "Open preview" button in the PageTree for certa…
Browse files Browse the repository at this point in the history
…in document types (#2054)

The "Open preview" button is shown for all document types in the
`PageTree`. But some document types (e.g., links) don't have a preview.
Clicking on the preview button causes an error.

Now, it's possible to disable the button by setting `hasNoPreview` for
the document:

```diff
export const Link: DocumentInterface<Pick<GQLLink, "content">, GQLLinkInput> = {
    // ...
+   hasNoSitePreview: true,
};
```

(For now the button is disabled. I already asked UX for a crossed-out
Preview icon)
  • Loading branch information
thomasdax98 authored May 21, 2024
1 parent 8e3dec5 commit e10753b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .changeset/few-actors-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
"@comet/cms-admin": minor
---

Allow disabling the "Open preview" button in the `PageTree` for certain document types

The "Open preview" button is shown for all document types in the `PageTree`.
But some document types (e.g., links) don't have a preview.
Clicking on the preview button leads to an error page.

Now, it's possible to disable the button by setting `hasNoSitePreview` for the document:

```diff
export const Link: DocumentInterface<Pick<GQLLink, "content">, GQLLinkInput> = {
// ...
+ hasNoSitePreview: true,
};
```
1 change: 1 addition & 0 deletions demo/admin/src/links/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Link: DocumentInterface<Pick<GQLLink, "content">, GQLLinkInput> & D
return null;
},
menuIcon: LinkIcon,
hasNoSitePreview: true,
...createDocumentRootBlocksMethods(rootBlocks),
...createDocumentDependencyMethods({
rootQueryName: "link",
Expand Down
3 changes: 3 additions & 0 deletions packages/admin/admin-icons/icons/preview-unavailable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/admin/cms-admin/src/documents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export interface DocumentInterface<
anchors: (input: DocumentInput) => string[];
dependencies: (input: DocumentInput) => BlockDependency[];
replaceDependenciesInOutput: (output: DocumentOutput, replacements: ReplaceDependencyObject[]) => DocumentOutput;
hasNoSitePreview?: true;
}
8 changes: 5 additions & 3 deletions packages/admin/cms-admin/src/pages/pageTree/PageActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useApolloClient } from "@apollo/client";
import { IEditDialogApi, RowActionsItem, RowActionsMenu, useStackSwitchApi, writeClipboardText } from "@comet/admin";
import { Add, Delete, Domain, Edit, Preview, Settings } from "@comet/admin-icons";
import { Add, Delete, Domain, Edit, Preview, PreviewUnavailable, Settings } from "@comet/admin-icons";
import { Divider } from "@mui/material";
import React from "react";
import { FormattedMessage } from "react-intl";
Expand Down Expand Up @@ -31,7 +31,8 @@ export default function PageActions({ page, editDialog, children, siteUrl }: Pro
const client = useApolloClient();

const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
const isEditable = !!(page.visibility !== "Archived" && documentTypes[page.documentType].editComponent);
const documentType = documentTypes[page.documentType];
const isEditable = !!(page.visibility !== "Archived" && documentType.editComponent);

const handleDeleteClick = async () => {
const subTree = subTreeFromNode(page, tree);
Expand Down Expand Up @@ -75,10 +76,11 @@ export default function PageActions({ page, editDialog, children, siteUrl }: Pro
</RowActionsItem>,
<RowActionsItem
key="preview"
icon={<Preview />}
icon={documentType.hasNoSitePreview ? <PreviewUnavailable /> : <Preview />}
onClick={() => {
openSitePreviewWindow(page.path, contentScopeMatch.url);
}}
disabled={documentType.hasNoSitePreview}
>
<FormattedMessage id="comet.pages.pages.page.openPreview" defaultMessage="Open preview" />
</RowActionsItem>,
Expand Down

0 comments on commit e10753b

Please sign in to comment.