Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Štěpán Šonovský
bc
Commits
ae4ea272
There was an error fetching the commit references. Please try again later.
Commit
ae4ea272
authored
8 months ago
by
Štěpán Šonovský
Browse files
Options
Downloads
Patches
Plain Diff
feat: added fetching commits together in one query
parent
eb30567e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/app/components/CommitList.tsx
+6
-1
6 additions, 1 deletion
src/app/components/CommitList.tsx
src/app/components/CsvDownload.tsx
+37
-0
37 additions, 0 deletions
src/app/components/CsvDownload.tsx
src/app/hooks/useCommitDetails.ts
+23
-4
23 additions, 4 deletions
src/app/hooks/useCommitDetails.ts
with
66 additions
and
5 deletions
src/app/components/CommitList.tsx
+
6
−
1
View file @
ae4ea272
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
{
Commits
}
from
'
@gitbeaker/rest
'
;
import
useCommits
from
"
@/app/hooks/useCommits
"
;
import
CsvDownload
from
"
@/app/components/CsvDownload
"
;
interface
Commit
{
id
:
string
;
...
...
@@ -35,11 +36,15 @@ const CommitList: React.FC<CommitListProps> = ({ projectId, token, host, onCommi
</
li
>
))
}
</
ul
>
)
:
(
<
p
>
No commits found
</
p
>
)
}
<
CsvDownload
commits
=
{
commits
}
projectId
=
{
projectId
}
token
=
{
token
}
/>
</
div
>
);
);
};
...
...
This diff is collapsed.
Click to expand it.
src/app/components/CsvDownload.tsx
0 → 100644
+
37
−
0
View file @
ae4ea272
import
{
useState
,
useEffect
}
from
'
react
'
;
import
useCommitDetails
,
{
useCommitData
}
from
"
@/app/hooks/useCommitDetails
"
;
type
CommitDetails
=
{
author
:
string
;
createdAt
:
string
;
projectId
:
string
;
};
const
CsvDownload
=
({
commits
,
projectId
,
token
})
=>
{
const
{
data
,
isLoading
}
=
useCommitData
(
projectId
,
commits
,
token
);
console
.
log
(
data
);
return
(
<
div
>
{
!
isLoading
&&
data
?
(
<
div
>
{
data
.
map
((
commit
)
=>
(
<
div
key
=
{
commit
.
id
}
>
<
p
>
{
commit
.
title
}
</
p
>
<
p
>
{
commit
.
created_at
}
</
p
>
<
p
>
{
commit
.
projectId
}
</
p
>
</
div
>
))
}
</
div
>
)
:
(
<
p
>
Loading...
</
p
>
)
}
</
div
>
);
};
export
default
CsvDownload
;
This diff is collapsed.
Click to expand it.
src/app/hooks/useCommitDetails.ts
+
23
−
4
View file @
ae4ea272
import
{
useState
,
useEffect
}
from
'
react
'
;
import
{
useState
,
useEffect
}
from
'
react
'
;
import
axios
from
'
axios
'
;
import
{
host
}
from
"
@/utils
"
;
import
{
useQuery
}
from
"
@tanstack/react-query
"
;
export
const
useCommitData
=
(
projectId
,
commitIds
,
token
)
=>
{
const
{
data
,
isLoading
}
=
useQuery
({
queryKey
:
[
'
commitData
'
,
projectId
,
commitIds
],
queryFn
:
async
()
=>
{
const
promises
=
commitIds
.
map
(
commitId
=>
axios
.
get
(
`
${
host
}
/api/v4/projects/
${
projectId
}
/repository/commits/
${
commitId
.
id
}
`
,
{
headers
:
{
'
PRIVATE-TOKEN
'
:
token
}
}).
then
(
response
=>
response
.
data
)
);
return
Promise
.
all
(
promises
);
}
});
return
{
data
,
isLoading
};
};
const
useCommitDetails
=
(
projectId
:
string
,
commitId
:
string
,
token
:
string
)
=>
{
const
[
commit
,
setCommitDetails
]
=
useState
(
null
);
const
[
commit
,
setCommitDetails
]
=
useState
(
[]
);
const
[
loading
,
setLoading
]
=
useState
(
true
);
const
[
error
,
setError
]
=
useState
(
null
);
...
...
@@ -12,7 +31,7 @@ const useCommitDetails = (projectId: string, commitId: string, token: string) =>
setLoading
(
true
);
try
{
const
response
=
await
axios
.
get
(
`
${
host
}
/api/v4/projects/
${
projectId
}
/repository/commits/
${
commitId
}
`
,
{
headers
:
{
'
PRIVATE-TOKEN
'
:
token
}
headers
:
{
'
PRIVATE-TOKEN
'
:
token
}
});
setCommitDetails
(
response
.
data
);
}
catch
(
err
)
{
...
...
@@ -25,7 +44,7 @@ const useCommitDetails = (projectId: string, commitId: string, token: string) =>
fetchCommitDetails
();
},
[
projectId
,
commitId
,
token
]);
return
{
commit
,
loading
,
error
};
return
{
commit
,
loading
,
error
};
};
export
default
useCommitDetails
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment