feat: disable atomic operation on nestjs graphql models (#751)

* feat: no atomic

* feat: update front not atomic operations

* feat: optional fields for person model & use proper gql type

* Fix bug display name

* Fix bug update user

* Fixed bug avatar URL

* Fixed display name on people cell

* Fix lint

* Fixed storybook display name

* Fix storybook requests

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Jérémy M
2023-07-20 21:23:35 +02:00
committed by GitHub
parent 663c4d5c3f
commit 872ec9e6bb
58 changed files with 622 additions and 652 deletions

View File

@ -8,7 +8,7 @@ import {
Company,
User,
useSearchUserQuery,
useUpdateCompanyMutation,
useUpdateOneCompanyMutation,
} from '~/generated/graphql';
export type OwnProps = {
@ -31,7 +31,7 @@ export function CompanyAccountOwnerPicker({
const [searchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const companies = useFilteredSearchEntityQuery({
queryHook: useSearchUserQuery,
@ -51,8 +51,10 @@ export function CompanyAccountOwnerPicker({
async function handleEntitySelected(selectedUser: UserForSelect) {
await updateCompany({
variables: {
...company,
accountOwnerId: selectedUser.id,
where: { id: company.id },
data: {
accountOwner: { connect: { id: selectedUser.id } },
},
},
});

View File

@ -4,7 +4,7 @@ import { getOperationName } from '@apollo/client/utilities';
import { EditableCellChip } from '@/ui/table/editable-cell/types/EditableChip';
import {
GetCompaniesQuery,
useUpdateCompanyMutation,
useUpdateOneCompanyMutation,
} from '~/generated/graphql';
import { getLogoUrlFromDomainName } from '~/utils';
@ -20,7 +20,7 @@ type OwnProps = {
};
export function CompanyEditableNameChipCell({ company }: OwnProps) {
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const [internalValue, setInternalValue] = useState(company.name ?? '');
@ -44,8 +44,10 @@ export function CompanyEditableNameChipCell({ company }: OwnProps) {
onSubmit={() =>
updateCompany({
variables: {
id: company.id,
name: internalValue,
where: { id: company.id },
data: {
name: internalValue,
},
},
refetchQueries: [getOperationName(GET_COMPANY) ?? ''],
})

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconMap } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'address'>;
@ -14,7 +14,7 @@ type OwnProps = {
export function CompanyAddressEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.address);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.address);
@ -27,8 +27,12 @@ export function CompanyAddressEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
address: internalValue ?? '',
where: {
id: company.id,
},
data: {
address: internalValue ?? '',
},
},
});
}

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { EditableFieldEditModeDate } from '@/ui/editable-field/variants/components/EditableFieldEditModeDate';
import { IconCalendar } from '@/ui/icon';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
import { formatToHumanReadableDate } from '~/utils';
import { parseDate } from '~/utils/date-utils';
@ -16,7 +16,7 @@ type OwnProps = {
export function CompanyCreatedAtEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.createdAt);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.createdAt);
@ -29,8 +29,12 @@ export function CompanyCreatedAtEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
createdAt: internalValue ?? '',
where: {
id: company.id,
},
data: {
createdAt: internalValue ?? '',
},
},
});
}

View File

@ -6,7 +6,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconLink } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'domainName'>;
@ -15,7 +15,7 @@ type OwnProps = {
export function CompanyDomainNameEditableField({ company }: OwnProps) {
const [internalValue, setInternalValue] = useState(company.domainName);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.domainName);
@ -28,8 +28,12 @@ export function CompanyDomainNameEditableField({ company }: OwnProps) {
async function handleSubmit() {
await updateCompany({
variables: {
id: company.id,
domainName: internalValue ?? '',
where: {
id: company.id,
},
data: {
domainName: internalValue ?? '',
},
},
});
}

View File

@ -5,7 +5,7 @@ import { FieldContext } from '@/ui/editable-field/states/FieldContext';
import { IconUsers } from '@/ui/icon';
import { InplaceInputText } from '@/ui/inplace-input/components/InplaceInputText';
import { RecoilScope } from '@/ui/recoil-scope/components/RecoilScope';
import { Company, useUpdateCompanyMutation } from '~/generated/graphql';
import { Company, useUpdateOneCompanyMutation } from '~/generated/graphql';
type OwnProps = {
company: Pick<Company, 'id' | 'employees'>;
@ -16,7 +16,7 @@ export function CompanyEmployeesEditableField({ company }: OwnProps) {
company.employees?.toString(),
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
useEffect(() => {
setInternalValue(company.employees?.toString());
@ -38,8 +38,12 @@ export function CompanyEmployeesEditableField({ company }: OwnProps) {
await updateCompany({
variables: {
id: company.id,
employees: numberValue,
where: {
id: company.id,
},
data: {
employees: numberValue,
},
},
});

View File

@ -1,26 +1,11 @@
import { gql } from '@apollo/client';
export const UPDATE_COMPANY = gql`
mutation UpdateCompany(
$id: String
$name: String
$domainName: String
$accountOwnerId: String
$createdAt: DateTime
$address: String
$employees: Int
export const UPDATE_ONE_COMPANY = gql`
mutation UpdateOneCompany(
$where: CompanyWhereUniqueInput!
$data: CompanyUpdateInput!
) {
updateOneCompany(
where: { id: $id }
data: {
accountOwner: { connect: { id: $accountOwnerId } }
address: { set: $address }
domainName: { set: $domainName }
employees: { set: $employees }
name: { set: $name }
createdAt: { set: $createdAt }
}
) {
updateOneCompany(data: $data, where: $where) {
accountOwner {
id
email
@ -38,25 +23,9 @@ export const UPDATE_COMPANY = gql`
}
`;
export const INSERT_COMPANY = gql`
mutation InsertCompany(
$id: String!
$name: String!
$domainName: String!
$createdAt: DateTime
$address: String!
$employees: Int
) {
createOneCompany(
data: {
id: $id
name: $name
domainName: $domainName
createdAt: $createdAt
address: $address
employees: $employees
}
) {
export const INSERT_ONE_COMPANY = gql`
mutation InsertOneCompany($data: CompanyCreateInput!) {
createOneCompany(data: $data) {
address
createdAt
domainName
@ -67,8 +36,8 @@ export const INSERT_COMPANY = gql`
}
`;
export const DELETE_COMPANIES = gql`
mutation DeleteCompanies($ids: [String!]) {
export const DELETE_MANY_COMPANIES = gql`
mutation DeleteManyCompanies($ids: [String!]) {
deleteManyCompany(where: { id: { in: $ids } }) {
count
}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyAddressFamilyState } from '@/companies/states/companyAddressFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyAddressCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const address = useRecoilValue(
companyAddressFamilyState(currentRowEntityId ?? ''),
@ -27,8 +27,12 @@ export function EditableCompanyAddressCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
address: internalValue,
where: {
id: currentRowEntityId,
},
data: {
address: internalValue,
},
},
})
}

View File

@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil';
import { companyCreatedAtFamilyState } from '@/companies/states/companyCreatedAtFamilyState';
import { EditableCellDate } from '@/ui/table/editable-cell/types/EditableCellDate';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyCreatedAtCell() {
const currentRowEntityId = useCurrentRowEntityId();
@ -13,7 +13,7 @@ export function EditableCompanyCreatedAtCell() {
companyCreatedAtFamilyState(currentRowEntityId ?? ''),
);
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
return (
<EditableCellDate
@ -22,8 +22,12 @@ export function EditableCompanyCreatedAtCell() {
await updateCompany({
variables: {
id: currentRowEntityId,
createdAt: newDate.toISOString(),
where: {
id: currentRowEntityId,
},
data: {
createdAt: newDate.toISOString(),
},
},
});
}}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyDomainNameFamilyState } from '@/companies/states/companyDomainNameFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyDomainNameCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const name = useRecoilValue(
companyDomainNameFamilyState(currentRowEntityId ?? ''),
@ -26,8 +26,12 @@ export function EditableCompanyDomainNameCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
domainName: internalValue,
where: {
id: currentRowEntityId,
},
data: {
domainName: internalValue,
},
},
})
}

View File

@ -4,12 +4,12 @@ import { useRecoilValue } from 'recoil';
import { companyEmployeesFamilyState } from '@/companies/states/companyEmployeesFamilyState';
import { EditableCellText } from '@/ui/table/editable-cell/types/EditableCellText';
import { useCurrentRowEntityId } from '@/ui/table/hooks/useCurrentEntityId';
import { useUpdateCompanyMutation } from '~/generated/graphql';
import { useUpdateOneCompanyMutation } from '~/generated/graphql';
export function EditableCompanyEmployeesCell() {
const currentRowEntityId = useCurrentRowEntityId();
const [updateCompany] = useUpdateCompanyMutation();
const [updateCompany] = useUpdateOneCompanyMutation();
const employees = useRecoilValue(
companyEmployeesFamilyState(currentRowEntityId ?? ''),
@ -29,8 +29,12 @@ export function EditableCompanyEmployeesCell() {
onSubmit={() =>
updateCompany({
variables: {
id: currentRowEntityId,
employees: parseInt(internalValue),
where: {
id: currentRowEntityId,
},
data: {
employees: parseInt(internalValue),
},
},
})
}

View File

@ -6,14 +6,14 @@ import { IconTrash } from '@/ui/icon/index';
import { EntityTableActionBarButton } from '@/ui/table/action-bar/components/EntityTableActionBarButton';
import { useResetTableRowSelection } from '@/ui/table/hooks/useResetTableRowSelection';
import { selectedRowIdsSelector } from '@/ui/table/states/selectedRowIdsSelector';
import { useDeleteCompaniesMutation } from '~/generated/graphql';
import { useDeleteManyCompaniesMutation } from '~/generated/graphql';
export function TableActionBarButtonDeleteCompanies() {
const selectedRowIds = useRecoilValue(selectedRowIdsSelector);
const resetRowSelection = useResetTableRowSelection();
const [deleteCompanies] = useDeleteCompaniesMutation({
const [deleteCompanies] = useDeleteManyCompaniesMutation({
refetchQueries: [getOperationName(GET_COMPANIES) ?? ''],
});

View File

@ -10,7 +10,7 @@ export type PipelineProgressForBoard = Pick<
| 'probability'
| 'pointOfContactId'
> & {
pointOfContact?: Pick<Person, 'id' | 'firstName' | 'lastName'> | null;
pointOfContact?: Pick<Person, 'id' | 'displayName'> | null;
};
export type CompanyProgress = {