mirror of
https://github.com/lingble/twenty.git
synced 2025-11-01 05:07:56 +00:00
Lucas/t 364 on comment drawer i can fetch all comment threads with (#193)
* Added prisma to suggested extension in container * Added comments and authors on drawer with proper resolving * Fix lint * Fix console log * Fixed generated front graphql from rebase
This commit is contained in:
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@@ -2,6 +2,7 @@
|
|||||||
"recommendations": [
|
"recommendations": [
|
||||||
"ms-vscode-remote.remote-containers",
|
"ms-vscode-remote.remote-containers",
|
||||||
"ms-vscode.makefile-tools",
|
"ms-vscode.makefile-tools",
|
||||||
"dbaeumer.vscode-eslint"
|
"dbaeumer.vscode-eslint",
|
||||||
|
"Prisma.prisma"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -101,11 +101,28 @@ export type CommentThreadCreateNestedOneWithoutCommentsInput = {
|
|||||||
connect?: InputMaybe<CommentThreadWhereUniqueInput>;
|
connect?: InputMaybe<CommentThreadWhereUniqueInput>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CommentThreadOrderByWithRelationInput = {
|
||||||
|
commentThreadTargets?: InputMaybe<CommentThreadTargetOrderByRelationAggregateInput>;
|
||||||
|
comments?: InputMaybe<CommentOrderByRelationAggregateInput>;
|
||||||
|
createdAt?: InputMaybe<SortOrder>;
|
||||||
|
deletedAt?: InputMaybe<SortOrder>;
|
||||||
|
id?: InputMaybe<SortOrder>;
|
||||||
|
updatedAt?: InputMaybe<SortOrder>;
|
||||||
|
};
|
||||||
|
|
||||||
export type CommentThreadRelationFilter = {
|
export type CommentThreadRelationFilter = {
|
||||||
is?: InputMaybe<CommentThreadWhereInput>;
|
is?: InputMaybe<CommentThreadWhereInput>;
|
||||||
isNot?: InputMaybe<CommentThreadWhereInput>;
|
isNot?: InputMaybe<CommentThreadWhereInput>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export enum CommentThreadScalarFieldEnum {
|
||||||
|
CreatedAt = 'createdAt',
|
||||||
|
DeletedAt = 'deletedAt',
|
||||||
|
Id = 'id',
|
||||||
|
UpdatedAt = 'updatedAt',
|
||||||
|
WorkspaceId = 'workspaceId'
|
||||||
|
}
|
||||||
|
|
||||||
export type CommentThreadTarget = {
|
export type CommentThreadTarget = {
|
||||||
__typename?: 'CommentThreadTarget';
|
__typename?: 'CommentThreadTarget';
|
||||||
commentThread: CommentThread;
|
commentThread: CommentThread;
|
||||||
@@ -142,6 +159,10 @@ export type CommentThreadTargetListRelationFilter = {
|
|||||||
some?: InputMaybe<CommentThreadTargetWhereInput>;
|
some?: InputMaybe<CommentThreadTargetWhereInput>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type CommentThreadTargetOrderByRelationAggregateInput = {
|
||||||
|
_count?: InputMaybe<SortOrder>;
|
||||||
|
};
|
||||||
|
|
||||||
export type CommentThreadTargetWhereInput = {
|
export type CommentThreadTargetWhereInput = {
|
||||||
AND?: InputMaybe<Array<CommentThreadTargetWhereInput>>;
|
AND?: InputMaybe<Array<CommentThreadTargetWhereInput>>;
|
||||||
NOT?: InputMaybe<Array<CommentThreadTargetWhereInput>>;
|
NOT?: InputMaybe<Array<CommentThreadTargetWhereInput>>;
|
||||||
@@ -808,6 +829,7 @@ export type PipelineWhereUniqueInput = {
|
|||||||
|
|
||||||
export type Query = {
|
export type Query = {
|
||||||
__typename?: 'Query';
|
__typename?: 'Query';
|
||||||
|
findManyCommentThreads: Array<CommentThread>;
|
||||||
findManyCompany: Array<Company>;
|
findManyCompany: Array<Company>;
|
||||||
findManyPerson: Array<Person>;
|
findManyPerson: Array<Person>;
|
||||||
findManyPipeline: Array<Pipeline>;
|
findManyPipeline: Array<Pipeline>;
|
||||||
@@ -816,6 +838,16 @@ export type Query = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export type QueryFindManyCommentThreadsArgs = {
|
||||||
|
cursor?: InputMaybe<CommentThreadWhereUniqueInput>;
|
||||||
|
distinct?: InputMaybe<Array<CommentThreadScalarFieldEnum>>;
|
||||||
|
orderBy?: InputMaybe<Array<CommentThreadOrderByWithRelationInput>>;
|
||||||
|
skip?: InputMaybe<Scalars['Int']>;
|
||||||
|
take?: InputMaybe<Scalars['Int']>;
|
||||||
|
where?: InputMaybe<CommentThreadWhereInput>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export type QueryFindManyCompanyArgs = {
|
export type QueryFindManyCompanyArgs = {
|
||||||
cursor?: InputMaybe<CompanyWhereUniqueInput>;
|
cursor?: InputMaybe<CompanyWhereUniqueInput>;
|
||||||
distinct?: InputMaybe<Array<CompanyScalarFieldEnum>>;
|
distinct?: InputMaybe<Array<CompanyScalarFieldEnum>>;
|
||||||
@@ -1063,6 +1095,13 @@ export type GetPeopleCountsQueryVariables = Exact<{
|
|||||||
|
|
||||||
export type GetPeopleCountsQuery = { __typename?: 'Query', people: Array<{ __typename?: 'Person', commentsCount: number }> };
|
export type GetPeopleCountsQuery = { __typename?: 'Query', people: Array<{ __typename?: 'Person', commentsCount: number }> };
|
||||||
|
|
||||||
|
export type GetCommentThreadsByTargetsQueryVariables = Exact<{
|
||||||
|
commentThreadTargetIds: Array<Scalars['String']> | Scalars['String'];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
|
||||||
|
export type GetCommentThreadsByTargetsQuery = { __typename?: 'Query', findManyCommentThreads: Array<{ __typename?: 'CommentThread', id: string, comments?: Array<{ __typename?: 'Comment', id: string, body: string, createdAt: any, updatedAt: any, author: { __typename?: 'User', id: string, displayName: string, avatarUrl?: string | null } }> | null }> };
|
||||||
|
|
||||||
export type GetCompaniesQueryVariables = Exact<{
|
export type GetCompaniesQueryVariables = Exact<{
|
||||||
orderBy?: InputMaybe<Array<CompanyOrderByWithRelationInput> | CompanyOrderByWithRelationInput>;
|
orderBy?: InputMaybe<Array<CompanyOrderByWithRelationInput> | CompanyOrderByWithRelationInput>;
|
||||||
where?: InputMaybe<CompanyWhereInput>;
|
where?: InputMaybe<CompanyWhereInput>;
|
||||||
@@ -1258,6 +1297,54 @@ export function useGetPeopleCountsLazyQuery(baseOptions?: Apollo.LazyQueryHookOp
|
|||||||
export type GetPeopleCountsQueryHookResult = ReturnType<typeof useGetPeopleCountsQuery>;
|
export type GetPeopleCountsQueryHookResult = ReturnType<typeof useGetPeopleCountsQuery>;
|
||||||
export type GetPeopleCountsLazyQueryHookResult = ReturnType<typeof useGetPeopleCountsLazyQuery>;
|
export type GetPeopleCountsLazyQueryHookResult = ReturnType<typeof useGetPeopleCountsLazyQuery>;
|
||||||
export type GetPeopleCountsQueryResult = Apollo.QueryResult<GetPeopleCountsQuery, GetPeopleCountsQueryVariables>;
|
export type GetPeopleCountsQueryResult = Apollo.QueryResult<GetPeopleCountsQuery, GetPeopleCountsQueryVariables>;
|
||||||
|
export const GetCommentThreadsByTargetsDocument = gql`
|
||||||
|
query GetCommentThreadsByTargets($commentThreadTargetIds: [String!]!) {
|
||||||
|
findManyCommentThreads(
|
||||||
|
where: {commentThreadTargets: {some: {commentableId: {in: $commentThreadTargetIds}}}}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
comments {
|
||||||
|
id
|
||||||
|
body
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
author {
|
||||||
|
id
|
||||||
|
displayName
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __useGetCommentThreadsByTargetsQuery__
|
||||||
|
*
|
||||||
|
* To run a query within a React component, call `useGetCommentThreadsByTargetsQuery` and pass it any options that fit your needs.
|
||||||
|
* When your component renders, `useGetCommentThreadsByTargetsQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||||
|
* you can use to render your UI.
|
||||||
|
*
|
||||||
|
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const { data, loading, error } = useGetCommentThreadsByTargetsQuery({
|
||||||
|
* variables: {
|
||||||
|
* commentThreadTargetIds: // value for 'commentThreadTargetIds'
|
||||||
|
* },
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
export function useGetCommentThreadsByTargetsQuery(baseOptions: Apollo.QueryHookOptions<GetCommentThreadsByTargetsQuery, GetCommentThreadsByTargetsQueryVariables>) {
|
||||||
|
const options = {...defaultOptions, ...baseOptions}
|
||||||
|
return Apollo.useQuery<GetCommentThreadsByTargetsQuery, GetCommentThreadsByTargetsQueryVariables>(GetCommentThreadsByTargetsDocument, options);
|
||||||
|
}
|
||||||
|
export function useGetCommentThreadsByTargetsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetCommentThreadsByTargetsQuery, GetCommentThreadsByTargetsQueryVariables>) {
|
||||||
|
const options = {...defaultOptions, ...baseOptions}
|
||||||
|
return Apollo.useLazyQuery<GetCommentThreadsByTargetsQuery, GetCommentThreadsByTargetsQueryVariables>(GetCommentThreadsByTargetsDocument, options);
|
||||||
|
}
|
||||||
|
export type GetCommentThreadsByTargetsQueryHookResult = ReturnType<typeof useGetCommentThreadsByTargetsQuery>;
|
||||||
|
export type GetCommentThreadsByTargetsLazyQueryHookResult = ReturnType<typeof useGetCommentThreadsByTargetsLazyQuery>;
|
||||||
|
export type GetCommentThreadsByTargetsQueryResult = Apollo.QueryResult<GetCommentThreadsByTargetsQuery, GetCommentThreadsByTargetsQueryVariables>;
|
||||||
export const GetCompaniesDocument = gql`
|
export const GetCompaniesDocument = gql`
|
||||||
query GetCompanies($orderBy: [CompanyOrderByWithRelationInput!], $where: CompanyWhereInput) {
|
query GetCompanies($orderBy: [CompanyOrderByWithRelationInput!], $where: CompanyWhereInput) {
|
||||||
companies: findManyCompany(orderBy: $orderBy, where: $where) {
|
companies: findManyCompany(orderBy: $orderBy, where: $where) {
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { CommentThreadForDrawer } from '@/comments/types/CommentThreadForDrawer';
|
||||||
|
|
||||||
|
import { CommentTextInput } from './CommentTextInput';
|
||||||
|
|
||||||
|
type OwnProps = {
|
||||||
|
commentThread: CommentThreadForDrawer;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CommentThread({ commentThread }: OwnProps) {
|
||||||
|
function handleSendComment(text: string) {
|
||||||
|
console.log(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{commentThread.comments?.map((comment) => (
|
||||||
|
<div key={comment.id}>
|
||||||
|
<div>
|
||||||
|
{comment.author?.displayName} - {comment.createdAt}
|
||||||
|
</div>
|
||||||
|
<div>{comment.body}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<CommentTextInput onSend={handleSendComment} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,30 +1,36 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { CommentThreadForDrawer } from '@/comments/types/CommentThreadForDrawer';
|
||||||
import { RightDrawerBody } from '@/ui/layout/right-drawer/components/RightDrawerBody';
|
import { RightDrawerBody } from '@/ui/layout/right-drawer/components/RightDrawerBody';
|
||||||
import { RightDrawerPage } from '@/ui/layout/right-drawer/components/RightDrawerPage';
|
import { RightDrawerPage } from '@/ui/layout/right-drawer/components/RightDrawerPage';
|
||||||
import { RightDrawerTopBar } from '@/ui/layout/right-drawer/components/RightDrawerTopBar';
|
import { RightDrawerTopBar } from '@/ui/layout/right-drawer/components/RightDrawerTopBar';
|
||||||
|
import { useGetCommentThreadsByTargetsQuery } from '~/generated/graphql';
|
||||||
|
|
||||||
import { commentableEntityArrayState } from '../../states/commentableEntityArrayState';
|
import { commentableEntityArrayState } from '../../states/commentableEntityArrayState';
|
||||||
|
|
||||||
import { CommentTextInput } from './CommentTextInput';
|
import { CommentThread } from './CommentThread';
|
||||||
|
|
||||||
export function RightDrawerComments() {
|
export function RightDrawerComments() {
|
||||||
const [commentableEntityArray] = useRecoilState(commentableEntityArrayState);
|
const [commentableEntityArray] = useRecoilState(commentableEntityArrayState);
|
||||||
|
|
||||||
function handleSendComment(text: string) {
|
const { data: queryResult } = useGetCommentThreadsByTargetsQuery({
|
||||||
console.log(text);
|
variables: {
|
||||||
}
|
commentThreadTargetIds: commentableEntityArray.map(
|
||||||
|
(commentableEntity) => commentableEntity.id,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const commentThreads: CommentThreadForDrawer[] =
|
||||||
|
queryResult?.findManyCommentThreads ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RightDrawerPage>
|
<RightDrawerPage>
|
||||||
<RightDrawerTopBar title="Comments" />
|
<RightDrawerTopBar title="Comments" />
|
||||||
<RightDrawerBody>
|
<RightDrawerBody>
|
||||||
{commentableEntityArray.map((commentableEntity) => (
|
{commentThreads.map((commentThread) => (
|
||||||
<div key={commentableEntity.id}>
|
<CommentThread commentThread={commentThread} />
|
||||||
{commentableEntity.type} - {commentableEntity.id}
|
|
||||||
</div>
|
|
||||||
))}
|
))}
|
||||||
<CommentTextInput onSend={handleSendComment} />
|
|
||||||
</RightDrawerBody>
|
</RightDrawerBody>
|
||||||
</RightDrawerPage>
|
</RightDrawerPage>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,3 +34,28 @@ export const usePeopleCommentsCountQuery = (personId: string) => {
|
|||||||
});
|
});
|
||||||
return { ...rest, data: data?.people[0].commentsCount };
|
return { ...rest, data: data?.people[0].commentsCount };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const GET_COMMENT_THREADS_BY_TARGETS = gql`
|
||||||
|
query GetCommentThreadsByTargets($commentThreadTargetIds: [String!]!) {
|
||||||
|
findManyCommentThreads(
|
||||||
|
where: {
|
||||||
|
commentThreadTargets: {
|
||||||
|
some: { commentableId: { in: $commentThreadTargetIds } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
id
|
||||||
|
comments {
|
||||||
|
id
|
||||||
|
body
|
||||||
|
createdAt
|
||||||
|
updatedAt
|
||||||
|
author {
|
||||||
|
id
|
||||||
|
displayName
|
||||||
|
avatarUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { GetCommentThreadsByTargetsQuery } from '~/generated/graphql';
|
||||||
|
|
||||||
|
export type CommentThreadForDrawer =
|
||||||
|
GetCommentThreadsByTargetsQuery['findManyCommentThreads'][0];
|
||||||
@@ -23,6 +23,7 @@ import { CommentThreadRelationsResolver } from './resolvers/relations/comment-th
|
|||||||
import { PipelineRelationsResolver } from './resolvers/relations/pipeline-relations.resolver';
|
import { PipelineRelationsResolver } from './resolvers/relations/pipeline-relations.resolver';
|
||||||
import { PipelineStageRelationsResolver } from './resolvers/relations/pipeline-stage-relations.resolver';
|
import { PipelineStageRelationsResolver } from './resolvers/relations/pipeline-stage-relations.resolver';
|
||||||
import { GraphQLError } from 'graphql';
|
import { GraphQLError } from 'graphql';
|
||||||
|
import { CommentRelationsResolver } from './resolvers/relations/comment-relations.resolver';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -51,6 +52,7 @@ import { GraphQLError } from 'graphql';
|
|||||||
PipelineStageResolver,
|
PipelineStageResolver,
|
||||||
|
|
||||||
CompanyRelationsResolver,
|
CompanyRelationsResolver,
|
||||||
|
CommentRelationsResolver,
|
||||||
PersonRelationsResolver,
|
PersonRelationsResolver,
|
||||||
UserRelationsResolver,
|
UserRelationsResolver,
|
||||||
WorkspaceMemberRelationsResolver,
|
WorkspaceMemberRelationsResolver,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Resolver, Args, Mutation } from '@nestjs/graphql';
|
import { Resolver, Args, Mutation, Query } from '@nestjs/graphql';
|
||||||
import { UseGuards } from '@nestjs/common';
|
import { UseGuards } from '@nestjs/common';
|
||||||
import { JwtAuthGuard } from 'src/auth/guards/jwt.auth.guard';
|
import { JwtAuthGuard } from 'src/auth/guards/jwt.auth.guard';
|
||||||
import { PrismaService } from 'src/database/prisma.service';
|
import { PrismaService } from 'src/database/prisma.service';
|
||||||
@@ -7,11 +7,16 @@ import { AuthWorkspace } from './decorators/auth-workspace.decorator';
|
|||||||
import { CommentThread } from '../@generated/comment-thread/comment-thread.model';
|
import { CommentThread } from '../@generated/comment-thread/comment-thread.model';
|
||||||
import { CreateOneCommentThreadArgs } from '../@generated/comment-thread/create-one-comment-thread.args';
|
import { CreateOneCommentThreadArgs } from '../@generated/comment-thread/create-one-comment-thread.args';
|
||||||
import { CreateOneCommentThreadGuard } from './guards/create-one-comment-thread.guard';
|
import { CreateOneCommentThreadGuard } from './guards/create-one-comment-thread.guard';
|
||||||
|
import { FindManyCommentThreadArgs } from '../@generated/comment-thread/find-many-comment-thread.args';
|
||||||
|
import { ArgsService } from './services/args.service';
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Resolver(() => CommentThread)
|
@Resolver(() => CommentThread)
|
||||||
export class CommentThreadResolver {
|
export class CommentThreadResolver {
|
||||||
constructor(private readonly prismaService: PrismaService) {}
|
constructor(
|
||||||
|
private readonly prismaService: PrismaService,
|
||||||
|
private readonly argsService: ArgsService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@UseGuards(CreateOneCommentThreadGuard)
|
@UseGuards(CreateOneCommentThreadGuard)
|
||||||
@Mutation(() => CommentThread, {
|
@Mutation(() => CommentThread, {
|
||||||
@@ -35,4 +40,21 @@ export class CommentThreadResolver {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Query(() => [CommentThread])
|
||||||
|
async findManyCommentThreads(
|
||||||
|
@Args() args: FindManyCommentThreadArgs,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
|
) {
|
||||||
|
const preparedArgs =
|
||||||
|
await this.argsService.prepareFindManyArgs<FindManyCommentThreadArgs>(
|
||||||
|
args,
|
||||||
|
workspace,
|
||||||
|
);
|
||||||
|
const result = await this.prismaService.commentThread.findMany(
|
||||||
|
preparedArgs,
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import * as TypeGraphQL from '@nestjs/graphql';
|
||||||
|
import { PrismaService } from 'src/database/prisma.service';
|
||||||
|
import { User } from 'src/api/@generated/user/user.model';
|
||||||
|
import { Comment } from 'src/api/@generated/comment/comment.model';
|
||||||
|
|
||||||
|
@TypeGraphQL.Resolver(() => Comment)
|
||||||
|
export class CommentRelationsResolver {
|
||||||
|
constructor(private readonly prismaService: PrismaService) {}
|
||||||
|
|
||||||
|
@TypeGraphQL.ResolveField(() => User, {
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
async author(@TypeGraphQL.Parent() comment: Comment): Promise<User | null> {
|
||||||
|
return await this.prismaService.comment
|
||||||
|
.findFirst({
|
||||||
|
where: {
|
||||||
|
id: comment.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.author({});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user