fix(server): use new LocalWorkspace ServerFeature instead (#13091)

keep compatibility

close AF-2720



#### PR Dependency Tree


* **PR #13091** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

* **New Features**
* Added a new `LocalWorkspace` feature flag to server configuration,
enabling more flexible feature management.

* **Deprecations**
* The `allowGuestDemoWorkspace` flag is now deprecated and will be
removed in version 0.25.0. Please use the `features` array for feature
checks instead.

* **Bug Fixes**
* Updated UI and logic throughout the app to rely on the new
`LocalWorkspace` feature flag rather than the deprecated boolean flag.

* **Chores**
* Removed references to `allowGuestDemoWorkspace` from configuration,
queries, and type definitions for improved consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


#### PR Dependency Tree


* **PR #13091** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)
This commit is contained in:
fengmk2
2025-07-08 23:23:42 +08:00
committed by GitHub
parent 15db657b1c
commit 95f88c378c
18 changed files with 79 additions and 37 deletions

View File

@@ -2,6 +2,7 @@
/**
* @vitest-environment happy-dom
*/
import { ServerFeature } from '@affine/graphql';
import { renderHook, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, test, vi } from 'vitest';
@@ -24,8 +25,10 @@ vi.mock('@toeverything/infra', () => {
server: {
config$: {
value: {
get allowGuestDemoWorkspace() {
return allowGuestDemo;
get features() {
return allowGuestDemo !== false
? [ServerFeature.LocalWorkspace]
: [];
},
},
},

View File

@@ -5,6 +5,7 @@ import {
} from '@affine/component';
import { AuthService, DefaultServerService } from '@affine/core/modules/cloud';
import { UserFriendlyError } from '@affine/error';
import { ServerFeature } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import { useService, useServices } from '@toeverything/infra';
import { useCallback } from 'react';
@@ -32,12 +33,15 @@ export const useSignOut = ({
const signOut = useCallback(async () => {
onConfirm?.()?.catch(console.error);
const enableLocalWorkspace =
BUILD_CONFIG.isNative ||
defaultServerService.server.config$.value.features.includes(
ServerFeature.LocalWorkspace
);
try {
await authService.signOut();
if (
defaultServerService.server.config$.value.allowGuestDemoWorkspace !==
false
) {
if (enableLocalWorkspace) {
jumpToIndex();
} else {
jumpToSignIn();

View File

@@ -1,5 +1,6 @@
import { MenuItem } from '@affine/component/ui/menu';
import { DefaultServerService } from '@affine/core/modules/cloud';
import { ServerFeature } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import { ImportIcon, PlusIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
@@ -15,10 +16,13 @@ export const AddWorkspace = ({
}) => {
const t = useI18n();
const defaultServerService = useService(DefaultServerService);
const allowGuestDemo = useLiveData(
defaultServerService.server.config$.selector(c => c.allowGuestDemoWorkspace)
const enableLocalWorkspace = useLiveData(
defaultServerService.server.config$.selector(
c =>
c.features.includes(ServerFeature.LocalWorkspace) ||
BUILD_CONFIG.isNative
)
);
const guestDemoEnabled = allowGuestDemo !== false;
return (
<>
@@ -45,7 +49,7 @@ export const AddWorkspace = ({
className={styles.ItemContainer}
>
<div className={styles.ItemText}>
{guestDemoEnabled
{enableLocalWorkspace
? t['com.affine.workspaceList.addWorkspace.create']()
: t['com.affine.workspaceList.addWorkspace.create-cloud']()}
</div>

View File

@@ -3,6 +3,7 @@ import { MenuItem } from '@affine/component/ui/menu';
import { AuthService, DefaultServerService } from '@affine/core/modules/cloud';
import { GlobalDialogService } from '@affine/core/modules/dialogs';
import { type WorkspaceMetadata } from '@affine/core/modules/workspace';
import { ServerFeature } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import { Logo1Icon } from '@blocksuite/icons/rc';
@@ -74,11 +75,12 @@ export const UserWithWorkspaceList = ({
}, [globalDialogService]);
const onNewWorkspace = useCallback(() => {
if (
!isAuthenticated &&
defaultServerService.server.config$.value.allowGuestDemoWorkspace ===
false
) {
const enableLocalWorkspace =
BUILD_CONFIG.isNative ||
defaultServerService.server.config$.value.features.includes(
ServerFeature.LocalWorkspace
);
if (!isAuthenticated && !enableLocalWorkspace) {
return openSignInModal();
}
track.$.navigationPanel.workspaceList.createWorkspace();