Skip to content

Commit

Permalink
feat: filter out empty workpace in sidebar list (toeverything#7960)
Browse files Browse the repository at this point in the history
fix PD-1567
  • Loading branch information
darkskygit committed Aug 28, 2024
1 parent 0668568 commit dde4574
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
15 changes: 15 additions & 0 deletions packages/backend/server/src/core/workspaces/resolvers/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/server/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
6 changes: 5 additions & 1 deletion packages/common/infra/src/modules/workspace/metadata.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WorkspaceFlavour } from '@affine/env/workspace';
import type { WorkspaceMetadata } from '@toeverything/infra';
import { Suspense } from 'react';

Expand Down Expand Up @@ -58,9 +59,13 @@ const SortableWorkspaceItem = ({
export const WorkspaceList = (props: WorkspaceListProps) => {
const workspaceList = props.items;

return workspaceList.map(item => (
<Suspense fallback={<WorkspaceCardSkeleton />} key={item.id}>
<SortableWorkspaceItem key={item.id} {...props} item={item} />
</Suspense>
));
return workspaceList
.filter(
w => w.flavour !== WorkspaceFlavour.AFFINE_CLOUD || w.initialized === true
)
.map(item => (
<Suspense fallback={<WorkspaceCardSkeleton />} key={item.id}>
<SortableWorkspaceItem key={item.id} {...props} item={item} />
</Suspense>
));
};
13 changes: 10 additions & 3 deletions packages/frontend/core/src/modules/workspace-engine/impls/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/graphql/src/graphql/get-workspaces.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query getWorkspaces {
workspaces {
id
initialized
owner {
id
}
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/graphql/src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ export const getWorkspacesQuery = {
query getWorkspaces {
workspaces {
id
initialized
owner {
id
}
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/graphql/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,8 @@ export interface WorkspaceType {
features: Array<FeatureType>;
histories: Array<DocHistoryType>;
id: Scalars['ID']['output'];
/** is current workspace initialized */
initialized: Scalars['Boolean']['output'];
/** member count of workspace */
memberCount: Scalars['Int']['output'];
/** Members of workspace */
Expand Down Expand Up @@ -1843,6 +1845,7 @@ export type GetWorkspacesQuery = {
workspaces: Array<{
__typename?: 'WorkspaceType';
id: string;
initialized: boolean;
owner: { __typename?: 'UserType'; id: string };
}>;
};
Expand Down

0 comments on commit dde4574

Please sign in to comment.