diff --git a/packages/backend/server/src/core/workspaces/resolvers/workspace.ts b/packages/backend/server/src/core/workspaces/resolvers/workspace.ts index 76c84407fa33b..ea7ff150b7a19 100644 --- a/packages/backend/server/src/core/workspaces/resolvers/workspace.ts +++ b/packages/backend/server/src/core/workspaces/resolvers/workspace.ts @@ -94,6 +94,21 @@ export class WorkspaceResolver { }); } + @ResolveField(() => Boolean, { + description: 'is current workspace initialized', + complexity: 2, + }) + async initialized(@Parent() workspace: WorkspaceType) { + return this.prisma.snapshot + .count({ + where: { + id: workspace.id, + workspaceId: workspace.id, + }, + }) + .then(count => count > 0); + } + @ResolveField(() => UserType, { description: 'Owner of workspace', complexity: 2, diff --git a/packages/backend/server/src/schema.gql b/packages/backend/server/src/schema.gql index 625a391927a07..b97103c91a6b0 100644 --- a/packages/backend/server/src/schema.gql +++ b/packages/backend/server/src/schema.gql @@ -893,6 +893,9 @@ type WorkspaceType { histories(before: DateTime, guid: String!, take: Int): [DocHistoryType!]! id: ID! + """is current workspace initialized""" + initialized: Boolean! + """member count of workspace""" memberCount: Int! diff --git a/packages/common/infra/src/modules/workspace/metadata.ts b/packages/common/infra/src/modules/workspace/metadata.ts index d73b79f8a65e2..990d4c7ffe044 100644 --- a/packages/common/infra/src/modules/workspace/metadata.ts +++ b/packages/common/infra/src/modules/workspace/metadata.ts @@ -1,3 +1,7 @@ import type { WorkspaceFlavour } from '@affine/env/workspace'; -export type WorkspaceMetadata = { id: string; flavour: WorkspaceFlavour }; +export type WorkspaceMetadata = { + id: string; + flavour: WorkspaceFlavour; + initialized?: boolean; +}; diff --git a/packages/frontend/component/src/components/workspace-list/index.tsx b/packages/frontend/component/src/components/workspace-list/index.tsx index 81944666e48ac..fca83d7c03340 100644 --- a/packages/frontend/component/src/components/workspace-list/index.tsx +++ b/packages/frontend/component/src/components/workspace-list/index.tsx @@ -1,3 +1,4 @@ +import { WorkspaceFlavour } from '@affine/env/workspace'; import type { WorkspaceMetadata } from '@toeverything/infra'; import { Suspense } from 'react'; @@ -58,9 +59,13 @@ const SortableWorkspaceItem = ({ export const WorkspaceList = (props: WorkspaceListProps) => { const workspaceList = props.items; - return workspaceList.map(item => ( - } key={item.id}> - - - )); + return workspaceList + .filter( + w => w.flavour !== WorkspaceFlavour.AFFINE_CLOUD || w.initialized === true + ) + .map(item => ( + } key={item.id}> + + + )); }; diff --git a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts index f56e966960069..f04ce6c665bcb 100644 --- a/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts +++ b/packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts @@ -117,7 +117,10 @@ export class CloudWorkspaceFlavourProviderService this.revalidate(); await this.waitForLoaded(); - return { id: workspaceId, flavour: WorkspaceFlavour.AFFINE_CLOUD }; + return { + id: workspaceId, + flavour: WorkspaceFlavour.AFFINE_CLOUD, + }; } revalidate = effect( map(() => { @@ -138,12 +141,16 @@ export class CloudWorkspaceFlavourProviderService }, }); - const ids = workspaces.map(({ id }) => id); + const ids = workspaces.map(({ id, initialized }) => ({ + id, + initialized, + })); return { accountId, - workspaces: ids.map(id => ({ + workspaces: ids.map(({ id, initialized }) => ({ id, flavour: WorkspaceFlavour.AFFINE_CLOUD, + initialized, })), }; }).pipe( diff --git a/packages/frontend/graphql/src/graphql/get-workspaces.gql b/packages/frontend/graphql/src/graphql/get-workspaces.gql index 946fe8ab6bdbf..354a8de4b7b8c 100644 --- a/packages/frontend/graphql/src/graphql/get-workspaces.gql +++ b/packages/frontend/graphql/src/graphql/get-workspaces.gql @@ -1,6 +1,7 @@ query getWorkspaces { workspaces { id + initialized owner { id } diff --git a/packages/frontend/graphql/src/graphql/index.ts b/packages/frontend/graphql/src/graphql/index.ts index b78f0d4eb4c08..9ffcaeccd9a08 100644 --- a/packages/frontend/graphql/src/graphql/index.ts +++ b/packages/frontend/graphql/src/graphql/index.ts @@ -677,6 +677,7 @@ export const getWorkspacesQuery = { query getWorkspaces { workspaces { id + initialized owner { id } diff --git a/packages/frontend/graphql/src/schema.ts b/packages/frontend/graphql/src/schema.ts index 2ba9e554bc624..3aa326ddc5fb8 100644 --- a/packages/frontend/graphql/src/schema.ts +++ b/packages/frontend/graphql/src/schema.ts @@ -1203,6 +1203,8 @@ export interface WorkspaceType { features: Array; histories: Array; id: Scalars['ID']['output']; + /** is current workspace initialized */ + initialized: Scalars['Boolean']['output']; /** member count of workspace */ memberCount: Scalars['Int']['output']; /** Members of workspace */ @@ -1843,6 +1845,7 @@ export type GetWorkspacesQuery = { workspaces: Array<{ __typename?: 'WorkspaceType'; id: string; + initialized: boolean; owner: { __typename?: 'UserType'; id: string }; }>; };