diff --git a/front/src/generated/graphql.tsx b/front/src/generated/graphql.tsx index b0df0061c..cd5e4087f 100644 --- a/front/src/generated/graphql.tsx +++ b/front/src/generated/graphql.tsx @@ -565,6 +565,7 @@ export type ClientConfig = { __typename?: 'ClientConfig'; authProviders: AuthProviders; debugMode: Scalars['Boolean']; + flexibleBackendEnabled: Scalars['Boolean']; signInPrefilled: Scalars['Boolean']; support: Support; telemetry: Telemetry; @@ -1064,6 +1065,7 @@ export type Mutation = { UpdateOneWorkspaceMember: WorkspaceMember; allowImpersonation: WorkspaceMember; challenge: LoginToken; + createCustomField: Scalars['String']; createEvent: Analytics; createFavoriteForCompany: Favorite; createFavoriteForPerson: Favorite; @@ -1135,6 +1137,13 @@ export type MutationChallengeArgs = { }; +export type MutationCreateCustomFieldArgs = { + name: Scalars['String']; + objectId: Scalars['String']; + type: Scalars['String']; +}; + + export type MutationCreateEventArgs = { data: Scalars['JSON']; type: Scalars['String']; @@ -1528,6 +1537,21 @@ export type NestedStringNullableFilter = { startsWith?: InputMaybe; }; +export type PageInfo = { + __typename?: 'PageInfo'; + endCursor?: Maybe; + hasNextPage: Scalars['Boolean']; + hasPreviousPage: Scalars['Boolean']; + startCursor?: Maybe; +}; + +export type PaginatedUniversalEntity = { + __typename?: 'PaginatedUniversalEntity'; + edges?: Maybe>; + pageInfo?: Maybe; + totalCount: Scalars['Float']; +}; + export type Person = { __typename?: 'Person'; ActivityTarget?: Maybe>; @@ -2099,7 +2123,9 @@ export type Query = { clientConfig: ClientConfig; currentUser: User; currentWorkspace: Workspace; + deleteOneCustom: UniversalEntity; findFavorites: Array; + findMany: PaginatedUniversalEntity; findManyActivities: Array; findManyCompany: Array; findManyPerson: Array; @@ -2112,9 +2138,11 @@ export type Query = { findManyViewFilter: Array; findManyViewSort: Array; findManyWorkspaceMember: Array; + findUnique: UniversalEntity; findUniqueCompany: Company; findUniquePerson: Person; findWorkspaceFromInviteHash: Workspace; + updateOneCustom: UniversalEntity; }; @@ -2128,6 +2156,21 @@ export type QueryCheckWorkspaceInviteHashIsValidArgs = { }; +export type QueryFindManyArgs = { + after?: InputMaybe; + before?: InputMaybe; + cursor?: InputMaybe; + distinct?: InputMaybe>; + entity: Scalars['String']; + first?: InputMaybe; + last?: InputMaybe; + orderBy?: InputMaybe; + skip?: InputMaybe; + take?: InputMaybe; + where?: InputMaybe; +}; + + export type QueryFindManyActivitiesArgs = { cursor?: InputMaybe; distinct?: InputMaybe>; @@ -2248,6 +2291,12 @@ export type QueryFindManyWorkspaceMemberArgs = { }; +export type QueryFindUniqueArgs = { + entity: Scalars['String']; + where?: InputMaybe; +}; + + export type QueryFindUniqueCompanyArgs = { where: CompanyWhereUniqueInput; }; @@ -2314,6 +2363,39 @@ export type Telemetry = { enabled: Scalars['Boolean']; }; +export enum TypeOrmSortOrder { + Asc = 'ASC', + Desc = 'DESC' +} + +export type UniversalEntity = { + __typename?: 'UniversalEntity'; + createdAt: Scalars['DateTime']; + data: Scalars['JSON']; + id: Scalars['ID']; + updatedAt: Scalars['DateTime']; +}; + +export type UniversalEntityEdge = { + __typename?: 'UniversalEntityEdge'; + cursor?: Maybe; + node?: Maybe; +}; + +export type UniversalEntityInput = { + createdAt?: InputMaybe; + data?: InputMaybe; + id?: InputMaybe; + updatedAt?: InputMaybe; +}; + +export type UniversalEntityOrderByRelationInput = { + createdAt?: InputMaybe; + data?: InputMaybe; + id?: InputMaybe; + updatedAt?: InputMaybe; +}; + export type User = { __typename?: 'User'; assignedActivities?: Maybe>; @@ -3657,6 +3739,8 @@ export type GetUsersQueryVariables = Exact<{ [key: string]: never; }>; export type GetUsersQuery = { __typename?: 'Query', findManyUser: Array<{ __typename?: 'User', id: string, email: string, displayName: string, firstName?: string | null, lastName?: string | null }> }; +export type ViewFieldFragmentFragment = { __typename?: 'ViewField', index: number, isVisible: boolean, key: string, name: string, size?: number | null, viewId: string }; + export type CreateViewMutationVariables = Exact<{ data: ViewCreateInput; }>; @@ -3720,7 +3804,7 @@ export type UpdateViewFieldMutationVariables = Exact<{ }>; -export type UpdateViewFieldMutation = { __typename?: 'Mutation', updateOneViewField: { __typename?: 'ViewField', index: number, isVisible: boolean, key: string, name: string, size?: number | null } }; +export type UpdateViewFieldMutation = { __typename?: 'Mutation', updateOneViewField: { __typename?: 'ViewField', index: number, isVisible: boolean, key: string, name: string, size?: number | null, viewId: string } }; export type UpdateViewFilterMutationVariables = Exact<{ data: ViewFilterUpdateInput; @@ -3744,7 +3828,7 @@ export type GetViewFieldsQueryVariables = Exact<{ }>; -export type GetViewFieldsQuery = { __typename?: 'Query', viewFields: Array<{ __typename?: 'ViewField', index: number, isVisible: boolean, key: string, name: string, size?: number | null }> }; +export type GetViewFieldsQuery = { __typename?: 'Query', viewFields: Array<{ __typename?: 'ViewField', index: number, isVisible: boolean, key: string, name: string, size?: number | null, viewId: string }> }; export type GetViewFiltersQueryVariables = Exact<{ where?: InputMaybe; @@ -4045,6 +4129,16 @@ export const UserFieldsFragmentFragmentDoc = gql` lastName } `; +export const ViewFieldFragmentFragmentDoc = gql` + fragment ViewFieldFragment on ViewField { + index + isVisible + key + name + size + viewId +} + `; export const WorkspaceMemberFieldsFragmentFragmentDoc = gql` fragment workspaceMemberFieldsFragment on WorkspaceMember { id @@ -6754,14 +6848,10 @@ export type UpdateViewMutationOptions = Apollo.BaseMutationOptions; /** @@ -6866,14 +6956,10 @@ export type UpdateViewSortMutationOptions = Apollo.BaseMutationOptions { }, }, }, + ViewField: { keyFields: ['viewId', 'key'] }, }, }), defaultOptions: { diff --git a/front/src/modules/ui/table/components/EntityTableHeader.tsx b/front/src/modules/ui/table/components/EntityTableHeader.tsx index 1accad3be..4dbd1dd65 100644 --- a/front/src/modules/ui/table/components/EntityTableHeader.tsx +++ b/front/src/modules/ui/table/components/EntityTableHeader.tsx @@ -126,6 +126,10 @@ export const EntityTableHeader = () => { ), ); + set(resizeFieldOffsetState, 0); + setInitialPointerPositionX(null); + setResizedFieldKey(null); + if (nextWidth !== tableColumnsByKey[resizedFieldKey].size) { const nextColumns = tableColumns.map((column) => column.key === resizedFieldKey @@ -135,10 +139,6 @@ export const EntityTableHeader = () => { await handleColumnsChange(nextColumns); } - - set(resizeFieldOffsetState, 0); - setInitialPointerPositionX(null); - setResizedFieldKey(null); }, [resizedFieldKey, tableColumnsByKey, tableColumns, handleColumnsChange], ); diff --git a/front/src/modules/ui/table/hooks/useTableColumns.ts b/front/src/modules/ui/table/hooks/useTableColumns.ts index 85a32200e..2842250dd 100644 --- a/front/src/modules/ui/table/hooks/useTableColumns.ts +++ b/front/src/modules/ui/table/hooks/useTableColumns.ts @@ -34,10 +34,10 @@ export const useTableColumns = () => { const handleColumnsChange = useCallback( async (columns: ColumnDefinition[]) => { - await onColumnsChange?.(columns); - setSavedTableColumns(columns); setTableColumns(columns); + + await onColumnsChange?.(columns); }, [onColumnsChange, setSavedTableColumns, setTableColumns], ); diff --git a/front/src/modules/views/graphql/fragments/viewFieldFragment.ts b/front/src/modules/views/graphql/fragments/viewFieldFragment.ts new file mode 100644 index 000000000..95d93b22d --- /dev/null +++ b/front/src/modules/views/graphql/fragments/viewFieldFragment.ts @@ -0,0 +1,12 @@ +import { gql } from '@apollo/client'; + +export const VIEW_FIELD_FRAGMENT = gql` + fragment ViewFieldFragment on ViewField { + index + isVisible + key + name + size + viewId + } +`; diff --git a/front/src/modules/views/graphql/mutations/updateViewField.ts b/front/src/modules/views/graphql/mutations/updateViewField.ts index 11a8b21d5..efb5776ee 100644 --- a/front/src/modules/views/graphql/mutations/updateViewField.ts +++ b/front/src/modules/views/graphql/mutations/updateViewField.ts @@ -6,11 +6,7 @@ export const UPDATE_VIEW_FIELD = gql` $where: ViewFieldWhereUniqueInput! ) { updateOneViewField(data: $data, where: $where) { - index - isVisible - key - name - size + ...ViewFieldFragment } } `; diff --git a/front/src/modules/views/graphql/queries/getViewFields.ts b/front/src/modules/views/graphql/queries/getViewFields.ts index cd0cad9d1..daecea978 100644 --- a/front/src/modules/views/graphql/queries/getViewFields.ts +++ b/front/src/modules/views/graphql/queries/getViewFields.ts @@ -6,11 +6,7 @@ export const GET_VIEW_FIELDS = gql` $orderBy: [ViewFieldOrderByWithRelationInput!] ) { viewFields: findManyViewField(where: $where, orderBy: $orderBy) { - index - isVisible - key - name - size + ...ViewFieldFragment } } `; diff --git a/front/src/modules/views/hooks/useTableViewFields.ts b/front/src/modules/views/hooks/useTableViewFields.ts index 19273da85..5e88a840e 100644 --- a/front/src/modules/views/hooks/useTableViewFields.ts +++ b/front/src/modules/views/hooks/useTableViewFields.ts @@ -1,4 +1,5 @@ -import { useCallback } from 'react'; +import { useCallback, useState } from 'react'; +import { getOperationName } from '@apollo/client/utilities'; import { useRecoilValue, useSetRecoilState } from 'recoil'; import type { ViewFieldMetadata } from '@/ui/editable-field/types/ViewField'; @@ -20,6 +21,8 @@ import { import { assertNotNull } from '~/utils/assert'; import { isDeeplyEqual } from '~/utils/isDeeplyEqual'; +import { GET_VIEW_FIELDS } from '../graphql/queries/getViewFields'; + const toViewFieldInput = ( objectId: 'company' | 'person', fieldDefinition: ColumnDefinition, @@ -45,6 +48,7 @@ export const useTableViewFields = ({ currentViewIdScopedState, TableRecoilScopeContext, ); + const [previousViewId, setPreviousViewId] = useState(); const [availableTableColumns, setAvailableTableColumns] = useRecoilScopedState( availableTableColumnsScopedState, @@ -78,6 +82,7 @@ export const useTableViewFields = ({ viewId, })), }, + refetchQueries: [getOperationName(GET_VIEW_FIELDS) ?? ''], }); }, [createViewFieldsMutation, currentViewId, objectId], @@ -107,7 +112,7 @@ export const useTableViewFields = ({ [currentViewId, updateViewFieldMutation], ); - const { refetch } = useGetViewFieldsQuery({ + useGetViewFieldsQuery({ skip: !currentViewId || skipFetch, variables: { orderBy: { index: SortOrder.Asc }, @@ -118,8 +123,7 @@ export const useTableViewFields = ({ onCompleted: async (data) => { if (!data.viewFields.length) { // Populate if empty - await createViewFields(columnDefinitions); - return refetch(); + return createViewFields(columnDefinitions); } const nextColumns = data.viewFields @@ -141,9 +145,14 @@ export const useTableViewFields = ({ }) .filter>(assertNotNull); - if (!isDeeplyEqual(tableColumns, nextColumns)) { - setSavedTableColumns(nextColumns); + setSavedTableColumns(nextColumns); + + if ( + previousViewId !== currentViewId && + !isDeeplyEqual(tableColumns, nextColumns) + ) { setTableColumns(nextColumns); + setPreviousViewId(currentViewId); } if (!availableTableColumns.length) { @@ -169,16 +178,8 @@ export const useTableViewFields = ({ savedTableColumnsByKey[column.key].isVisible !== column.isVisible), ); await updateViewFields(viewFieldsToUpdate); - - await refetch(); }, - [ - createViewFields, - currentViewId, - refetch, - savedTableColumnsByKey, - updateViewFields, - ], + [createViewFields, currentViewId, savedTableColumnsByKey, updateViewFields], ); return { createViewFields, persistColumns };