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

Fix/adm 937 #112

Closed
wants to merge 69 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7d7e852
ADM-898[backend][frontend]: feat: block' in board mapping is mutually…
yulongcai Apr 12, 2024
6b43c85
ADM-919[backend] : Speed up the generating of pipeline data in repor…
yulongcai Apr 12, 2024
26a2bbb
chore(deps): update dependency node to v20 (#1375)[docs]
renovate[bot] Apr 14, 2024
598975e
fix(deps): update dependency @emotion/styled to v11.11.5 (#1363)
renovate[bot] Apr 14, 2024
c6f64b1
fix(deps): update dependency @reduxjs/toolkit to v2.2.3 (#1364)
renovate[bot] Apr 14, 2024
578e1c4
fix(deps): update dependency org.springframework:spring-core to v6.1.…
renovate[bot] Apr 14, 2024
26af590
fix(deps): update dependency typescript to v5.4.5 (#1366)
renovate[bot] Apr 15, 2024
221a062
fix(deps): update dependency vite to v5.2.8 (#1367)
renovate[bot] Apr 15, 2024
d223672
ADM-898: [frontend] fix: fix flag card logic (#1377)
TingyuDong Apr 15, 2024
2e9711d
ADM-878:[frontend]feature: add chart API ability for metrics board co…
weiraneve Apr 15, 2024
9411cd9
ADM-919:[backend] feat: delete fetch author from GitHub (#1379)
yulongcai Apr 15, 2024
d8c3fea
ADM-878:[frontend]refactor: rename date range (#1381)
weiraneve Apr 15, 2024
22590c5
ADM-919:[backend] fix: set code committer is null when author is null…
yulongcai Apr 15, 2024
f465952
fix(deps): update dependency org.yaml:snakeyaml to v2.2 (#1373)[backend]
renovate[bot] Apr 15, 2024
05ad6a7
chore(deps): update dependency prettier-plugin-sort-imports to v1.8.5…
renovate[bot] Apr 15, 2024
aa9a2d2
fix(deps): update material-ui monorepo (#1368)
renovate[bot] Apr 15, 2024
c59344e
Adm 889 - remove some 'name' column in DORA Metrics Detail page (#1380)
Rui7ing Apr 16, 2024
f8c0323
chore(deps): bump gradle/wrapper-validation-action from 2 to 3 (#1384)
dependabot[bot] Apr 17, 2024
aebbd87
fix(deps): [backend]update dependency org.springframework.cloud:sprin…
renovate[bot] Apr 18, 2024
cf74ad2
chore(deps): update plugin com.github.jk1.dependency-license-report t…
renovate[bot] Apr 18, 2024
de335b1
fix(deps): update dependency org.springdoc:springdoc-openapi-starter-…
renovate[bot] Apr 18, 2024
935faf2
Revert "fix(deps): [backend]update dependency org.springframework.clo…
guzhongren Apr 18, 2024
fea3c9a
ADM-898:[backend] fix: fix bug for exist block column when choose fla…
yulongcai Apr 18, 2024
7ea514e
Adm-909[frontend] sort time range (#1378)
pfpatrick Apr 18, 2024
409a892
Revert "Adm-909[frontend] sort time range (#1378)"
pfpatrick Apr 18, 2024
b9f0ea8
Adm-909[frontend] sort time range (#1394)
pfpatrick Apr 19, 2024
6984484
ADM-913 [frontend]:receive multiple time ranges in metrics page- pipe…
Leiqiuhong Apr 19, 2024
bb3e0b9
ADM-914:[backend][frontend] feat: set file name with time range when …
yulongcai Apr 19, 2024
50289f0
fix(e2e): fix e2e case
guzhongren Apr 19, 2024
4c4750a
chore(deps): bump gradle/gradle-build-action from 3.2.1 to 3.3.0 (#1383)
dependabot[bot] Apr 20, 2024
f643b86
ADM-913: [frontend] fix: improve test covarage (#1395)
neomgb Apr 21, 2024
5bd7e1b
chore(deps): update plugin org.sonarqube to v5 (#1400)[backend]
renovate[bot] Apr 21, 2024
6a04175
fix security issue according sonar (#1405)
yulongcai Apr 22, 2024
5628bea
chore(deps): update dependency license-compliance to v3 (#1399)[front…
renovate[bot] Apr 22, 2024
a1254fb
AMD-902 [frontend] feat: pipeline configuration need to retain modifi…
neomgb Apr 23, 2024
99274b4
fix(deps): update dependency org.awaitility:awaitility to v4 (#1402)[…
renovate[bot] Apr 23, 2024
6a20213
fix(trivy):ignore trivy[backend]
guzhongren Apr 23, 2024
527e16d
fix(playwright): update e2e base image
guzhongren Apr 24, 2024
79a8ee4
fix(deps): update dependency pmd to v7 (#1403)[backend]
renovate[bot] Apr 24, 2024
9462ea9
chore(deps): bump gradle/gradle-build-action from 3.3.0 to 3.3.1 (#1406)
dependabot[bot] Apr 25, 2024
76932ad
fix(deps): update dependency remark-smartypants to v3 (#1404)[docs]
renovate[bot] Apr 25, 2024
4017224
fix(deps): update dependency @astrojs/check to v0.5.10 (#1397)[docs]
renovate[bot] Apr 25, 2024
7fa4296
chore(deps): update pnpm to v9 (#1401) [docs]
renovate[bot] Apr 26, 2024
87705ba
ADM-927:[frontend]feat: add metrics board and pipeline failed status …
weiraneve Apr 26, 2024
dca98d2
Feat/form management config (#1409)
mrcuriosity-tw Apr 26, 2024
7db10fc
[ADM-887] fix: adjust the aria-label selector to fix the e2e test. (#…
mrcuriosity-tw Apr 26, 2024
b4e7b53
[ADM-887]: adjust unique selector to fix the e2e. (#1412)
mrcuriosity-tw Apr 26, 2024
94f7fd2
chore(deps): update dependency @astrojs/sitemap to v3.1.4 (#1413)[docs]
renovate[bot] Apr 27, 2024
aa00ead
chore(deps): update dependency eslint-plugin-n to v17 (#1398)[frontend]
renovate[bot] Apr 27, 2024
4bfb189
ADM-926:[frontend]feat: add e2e test for charting (#1419)
yulongcai Apr 28, 2024
faf9ede
ADM 927: [frontend] Fix code smell and message text color (#1420)
PengxiWPix Apr 28, 2024
8760abf
ADM-926-fix:[frontend] fix: add two time range to test (#1421)
yulongcai Apr 29, 2024
a0c4367
ADM-926-fix:[frontend] fix: add mapping in generate config file (#1422)
yulongcai Apr 29, 2024
d112ac8
ci(e2e): speedup e2e
guzhongren Apr 29, 2024
6c7b877
fix(e2e): format
guzhongren Apr 29, 2024
4386632
Adm 937[backend][frontend]: Pipeline crew setting could filter out de…
zhou-yinyuan Apr 30, 2024
0684495
chore(deps): update gradle/gradle-build-action action to v3.3.2 (#1416)
renovate[bot] Apr 30, 2024
3f82e95
fix(deps): update dependency @emotion/styled to v11.11.5 (#1417)[fron…
renovate[bot] Apr 30, 2024
6f99b2c
chore(deps): update dependency prettier-plugin-sort-imports to v1.8.5…
renovate[bot] Apr 30, 2024
d3e5697
ADM-879 [frontend] Generate data reports for multiple time ranges (#1…
Leiqiuhong Apr 30, 2024
79fe2d6
Adm-879-fix [frontend]: fix the notification close logic (#1426)
Leiqiuhong Apr 30, 2024
dae9844
chore(deps): update dependency msw to v2 (#1374)[frontend]
renovate[bot] May 3, 2024
bf12a13
Upgrade[frontend] (#1428)
guzhongren May 3, 2024
4b98284
[ADM-931]: [frontend]: optimization of sorting button (#1427)
mrcuriosity-tw May 6, 2024
63d4e32
Adm-897 [frontend]: hide retry button (#1429)
Leiqiuhong May 6, 2024
679b4c8
fix(security): fix security issue
guzhongren May 6, 2024
77d4dc8
[ADM-931] feat: disable the sort button given invalid date (#1431)
mrcuriosity-tw May 7, 2024
827d783
ADM-928:[frontend]feat: add metrics failed date range viewer icon (#1…
weiraneve May 7, 2024
cc60d3d
ADM-937 [frontend]: fix the bug about config file pipeline crew
zhou-yinyuan May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ADM-878:[frontend]feature: add chart API ability for metrics board co…
…nfiguration (#1362)

* ADM-878:[frontend]feat: fix error message when board info gets error code

* ADM-878:[frontend]feat: add metrics board info multiple fetch and combine

* ADM-878:[frontend]feat: update board info combine logic

* ADM-878:[frontend]fix: code style fix

* ADM-878:[frontend]feat: handle board mappings logic

* ADM-878:[frontend]refactor: extract combine logic

* ADM-878:[frontend]refactor: move combine and dispatch logic for use-callback

* ADM-878:[frontend]refactor: order the board info list

* ADM-878:[frontend]feat: refactored ordering into hook

* ADM-878:[frontend]feat: refactor data structure and fix UT

* ADM-878:[frontend]fix: fix UT and lint

* ADM-878:[frontend]refactor: remove a code annotation

* ADM-878:[frontend]refactor: refactor loading state timing after board info request

* ADM-878:[frontend]fix: fix code style

* ADM-878:[frontend]fix: fix prettier

* ADM-878:[frontend]fix: fix test coverage

* ADM-878:[frontend]refactor: extract combine board info to utils

* ADM-878:[frontend]refactor: update some code style

---------

Co-authored-by: PengxiWPix <[email protected]>
weiraneve and PengxiWPix authored Apr 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2e9711d88842f3404985e19949944a689f368126
54 changes: 50 additions & 4 deletions frontend/__tests__/containers/MetricsStep/MetricsStep.test.tsx
Original file line number Diff line number Diff line change
@@ -310,10 +310,56 @@ describe('MetricsStep', () => {
return res(
ctx.status(HttpStatusCode.Ok),
ctx.json({
ignoredTargetFields: [],
jiraColumns: [],
targetFields: [],
users: [],
ignoredTargetFields: [
{
key: 'description',
name: 'Description',
flag: false,
},
{
key: 'customfield_10015',
name: 'Start date',
flag: false,
},
],
jiraColumns: [
{
key: 'To Do',
value: {
name: 'TODO',
statuses: ['TODO'],
},
},
{
key: 'In Progress',
value: {
name: 'Doing',
statuses: ['DOING'],
},
},
],
targetFields: [
{
key: 'issuetype',
name: 'Issue Type',
flag: false,
},
{
key: 'parent',
name: 'Parent',
flag: false,
},
],
users: [
'heartbeat user',
'Yunsong Yang',
'Yufan Wang',
'Weiran Sun',
'Xuebing Li',
'Junbo Dai',
'Wenting Yan',
'Xingmeng Tao',
],
}),
);
}),
10 changes: 10 additions & 0 deletions frontend/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
@@ -642,6 +642,16 @@ export const MOCK_PIPELINE_VERIFY_FORBIDDEN_ERROR_TEXT =

export const FAKE_TOKEN = 'fake-token';

export const FAKE_DATE_EARLIER = {
startDate: '2024-02-01T00:00:00.000+08:00',
endDate: '2024-02-14T23:59:59.999+08:00',
};

export const FAKE_DATE_LATER = {
startDate: '2024-03-01T00:00:00.000+08:00',
endDate: '2024-03-14T23:59:59.999+08:00',
};

export const FAKE_PIPELINE_TOKEN = 'bkua_mockTokenMockTokenMockTokenMockToken1234';

export const ADVANCED_SETTINGS_TITLE = 'Advanced settings';
35 changes: 26 additions & 9 deletions frontend/__tests__/hooks/useGetBoardInfo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MOCK_BOARD_INFO_URL, FAKE_TOKEN, FAKE_DATE_EARLIER, FAKE_DATE_LATER } from '@test/fixtures';
import { useGetBoardInfoEffect } from '@src/hooks/useGetBoardInfo';
import { renderHook, act, waitFor } from '@testing-library/react';
import { MOCK_BOARD_INFO_URL, FAKE_TOKEN } from '@test/fixtures';
import { setupServer } from 'msw/node';
import { HttpStatusCode } from 'axios';
import { rest } from 'msw';
@@ -14,9 +14,18 @@ const mockBoardConfig = {
site: 'fake',
email: '[email protected]',
token: FAKE_TOKEN,
startTime: null,
endTime: null,
dateRanges: [
{
startDate: FAKE_DATE_LATER.startDate,
endDate: FAKE_DATE_LATER.endDate,
},
{
startDate: FAKE_DATE_EARLIER.startDate,
endDate: FAKE_DATE_EARLIER.endDate,
},
],
};

describe('use get board info', () => {
beforeAll(() => server.listen());
afterAll(() => {
@@ -35,18 +44,26 @@ describe('use get board info', () => {
'No card within selected date range!',
'Please go back to the previous page and change your collection date, or check your board info!',
],
[HttpStatusCode.BadRequest, 'Invalid input!', 'Please go back to the previous page and check your board info!'],
[
HttpStatusCode.BadRequest,
'Failed to get the board configuration!',
'Please go back to the previous page to check your board info, or change your time range!',
],
[
HttpStatusCode.Unauthorized,
'Unauthorized request!',
'Please go back to the previous page and check your board info!',
'Failed to get the board configuration!',
'Please go back to the previous page to check your board info, or change your time range!',
],
[
HttpStatusCode.Forbidden,
'Forbidden request!',
'Please go back to the previous page and change your board token with correct access permission.',
'Failed to get the board configuration!',
'Please go back to the previous page to check your board info, or change your time range!',
],
[
HttpStatusCode.NotFound,
'Failed to get the board configuration!',
'Please go back to the previous page to check your board info, or change your time range!',
],
[HttpStatusCode.NotFound, 'Not found!', 'Please go back to the previous page and check your board info!'],
])('should got error message when got code is %s', async (code, title, message) => {
server.use(
rest.post(MOCK_BOARD_INFO_URL, (_, res, ctx) => {
141 changes: 141 additions & 0 deletions frontend/__tests__/utils/Util.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
combineBoardInfo,
convertCycleTimeSettings,
exportToJsonFile,
filterAndMapCycleTimeSettings,
@@ -17,6 +18,7 @@ import {
import { CleanedBuildKiteEmoji, OriginBuildKiteEmoji } from '@src/constants/emojis/emoji';
import { CYCLE_TIME_SETTINGS_TYPES, METRICS_CONSTANTS } from '@src/constants/resources';
import { ICycleTimeSetting, IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { BoardInfoResponse } from '@src/hooks/useGetBoardInfo';
import { EMPTY_STRING } from '@src/constants/commons';
import { PIPELINE_TOOL_TYPES } from '../fixtures';

@@ -429,3 +431,142 @@ describe('sortDateRanges function', () => {
expect(sortedDateRanges).toStrictEqual(expectResult.reverse());
});
});

describe('combineBoardInfo function', () => {
const boardInfoResponses: BoardInfoResponse[] = [
{
ignoredTargetFields: [
{
key: 'description',
name: 'Description',
flag: 'false',
},
{
key: 'customfield_10015',
name: 'Start date',
flag: 'false',
},
],
jiraColumns: [
{
key: 'To Do',
value: '{ name: TODO, statuses: [TODO]}',
},
{
key: 'In Progress',
value: '{ name: DOING, statuses: [DOING]}',
},
],
targetFields: [
{
key: 'issuetype',
name: 'Issue Type',
flag: 'false',
},
{
key: 'parent',
name: 'Parent',
flag: 'false',
},
],
users: ['heartbeat user', 'Yunsong Yang'],
},
{
ignoredTargetFields: [
{
key: 'description',
name: 'Description',
flag: 'false',
},
{
key: 'customfield_10015',
name: 'Start date',
flag: 'false',
},
],
jiraColumns: [
{
key: 'To Do',
value: '{ name: TODO, statuses: [TODO]}',
},
{
key: 'In Progress',
value: '{ name: DOING, statuses: [DOING]}',
},
],
targetFields: [
{
key: 'issuetype',
name: 'Issue Type',
flag: 'false',
},
{
key: 'parent',
name: 'Parent',
flag: 'false',
},
],
users: [
'heartbeat user',
'Yunsong Yang',
'Yufan Wang',
'Weiran Sun',
'Xuebing Li',
'Junbo Dai',
'Wenting Yan',
'Xingmeng Tao',
],
},
];
const expectResults = {
ignoredTargetFields: [
{
key: 'description',
name: 'Description',
flag: 'false',
},
{
key: 'customfield_10015',
name: 'Start date',
flag: 'false',
},
],
jiraColumns: [
{
key: 'To Do',
value: '{ name: TODO, statuses: [TODO]}',
},
{
key: 'In Progress',
value: '{ name: DOING, statuses: [DOING]}',
},
],
targetFields: [
{
key: 'issuetype',
name: 'Issue Type',
flag: 'false',
},
{
key: 'parent',
name: 'Parent',
flag: 'false',
},
],
users: [
'heartbeat user',
'Yunsong Yang',
'Yufan Wang',
'Weiran Sun',
'Xuebing Li',
'Junbo Dai',
'Wenting Yan',
'Xingmeng Tao',
],
};

it('should combine board info', () => {
const combineBoardData = combineBoardInfo(boardInfoResponses);
expect(combineBoardData).toStrictEqual(expectResults);
});
});
7 changes: 7 additions & 0 deletions frontend/src/clients/board/dto/request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TDateRange } from '@src/context/config/configSlice';

export interface BoardRequestDTO {
token: string;
type: string;
@@ -16,3 +18,8 @@ export interface BoardInfoRequestDTO {
boardId: string;
projectKey: string;
}

export interface BoardInfoConfigDTO extends BoardRequestDTO {
dateRanges: TDateRange | null;
projectKey: string;
}
2 changes: 2 additions & 0 deletions frontend/src/constants/resources.ts
Original file line number Diff line number Diff line change
@@ -342,13 +342,15 @@ export const BOARD_CONFIG_INFO_TITLE = {
UNAUTHORIZED_REQUEST: 'Unauthorized request!',
NOT_FOUND: 'Not found!',
NO_CONTENT: 'No card within selected date range!',
GENERAL_ERROR: 'Failed to get the board configuration!',
EMPTY: '',
};

export const BOARD_CONFIG_INFO_ERROR = {
FORBIDDEN: 'Please go back to the previous page and change your board token with correct access permission.',
NOT_FOUND: 'Please go back to the previous page and check your board info!',
NOT_CONTENT: 'Please go back to the previous page and change your collection date, or check your board info!',
GENERAL_ERROR: 'Please go back to the previous page to check your board info, or change your time range!',
RETRY: 'Data loading failed, please',
};

36 changes: 19 additions & 17 deletions frontend/src/containers/MetricsStep/index.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import {
selectBoard,
selectDateRange,
selectIsProjectCreated,
selectJiraColumns,
selectMetrics,
selectUsers,
updateBoardVerifyState,
selectBoard,
updateJiraVerifyResponse,
selectUsers,
selectJiraColumns,
} from '@src/context/config/configSlice';
import {
selectMetricsContent,
updateMetricsState,
selectShouldGetBoardConfig,
updateShouldGetBoardConfig,
updateFirstTimeRoadMetricsBoardData,
updateMetricsState,
updateShouldGetBoardConfig,
} from '@src/context/Metrics/metricsSlice';
import {
MetricSelectionHeader,
MetricSelectionWrapper,
MetricsSelectionTitle,
StyledErrorMessage,
StyledRetryButton,
} from '@src/containers/MetricsStep/style';
import { CYCLE_TIME_SETTINGS_TYPES, DONE, REQUIRED_DATA, AXIOS_REQUEST_ERROR_CODE } from '@src/constants/resources';
import { AXIOS_REQUEST_ERROR_CODE, CYCLE_TIME_SETTINGS_TYPES, DONE, REQUIRED_DATA } from '@src/constants/resources';
import { DeploymentFrequencySettings } from '@src/containers/MetricsStep/DeploymentFrequencySettings';
import { StyledRetryButton, StyledErrorMessage } from '@src/containers/MetricsStep/style';
import { closeAllNotifications } from '@src/context/notification/NotificationSlice';
import { Classification } from '@src/containers/MetricsStep/Classification';
import { shouldMetricsLoad } from '@src/context/stepper/StepperSlice';
import DateRangeViewer from '@src/components/Common/DateRangeViewer';
import { useGetBoardInfoEffect } from '@src/hooks/useGetBoardInfo';
import { combineBoardInfo, sortDateRanges } from '@src/utils/util';
import { CycleTime } from '@src/containers/MetricsStep/CycleTime';
import { RealDone } from '@src/containers/MetricsStep/RealDone';
import EmptyContent from '@src/components/Common/EmptyContent';
import { useAppSelector, useAppDispatch } from '@src/hooks';
import { useAppDispatch, useAppSelector } from '@src/hooks';
import { Crews } from '@src/containers/MetricsStep/Crews';
import { useCallback, useLayoutEffect } from 'react';
import { Loading } from '@src/components/Loading';
import { sortDateRanges } from '@src/utils/util';
import ReworkSettings from './ReworkSettings';
import { Advance } from './Advance/Advance';
import isEmpty from 'lodash/isEmpty';
import { theme } from '@src/theme';
import merge from 'lodash/merge';
import dayjs from 'dayjs';

const MetricsStep = () => {
const boardConfig = useAppSelector(selectBoard);
@@ -68,20 +68,22 @@ const MetricsStep = () => {
const shouldGetBoardConfig = useAppSelector(selectShouldGetBoardConfig);

const getInfo = useCallback(
() =>
async () => {
getBoardInfo({
...boardConfig,
startTime: dayjs(startDate).valueOf().toString(),
endTime: dayjs(endDate).valueOf().toString(),
dateRanges,
}).then((res) => {
if (res.data) {
if (res && res[0].data) {
const boardInfo = res?.map((r) => r.data);
const commonPayload = combineBoardInfo(boardInfo!);
dispatch(updateBoardVerifyState(true));
dispatch(updateJiraVerifyResponse(res.data));
dispatch(updateMetricsState(merge(res.data, { isProjectCreated: isProjectCreated })));
dispatch(updateJiraVerifyResponse(commonPayload));
dispatch(updateMetricsState(merge(commonPayload, { isProjectCreated: isProjectCreated })));
dispatch(updateShouldGetBoardConfig(false));
dispatch(updateFirstTimeRoadMetricsBoardData(false));
}
}),
});
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);
84 changes: 56 additions & 28 deletions frontend/src/hooks/useGetBoardInfo.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
import { BOARD_CONFIG_INFO_ERROR, BOARD_CONFIG_INFO_TITLE } from '@src/constants/resources';
import { boardInfoClient } from '@src/clients/board/BoardInfoClient';
import { BoardInfoRequestDTO } from '@src/clients/board/dto/request';
import { BoardInfoConfigDTO } from '@src/clients/board/dto/request';
import { AXIOS_REQUEST_ERROR_CODE } from '@src/constants/resources';
import { AxiosResponse, HttpStatusCode } from 'axios';
import { ReactNode, useState } from 'react';
import get from 'lodash/get';
import dayjs from 'dayjs';

export type JiraColumns = Record<string, string>[];
export type TargetFields = Record<string, string>[];
export type Users = string[];
export interface BoardInfoResponse {
jiraColumns: JiraColumns;
targetFields: TargetFields;
ignoredTargetFields: TargetFields;
users: Users;
}
export interface useGetBoardInfoInterface {
getBoardInfo: (data: BoardInfoRequestDTO) => Promise<AxiosResponse<BoardInfoResponse>>;
getBoardInfo: (data: BoardInfoConfigDTO) => Promise<Awaited<AxiosResponse<BoardInfoResponse>[]> | undefined>;
isLoading: boolean;
errorMessage: Record<string, ReactNode>;
}

const codeMapping = (code: string | number) => {
const codes = {
[HttpStatusCode.BadRequest]: {
title: BOARD_CONFIG_INFO_TITLE.INVALID_INPUT,
message: BOARD_CONFIG_INFO_ERROR.NOT_FOUND,
title: BOARD_CONFIG_INFO_TITLE.GENERAL_ERROR,
message: BOARD_CONFIG_INFO_ERROR.GENERAL_ERROR,
code: HttpStatusCode.BadRequest,
},
[HttpStatusCode.Unauthorized]: {
title: BOARD_CONFIG_INFO_TITLE.UNAUTHORIZED_REQUEST,
message: BOARD_CONFIG_INFO_ERROR.NOT_FOUND,
title: BOARD_CONFIG_INFO_TITLE.GENERAL_ERROR,
message: BOARD_CONFIG_INFO_ERROR.GENERAL_ERROR,
code: HttpStatusCode.Unauthorized,
},
[HttpStatusCode.Forbidden]: {
title: BOARD_CONFIG_INFO_TITLE.FORBIDDEN_REQUEST,
message: BOARD_CONFIG_INFO_ERROR.FORBIDDEN,
title: BOARD_CONFIG_INFO_TITLE.GENERAL_ERROR,
message: BOARD_CONFIG_INFO_ERROR.GENERAL_ERROR,
code: HttpStatusCode.Forbidden,
},
[HttpStatusCode.NotFound]: {
title: BOARD_CONFIG_INFO_TITLE.NOT_FOUND,
message: BOARD_CONFIG_INFO_ERROR.NOT_FOUND,
title: BOARD_CONFIG_INFO_TITLE.GENERAL_ERROR,
message: BOARD_CONFIG_INFO_ERROR.GENERAL_ERROR,
code: HttpStatusCode.NotFound,
},
[AXIOS_REQUEST_ERROR_CODE.TIMEOUT]: {
@@ -55,27 +57,53 @@ export const useGetBoardInfoEffect = (): useGetBoardInfoInterface => {
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState({});

const getBoardInfo = (data: BoardInfoRequestDTO) => {
const getBoardInfo = async (data: BoardInfoConfigDTO) => {
setIsLoading(true);
setErrorMessage({});
return boardInfoClient
.getBoardInfo(data)
.then((res) => {
if (!res.data) {
setErrorMessage({
title: BOARD_CONFIG_INFO_TITLE.NO_CONTENT,
message: BOARD_CONFIG_INFO_ERROR.NOT_CONTENT,
code: HttpStatusCode.NoContent,

if (data.dateRanges) {
const dateRangeCopy = Array.from(data.dateRanges);
dateRangeCopy.sort((a, b) => dayjs(a.startDate).valueOf() - dayjs(b.startDate).valueOf());
const allBoardData = dateRangeCopy.map((info) => {
const request = {
token: data.token,
type: data.type,
site: data.site,
email: data.email,
boardId: data.boardId,
projectKey: data.projectKey,
};
const boardInfoRequest = {
...request,
startTime: dayjs(info.startDate).valueOf().toString(),
endTime: dayjs(info.endDate).valueOf().toString(),
};

return boardInfoClient
.getBoardInfo(boardInfoRequest)
.then((res) => {
if (!res.data) {
setErrorMessage({
title: BOARD_CONFIG_INFO_TITLE.NO_CONTENT,
message: BOARD_CONFIG_INFO_ERROR.NOT_CONTENT,
code: HttpStatusCode.NoContent,
});
}
return res;
})
.catch((err) => {
const { code } = err;
setErrorMessage(codeMapping(code));
return err;
});
}
return res;
})
.catch((err) => {
const { code } = err;
setErrorMessage(codeMapping(code));
return err;
})
.finally(() => setIsLoading(false));
});

return Promise.all(allBoardData)
.then((res) => {
return res;
})
.finally(() => setIsLoading(false));
}
};
return {
getBoardInfo,
24 changes: 23 additions & 1 deletion frontend/src/utils/util.ts
Original file line number Diff line number Diff line change
@@ -2,9 +2,10 @@ import { CYCLE_TIME_LIST, CYCLE_TIME_SETTINGS_TYPES, METRICS_CONSTANTS } from '@
import { CleanedBuildKiteEmoji, OriginBuildKiteEmoji } from '@src/constants/emojis/emoji';
import { ICycleTimeSetting, IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { ITargetFieldType } from '@src/components/Common/MultiAutoComplete/styles';
import { BoardInfoResponse } from '@src/hooks/useGetBoardInfo';
import { DATE_FORMAT_TEMPLATE } from '@src/constants/template';
import { TDateRange } from '@src/context/config/configSlice';
import { includes, isEqual, sortBy } from 'lodash';
import { includes, isEqual, sortBy, uniqBy } from 'lodash';
import duration from 'dayjs/plugin/duration';
import dayjs from 'dayjs';

@@ -160,3 +161,24 @@ export function convertCycleTimeSettings(
export function existBlockState(cycleTimeSettings: ICycleTimeSetting[]) {
return cycleTimeSettings.some(({ value }) => METRICS_CONSTANTS.blockValue === value);
}

export function combineBoardInfo(boardInfoResponses: BoardInfoResponse[]) {
if (boardInfoResponses) {
const allUsers = [...new Set(boardInfoResponses.flatMap((result) => result.users))];
const allTargetFields = uniqBy(
boardInfoResponses.flatMap((result) => result.targetFields),
(elem) => [elem.key, elem.name, elem.flag].join(),
);
const allJiraColumns = boardInfoResponses[boardInfoResponses.length - 1].jiraColumns;
const allIgnoredTargetFields = uniqBy(
boardInfoResponses.flatMap((result) => result.ignoredTargetFields),
(elem) => [elem.key, elem.name, elem.flag].join(),
);
return {
users: allUsers,
targetFields: allTargetFields,
ignoredTargetFields: allIgnoredTargetFields,
jiraColumns: allJiraColumns,
};
}
}