Fixed bug for refectch activities and create activity on the currently filtered user. (#1493)
* Fixed bug for refectch activities and create activity on the currently filtered user. * Refactor optimistif effect --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const COMPANY_FIELDS_FRAGMENT = gql`
|
||||
fragment CompanyFieldsFragment on Company {
|
||||
fragment companyFieldsFragment on Company {
|
||||
accountOwner {
|
||||
id
|
||||
email
|
||||
@ -18,5 +18,6 @@ export const COMPANY_FIELDS_FRAGMENT = gql`
|
||||
idealCustomerProfile
|
||||
id
|
||||
name
|
||||
_activityCount
|
||||
}
|
||||
`;
|
||||
|
||||
@ -3,7 +3,7 @@ import { gql } from '@apollo/client';
|
||||
export const INSERT_ONE_COMPANY = gql`
|
||||
mutation InsertOneCompany($data: CompanyCreateInput!) {
|
||||
createOneCompany(data: $data) {
|
||||
...CompanyFieldsFragment
|
||||
...companyFieldsFragment
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -6,7 +6,7 @@ export const UPDATE_ONE_COMPANY = gql`
|
||||
$data: CompanyUpdateInput!
|
||||
) {
|
||||
updateOneCompany(data: $data, where: $where) {
|
||||
...CompanyFieldsFragment
|
||||
...companyFieldsFragment
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
import { Company } from '~/generated/graphql';
|
||||
|
||||
import { GET_COMPANIES } from '../queries/getCompanies';
|
||||
|
||||
export const getCompaniesOptimisticEffectDefinition = {
|
||||
key: 'generic-entity-table-data-companies',
|
||||
typename: 'Company',
|
||||
query: GET_COMPANIES,
|
||||
resolver: ({
|
||||
currentData,
|
||||
newData,
|
||||
}: {
|
||||
currentData: Company[];
|
||||
newData: Company[];
|
||||
}) => {
|
||||
return [...newData, ...currentData];
|
||||
},
|
||||
};
|
||||
@ -1,47 +0,0 @@
|
||||
import { ApolloCache } from '@apollo/client';
|
||||
|
||||
import {
|
||||
Company,
|
||||
GetCompaniesQuery,
|
||||
GetCompaniesQueryVariables,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { GET_COMPANIES } from '../queries/getCompanies';
|
||||
|
||||
function optimisticEffectResolver({
|
||||
cache,
|
||||
entities,
|
||||
variables,
|
||||
}: {
|
||||
cache: ApolloCache<Company>;
|
||||
entities: Company[];
|
||||
variables: GetCompaniesQueryVariables;
|
||||
}) {
|
||||
const existingData = cache.readQuery<GetCompaniesQuery>({
|
||||
query: GET_COMPANIES,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
});
|
||||
|
||||
if (!existingData) {
|
||||
return;
|
||||
}
|
||||
|
||||
cache.writeQuery({
|
||||
query: GET_COMPANIES,
|
||||
variables: { orderBy: variables.orderBy, where: variables.where },
|
||||
data: {
|
||||
companies: [...entities, ...existingData.companies],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getCompaniesOptimisticEffect(
|
||||
variables: GetCompaniesQueryVariables,
|
||||
) {
|
||||
return {
|
||||
key: 'generic-entity-table-data-companies',
|
||||
variables: variables,
|
||||
typename: 'Company',
|
||||
resolver: optimisticEffectResolver,
|
||||
};
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { companiesAvailableColumnDefinitions } from '@/companies/constants/companiesAvailableColumnDefinitions';
|
||||
import { getCompaniesOptimisticEffect } from '@/companies/graphql/optimistic-effects/getCompaniesOptimisticEffect';
|
||||
import { getCompaniesOptimisticEffectDefinition } from '@/companies/graphql/optimistic-effect-definitions/getCompaniesOptimisticEffectDefinition';
|
||||
import { useCompanyTableActionBarEntries } from '@/companies/hooks/useCompanyTableActionBarEntries';
|
||||
import { useCompanyTableContextMenuEntries } from '@/companies/hooks/useCompanyTableContextMenuEntries';
|
||||
import { useSpreadsheetCompanyImport } from '@/companies/hooks/useSpreadsheetCompanyImport';
|
||||
@ -53,7 +53,9 @@ export function CompanyTable() {
|
||||
<GenericEntityTableData
|
||||
getRequestResultKey="companies"
|
||||
useGetRequest={useGetCompaniesQuery}
|
||||
getRequestOptimisticEffect={getCompaniesOptimisticEffect}
|
||||
getRequestOptimisticEffectDefinition={
|
||||
getCompaniesOptimisticEffectDefinition
|
||||
}
|
||||
orderBy={sortsOrderBy}
|
||||
whereFilters={filtersWhere}
|
||||
filterDefinitionArray={companiesFilters}
|
||||
|
||||
Reference in New Issue
Block a user