refactor: rename WorkspacePlugin to WorkspaceAdapter (#2330)

This commit is contained in:
Himself65
2023-05-12 01:43:39 +08:00
committed by GitHub
parent 39c83bd25b
commit 063ffda09d
28 changed files with 189 additions and 83 deletions

View File

@@ -1,4 +1,7 @@
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import type {
AffineLegacyCloudWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
@@ -24,8 +27,8 @@ const tabIcons = {
ShareWorkspace: <PublishIcon />,
};
export type ShareMenuProps<
Workspace extends AffineWorkspace | LocalWorkspace =
| AffineWorkspace
Workspace extends AffineLegacyCloudWorkspace | LocalWorkspace =
| AffineLegacyCloudWorkspace
| LocalWorkspace
> = {
workspace: Workspace;

View File

@@ -1,5 +1,8 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import type {
AffineLegacyCloudWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
import type { FC } from 'react';
@@ -26,7 +29,9 @@ const ShareLocalWorkspace: FC<ShareMenuProps<LocalWorkspace>> = props => {
);
};
const ShareAffineWorkspace: FC<ShareMenuProps<AffineWorkspace>> = props => {
const ShareAffineWorkspace: FC<
ShareMenuProps<AffineLegacyCloudWorkspace>
> = props => {
const isPublicWorkspace = props.workspace.public;
const t = useAFFiNEI18N();
return (
@@ -55,7 +60,9 @@ export const ShareWorkspace: FC<ShareMenuProps> = props => {
);
} else if (props.workspace.flavour === WorkspaceFlavour.AFFINE) {
return (
<ShareAffineWorkspace {...(props as ShareMenuProps<AffineWorkspace>)} />
<ShareAffineWorkspace
{...(props as ShareMenuProps<AffineLegacyCloudWorkspace>)}
/>
);
}
throw new Error('Unreachable');

View File

@@ -1,6 +1,6 @@
import type {
AffineLegacyCloudWorkspace,
AffinePublicWorkspace,
AffineWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import type { Workspace } from '@blocksuite/store';
@@ -15,7 +15,11 @@ import { avatarImageStyle, avatarStyle } from './index.css';
export type WorkspaceAvatarProps = {
size?: number;
workspace: AffineWorkspace | LocalWorkspace | AffinePublicWorkspace | null;
workspace:
| AffineLegacyCloudWorkspace
| LocalWorkspace
| AffinePublicWorkspace
| null;
className?: string;
};

View File

@@ -1,6 +1,9 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { PermissionType } from '@affine/workspace/affine/api';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import type {
AffineLegacyCloudWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { SettingsIcon } from '@blocksuite/icons';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
@@ -16,7 +19,7 @@ import {
} from './styles';
export type WorkspaceTypeProps = {
workspace: AffineWorkspace | LocalWorkspace;
workspace: AffineLegacyCloudWorkspace | LocalWorkspace;
};
import {
@@ -78,9 +81,11 @@ const WorkspaceType: FC<WorkspaceTypeProps> = ({ workspace }) => {
export type WorkspaceCardProps = {
currentWorkspaceId: string | null;
workspace: AffineWorkspace | LocalWorkspace;
onClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
onSettingClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
workspace: AffineLegacyCloudWorkspace | LocalWorkspace;
onClick: (workspace: AffineLegacyCloudWorkspace | LocalWorkspace) => void;
onSettingClick: (
workspace: AffineLegacyCloudWorkspace | LocalWorkspace
) => void;
};
export const WorkspaceCard: FC<WorkspaceCardProps> = ({

View File

@@ -1,4 +1,7 @@
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import type {
AffineLegacyCloudWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import type { DragEndEvent } from '@dnd-kit/core';
import {
DndContext,
@@ -14,15 +17,17 @@ import { WorkspaceCard } from '../workspace-card';
export type WorkspaceListProps = {
disabled?: boolean;
currentWorkspaceId: string | null;
items: (AffineWorkspace | LocalWorkspace)[];
onClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
onSettingClick: (workspace: AffineWorkspace | LocalWorkspace) => void;
items: (AffineLegacyCloudWorkspace | LocalWorkspace)[];
onClick: (workspace: AffineLegacyCloudWorkspace | LocalWorkspace) => void;
onSettingClick: (
workspace: AffineLegacyCloudWorkspace | LocalWorkspace
) => void;
onDragEnd: (event: DragEndEvent) => void;
};
const SortableWorkspaceItem: FC<
Omit<WorkspaceListProps, 'items'> & {
item: AffineWorkspace | LocalWorkspace;
item: AffineLegacyCloudWorkspace | LocalWorkspace;
}
> = props => {
const { setNodeRef, attributes, listeners, transform } = useSortable({

View File

@@ -1,5 +1,8 @@
import { PermissionType, WorkspaceType } from '@affine/workspace/affine/api';
import type { AffineWorkspace, LocalWorkspace } from '@affine/workspace/type';
import type {
AffineLegacyCloudWorkspace,
LocalWorkspace,
} from '@affine/workspace/type';
import { WorkspaceFlavour } from '@affine/workspace/type';
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
import type { Page } from '@blocksuite/store';
@@ -50,7 +53,7 @@ const localWorkspace: LocalWorkspace = {
providers: [],
};
const affineWorkspace: AffineWorkspace = {
const affineWorkspace: AffineLegacyCloudWorkspace = {
id: 'test-workspace',
flavour: WorkspaceFlavour.AFFINE,
blockSuiteWorkspace,

View File

@@ -80,13 +80,16 @@ export interface AffineWebSocketProvider extends BackgroundProvider {
export type Provider = BackgroundProvider | NecessaryProvider;
export interface AffineWorkspace extends RemoteWorkspace {
export interface AffineLegacyCloudWorkspace extends RemoteWorkspace {
flavour: WorkspaceFlavour.AFFINE;
// empty
blockSuiteWorkspace: BlockSuiteWorkspace;
providers: Provider[];
}
// todo: update type with nest.js
export type AffineCloudWorkspace = LocalWorkspace;
export interface LocalWorkspace {
flavour: WorkspaceFlavour.LOCAL;
id: string;
@@ -101,6 +104,12 @@ export interface AffinePublicWorkspace {
providers: Provider[];
}
export const enum ReleaseType {
// if workspace is not released yet, we will not show it in the workspace list
UNRELEASED = 'unreleased',
STABLE = 'stable',
}
export const enum LoadPriority {
HIGH = 1,
MEDIUM = 2,
@@ -108,7 +117,18 @@ export const enum LoadPriority {
}
export const enum WorkspaceFlavour {
/**
* AFFiNE Workspace is the workspace
* that hosted on the Legacy AFFiNE Cloud Server.
*
* @deprecated
* We no longer maintain this kind of workspace, please use AFFiNE-Cloud instead.
*/
AFFINE = 'affine',
/**
* New AFFiNE Cloud Workspace using Nest.js Server.
*/
AFFINE_CLOUD = 'affine-cloud',
LOCAL = 'local',
PUBLIC = 'affine-public',
}
@@ -125,9 +145,11 @@ export type SettingPanel = (typeof settingPanel)[keyof typeof settingPanel];
// built-in workspaces
export interface WorkspaceRegistry {
[WorkspaceFlavour.AFFINE]: AffineWorkspace;
[WorkspaceFlavour.AFFINE]: AffineLegacyCloudWorkspace;
[WorkspaceFlavour.LOCAL]: LocalWorkspace;
[WorkspaceFlavour.PUBLIC]: AffinePublicWorkspace;
// todo: update workspace type to new
[WorkspaceFlavour.AFFINE_CLOUD]: AffineCloudWorkspace;
}
export interface WorkspaceCRUD<Flavour extends keyof WorkspaceRegistry> {