From 247abea9e7f16341da485674996feb6c51d0fb82 Mon Sep 17 00:00:00 2001 From: JOSEPH LE Date: Tue, 11 Jun 2024 11:29:45 +0700 Subject: [PATCH] update assignee history --- BACKEND/app/Services/JiraService.php | 13 ++- FRONTEND/src/pages/Worklogs/Worklogs.tsx | 133 ++++++++++++++++------- 2 files changed, 104 insertions(+), 42 deletions(-) diff --git a/BACKEND/app/Services/JiraService.php b/BACKEND/app/Services/JiraService.php index b372556..dc73a5d 100644 --- a/BACKEND/app/Services/JiraService.php +++ b/BACKEND/app/Services/JiraService.php @@ -84,9 +84,18 @@ class JiraService 'body' => json_encode($body) ]); - return json_decode($response->getBody()->getContents(), true); - } + $issues = json_decode($response->getBody()->getContents(), true); + foreach ($issues['issues'] as &$issue) { + $issueKey = $issue['key']; + $issueResponse = $this->client->get("/rest/api/3/issue/{$issueKey}?expand=changelog"); + $issueDetails = json_decode($issueResponse->getBody()->getContents(), true); + $issue['changelog'] = $issueDetails['changelog']; + } + + return $issues; + } + public function getAllUsers() { $response = $this->client->get('/rest/api/3/users/search', [ diff --git a/FRONTEND/src/pages/Worklogs/Worklogs.tsx b/FRONTEND/src/pages/Worklogs/Worklogs.tsx index 0dfebe2..c16e96d 100644 --- a/FRONTEND/src/pages/Worklogs/Worklogs.tsx +++ b/FRONTEND/src/pages/Worklogs/Worklogs.tsx @@ -58,6 +58,7 @@ interface Issue { self: string key: string fields: IssueFields + changelog: Changelog } interface IssueFields { @@ -118,6 +119,31 @@ interface UserWorklog { issues: Issue[] } } + +interface Item { + field: string + fieldtype: string + fieldId: string + from: string | null + fromString: string | null + to: string | null + toString: string | null +} + +interface History { + id: string + author: UserInfo + created: string + items: Item[] +} + +interface Changelog { + startAt: number + maxResults: number + total: number + histories: History[] +} + const Worklogs = () => { const [loader, setLoader] = useState(true) const [updating, setUpdating] = useState(true) @@ -156,11 +182,11 @@ const Worklogs = () => { } setUpdating(true) - } catch (error:any) { + } catch (error: any) { console.log(error) notifications.show({ title: 'Error', - message: error.message??error, + message: error.message ?? error, color: 'red', }) } @@ -236,7 +262,6 @@ const Worklogs = () => { size="xs" label="To date:" value={new Date(date.endDate)} - // clearable m={'0 10px'} w={'20%'} @@ -426,7 +451,7 @@ const Worklogs = () => { [{iss.key}]{` ${iss.fields.summary}`} @@ -435,11 +460,15 @@ const Worklogs = () => { Estimate:{' '} - {iss.fields.timeoriginalestimate / 60 / 60}h + + {iss.fields.timeoriginalestimate / 60 / 60}h + Total time spent:{' '} - {iss.fields.timespent / 60 / 60}h + + {iss.fields.timespent / 60 / 60}h + @@ -452,41 +481,47 @@ const Worklogs = () => { ) : - {' '} - {iss.fields.worklog.worklogs?.reduce( - (accumulator, currentValue) => { - if ( - parseInt( - moment(date.startDate).format('YYYYMMDD'), - ) <= + {' '} + + {iss.fields.worklog.worklogs?.reduce( + (accumulator, currentValue) => { + if ( + parseInt( + moment(date.startDate).format( + 'YYYYMMDD', + ), + ) <= + parseInt( + moment(currentValue.started).format( + 'YYYYMMDD', + ), + ) && parseInt( moment(currentValue.started).format( 'YYYYMMDD', ), - ) && - parseInt( - moment(currentValue.started).format( - 'YYYYMMDD', - ), - ) <= - parseInt( - moment(date.endDate).format('YYYYMMDD'), - ) && - currentValue.updateAuthor.displayName === - user.username - ) { - return ( - accumulator + - currentValue.timeSpentSeconds - ) - } - return accumulator - }, - 0, - ) / - 60 / - 60} - h + ) <= + parseInt( + moment(date.endDate).format( + 'YYYYMMDD', + ), + ) && + currentValue.updateAuthor.displayName === + user.username + ) { + return ( + accumulator + + currentValue.timeSpentSeconds + ) + } + return accumulator + }, + 0, + ) / + 60 / + 60} + h + {iss.fields.worklog.worklogs?.map((log, index) => { @@ -574,6 +609,7 @@ const Worklogs = () => { > {iss.fields.status.name} + { [{iss.key}]{` ${iss.fields.summary}`} @@ -606,12 +642,29 @@ const Worklogs = () => { - Time spent: {iss.fields.timespent / 60 / 60}h + Time spent:{' '} + + {iss.fields.timespent / 60 / 60}h + Estimate:{' '} - {iss.fields.timeoriginalestimate / 60 / 60}h + + {iss.fields.timeoriginalestimate / 60 / 60}h + + {/* History issue */} + {iss.changelog.histories.map((h) => { + return h.items.find((i) => i.field === 'assignee') ? ( + {'Assigned at: ' + moment(h.created).format("HH:mm:ss DD/MM/YYYY")} + ) : h.items.find((i) => i.field === 'status')? ( + {h.items.find((i) => i.field === 'status') + ?.fromString+" ➯ "+h.items.find((i) => i.field === 'status') + ?.toString +": "+ moment(h.created).format("HH:mm:ss DD/MM/YYYY")} + ) : ( + '' + ) + })} ) })}