From a65bc3eda69affe186993e765465ba27a395ee84 Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Mon, 23 Oct 2023 18:03:06 +0530 Subject: [PATCH 1/2] fixed error msg for falsy start date (#565) --- .../member-profile/active-task/index.js | 12 ++- .../member-profile/contribution-type/index.js | 2 +- .../member-profile/contribution/index.js | 12 +-- src/constants/error-messages.js | 1 + src/helper-functions/taskProgress.js | 11 ++- src/helper-functions/time-was.js | 12 ++- .../components/member-profile/index.test.js | 87 +++++++++++++++++++ 7 files changed, 123 insertions(+), 14 deletions(-) diff --git a/src/components/member-profile/active-task/index.js b/src/components/member-profile/active-task/index.js index f011890e..c3f8c22e 100644 --- a/src/components/member-profile/active-task/index.js +++ b/src/components/member-profile/active-task/index.js @@ -5,14 +5,20 @@ import { percentageofDaysRemaining } from '@helper-functions/taskProgress'; import { estimatedDays } from '@helper-functions/estimated-days'; import { progressIndicator } from '@helper-functions/progressIndicator'; -const ActiveTask = ({ taskDetails }) => { +const ActiveTask = ({ taskDetails, devUser }) => { const { title, purpose, startedOn, endsOn, percentCompleted } = taskDetails; - const completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); + const completedDate = timeWas( + startedOn * 1000, + false, + endsOn * 1000, + devUser + ); const percentOfTaskLeft = 100 - percentCompleted; const percentageOfDaysRemaining = percentageofDaysRemaining( startedOn, endsOn, - completedDate + completedDate, + devUser ); const showEstimatedDay = estimatedDays( percentageOfDaysRemaining, diff --git a/src/components/member-profile/contribution-type/index.js b/src/components/member-profile/contribution-type/index.js index d2c90032..3051e5bb 100644 --- a/src/components/member-profile/contribution-type/index.js +++ b/src/components/member-profile/contribution-type/index.js @@ -52,7 +52,7 @@ const renderActiveTasks = (tasks, devUser) => { if (devUser) { if (tasks?.length > 0) { return tasks.map((task, index) => { - return ; + return ; }); } return ( diff --git a/src/components/member-profile/contribution/index.js b/src/components/member-profile/contribution/index.js index d6136db0..25d43aa7 100644 --- a/src/components/member-profile/contribution/index.js +++ b/src/components/member-profile/contribution/index.js @@ -115,22 +115,22 @@ const ContributionCard = ({ if (isTitleAvailable) { if (status !== 'VERIFIED') { completedText = Estimated Completion: ; - completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); + completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser); } else { - completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); + completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser); completedText = Completed in: ; - featureLiveDate = timeWas(endsOn * 1000, true); + featureLiveDate = timeWas(endsOn * 1000, true, Date.now(), devUser); featureLiveOnText = featureLiveDate; } } else { const createdAt = +new Date(prList[0].createdAt); const updatedAt = +new Date(prList[0].updatedAt); if (prList[0].state === 'closed') { - completedDate = timeWas(createdAt, false, updatedAt); + completedDate = timeWas(createdAt, false, updatedAt, devUser); completedText = ( Completed in ); - featureLiveDate = timeWas(updatedAt, true); + featureLiveDate = timeWas(updatedAt, true, Date.now(), devUser); featureLiveOnText = featureLiveDate; } } @@ -202,7 +202,7 @@ ContributionCard.propTypes = { imageLink: PropTypes.string.isRequired, devUser: PropTypes.bool.isRequired, url: PropTypes.string.isRequired, - urlObj: PropTypes.instanceOf(Object).isRequired, + urlObj: PropTypes.instanceOf(URL).isRequired, }; export default Contribution; diff --git a/src/constants/error-messages.js b/src/constants/error-messages.js index f17ce06e..065ffed5 100644 --- a/src/constants/error-messages.js +++ b/src/constants/error-messages.js @@ -4,3 +4,4 @@ export const emptyContributionsError = 'No Contributions have been received yet.'; export const emptyNoteworthyContributionsError = 'It would be wonderful to see some noteworthy contributions made.'; +export const notAvailableError = 'N/A'; diff --git a/src/helper-functions/taskProgress.js b/src/helper-functions/taskProgress.js index 63bd75b0..d8715305 100644 --- a/src/helper-functions/taskProgress.js +++ b/src/helper-functions/taskProgress.js @@ -1,8 +1,13 @@ import { timeWas } from '@helper-functions/time-was'; -const percentageofDaysRemaining = (startedOn, endsOn, completedDate) => { - const startDate = timeWas(startedOn * 1000, true, endsOn * 1000); - const endDate = timeWas(endsOn * 1000, true, startDate * 1000); +const percentageofDaysRemaining = ( + startedOn, + endsOn, + completedDate, + devUser +) => { + const startDate = timeWas(startedOn * 1000, true, endsOn * 1000, devUser); + const endDate = timeWas(endsOn * 1000, true, startDate * 1000, devUser); const date1 = new Date(startDate); const date2 = new Date(endDate); const diffTime = Math.abs(date2 - date1); diff --git a/src/helper-functions/time-was.js b/src/helper-functions/time-was.js index 12df17a5..ad9f4033 100644 --- a/src/helper-functions/time-was.js +++ b/src/helper-functions/time-was.js @@ -1,6 +1,16 @@ +import { notAvailableError } from '@constants/error-messages'; + const calc = (interval, cycle) => Math.floor(cycle / interval); -function timeWas(timestamp, completeDate = false, differentNow = Date.now()) { +function timeWas( + timestamp, + completeDate = false, + differentNow = Date.now(), + devUser +) { + if (devUser && (!timestamp || timestamp === 0)) { + return notAvailableError; + } const timeInSec = Math.floor(differentNow - timestamp) / 1000; /** diff --git a/src/test/unit/components/member-profile/index.test.js b/src/test/unit/components/member-profile/index.test.js index 2ac65574..361d9d49 100644 --- a/src/test/unit/components/member-profile/index.test.js +++ b/src/test/unit/components/member-profile/index.test.js @@ -8,6 +8,7 @@ import { emptyActiveTasksError, emptyContributionsError, emptyNoteworthyContributionsError, + notAvailableError, } from '@constants/error-messages'; const notaMember = { @@ -128,6 +129,92 @@ describe('Members Profile', () => { ); expect(emptyNoteworthyContributionsErrorElement).toBeInTheDocument(); }); + it('Should render notAvailable error message in completion date, if start date is falsy inside task/contrbution object', () => { + const tasksWithEmptyStartDateAsFalsy = [ + { + id: 'eHjZi3jzyqep43GvK2Rf', + percentCompleted: 50, + endsOn: '1698085740', + github: { + issue: { + html_url: 'https://github.com/Real-Dev-Squad/mobile-app/issues/263', + id: '1914069956', + assignee: 'harshitadatra', + status: 'open', + }, + }, + createdBy: 'amitprakash', + assignee: 'prakash', + title: 'Animation enhancement in Goals page', + type: 'feature', + priority: 'TBD', + startedOn: null, + status: 'IN_PROGRESS', + featureUrl: + 'https://github.com/Real-Dev-Squad/website-members/issues/562', + assigneeId: 'YzEVZ50DHr37oL1mqqbO', + }, + ]; + + const contributionsWithStartDateAsFalsy = { + all: [ + { + task: { + id: 'CdsWvmW2c9h5D08bHsYa', + title: 'Dummy Title', + endsOn: '1697155200', + startedOn: '0', + status: 'COMPLETED', + featureUrl: + 'https://github.com/Real-Dev-Squad/website-members/issues/562', + participants: [], + }, + prList: [], + }, + ], + noteworthy: [ + { + task: { + id: 'CdsWvmW2c9h5D08bHsYa', + title: 'Dummy Title', + endsOn: '1697155200', + startedOn: undefined, + featureUrl: + 'https://github.com/Real-Dev-Squad/website-members/issues/562', + status: 'COMPLETED', + participants: [], + }, + prList: [], + }, + ], + }; + render( + + + + + + + + ); + const notAvailableCompletetionDateElements = + screen.queryAllByText(notAvailableError); + notAvailableCompletetionDateElements.forEach((element) => { + expect(element).toHaveTextContent(notAvailableError); + }); + + expect(notAvailableCompletetionDateElements).toHaveLength(3); + }); it('Should render the info icon correctly', () => { render( From 4057012821612042b96e1337337b71382768640b Mon Sep 17 00:00:00 2001 From: Shubham Jain Date: Fri, 27 Oct 2023 17:32:34 +0530 Subject: [PATCH 2/2] removed feature flag from accordian and invalid date (#570) --- .../member-profile/active-task/index.js | 12 +-- .../member-profile/contribution-type/index.js | 101 ++++++------------ .../member-profile/contribution/index.js | 10 +- src/helper-functions/taskProgress.js | 11 +- src/helper-functions/time-was.js | 9 +- .../components/member-profile/index.test.js | 2 - 6 files changed, 45 insertions(+), 100 deletions(-) diff --git a/src/components/member-profile/active-task/index.js b/src/components/member-profile/active-task/index.js index c3f8c22e..f011890e 100644 --- a/src/components/member-profile/active-task/index.js +++ b/src/components/member-profile/active-task/index.js @@ -5,20 +5,14 @@ import { percentageofDaysRemaining } from '@helper-functions/taskProgress'; import { estimatedDays } from '@helper-functions/estimated-days'; import { progressIndicator } from '@helper-functions/progressIndicator'; -const ActiveTask = ({ taskDetails, devUser }) => { +const ActiveTask = ({ taskDetails }) => { const { title, purpose, startedOn, endsOn, percentCompleted } = taskDetails; - const completedDate = timeWas( - startedOn * 1000, - false, - endsOn * 1000, - devUser - ); + const completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); const percentOfTaskLeft = 100 - percentCompleted; const percentageOfDaysRemaining = percentageofDaysRemaining( startedOn, endsOn, - completedDate, - devUser + completedDate ); const showEstimatedDay = estimatedDays( percentageOfDaysRemaining, diff --git a/src/components/member-profile/contribution-type/index.js b/src/components/member-profile/contribution-type/index.js index 3051e5bb..f359a10e 100644 --- a/src/components/member-profile/contribution-type/index.js +++ b/src/components/member-profile/contribution-type/index.js @@ -17,53 +17,34 @@ const renderContributions = ( devUser, type ) => { - if (devUser) { - if (contributions?.length > 0) { - return contributions.map((noteWorthyContribution, index) => ( - - )); - } - return ( -

- {type === 'All' - ? emptyContributionsError - : emptyNoteworthyContributionsError} -

- ); + if (contributions?.length > 0) { + return contributions.map((noteWorthyContribution, index) => ( + + )); } - return contributions?.map((noteWorthyContribution, index) => ( - - )); + return ( +

+ {type === 'All' + ? emptyContributionsError + : emptyNoteworthyContributionsError} +

+ ); }; -const renderActiveTasks = (tasks, devUser) => { - if (devUser) { - if (tasks?.length > 0) { - return tasks.map((task, index) => { - return ; - }); - } - return ( -

{emptyActiveTasksError}

- ); +const renderActiveTasks = (tasks) => { + if (tasks?.length > 0) { + return tasks.map((task, index) => { + return ; + }); } return ( - tasks && - tasks.map((task, index) => { - return ; - }) +

{emptyActiveTasksError}

); }; @@ -81,18 +62,7 @@ const ContributionType = (props) => { }, [tasks.length, contributions.length]); const showMoreContentHandler = () => { - if (devUser) { - setShowMoreContent(!showMoreContent); - } else { - if (isContribution) { - if (contributions.length > 0) { - setShowMoreContent(!showMoreContent); - } - } - if (tasks.length > 0) { - setShowMoreContent(!showMoreContent); - } - } + setShowMoreContent(!showMoreContent); }; const showMoreContentClass = showMoreContent @@ -115,23 +85,16 @@ const ContributionType = (props) => {
{type !== 'Active tasks' ? (
- {devUser - ? renderContributions( - contributions, - fullName, - imageLink, - devUser, - type - ) - : renderContributions( - contributions, - fullName, - imageLink, - devUser - )} + {renderContributions( + contributions, + fullName, + imageLink, + devUser, + type + )}
) : ( -
{renderActiveTasks(tasks, devUser)}
+
{renderActiveTasks(tasks)}
)}

diff --git a/src/components/member-profile/contribution/index.js b/src/components/member-profile/contribution/index.js index 25d43aa7..afad425a 100644 --- a/src/components/member-profile/contribution/index.js +++ b/src/components/member-profile/contribution/index.js @@ -115,22 +115,22 @@ const ContributionCard = ({ if (isTitleAvailable) { if (status !== 'VERIFIED') { completedText = Estimated Completion: ; - completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser); + completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); } else { - completedDate = timeWas(startedOn * 1000, false, endsOn * 1000, devUser); + completedDate = timeWas(startedOn * 1000, false, endsOn * 1000); completedText = Completed in: ; - featureLiveDate = timeWas(endsOn * 1000, true, Date.now(), devUser); + featureLiveDate = timeWas(endsOn * 1000, true, Date.now()); featureLiveOnText = featureLiveDate; } } else { const createdAt = +new Date(prList[0].createdAt); const updatedAt = +new Date(prList[0].updatedAt); if (prList[0].state === 'closed') { - completedDate = timeWas(createdAt, false, updatedAt, devUser); + completedDate = timeWas(createdAt, false, updatedAt); completedText = ( Completed in ); - featureLiveDate = timeWas(updatedAt, true, Date.now(), devUser); + featureLiveDate = timeWas(updatedAt, true, Date.now()); featureLiveOnText = featureLiveDate; } } diff --git a/src/helper-functions/taskProgress.js b/src/helper-functions/taskProgress.js index d8715305..63bd75b0 100644 --- a/src/helper-functions/taskProgress.js +++ b/src/helper-functions/taskProgress.js @@ -1,13 +1,8 @@ import { timeWas } from '@helper-functions/time-was'; -const percentageofDaysRemaining = ( - startedOn, - endsOn, - completedDate, - devUser -) => { - const startDate = timeWas(startedOn * 1000, true, endsOn * 1000, devUser); - const endDate = timeWas(endsOn * 1000, true, startDate * 1000, devUser); +const percentageofDaysRemaining = (startedOn, endsOn, completedDate) => { + const startDate = timeWas(startedOn * 1000, true, endsOn * 1000); + const endDate = timeWas(endsOn * 1000, true, startDate * 1000); const date1 = new Date(startDate); const date2 = new Date(endDate); const diffTime = Math.abs(date2 - date1); diff --git a/src/helper-functions/time-was.js b/src/helper-functions/time-was.js index ad9f4033..31439cf3 100644 --- a/src/helper-functions/time-was.js +++ b/src/helper-functions/time-was.js @@ -2,13 +2,8 @@ import { notAvailableError } from '@constants/error-messages'; const calc = (interval, cycle) => Math.floor(cycle / interval); -function timeWas( - timestamp, - completeDate = false, - differentNow = Date.now(), - devUser -) { - if (devUser && (!timestamp || timestamp === 0)) { +function timeWas(timestamp, completeDate = false, differentNow = Date.now()) { + if (!timestamp || timestamp === 0 || !differentNow) { return notAvailableError; } const timeInSec = Math.floor(differentNow - timestamp) / 1000; diff --git a/src/test/unit/components/member-profile/index.test.js b/src/test/unit/components/member-profile/index.test.js index 361d9d49..651a3cba 100644 --- a/src/test/unit/components/member-profile/index.test.js +++ b/src/test/unit/components/member-profile/index.test.js @@ -108,7 +108,6 @@ describe('Members Profile', () => { @@ -199,7 +198,6 @@ describe('Members Profile', () => {