Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Morph strategy on PipelineProgress #1065

Merged
merged 9 commits into from
Aug 3, 2023
306 changes: 179 additions & 127 deletions front/src/generated/graphql.tsx

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions front/src/modules/companies/components/HooksCompanyBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function HooksCompanyBoard({
variables: {
where: {
id: {
in: pipelineProgresses.map((item) => item.progressableId),
in: pipelineProgresses.map((item) => item.companyId || ''),
},
},
},
Expand All @@ -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]: {
Expand Down
25 changes: 11 additions & 14 deletions front/src/modules/companies/components/NewCompanyProgressButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) => {
Expand All @@ -58,21 +56,20 @@ 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 || '',
},
});
},
[
goBackToPreviousHotkeyScope,
board,
setBoard,
createOnePipelineProgress,
createOneCompanyPipelineProgress,
pipelineStageId,
pipeline?.id,
],
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/companies/types/CompanyProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type PipelineProgressForBoard = Pick<
| 'id'
| 'amount'
| 'closeDate'
| 'progressableId'
| 'companyId'
| 'probability'
| 'pointOfContactId'
> & {
Expand Down
64 changes: 2 additions & 62 deletions front/src/modules/pipeline/queries/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export const GET_PIPELINE_PROGRESS = gql`
findManyPipelineProgress(where: $where, orderBy: $orderBy) {
id
pipelineStageId
progressableType
progressableId
companyId
personId
amount
closeDate
pointOfContactId
Expand All @@ -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,
Expand Down
58 changes: 58 additions & 0 deletions front/src/modules/pipeline/queries/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
`;
2 changes: 1 addition & 1 deletion front/src/pages/opportunities/opportunities-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const opportunitiesFilters: FilterDefinitionByEntity<PipelineProgress>[]
type: 'date',
},
{
field: 'progressableId',
field: 'companyId',
label: 'Company',
icon: (
<IconBuildingSkyscraper size={icon.size.md} stroke={icon.stroke.sm} />
Expand Down
22 changes: 5 additions & 17 deletions front/src/testing/mock-data/pipeline-progress.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import {
PipelineProgress,
PipelineProgressableType,
User,
} from '../../generated/graphql';
import { PipelineProgress, User } from '../../generated/graphql';

type MockedPipelineProgress = Pick<
PipelineProgress,
| 'id'
| 'amount'
| 'closeDate'
| 'progressableId'
| 'pipelineStageId'
| 'progressableType'
'id' | 'amount' | 'closeDate' | 'companyId' | 'pipelineStageId'
> & {
accountOwner: Pick<
User,
Expand All @@ -38,27 +29,24 @@ export const mockedPipelineProgressData: Array<MockedPipelineProgress> = [
id: '0ac8761c-1ad6-11ee-be56-0242ac120002',
amount: 78,
closeDate: '2021-10-01T00:00:00.000Z',
progressableId: '0',
companyId: '0',
accountOwner: accountOwner,
pipelineStageId: 'another-pipeline-stage-1',
progressableType: PipelineProgressableType.Company,
},
{
id: 'fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
progressableId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
pipelineStageId: 'fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
amount: 7,
closeDate: '2021-10-01T00:00:00.000Z',
accountOwner,
progressableType: PipelineProgressableType.Company,
},
{
id: '4a886c90-f4f2-4984-8222-882ebbb905d6',
progressableId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae',
companyId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae',
amount: 100,
closeDate: '2021-10-01T00:00:00.000Z',
accountOwner,
pipelineStageId: 'fe256b39-3ec3-4fe3-8998-b76aa0bfb600',
progressableType: PipelineProgressableType.Company,
},
];
13 changes: 3 additions & 10 deletions front/src/testing/mock-data/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ type MockedPipeline = Pick<
pipelineProgresses: Array<
Pick<
PipelineProgress,
| 'id'
| 'progressableType'
| 'progressableId'
| 'amount'
| 'closeDate'
| '__typename'
'id' | 'companyId' | 'amount' | 'closeDate' | '__typename'
>
>;
}
Expand All @@ -40,16 +35,14 @@ export const mockedPipelinesData: Array<MockedPipeline> = [
pipelineProgresses: [
{
id: 'fe256b39-3ec3-4fe7-8998-b76aa0bfb600',
progressableType: PipelineProgressableType.Company,
progressableId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
companyId: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
amount: null,
closeDate: null,
__typename: 'PipelineProgress',
},
{
id: '4a886c90-f4f2-4984-8222-882ebbb905d6',
progressableType: PipelineProgressableType.Company,
progressableId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae',
companyId: 'b396e6b9-dc5c-4643-bcff-61b6cf7523ae',
amount: null,
closeDate: null,
__typename: 'PipelineProgress',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- AlterTable
ALTER TABLE "pipeline_progresses" ADD COLUMN "companyId" TEXT,
ADD COLUMN "personId" TEXT;

-- AddForeignKey
ALTER TABLE "pipeline_progresses" ADD CONSTRAINT "pipeline_progresses_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pipeline_progresses" ADD CONSTRAINT "pipeline_progresses_personId_fkey" FOREIGN KEY ("personId") REFERENCES "people"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- This is a manually written data migration that copies the progressable ids to the right colums in pipeline progress.
UPDATE "pipeline_progresses" SET
"companyId"="progressableId"
WHERE "progressableType"='Company';

UPDATE "pipeline_progresses" SET
"personId"="progressableId"
WHERE "progressableType"='Person';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `progressableId` on the `pipeline_progresses` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "pipeline_progresses" DROP COLUMN "progressableId";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `progressableType` on the `pipeline_progresses` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "pipeline_progresses" DROP COLUMN "progressableType";
Loading
Loading