diff --git a/apps/core/src/components/affine/share-page-modal/index.tsx b/apps/core/src/components/affine/share-page-modal/index.tsx index 2f90249a15..80b0b9973f 100644 --- a/apps/core/src/components/affine/share-page-modal/index.tsx +++ b/apps/core/src/components/affine/share-page-modal/index.tsx @@ -4,7 +4,7 @@ import { WorkspaceFlavour, } from '@affine/env/workspace'; import type { Page } from '@blocksuite/store'; -import { useState } from 'react'; +import { useCallback, useState } from 'react'; import { useExportPage } from '../../../hooks/affine/use-export-page'; import { useIsSharedPage } from '../../../hooks/affine/use-is-shared-page'; @@ -20,6 +20,17 @@ export const SharePageModal = ({ workspace, page }: SharePageModalProps) => { const onTransformWorkspace = useOnTransformWorkspace(); const [open, setOpen] = useState(false); const exportHandler = useExportPage(page); + const handleConfirm = useCallback(() => { + if (workspace.flavour !== WorkspaceFlavour.LOCAL) { + return; + } + onTransformWorkspace( + WorkspaceFlavour.LOCAL, + WorkspaceFlavour.AFFINE_CLOUD, + workspace + ); + setOpen(false); + }, [onTransformWorkspace, workspace]); return ( <> { { - onTransformWorkspace( - WorkspaceFlavour.LOCAL, - WorkspaceFlavour.AFFINE_CLOUD, - workspace - ); - setOpen(false); - }} + onConfirm={handleConfirm} /> ) : null} diff --git a/apps/core/src/components/workspace-header.tsx b/apps/core/src/components/workspace-header.tsx index 836d39a4f0..82721ae6ee 100644 --- a/apps/core/src/components/workspace-header.tsx +++ b/apps/core/src/components/workspace-header.tsx @@ -7,9 +7,9 @@ import { import { Unreachable } from '@affine/env/constant'; import type { Collection } from '@affine/env/filter'; import type { PropertiesMeta } from '@affine/env/filter'; -import { +import type { WorkspaceFlavour, - type WorkspaceHeaderProps, + WorkspaceHeaderProps, } from '@affine/env/workspace'; import { WorkspaceSubPath } from '@affine/env/workspace'; import { useSetAtom } from 'jotai/react'; @@ -130,15 +130,12 @@ export function WorkspaceHeader({ // route in edit page if ('pageId' in currentEntry) { - const isCloudWorkspace = - currentWorkspace.flavour === WorkspaceFlavour.AFFINE_CLOUD; const currentPage = currentWorkspace.blockSuiteWorkspace.getPage( currentEntry.pageId ); - const sharePageModal = - isCloudWorkspace && currentPage ? ( - - ) : null; + const sharePageModal = currentPage ? ( + + ) : null; return (
-
+
{t['com.affine.share-menu.ShareViaExport']()}
+
+ {t['com.affine.share-menu.ShareViaExportDescription']()} +
-
-
- {t['com.affine.share-menu.ShareViaExportDescription']()} + {workspace.flavour !== WorkspaceFlavour.LOCAL ? ( +
+ +
+ {t['com.affine.share-menu.share-privately']()} +
+
+ {t['com.affine.share-menu.share-privately.description']()} +
+
+ +
- -
- -
-
+ ) : null} ); }; diff --git a/packages/component/src/components/share-menu/share-menu.tsx b/packages/component/src/components/share-menu/share-menu.tsx index dc52039d87..fe9e604930 100644 --- a/packages/component/src/components/share-menu/share-menu.tsx +++ b/packages/component/src/components/share-menu/share-menu.tsx @@ -1,10 +1,12 @@ -import type { - AffineCloudWorkspace, - AffineOfficialWorkspace, - AffinePublicWorkspace, - LocalWorkspace, +import { + type AffineCloudWorkspace, + type AffineOfficialWorkspace, + type AffinePublicWorkspace, + type LocalWorkspace, + WorkspaceFlavour, } from '@affine/env/workspace'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; +import { WebIcon } from '@blocksuite/icons'; import type { Page } from '@blocksuite/store'; import { Button } from '@toeverything/components/button'; import { Divider } from '@toeverything/components/divider'; @@ -30,15 +32,16 @@ export interface ShareMenuProps< exportHandler: (type: 'pdf' | 'html' | 'png' | 'markdown') => Promise; } -export const ShareMenu = (props: ShareMenuProps) => { - const { useIsSharedPage } = props; - const [isSharedPage] = useIsSharedPage( - props.workspace.id, - props.currentPage.id - ); +const ShareMenuContent = (props: ShareMenuProps) => { const t = useAFFiNEI18N(); - const content = ( + return (
+
+
+ +
+ {t['com.affine.share-menu.SharePage']()} +
@@ -46,22 +49,48 @@ export const ShareMenu = (props: ShareMenuProps) => {
); +}; + +const LocalShareMenu = (props: ShareMenuProps) => { + const t = useAFFiNEI18N(); return ( } contentOptions={{ - style: { - width: '410px', - height: 'auto', - padding: '12px', - transform: 'translateX(-10px)', - }, + className: styles.menuStyle, }} rootOptions={{ modal: false, }} > - + + ); +}; + +const CloudShareMenu = (props: ShareMenuProps) => { + const t = useAFFiNEI18N(); + + const { workspace, currentPage, useIsSharedPage } = props; + const [isSharedPage] = useIsSharedPage(workspace.id, currentPage.id); + + return ( + } + contentOptions={{ + className: styles.menuStyle, + }} + rootOptions={{ + modal: false, + }} + > + ); }; + +export const ShareMenu = (props: ShareMenuProps) => { + const { workspace } = props; + + if (workspace.flavour === WorkspaceFlavour.LOCAL) { + return ; + } + return ; +}; diff --git a/packages/component/src/components/share-menu/share-page.tsx b/packages/component/src/components/share-menu/share-page.tsx index f8ea801ff2..5b17c1a030 100644 --- a/packages/component/src/components/share-menu/share-page.tsx +++ b/packages/component/src/components/share-menu/share-page.tsx @@ -1,6 +1,6 @@ import { WorkspaceFlavour } from '@affine/env/workspace'; import { useAFFiNEI18N } from '@affine/i18n/hooks'; -import { ArrowRightSmallIcon, WebIcon } from '@blocksuite/icons'; +import { ArrowRightSmallIcon } from '@blocksuite/icons'; import { Button } from '@toeverything/components/button'; import { Menu, MenuItem, MenuTrigger } from '@toeverything/components/menu'; import { useState } from 'react'; @@ -17,28 +17,20 @@ import { useSharingUrl } from './use-share-url'; const CloudSvg = () => ( - - - - + + - - - - - ); @@ -47,25 +39,27 @@ export const LocalSharePage = (props: ShareMenuProps) => { return ( <> -
-
- -
- {t['com.affine.share-menu.SharePage']()} -
-
-
+
+
{t['com.affine.share-menu.EnableCloudDescription']()}
-
-
- +
+ +
); @@ -100,17 +94,11 @@ export const AffineSharePage = (props: ShareMenuProps) => { return ( <>
-
- -
- {t['com.affine.share-menu.SharePage']()} -
-
- {t['com.affine.share-menu.ShareWithLink']()} + {t['com.affine.share-menu.publish-to-web']()}
- {t['com.affine.share-menu.ShareWithLinkDescription']()} + {t['com.affine.share-menu.publish-to-web.description']()}
diff --git a/packages/i18n/src/resources/en.json b/packages/i18n/src/resources/en.json index e79a3c2369..76e433514e 100644 --- a/packages/i18n/src/resources/en.json +++ b/packages/i18n/src/resources/en.json @@ -313,7 +313,7 @@ "com.affine.settingSidebar.settings.general": "General", "com.affine.settingSidebar.settings.workspace": "Workspace", "com.affine.settingSidebar.title": "Settings", - "com.affine.share-menu.EnableCloudDescription": "Sharing page publicly requires AFFiNE Cloud service.", + "com.affine.share-menu.EnableCloudDescription": "Sharing page requires AFFiNE Cloud.", "com.affine.share-menu.shareButton": "Share", "com.affine.share-menu.sharedButton": "Shared", "com.affine.share-menu.SharedPage": "Shared Page", @@ -628,5 +628,10 @@ "com.affine.cmdk.affine.whats-new": "What's New", "com.affine.cmdk.affine.getting-started": "Getting Started", "com.affine.cmdk.affine.contact-us": "Contact Us", - "com.affine.cmdk.affine.restart-to-upgrade": "Restart to Upgrade" + "com.affine.cmdk.affine.restart-to-upgrade": "Restart to Upgrade", + "com.affine.share-menu.publish-to-web": "Publish to Web", + "com.affine.share-menu.publish-to-web.description": "Let anyone with a link view a read-only version of this page.", + "com.affine.share-menu.share-privately": "Share Privately", + "com.affine.share-menu.share-privately.description": "Only members of this Workspace can open this link.", + "com.affine.share-menu.copy-private-link": "Copy Private Link" } diff --git a/tests/affine-cloud/e2e/collaboration.spec.ts b/tests/affine-cloud/e2e/collaboration.spec.ts index f2aeb2cd9e..1c0823ac82 100644 --- a/tests/affine-cloud/e2e/collaboration.spec.ts +++ b/tests/affine-cloud/e2e/collaboration.spec.ts @@ -3,6 +3,7 @@ import { addUserToWorkspace, createRandomUser, enableCloudWorkspace, + enableCloudWorkspaceFromShareButton, loginUser, } from '@affine-test/kit/utils/cloud'; import { @@ -47,14 +48,14 @@ test.describe('collaboration', () => { }, page ); - await enableCloudWorkspace(page); + await enableCloudWorkspaceFromShareButton(page); const title = getBlockSuiteEditorTitle(page); await title.pressSequentially('TEST TITLE', { delay: 50, }); await page.keyboard.press('Enter', { delay: 50 }); await page.keyboard.type('TEST CONTENT', { delay: 50 }); - await page.getByTestId('share-menu-button').click(); + await page.getByTestId('cloud-share-menu-button').click(); await page.getByTestId('share-menu-create-link-button').click(); await page.getByTestId('share-menu-copy-link-button').click(); diff --git a/tests/kit/utils/cloud.ts b/tests/kit/utils/cloud.ts index 2d47482bbf..5c8fd8877f 100644 --- a/tests/kit/utils/cloud.ts +++ b/tests/kit/utils/cloud.ts @@ -176,3 +176,12 @@ export async function enableCloudWorkspace(page: Page) { await waitForEditorLoad(page); await clickNewPageButton(page); } +export async function enableCloudWorkspaceFromShareButton(page: Page) { + await page.getByTestId('local-share-menu-button').click(); + await page.getByTestId('share-menu-enable-affine-cloud-button').click(); + await page.getByTestId('confirm-enable-affine-cloud-button').click(); + // wait for upload and delete local workspace + await page.waitForTimeout(2000); + await waitForEditorLoad(page); + await clickNewPageButton(page); +}