-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useQuery, type UseQueryResult } from '@tanstack/react-query'; | ||
|
||
import type { | ||
IssueExtraDetailsResponse, | ||
IssueKeyList, | ||
} from '@/types/issueExtras'; | ||
|
||
import type { TIssue } from '@/types/issues'; | ||
|
||
import { RequestData } from './commonRequest'; | ||
|
||
const fetchIssueExtraDetailsData = async ( | ||
issueKeyList?: IssueKeyList, | ||
): Promise<IssueExtraDetailsResponse> => { | ||
const body = { | ||
issues: issueKeyList, | ||
}; | ||
|
||
const data = await RequestData.post<IssueExtraDetailsResponse>( | ||
`/api/issue/extras/`, | ||
body, | ||
); | ||
|
||
return data; | ||
}; | ||
|
||
export interface ITabsIssues { | ||
buildIssues?: TIssue[]; | ||
bootIssues?: TIssue[]; | ||
testIssues?: TIssue[]; | ||
} | ||
|
||
const makeIssueKeyList = ({ | ||
buildIssues, | ||
bootIssues, | ||
testIssues, | ||
}: ITabsIssues): IssueKeyList => { | ||
const result: IssueKeyList = []; | ||
|
||
buildIssues?.forEach(issue => { | ||
result.push([issue.id, issue.version]); | ||
}); | ||
bootIssues?.forEach(issue => { | ||
result.push([issue.id, issue.version]); | ||
}); | ||
testIssues?.forEach(issue => { | ||
result.push([issue.id, issue.version]); | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export const useIssueExtraDetails = ({ | ||
buildIssues, | ||
bootIssues, | ||
testIssues, | ||
enabled = true, | ||
}: ITabsIssues & { | ||
enabled: boolean; | ||
}): UseQueryResult<IssueExtraDetailsResponse> => { | ||
const issueKeyList = makeIssueKeyList({ | ||
buildIssues, | ||
bootIssues, | ||
testIssues, | ||
}); | ||
|
||
return useQuery({ | ||
queryKey: ['issueExtraData', issueKeyList], | ||
queryFn: () => fetchIssueExtraDetailsData(issueKeyList), | ||
enabled, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { TreeBranchItem } from './general'; | ||
import type { IssueKeys } from './issues'; | ||
|
||
type PossibleIssueTags = 'mainline' | 'stable' | 'linux-next'; | ||
|
||
type TIssueExtraDetails = IssueKeys & { | ||
first_seen?: Date; | ||
trees?: TreeBranchItem[]; | ||
tags?: PossibleIssueTags[]; | ||
}; | ||
|
||
export type IssueKeyList = [string, number][]; | ||
|
||
export type IssueExtraDetailsDict = Record< | ||
string, | ||
Record<number, TIssueExtraDetails> | ||
>; | ||
|
||
export type IssueExtraDetailsResponse = { | ||
issues: IssueExtraDetailsDict; | ||
}; |