From 5ebde33f5f73626188cc110c99374dce176e7fb7 Mon Sep 17 00:00:00 2001 From: Marie <51697796+ijreilly@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:50:33 +0200 Subject: [PATCH] Deprecate Probability field on Opportunity (#6207) Closes #5735. The field probability on opportunity will - - stop being created for new workspaces (after this PR is merged) - have "isCustom" value set to true and be displayed as such in the settings (after this PR is merged + sync-metadata is run on workspace) - still show in the views (all the time) This field is deprecated as a standard field but not replaced by another one, so we are not adding the `(deprecated)` suffix in the label. --- .../utils/getObjectMetadataItemsMock.ts | 17 --------- .../hooks/__mocks__/useFindManyRecords.ts | 2 - .../__mocks__/useFilteredSearchEntityQuery.ts | 2 - .../SignInBackgroundMockCompanies.ts | 4 -- .../standard-metadata-query-result.ts | 23 ----------- .../src/testing/mock-data/view-fields.ts | 8 ---- .../typeorm-seeds/workspace/opportunities.ts | 7 +--- .../demo-objects-prefill-data/opportunity.ts | 8 ---- .../view-opportunity-fields.ts | 10 ----- .../constants/standard-field-ids.ts | 2 +- .../company.workspace-entity.ts | 24 ++++++------ .../opportunity.workspace-entity.ts | 38 ++++++++++--------- 12 files changed, 34 insertions(+), 111 deletions(-) diff --git a/packages/twenty-front/src/modules/object-metadata/utils/getObjectMetadataItemsMock.ts b/packages/twenty-front/src/modules/object-metadata/utils/getObjectMetadataItemsMock.ts index d20e85583..7ae1d86e7 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/getObjectMetadataItemsMock.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/getObjectMetadataItemsMock.ts @@ -466,23 +466,6 @@ export const getObjectMetadataItemsMock = () => { fromRelationMetadata: null, toRelationMetadata: null, }, - { - __typename: 'field', - id: '20202020-3b9c-4e58-a3d2-c617d3b596b1', - type: 'TEXT', - name: 'probability', - label: 'Probability', - description: 'Opportunity probability', - icon: 'IconProgressCheck', - isCustom: false, - isActive: true, - isSystem: false, - isNullable: true, - createdAt: '2023-11-30T11:13:15.308Z', - updatedAt: '2023-11-30T11:13:15.308Z', - fromRelationMetadata: null, - toRelationMetadata: null, - }, { __typename: 'fieldEdge', node: { diff --git a/packages/twenty-front/src/modules/object-record/hooks/__mocks__/useFindManyRecords.ts b/packages/twenty-front/src/modules/object-record/hooks/__mocks__/useFindManyRecords.ts index f7251f35e..22caeadc1 100644 --- a/packages/twenty-front/src/modules/object-record/hooks/__mocks__/useFindManyRecords.ts +++ b/packages/twenty-front/src/modules/object-record/hooks/__mocks__/useFindManyRecords.ts @@ -27,7 +27,6 @@ export const query = gql` updatedAt companyId stage - probability closeDate amount { amountMicros @@ -53,7 +52,6 @@ export const query = gql` updatedAt companyId stage - probability closeDate amount { amountMicros diff --git a/packages/twenty-front/src/modules/search/hooks/__mocks__/useFilteredSearchEntityQuery.ts b/packages/twenty-front/src/modules/search/hooks/__mocks__/useFilteredSearchEntityQuery.ts index 7423e7bcb..34aaee597 100644 --- a/packages/twenty-front/src/modules/search/hooks/__mocks__/useFilteredSearchEntityQuery.ts +++ b/packages/twenty-front/src/modules/search/hooks/__mocks__/useFilteredSearchEntityQuery.ts @@ -25,7 +25,6 @@ export const query = gql` updatedAt companyId stage - probability closeDate amount { amountMicros @@ -50,7 +49,6 @@ export const query = gql` updatedAt companyId stage - probability closeDate amount { amountMicros diff --git a/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockCompanies.ts b/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockCompanies.ts index 609536b42..c1bd90732 100644 --- a/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockCompanies.ts +++ b/packages/twenty-front/src/modules/sign-in-background-mock/constants/SignInBackgroundMockCompanies.ts @@ -415,7 +415,6 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [ node: { __typename: 'Opportunity', id: '53f66647-0543-4cc2-9f96-95cc699960f2', - probability: '0.5', pointOfContactId: '93c72d2e-f517-42fd-80ae-14173b3b70ae', stage: 'NEW', amount: { @@ -633,7 +632,6 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [ node: { __typename: 'Opportunity', id: '81ab695d-2f89-406f-90ea-180f433b2445', - probability: '0.5', stage: 'NEW', pointOfContactId: '9b324a88-6784-4449-afdf-dc62cb8702f2', amount: { @@ -653,7 +651,6 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [ node: { __typename: 'Opportunity', id: '9b059852-35b1-4045-9cde-42f715148954', - probability: '0.5', stage: 'NEW', pointOfContactId: '98406e26-80f1-4dff-b570-a74942528de3', amount: { @@ -1221,7 +1218,6 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [ node: { __typename: 'Opportunity', id: '7c887ee3-be10-412b-a663-16bd3c2228e1', - probability: '0.5', stage: 'NEW', pointOfContactId: '86083141-1c0e-494c-a1b6-85b1c6fefaa5', amount: { diff --git a/packages/twenty-front/src/testing/mock-data/generated/standard-metadata-query-result.ts b/packages/twenty-front/src/testing/mock-data/generated/standard-metadata-query-result.ts index 3394a5c46..b537a84c2 100644 --- a/packages/twenty-front/src/testing/mock-data/generated/standard-metadata-query-result.ts +++ b/packages/twenty-front/src/testing/mock-data/generated/standard-metadata-query-result.ts @@ -5567,29 +5567,6 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery = "toRelationMetadata": null } }, - { - "__typename": "fieldEdge", - "node": { - "__typename": "field", - "id": "dd99cf8d-a10c-4d41-8469-6b5e03e5ae2e", - "type": "TEXT", - "name": "probability", - "label": "Probability", - "description": "Opportunity probability", - "icon": "IconProgressCheck", - "isCustom": false, - "isActive": true, - "isSystem": false, - "isNullable": false, - "createdAt": "2024-06-07T09:05:12.599Z", - "updatedAt": "2024-06-07T09:05:12.599Z", - "defaultValue": "'0'", - "options": null, - "relationDefinition": null, - "fromRelationMetadata": null, - "toRelationMetadata": null - } - }, { "__typename": "fieldEdge", "node": { diff --git a/packages/twenty-front/src/testing/mock-data/view-fields.ts b/packages/twenty-front/src/testing/mock-data/view-fields.ts index c644510c9..d54ed0581 100644 --- a/packages/twenty-front/src/testing/mock-data/view-fields.ts +++ b/packages/twenty-front/src/testing/mock-data/view-fields.ts @@ -142,14 +142,6 @@ export const mockedViewFieldsData = [ isVisible: true, size: 180, }, - { - id: 'e5a731bb-82b9-4abe-ad22-1ddea94722f9', - fieldMetadataId: 'probability', - viewId: mockedViewsData[2].id, - position: 1, - isVisible: true, - size: 150, - }, { id: '3159acd8-463f-458d-bf9a-af8ac6f57dc0', fieldMetadataId: 'closeDate', diff --git a/packages/twenty-server/src/database/typeorm-seeds/workspace/opportunities.ts b/packages/twenty-server/src/database/typeorm-seeds/workspace/opportunities.ts index b314205ef..b1c00b54d 100644 --- a/packages/twenty-server/src/database/typeorm-seeds/workspace/opportunities.ts +++ b/packages/twenty-server/src/database/typeorm-seeds/workspace/opportunities.ts @@ -1,7 +1,7 @@ import { EntityManager } from 'typeorm'; -import { DEV_SEED_PERSON_IDS } from 'src/database/typeorm-seeds/workspace/people'; import { DEV_SEED_COMPANY_IDS } from 'src/database/typeorm-seeds/workspace/companies'; +import { DEV_SEED_PERSON_IDS } from 'src/database/typeorm-seeds/workspace/people'; const tableName = 'opportunity'; @@ -25,7 +25,6 @@ export const seedOpportunity = async ( 'amountAmountMicros', 'amountCurrencyCode', 'closeDate', - 'probability', 'stage', 'position', 'pointOfContactId', @@ -39,7 +38,6 @@ export const seedOpportunity = async ( amountAmountMicros: 100000, amountCurrencyCode: 'USD', closeDate: new Date(), - probability: 0.5, stage: 'NEW', position: 1, pointOfContactId: DEV_SEED_PERSON_IDS.CHRISTOPH, @@ -51,7 +49,6 @@ export const seedOpportunity = async ( amountAmountMicros: 2000000, amountCurrencyCode: 'USD', closeDate: new Date(), - probability: 0.5, stage: 'MEETING', position: 2, pointOfContactId: DEV_SEED_PERSON_IDS.CHRISTOPHER_G, @@ -63,7 +60,6 @@ export const seedOpportunity = async ( amountAmountMicros: 300000, amountCurrencyCode: 'USD', closeDate: new Date(), - probability: 0.5, stage: 'PROPOSAL', position: 3, pointOfContactId: DEV_SEED_PERSON_IDS.NICHOLAS, @@ -75,7 +71,6 @@ export const seedOpportunity = async ( amountAmountMicros: 4000000, amountCurrencyCode: 'USD', closeDate: new Date(), - probability: 0.5, stage: 'PROPOSAL', position: 4, pointOfContactId: DEV_SEED_PERSON_IDS.MATTHEW, diff --git a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/opportunity.ts b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/opportunity.ts index e2d53abfb..23c511429 100644 --- a/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/opportunity.ts +++ b/packages/twenty-server/src/engine/workspace-manager/demo-objects-prefill-data/opportunity.ts @@ -3,12 +3,6 @@ import { v4 } from 'uuid'; const tableName = 'opportunity'; -const getRandomProbability = () => { - const firstDigit = Math.floor(Math.random() * 9) + 1; - - return firstDigit / 10; -}; - const getRandomStage = () => { const stages = ['NEW', 'SCREENING', 'MEETING', 'PROPOSAL', 'CUSTOMER']; @@ -28,7 +22,6 @@ const generateOpportunities = (companies) => { amountCurrencyCode: 'USD', closeDate: new Date(), stage: getRandomStage(), - probability: getRandomProbability(), pointOfContactId: company.personId, companyId: company.id, })); @@ -56,7 +49,6 @@ export const opportunityPrefillDemoData = async ( 'amountCurrencyCode', 'closeDate', 'stage', - 'probability', 'pointOfContactId', 'companyId', 'position', diff --git a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view-opportunity-fields.ts b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view-opportunity-fields.ts index 7e7ed6b59..baa08a95f 100644 --- a/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view-opportunity-fields.ts +++ b/packages/twenty-server/src/engine/workspace-manager/standard-objects-prefill-data/view-opportunity-fields.ts @@ -47,16 +47,6 @@ export const viewOpportunityFields = ( isVisible: true, size: 150, }, - { - fieldMetadataId: - objectMetadataMap[STANDARD_OBJECT_IDS.opportunity].fields[ - OPPORTUNITY_STANDARD_FIELD_IDS.probability - ], - viewId: viewId, - position: 4, - isVisible: true, - size: 150, - }, { fieldMetadataId: objectMetadataMap[STANDARD_OBJECT_IDS.opportunity].fields[ diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts index 63b64692a..0778c007c 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids.ts @@ -251,7 +251,7 @@ export const OPPORTUNITY_STANDARD_FIELD_IDS = { name: '20202020-8609-4f65-a2d9-44009eb422b5', amount: '20202020-583e-4642-8533-db761d5fa82f', closeDate: '20202020-527e-44d6-b1ac-c4158d307b97', - probability: '20202020-69d4-45f3-9703-690b09fafcf0', + probabilityDeprecated: '20202020-69d4-45f3-9703-690b09fafcf0', stage: '20202020-6f76-477d-8551-28cd65b2b4b9', position: '20202020-806d-493a-bbc6-6313e62958e2', pointOfContact: '20202020-8dfb-42fc-92b6-01afb759ed16', diff --git a/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts b/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts index fbe99fc9f..8f2d68f5d 100644 --- a/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts +++ b/packages/twenty-server/src/modules/company/standard-objects/company.workspace-entity.ts @@ -96,18 +96,6 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity { @WorkspaceIsNullable() annualRecurringRevenue: CurrencyMetadata | null; - @WorkspaceField({ - standardId: COMPANY_STANDARD_FIELD_IDS.address_deprecated, - type: FieldMetadataType.TEXT, - label: 'Address (deprecated) ', - description: - "This standard field has been deprecated and migrated as a custom field. Please consider using the new 'address' field type.", - icon: 'IconMap', - }) - @WorkspaceIsDeprecated() - @WorkspaceIsNullable() - address_old: string; - @WorkspaceField({ standardId: COMPANY_STANDARD_FIELD_IDS.address, type: FieldMetadataType.ADDRESS, @@ -231,4 +219,16 @@ export class CompanyWorkspaceEntity extends BaseWorkspaceEntity { @WorkspaceIsNullable() @WorkspaceIsSystem() timelineActivities: Relation; + + @WorkspaceField({ + standardId: COMPANY_STANDARD_FIELD_IDS.address_deprecated, + type: FieldMetadataType.TEXT, + label: 'Address (deprecated) ', + description: + 'Address of the company - deprecated in favor of new address field', + icon: 'IconMap', + }) + @WorkspaceIsDeprecated() + @WorkspaceIsNullable() + addressOld: string; } diff --git a/packages/twenty-server/src/modules/opportunity/standard-objects/opportunity.workspace-entity.ts b/packages/twenty-server/src/modules/opportunity/standard-objects/opportunity.workspace-entity.ts index 719ee7501..670ef37a0 100644 --- a/packages/twenty-server/src/modules/opportunity/standard-objects/opportunity.workspace-entity.ts +++ b/packages/twenty-server/src/modules/opportunity/standard-objects/opportunity.workspace-entity.ts @@ -6,6 +6,15 @@ import { RelationMetadataType, RelationOnDeleteAction, } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity'; +import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; +import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator'; +import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator'; +import { WorkspaceIsDeprecated } from 'src/engine/twenty-orm/decorators/workspace-is-deprecated.decorator'; +import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator'; +import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; +import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator'; +import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; +import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; import { OPPORTUNITY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids'; import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids'; import { ActivityTargetWorkspaceEntity } from 'src/modules/activity/standard-objects/activity-target.workspace-entity'; @@ -14,14 +23,6 @@ import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/com import { FavoriteWorkspaceEntity } from 'src/modules/favorite/standard-objects/favorite.workspace-entity'; import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity'; import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity'; -import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity'; -import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator'; -import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator'; -import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator'; -import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator'; -import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator'; -import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator'; -import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator'; @WorkspaceEntity({ standardId: STANDARD_OBJECT_IDS.opportunity, @@ -62,16 +63,6 @@ export class OpportunityWorkspaceEntity extends BaseWorkspaceEntity { @WorkspaceIsNullable() closeDate: Date | null; - @WorkspaceField({ - standardId: OPPORTUNITY_STANDARD_FIELD_IDS.probability, - type: FieldMetadataType.TEXT, - label: 'Probability', - description: 'Opportunity probability', - icon: 'IconProgressCheck', - defaultValue: "'0'", - }) - probability: string; - @WorkspaceField({ standardId: OPPORTUNITY_STANDARD_FIELD_IDS.stage, type: FieldMetadataType.SELECT, @@ -185,4 +176,15 @@ export class OpportunityWorkspaceEntity extends BaseWorkspaceEntity { }) @WorkspaceIsNullable() timelineActivities: Relation; + + @WorkspaceField({ + standardId: OPPORTUNITY_STANDARD_FIELD_IDS.probabilityDeprecated, + type: FieldMetadataType.TEXT, + label: 'Probability', + description: 'Opportunity probability', + icon: 'IconProgressCheck', + defaultValue: "'0'", + }) + @WorkspaceIsDeprecated() + probability: string; }