From 4b05567b4eee0c9dbeaf05dd162cb232427a6e0c Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Fri, 20 Oct 2023 15:22:18 +0530 Subject: [PATCH 01/14] Handled deletion of expired orgs --- src/js/components/orgs/playgroundCard.tsx | 13 +++++++++++-- src/js/components/orgs/taskOrgCard.tsx | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/js/components/orgs/playgroundCard.tsx b/src/js/components/orgs/playgroundCard.tsx index dca78b228..12d1d5548 100644 --- a/src/js/components/orgs/playgroundCard.tsx +++ b/src/js/components/orgs/playgroundCard.tsx @@ -121,7 +121,6 @@ const PlaygroundOrgCard = ({ const readyToDeleteOrg = isWaitingToDeleteOrg && !org.currently_refreshing_changes; const action = isWaitingToDeleteOrg; - if (readyToDeleteOrg) { setIsWaitingToDeleteOrg(null); if (org.has_unsaved_changes) { @@ -132,7 +131,17 @@ const PlaygroundOrgCard = ({ doDeleteOrg(); } } - }, [doDeleteOrg, doRefreshOrg, isWaitingToDeleteOrg, org]); + }, [doDeleteOrg, doRefreshOrg, isWaitingToDeleteOrg, org, dispatch]); + useEffect(() => { + if ( + org && + org?.expires_at !== null && + new Date(org?.expires_at) < new Date() + ) { + console.log('Called'); + doDeleteOrg(); + } + }, []); /* istanbul ignore next */ if (!(project || epic || task)) { diff --git a/src/js/components/orgs/taskOrgCard.tsx b/src/js/components/orgs/taskOrgCard.tsx index 743e6ba34..b44ed4ed9 100644 --- a/src/js/components/orgs/taskOrgCard.tsx +++ b/src/js/components/orgs/taskOrgCard.tsx @@ -1,6 +1,6 @@ import Card from '@salesforce/design-system-react/components/card'; import classNames from 'classnames'; -import React, { ReactNode, useCallback, useState } from 'react'; +import React, { ReactNode, useCallback, useEffect, useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import AssignTaskRoleModal from '@/js/components/githubUsers/assignTaskRole'; @@ -180,6 +180,7 @@ const TaskOrgCard = ({ handleRefresh?.(org); } }, [handleRefresh, org]); + const doCreateOrg = useCallback(() => { handleCreate(type); }, [handleCreate, type]); @@ -202,7 +203,16 @@ const TaskOrgCard = ({ // We consider an org out-of-date if it is not based on the first commit. const orgOutOfDate = Boolean(org && orgCommitIdx !== 0); const testOrgOutOfDate = type === ORG_TYPES.QA && orgOutOfDate; - + useEffect(() => { + if ( + org && + org?.expires_at !== null && + new Date(org?.expires_at) < new Date() + ) { + console.log('Called'); + doDeleteOrg(); + } + }, []); return (
{ - if ( - org && - org?.expires_at !== null && - new Date(org?.expires_at) < new Date() - ) { - doDeleteOrg(); - } - }, []); + // useEffect(() => { + // if ( + // org && + // org?.expires_at !== null && + // new Date(org?.expires_at) < new Date() + // ) { + // doDeleteOrg(); + // } + // }, []); /* istanbul ignore next */ if (!(project || epic || task)) { diff --git a/src/js/components/orgs/taskOrgCard.tsx b/src/js/components/orgs/taskOrgCard.tsx index 5ab9671dd..af1b4b9f7 100644 --- a/src/js/components/orgs/taskOrgCard.tsx +++ b/src/js/components/orgs/taskOrgCard.tsx @@ -203,15 +203,15 @@ const TaskOrgCard = ({ // We consider an org out-of-date if it is not based on the first commit. const orgOutOfDate = Boolean(org && orgCommitIdx !== 0); const testOrgOutOfDate = type === ORG_TYPES.QA && orgOutOfDate; - useEffect(() => { - if ( - org && - org?.expires_at !== null && - new Date(org?.expires_at) < new Date() - ) { - doDeleteOrg(); - } - }, []); + // useEffect(() => { + // if ( + // org && + // org?.expires_at !== null && + // new Date(org?.expires_at) < new Date() + // ) { + // doDeleteOrg(); + // } + // }, []); return (
Date: Mon, 23 Oct 2023 12:47:09 +0530 Subject: [PATCH 08/14] Test Fixes --- test/js/components/tasks/detail.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/js/components/tasks/detail.test.jsx b/test/js/components/tasks/detail.test.jsx index 4c09408f3..f1d0b0233 100644 --- a/test/js/components/tasks/detail.test.jsx +++ b/test/js/components/tasks/detail.test.jsx @@ -78,7 +78,7 @@ const defaultOrg = { owner: sampleUser1.id, owner_gh_username: sampleGitHubUser1.username, owner_gh_id: sampleGitHubUser1.id, - expires_at: '2019-09-16T12:58:53.721Z', + expires_at: new Date(new Date().getTime() + 86400000).toISOString(), latest_commit: '617a51', latest_commit_url: '/test/commit/url/', latest_commit_at: '2019-08-16T12:58:53.721Z', From fbd7e67c2ad152593c649ced5b0ac12de0baf124 Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Mon, 23 Oct 2023 12:56:50 +0530 Subject: [PATCH 09/14] Test Fixes --- test/js/components/epics/detail.test.jsx | 2 +- test/js/components/orgs/playgroundCard.test.jsx | 2 +- test/js/components/orgs/taskOrgCards.test.jsx | 2 +- test/js/components/projects/detail.test.jsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/js/components/epics/detail.test.jsx b/test/js/components/epics/detail.test.jsx index 130a22cf3..f35b56e40 100644 --- a/test/js/components/epics/detail.test.jsx +++ b/test/js/components/epics/detail.test.jsx @@ -56,7 +56,7 @@ const defaultOrg = { owner: sampleUser1.id, owner_gh_username: sampleGitHubUser1.username, owner_gh_id: sampleGitHubUser1.id, - expires_at: '2019-09-16T12:58:53.721Z', + expires_at: new Date(new Date().getTime() + 86400000).toISOString(), latest_commit: '617a51', latest_commit_url: '/test/commit/url/', latest_commit_at: '2019-08-16T12:58:53.721Z', diff --git a/test/js/components/orgs/playgroundCard.test.jsx b/test/js/components/orgs/playgroundCard.test.jsx index 309b7fefe..e843fca93 100644 --- a/test/js/components/orgs/playgroundCard.test.jsx +++ b/test/js/components/orgs/playgroundCard.test.jsx @@ -57,7 +57,7 @@ const defaultOrg = { owner: 'user-id', owner_gh_username: 'user-name', owner_gh_id: 123456, - expires_at: '2019-09-16T12:58:53.721Z', + expires_at: new Date(new Date().getTime() + 86400000).toISOString(), latest_commit: '617a512', latest_commit_url: '/test/commit/url/', latest_commit_at: '2019-08-16T12:58:53.721Z', diff --git a/test/js/components/orgs/taskOrgCards.test.jsx b/test/js/components/orgs/taskOrgCards.test.jsx index 23db2293d..9c85c06d2 100644 --- a/test/js/components/orgs/taskOrgCards.test.jsx +++ b/test/js/components/orgs/taskOrgCards.test.jsx @@ -52,7 +52,7 @@ const defaultOrgs = { owner: sampleUser1.id, owner_gh_username: sampleGitHubUser1.username, owner_gh_id: sampleGitHubUser1.id, - expires_at: '2019-09-16T12:58:53.721Z', + expires_at: new Date(new Date().getTime() + 86400000).toISOString(), latest_commit: '617a512-longlong', latest_commit_url: '/test/commit/url/', latest_commit_at: '2019-08-16T12:58:53.721Z', diff --git a/test/js/components/projects/detail.test.jsx b/test/js/components/projects/detail.test.jsx index 39f77abf7..7aac24fc6 100644 --- a/test/js/components/projects/detail.test.jsx +++ b/test/js/components/projects/detail.test.jsx @@ -50,7 +50,7 @@ const defaultOrg = { owner: 'my-user', owner_gh_username: 'currentUser', owner_gh_id: 123456, - expires_at: '2019-09-16T12:58:53.721Z', + expires_at: new Date(new Date().getTime() + 86400000).toISOString(), latest_commit: '617a51', latest_commit_url: '/test/commit/url/', latest_commit_at: '2019-08-16T12:58:53.721Z', From 28de88cfcc33ecb2ab21dc4c245c70c7a79effbe Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Mon, 23 Oct 2023 15:34:35 +0530 Subject: [PATCH 10/14] Added Tests --- .../components/orgs/playgroundCard.test.jsx | 21 +++++++++++++++++++ test/js/components/orgs/taskOrgCards.test.jsx | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/test/js/components/orgs/playgroundCard.test.jsx b/test/js/components/orgs/playgroundCard.test.jsx index e843fca93..50402f185 100644 --- a/test/js/components/orgs/playgroundCard.test.jsx +++ b/test/js/components/orgs/playgroundCard.test.jsx @@ -236,6 +236,27 @@ describe('', () => { const args = deleteObject.mock.calls[0][0]; + expect(args.objectType).toBe('scratch_org'); + expect(args.object.id).toEqual(defaultOrg.id); + }); + }); + describe('delete expired org', () => { + test('checks for expiry status and then deletes org', async () => { + const org = { + ...defaultOrg, + expires_at: new Date().toISOString(), + unsaved_changes: {}, + total_unsaved_changes: 0, + has_unsaved_changes: false, + }; + const { findByText } = setup({ org }); + + await findByText('Deleting Org…'); + + expect(deleteObject).toHaveBeenCalledTimes(1); + + const args = deleteObject.mock.calls[0][0]; + expect(args.objectType).toBe('scratch_org'); expect(args.object.id).toEqual(defaultOrg.id); }); diff --git a/test/js/components/orgs/taskOrgCards.test.jsx b/test/js/components/orgs/taskOrgCards.test.jsx index 9c85c06d2..749a67fae 100644 --- a/test/js/components/orgs/taskOrgCards.test.jsx +++ b/test/js/components/orgs/taskOrgCards.test.jsx @@ -913,7 +913,28 @@ describe('', () => { expect(args.object.id).toBe('org-id'); }); }); + test('checks and then deletes expired org', async () => { + const { findByText } = setup({ + orgs: { + ...defaultOrgs, + Dev: { + ...defaultOrgs.Dev, + expires_at: new Date().toISOString(), + unsaved_changes: {}, + total_unsaved_changes: 0, + has_unsaved_changes: false, + }, + }, + }); + await findByText('Deleting Org…'); + expect(deleteObject).toHaveBeenCalledTimes(1); + + const deleteArgs = deleteObject.mock.calls[0][0]; + + expect(deleteArgs.objectType).toBe('scratch_org'); + expect(deleteArgs.object.id).toBe('org-id'); + }); describe('Dev org', () => { test('refreshes and then deletes org', async () => { const { findByText, getByText } = setup({ From a81d7ad433cc8e7fe08e8dad871f8bec45e8ec10 Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Wed, 1 Nov 2023 11:43:09 +0530 Subject: [PATCH 11/14] Minor Test Fixes --- test/js/components/orgs/playgroundCard.test.jsx | 2 +- test/js/components/orgs/taskOrgCards.test.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/js/components/orgs/playgroundCard.test.jsx b/test/js/components/orgs/playgroundCard.test.jsx index 50402f185..18a3c2859 100644 --- a/test/js/components/orgs/playgroundCard.test.jsx +++ b/test/js/components/orgs/playgroundCard.test.jsx @@ -250,7 +250,7 @@ describe('', () => { has_unsaved_changes: false, }; const { findByText } = setup({ org }); - + expect.assertions(3); await findByText('Deleting Org…'); expect(deleteObject).toHaveBeenCalledTimes(1); diff --git a/test/js/components/orgs/taskOrgCards.test.jsx b/test/js/components/orgs/taskOrgCards.test.jsx index 749a67fae..ab4bda38e 100644 --- a/test/js/components/orgs/taskOrgCards.test.jsx +++ b/test/js/components/orgs/taskOrgCards.test.jsx @@ -927,7 +927,7 @@ describe('', () => { }, }); await findByText('Deleting Org…'); - + expect.assertions(3); expect(deleteObject).toHaveBeenCalledTimes(1); const deleteArgs = deleteObject.mock.calls[0][0]; From 657b5771fbc0123d9905e86defdd12c145ce2a37 Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Wed, 1 Nov 2023 12:44:42 +0530 Subject: [PATCH 12/14] Fixed Generation of Incorrect dif links for out of date orgs --- locales_dev/en/translation.json | 3 --- src/js/components/orgs/cards/orgInfo.tsx | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/locales_dev/en/translation.json b/locales_dev/en/translation.json index c47eb20ae..a26806896 100644 --- a/locales_dev/en/translation.json +++ b/locales_dev/en/translation.json @@ -59,7 +59,6 @@ "Complete a Task": "Complete a Task", "Completed item": "Completed item", "Confirm": "Confirm", - "Confirm Changing Developer and Deleting Dev Org": "Confirm Changing Developer and Deleting Dev Org", "Confirm Deleting Account": "Confirm Deleting Account", "Confirm Deleting Epic": "Confirm Deleting Epic", "Confirm Deleting Org With Unretrieved Changes": "Confirm Deleting Org With Unretrieved Changes", @@ -174,7 +173,6 @@ "GitHub Repository Name": "GitHub Repository Name", "Go Back": "Go Back", "Heading": "Heading", - "Health Check": "Health Check", "Hello! What can Metecho help you do today?": "Hello! What can Metecho help you do today?", "Help Walkthrough": "Help Walkthrough", "Home": "Home", @@ -397,7 +395,6 @@ "Tester": "Tester", "Tester & Test Org": "Tester & Test Org", "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}": "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}", - "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.": "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.", "There are no available Epic Collaborators.": "There are no available Epic Collaborators.", diff --git a/src/js/components/orgs/cards/orgInfo.tsx b/src/js/components/orgs/cards/orgInfo.tsx index 03650080a..64d8a8a2f 100644 --- a/src/js/components/orgs/cards/orgInfo.tsx +++ b/src/js/components/orgs/cards/orgInfo.tsx @@ -87,7 +87,7 @@ const OrgInfo = ({ // synced status for orgs if (baseCommit) { // eslint-disable-next-line max-len - compareChangesUrl = `${repoUrl}/compare/${org.latest_commit}...${baseCommit}`; + compareChangesUrl = `${repoUrl}/compare/${baseCommit}...${org.latest_commit}`; } outOfDateMsg = (
  • From 9a6ba3d0846024a8be9d1885d92513722f5f255f Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Fri, 3 Nov 2023 15:39:38 +0530 Subject: [PATCH 13/14] Reverting Translation.json --- locales_dev/en/translation.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locales_dev/en/translation.json b/locales_dev/en/translation.json index a26806896..c47eb20ae 100644 --- a/locales_dev/en/translation.json +++ b/locales_dev/en/translation.json @@ -59,6 +59,7 @@ "Complete a Task": "Complete a Task", "Completed item": "Completed item", "Confirm": "Confirm", + "Confirm Changing Developer and Deleting Dev Org": "Confirm Changing Developer and Deleting Dev Org", "Confirm Deleting Account": "Confirm Deleting Account", "Confirm Deleting Epic": "Confirm Deleting Epic", "Confirm Deleting Org With Unretrieved Changes": "Confirm Deleting Org With Unretrieved Changes", @@ -173,6 +174,7 @@ "GitHub Repository Name": "GitHub Repository Name", "Go Back": "Go Back", "Heading": "Heading", + "Health Check": "Health Check", "Hello! What can Metecho help you do today?": "Hello! What can Metecho help you do today?", "Help Walkthrough": "Help Walkthrough", "Home": "Home", @@ -395,6 +397,7 @@ "Tester": "Tester", "Tester & Test Org": "Tester & Test Org", "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}": "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}", + "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.": "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.", "There are no available Epic Collaborators.": "There are no available Epic Collaborators.", From e50747b108b7da97086075a651c6cee4dafbb3d5 Mon Sep 17 00:00:00 2001 From: jain-naman-sf Date: Sat, 4 Nov 2023 09:41:10 +0530 Subject: [PATCH 14/14] Reverting Translation.json --- locales_dev/en/translation.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locales_dev/en/translation.json b/locales_dev/en/translation.json index a26806896..c47eb20ae 100644 --- a/locales_dev/en/translation.json +++ b/locales_dev/en/translation.json @@ -59,6 +59,7 @@ "Complete a Task": "Complete a Task", "Completed item": "Completed item", "Confirm": "Confirm", + "Confirm Changing Developer and Deleting Dev Org": "Confirm Changing Developer and Deleting Dev Org", "Confirm Deleting Account": "Confirm Deleting Account", "Confirm Deleting Epic": "Confirm Deleting Epic", "Confirm Deleting Org With Unretrieved Changes": "Confirm Deleting Org With Unretrieved Changes", @@ -173,6 +174,7 @@ "GitHub Repository Name": "GitHub Repository Name", "Go Back": "Go Back", "Heading": "Heading", + "Health Check": "Health Check", "Hello! What can Metecho help you do today?": "Hello! What can Metecho help you do today?", "Help Walkthrough": "Help Walkthrough", "Home": "Home", @@ -395,6 +397,7 @@ "Tester": "Tester", "Tester & Test Org": "Tester & Test Org", "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}": "The current scratch org cannot be transferred to the selected GitHub user. Remove the scratch org before transferring this task or correct the following issues: {{issueDescription}}", + "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Changing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?": "The existing Dev Org for this Task has unretrieved changes. Removing the assigned Developer will also delete the Org, and any changes will be lost. Are you sure you want to do that?", "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.": "The last line of the log is “{{message}}” If you need support, your scratch org id is {{orgId}}.", "There are no available Epic Collaborators.": "There are no available Epic Collaborators.",