Refactor: Morph strategy on PipelineProgress (#1065)
* Deprecate pipelineprogress backref on person to improve naming * Remove deprecated point of contact fields * Add company and person entities on pipelineprogress * Migrate data from old progressable to new entity fields * Codegen frontend * Use company Id, deprecate progressableId * Get rid of deprecated progressableId field * Remove deprecated progressableType field from pipeline progress * Remove useless migrations
This commit is contained in:
@ -119,7 +119,7 @@ export function HooksCompanyBoard({
|
||||
variables: {
|
||||
where: {
|
||||
id: {
|
||||
in: pipelineProgresses.map((item) => item.progressableId),
|
||||
in: pipelineProgresses.map((item) => item.companyId || ''),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -145,7 +145,9 @@ export function HooksCompanyBoard({
|
||||
},
|
||||
pipelineProgress: PipelineProgressForBoard,
|
||||
) => {
|
||||
const company = companiesDict[pipelineProgress.progressableId];
|
||||
const company =
|
||||
pipelineProgress.companyId && companiesDict[pipelineProgress.companyId];
|
||||
if (!company) return acc;
|
||||
return {
|
||||
...acc,
|
||||
[pipelineProgress.id]: {
|
||||
|
||||
@ -15,10 +15,7 @@ import { relationPickerSearchFilterScopedState } from '@/ui/input/relation-picke
|
||||
import { RelationPickerHotkeyScope } from '@/ui/input/relation-picker/types/RelationPickerHotkeyScope';
|
||||
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
import {
|
||||
PipelineProgressableType,
|
||||
useCreateOnePipelineProgressMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { useCreateOneCompanyPipelineProgressMutation } from '~/generated/graphql';
|
||||
|
||||
import { useFilteredSearchCompanyQuery } from '../queries';
|
||||
|
||||
@ -36,12 +33,13 @@ export function NewCompanyProgressButton() {
|
||||
setHotkeyScopeAndMemorizePreviousScope,
|
||||
} = usePreviousHotkeyScope();
|
||||
|
||||
const [createOnePipelineProgress] = useCreateOnePipelineProgressMutation({
|
||||
refetchQueries: [
|
||||
getOperationName(GET_PIPELINE_PROGRESS) ?? '',
|
||||
getOperationName(GET_PIPELINES) ?? '',
|
||||
],
|
||||
});
|
||||
const [createOneCompanyPipelineProgress] =
|
||||
useCreateOneCompanyPipelineProgressMutation({
|
||||
refetchQueries: [
|
||||
getOperationName(GET_PIPELINE_PROGRESS) ?? '',
|
||||
getOperationName(GET_PIPELINES) ?? '',
|
||||
],
|
||||
});
|
||||
|
||||
const handleEntitySelect = useCallback(
|
||||
async (company: any) => {
|
||||
@ -58,13 +56,12 @@ export function NewCompanyProgressButton() {
|
||||
);
|
||||
newBoard[destinationColumnIndex].pipelineProgressIds.push(newUuid);
|
||||
setBoard(newBoard);
|
||||
await createOnePipelineProgress({
|
||||
await createOneCompanyPipelineProgress({
|
||||
variables: {
|
||||
uuid: newUuid,
|
||||
pipelineStageId: pipelineStageId || '',
|
||||
pipelineId: pipeline?.id || '',
|
||||
entityId: company.id || '',
|
||||
entityType: PipelineProgressableType.Company,
|
||||
companyId: company.id || '',
|
||||
},
|
||||
});
|
||||
},
|
||||
@ -72,7 +69,7 @@ export function NewCompanyProgressButton() {
|
||||
goBackToPreviousHotkeyScope,
|
||||
board,
|
||||
setBoard,
|
||||
createOnePipelineProgress,
|
||||
createOneCompanyPipelineProgress,
|
||||
pipelineStageId,
|
||||
pipeline?.id,
|
||||
],
|
||||
|
||||
@ -6,7 +6,7 @@ export type PipelineProgressForBoard = Pick<
|
||||
| 'id'
|
||||
| 'amount'
|
||||
| 'closeDate'
|
||||
| 'progressableId'
|
||||
| 'companyId'
|
||||
| 'probability'
|
||||
| 'pointOfContactId'
|
||||
> & {
|
||||
|
||||
@ -33,8 +33,8 @@ export const GET_PIPELINE_PROGRESS = gql`
|
||||
findManyPipelineProgress(where: $where, orderBy: $orderBy) {
|
||||
id
|
||||
pipelineStageId
|
||||
progressableType
|
||||
progressableId
|
||||
companyId
|
||||
personId
|
||||
amount
|
||||
closeDate
|
||||
pointOfContactId
|
||||
@ -50,66 +50,6 @@ export const GET_PIPELINE_PROGRESS = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_PIPELINE_PROGRESS = gql`
|
||||
mutation UpdateOnePipelineProgress(
|
||||
$id: String
|
||||
$amount: Int
|
||||
$closeDate: DateTime
|
||||
$probability: Int
|
||||
$pointOfContactId: String
|
||||
) {
|
||||
updateOnePipelineProgress(
|
||||
where: { id: $id }
|
||||
data: {
|
||||
amount: $amount
|
||||
closeDate: $closeDate
|
||||
probability: $probability
|
||||
pointOfContact: { connect: { id: $pointOfContactId } }
|
||||
}
|
||||
) {
|
||||
id
|
||||
amount
|
||||
closeDate
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_PIPELINE_PROGRESS_STAGE = gql`
|
||||
mutation UpdateOnePipelineProgressStage(
|
||||
$id: String
|
||||
$pipelineStageId: String
|
||||
) {
|
||||
updateOnePipelineProgress(
|
||||
where: { id: $id }
|
||||
data: { pipelineStage: { connect: { id: $pipelineStageId } } }
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const ADD_ENTITY_TO_PIPELINE = gql`
|
||||
mutation CreateOnePipelineProgress(
|
||||
$uuid: String!
|
||||
$entityType: PipelineProgressableType!
|
||||
$entityId: String!
|
||||
$pipelineId: String!
|
||||
$pipelineStageId: String!
|
||||
) {
|
||||
createOnePipelineProgress(
|
||||
data: {
|
||||
id: $uuid
|
||||
progressableType: $entityType
|
||||
progressableId: $entityId
|
||||
pipeline: { connect: { id: $pipelineId } }
|
||||
pipelineStage: { connect: { id: $pipelineStageId } }
|
||||
}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const defaultPipelineProgressOrderBy: PipelineProgresses_Order_By[] = [
|
||||
{
|
||||
createdAt: Order_By.Asc,
|
||||
|
||||
@ -17,3 +17,61 @@ export const UPDATE_PIPELINE_STAGE = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_PIPELINE_PROGRESS = gql`
|
||||
mutation UpdateOnePipelineProgress(
|
||||
$id: String
|
||||
$amount: Int
|
||||
$closeDate: DateTime
|
||||
$probability: Int
|
||||
$pointOfContactId: String
|
||||
) {
|
||||
updateOnePipelineProgress(
|
||||
where: { id: $id }
|
||||
data: {
|
||||
amount: $amount
|
||||
closeDate: $closeDate
|
||||
probability: $probability
|
||||
pointOfContact: { connect: { id: $pointOfContactId } }
|
||||
}
|
||||
) {
|
||||
id
|
||||
amount
|
||||
closeDate
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_PIPELINE_PROGRESS_STAGE = gql`
|
||||
mutation UpdateOnePipelineProgressStage(
|
||||
$id: String
|
||||
$pipelineStageId: String
|
||||
) {
|
||||
updateOnePipelineProgress(
|
||||
where: { id: $id }
|
||||
data: { pipelineStage: { connect: { id: $pipelineStageId } } }
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const CREATE_COMPANY_PIPELINE_PROGRESS = gql`
|
||||
mutation CreateOneCompanyPipelineProgress(
|
||||
$uuid: String!
|
||||
$companyId: String!
|
||||
$pipelineId: String!
|
||||
$pipelineStageId: String!
|
||||
) {
|
||||
createOnePipelineProgress(
|
||||
data: {
|
||||
id: $uuid
|
||||
company: { connect: { id: $companyId } }
|
||||
pipeline: { connect: { id: $pipelineId } }
|
||||
pipelineStage: { connect: { id: $pipelineStageId } }
|
||||
}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user