Skip to content

Commit

Permalink
eat: create ViewField model (twentyhq#961)
Browse files Browse the repository at this point in the history
* feat: create ViewField model

- Created ViewField prisma model
- Added ViewField server resolvers for findMany/updateOne
- Added getViewFields/updateViewField graphql queries

Closes twentyhq#849

* chore: update node version in .nvmrc files
  • Loading branch information
thaisguigon authored and AdityaPimpalkar committed Aug 4, 2023
1 parent 17e991e commit 35c394e
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 2 deletions.
2 changes: 1 addition & 1 deletion front/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.6.0
18.16.0
194 changes: 194 additions & 0 deletions front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,17 @@ export enum FileFolder {
WorkspaceLogo = 'WorkspaceLogo'
}

export type IntFilter = {
equals?: InputMaybe<Scalars['Int']>;
gt?: InputMaybe<Scalars['Int']>;
gte?: InputMaybe<Scalars['Int']>;
in?: InputMaybe<Array<Scalars['Int']>>;
lt?: InputMaybe<Scalars['Int']>;
lte?: InputMaybe<Scalars['Int']>;
not?: InputMaybe<NestedIntFilter>;
notIn?: InputMaybe<Array<Scalars['Int']>>;
};

export type IntNullableFilter = {
equals?: InputMaybe<Scalars['Int']>;
gt?: InputMaybe<Scalars['Int']>;
Expand Down Expand Up @@ -843,6 +854,7 @@ export type Mutation = {
updateOnePerson?: Maybe<Person>;
updateOnePipelineProgress?: Maybe<PipelineProgress>;
updateOnePipelineStage?: Maybe<PipelineStage>;
updateOneViewField: ViewField;
updateUser: User;
updateWorkspace: Workspace;
uploadAttachment: Scalars['String'];
Expand Down Expand Up @@ -964,6 +976,12 @@ export type MutationUpdateOnePipelineStageArgs = {
};


export type MutationUpdateOneViewFieldArgs = {
data: ViewFieldUpdateInput;
where: ViewFieldWhereUniqueInput;
};


export type MutationUpdateUserArgs = {
data: UserUpdateInput;
where: UserWhereUniqueInput;
Expand Down Expand Up @@ -1069,6 +1087,17 @@ export type NestedEnumPipelineProgressableTypeFilter = {
notIn?: InputMaybe<Array<PipelineProgressableType>>;
};

export type NestedIntFilter = {
equals?: InputMaybe<Scalars['Int']>;
gt?: InputMaybe<Scalars['Int']>;
gte?: InputMaybe<Scalars['Int']>;
in?: InputMaybe<Array<Scalars['Int']>>;
lt?: InputMaybe<Scalars['Int']>;
lte?: InputMaybe<Scalars['Int']>;
not?: InputMaybe<NestedIntFilter>;
notIn?: InputMaybe<Array<Scalars['Int']>>;
};

export type NestedIntNullableFilter = {
equals?: InputMaybe<Scalars['Int']>;
gt?: InputMaybe<Scalars['Int']>;
Expand Down Expand Up @@ -1590,6 +1619,7 @@ export type Query = {
findManyPipelineProgress: Array<PipelineProgress>;
findManyPipelineStage: Array<PipelineStage>;
findManyUser: Array<User>;
findManyViewField: Array<ViewField>;
findManyWorkspaceMember: Array<WorkspaceMember>;
findUniqueCompany: Company;
findUniquePerson: Person;
Expand Down Expand Up @@ -1676,6 +1706,16 @@ export type QueryFindManyUserArgs = {
};


export type QueryFindManyViewFieldArgs = {
cursor?: InputMaybe<ViewFieldWhereUniqueInput>;
distinct?: InputMaybe<Array<ViewFieldScalarFieldEnum>>;
orderBy?: InputMaybe<Array<ViewFieldOrderByWithRelationInput>>;
skip?: InputMaybe<Scalars['Int']>;
take?: InputMaybe<Scalars['Int']>;
where?: InputMaybe<ViewFieldWhereInput>;
};


export type QueryFindManyWorkspaceMemberArgs = {
cursor?: InputMaybe<WorkspaceMemberWhereUniqueInput>;
distinct?: InputMaybe<Array<WorkspaceMemberScalarFieldEnum>>;
Expand Down Expand Up @@ -1961,6 +2001,66 @@ export type Verify = {
user: User;
};

export type ViewField = {
__typename?: 'ViewField';
fieldName: Scalars['String'];
id: Scalars['ID'];
index: Scalars['Int'];
isVisible: Scalars['Boolean'];
objectName: Scalars['String'];
sizeInPx: Scalars['Int'];
};

export type ViewFieldOrderByWithRelationInput = {
fieldName?: InputMaybe<SortOrder>;
id?: InputMaybe<SortOrder>;
index?: InputMaybe<SortOrder>;
isVisible?: InputMaybe<SortOrder>;
objectName?: InputMaybe<SortOrder>;
sizeInPx?: InputMaybe<SortOrder>;
};

export enum ViewFieldScalarFieldEnum {
FieldName = 'fieldName',
Id = 'id',
Index = 'index',
IsVisible = 'isVisible',
ObjectName = 'objectName',
SizeInPx = 'sizeInPx',
WorkspaceId = 'workspaceId'
}

export type ViewFieldUpdateInput = {
fieldName?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['String']>;
index?: InputMaybe<Scalars['Int']>;
isVisible?: InputMaybe<Scalars['Boolean']>;
objectName?: InputMaybe<Scalars['String']>;
sizeInPx?: InputMaybe<Scalars['Int']>;
};

export type ViewFieldUpdateManyWithoutWorkspaceNestedInput = {
connect?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
disconnect?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
set?: InputMaybe<Array<ViewFieldWhereUniqueInput>>;
};

export type ViewFieldWhereInput = {
AND?: InputMaybe<Array<ViewFieldWhereInput>>;
NOT?: InputMaybe<Array<ViewFieldWhereInput>>;
OR?: InputMaybe<Array<ViewFieldWhereInput>>;
fieldName?: InputMaybe<StringFilter>;
id?: InputMaybe<StringFilter>;
index?: InputMaybe<IntFilter>;
isVisible?: InputMaybe<BoolFilter>;
objectName?: InputMaybe<StringFilter>;
sizeInPx?: InputMaybe<IntFilter>;
};

export type ViewFieldWhereUniqueInput = {
id?: InputMaybe<Scalars['String']>;
};

export type Workspace = {
__typename?: 'Workspace';
Attachment?: Maybe<Array<Attachment>>;
Expand All @@ -1979,6 +2079,7 @@ export type Workspace = {
pipelineStages?: Maybe<Array<PipelineStage>>;
pipelines?: Maybe<Array<Pipeline>>;
updatedAt: Scalars['DateTime'];
viewFields?: Maybe<Array<ViewField>>;
workspaceMember?: Maybe<Array<WorkspaceMember>>;
};

Expand Down Expand Up @@ -2053,6 +2154,7 @@ export type WorkspaceUpdateInput = {
pipelineStages?: InputMaybe<PipelineStageUpdateManyWithoutWorkspaceNestedInput>;
pipelines?: InputMaybe<PipelineUpdateManyWithoutWorkspaceNestedInput>;
updatedAt?: InputMaybe<Scalars['DateTime']>;
viewFields?: InputMaybe<ViewFieldUpdateManyWithoutWorkspaceNestedInput>;
workspaceMember?: InputMaybe<WorkspaceMemberUpdateManyWithoutWorkspaceNestedInput>;
};

Expand Down Expand Up @@ -2448,6 +2550,21 @@ export type RemoveProfilePictureMutationVariables = Exact<{

export type RemoveProfilePictureMutation = { __typename?: 'Mutation', updateUser: { __typename?: 'User', id: string, avatarUrl?: string | null } };

export type GetViewFieldsQueryVariables = Exact<{
where?: InputMaybe<ViewFieldWhereInput>;
}>;


export type GetViewFieldsQuery = { __typename?: 'Query', viewFields: Array<{ __typename?: 'ViewField', id: string, fieldName: string, isVisible: boolean, sizeInPx: number, index: number }> };

export type UpdateViewFieldMutationVariables = Exact<{
data: ViewFieldUpdateInput;
where: ViewFieldWhereUniqueInput;
}>;


export type UpdateViewFieldMutation = { __typename?: 'Mutation', updateOneViewField: { __typename?: 'ViewField', id: string, fieldName: string, isVisible: boolean, sizeInPx: number, index: number } };

export type GetWorkspaceMembersQueryVariables = Exact<{ [key: string]: never; }>;


Expand Down Expand Up @@ -4669,6 +4786,83 @@ export function useRemoveProfilePictureMutation(baseOptions?: Apollo.MutationHoo
export type RemoveProfilePictureMutationHookResult = ReturnType<typeof useRemoveProfilePictureMutation>;
export type RemoveProfilePictureMutationResult = Apollo.MutationResult<RemoveProfilePictureMutation>;
export type RemoveProfilePictureMutationOptions = Apollo.BaseMutationOptions<RemoveProfilePictureMutation, RemoveProfilePictureMutationVariables>;
export const GetViewFieldsDocument = gql`
query GetViewFields($where: ViewFieldWhereInput) {
viewFields: findManyViewField(where: $where) {
id
fieldName
isVisible
sizeInPx
index
}
}
`;

/**
* __useGetViewFieldsQuery__
*
* To run a query within a React component, call `useGetViewFieldsQuery` and pass it any options that fit your needs.
* When your component renders, `useGetViewFieldsQuery` 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 } = useGetViewFieldsQuery({
* variables: {
* where: // value for 'where'
* },
* });
*/
export function useGetViewFieldsQuery(baseOptions?: Apollo.QueryHookOptions<GetViewFieldsQuery, GetViewFieldsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<GetViewFieldsQuery, GetViewFieldsQueryVariables>(GetViewFieldsDocument, options);
}
export function useGetViewFieldsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetViewFieldsQuery, GetViewFieldsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<GetViewFieldsQuery, GetViewFieldsQueryVariables>(GetViewFieldsDocument, options);
}
export type GetViewFieldsQueryHookResult = ReturnType<typeof useGetViewFieldsQuery>;
export type GetViewFieldsLazyQueryHookResult = ReturnType<typeof useGetViewFieldsLazyQuery>;
export type GetViewFieldsQueryResult = Apollo.QueryResult<GetViewFieldsQuery, GetViewFieldsQueryVariables>;
export const UpdateViewFieldDocument = gql`
mutation UpdateViewField($data: ViewFieldUpdateInput!, $where: ViewFieldWhereUniqueInput!) {
updateOneViewField(data: $data, where: $where) {
id
fieldName
isVisible
sizeInPx
index
}
}
`;
export type UpdateViewFieldMutationFn = Apollo.MutationFunction<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>;

/**
* __useUpdateViewFieldMutation__
*
* To run a mutation, you first call `useUpdateViewFieldMutation` within a React component and pass it any options that fit your needs.
* When your component renders, `useUpdateViewFieldMutation` returns a tuple that includes:
* - A mutate function that you can call at any time to execute the mutation
* - An object with fields that represent the current status of the mutation's execution
*
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
*
* @example
* const [updateViewFieldMutation, { data, loading, error }] = useUpdateViewFieldMutation({
* variables: {
* data: // value for 'data'
* where: // value for 'where'
* },
* });
*/
export function useUpdateViewFieldMutation(baseOptions?: Apollo.MutationHookOptions<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useMutation<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>(UpdateViewFieldDocument, options);
}
export type UpdateViewFieldMutationHookResult = ReturnType<typeof useUpdateViewFieldMutation>;
export type UpdateViewFieldMutationResult = Apollo.MutationResult<UpdateViewFieldMutation>;
export type UpdateViewFieldMutationOptions = Apollo.BaseMutationOptions<UpdateViewFieldMutation, UpdateViewFieldMutationVariables>;
export const GetWorkspaceMembersDocument = gql`
query GetWorkspaceMembers {
workspaceMembers: findManyWorkspaceMember {
Expand Down
13 changes: 13 additions & 0 deletions front/src/modules/views/queries/select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';

export const GET_VIEW_FIELDS = gql`
query GetViewFields($where: ViewFieldWhereInput) {
viewFields: findManyViewField(where: $where) {
id
fieldName
isVisible
sizeInPx
index
}
}
`;
16 changes: 16 additions & 0 deletions front/src/modules/views/queries/update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { gql } from '@apollo/client';

export const UPDATE_VIEW_FIELD = gql`
mutation UpdateViewField(
$data: ViewFieldUpdateInput!
$where: ViewFieldWhereUniqueInput!
) {
updateOneViewField(data: $data, where: $where) {
id
fieldName
isVisible
sizeInPx
index
}
}
`;
2 changes: 1 addition & 1 deletion server/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.10.0
18.16.0
5 changes: 5 additions & 0 deletions server/src/ability/ability.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Attachment,
UserSettings,
Favorite,
ViewField,
} from '@prisma/client';

import { AbilityAction } from './ability.action';
Expand All @@ -38,6 +39,7 @@ type SubjectsAbility = Subjects<{
Attachment: Attachment;
UserSettings: UserSettings;
Favorite: Favorite;
ViewField: ViewField;
}>;

export type AppAbility = PureAbility<
Expand Down Expand Up @@ -136,6 +138,9 @@ export class AbilityFactory {
can(AbilityAction.Delete, 'Favorite', {
workspaceId: workspace.id,
});
// ViewField
can(AbilityAction.Read, 'ViewField', { workspaceId: workspace.id });
can(AbilityAction.Update, 'ViewField', { workspaceId: workspace.id });

return build();
}
Expand Down
10 changes: 10 additions & 0 deletions server/src/ability/ability.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ import {
CreateFavoriteAbilityHandler,
ReadFavoriteAbilityHandler,
} from './handlers/favorite.ability-handler';
import {
ReadViewFieldAbilityHandler,
UpdateViewFieldAbilityHandler,
} from './handlers/view-field.ability-handler';

@Global()
@Module({
Expand Down Expand Up @@ -185,6 +189,9 @@ import {
//Favorite
ReadFavoriteAbilityHandler,
CreateFavoriteAbilityHandler,
// ViewField
ReadViewFieldAbilityHandler,
UpdateViewFieldAbilityHandler,
],
exports: [
AbilityFactory,
Expand Down Expand Up @@ -269,6 +276,9 @@ import {
//Favorite
ReadFavoriteAbilityHandler,
CreateFavoriteAbilityHandler,
// ViewField
ReadViewFieldAbilityHandler,
UpdateViewFieldAbilityHandler,
],
})
export class AbilityModule {}
Loading

0 comments on commit 35c394e

Please sign in to comment.