| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2024-09-24 09:42:07 +02:00
										 |  |  |  * Copyright (c) 2020 - present Cloudogu GmbH | 
					
						
							| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2024-09-24 09:42:07 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify it under | 
					
						
							|  |  |  |  * the terms of the GNU Affero General Public License as published by the Free | 
					
						
							|  |  |  |  * Software Foundation, version 3. | 
					
						
							| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2024-09-24 09:42:07 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, but WITHOUT | 
					
						
							|  |  |  |  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
					
						
							|  |  |  |  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | 
					
						
							|  |  |  |  * details. | 
					
						
							| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2024-09-24 09:42:07 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program. If not, see https://www.gnu.org/licenses/.
 | 
					
						
							| 
									
										
										
										
											2020-03-23 15:35:58 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-09-24 09:42:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  | import React, { FC } from "react"; | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  | import { Redirect, useRouteMatch } from "react-router-dom"; | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  | import { useTranslation } from "react-i18next"; | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  | import { useChangesets } from "@scm-manager/ui-api"; | 
					
						
							| 
									
										
										
										
											2022-08-16 13:03:21 +02:00
										 |  |  | import { Branch, ChangesetCollection, Repository } from "@scm-manager/ui-types"; | 
					
						
							| 
									
										
										
										
											2025-02-27 11:11:57 +01:00
										 |  |  | import { ChangesetList, LinkPaginator, urls } from "@scm-manager/ui-components"; | 
					
						
							|  |  |  | import { ErrorNotification, Notification, Loading, useDocumentTitle } from "@scm-manager/ui-core"; | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | export const usePage = () => { | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |   const match = useRouteMatch(); | 
					
						
							|  |  |  |   return urls.getPageFromMatch(match); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-10-16 20:19:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  | type Props = { | 
					
						
							|  |  |  |   repository: Repository; | 
					
						
							|  |  |  |   branch?: Branch; | 
					
						
							|  |  |  |   url: string; | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-10 16:41:01 +01:00
										 |  |  | const Changesets: FC<Props> = ({ repository, branch, ...props }) => { | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  |   const page = usePage(); | 
					
						
							| 
									
										
										
										
											2022-08-16 13:03:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  |   const { isLoading, error, data } = useChangesets(repository, { branch, page: page - 1 }); | 
					
						
							| 
									
										
										
										
											2024-12-10 16:41:01 +01:00
										 |  |  |   const [t] = useTranslation("repos"); | 
					
						
							|  |  |  |   const getDocumentTitle = () => { | 
					
						
							|  |  |  |     if (data?.pageTotal && data.pageTotal > 1 && page) { | 
					
						
							|  |  |  |       if (branch) { | 
					
						
							|  |  |  |         return t("changesets.commitsWithPageRevisionAndNamespaceName", { | 
					
						
							|  |  |  |           page, | 
					
						
							|  |  |  |           total: data.pageTotal, | 
					
						
							|  |  |  |           revision: branch.name, | 
					
						
							|  |  |  |           namespace: repository.namespace, | 
					
						
							|  |  |  |           name: repository.name, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         return t("changesets.commitsWithPageAndNamespaceName", { | 
					
						
							|  |  |  |           page, | 
					
						
							|  |  |  |           total: data.pageTotal, | 
					
						
							|  |  |  |           namespace: repository.namespace, | 
					
						
							|  |  |  |           name: repository.name, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else if (branch) { | 
					
						
							|  |  |  |       return t("changesets.commitsWithRevisionAndNamespaceName", { | 
					
						
							|  |  |  |         revision: branch.name, | 
					
						
							|  |  |  |         namespace: repository.namespace, | 
					
						
							|  |  |  |         name: repository.name, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return t("changesets.commitsWithNamespaceName", { | 
					
						
							|  |  |  |         namespace: repository.namespace, | 
					
						
							|  |  |  |         name: repository.name, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   useDocumentTitle(getDocumentTitle()); | 
					
						
							| 
									
										
										
										
											2022-08-16 13:03:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-10 16:41:01 +01:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <ChangesetsPanel | 
					
						
							|  |  |  |       isLoading={isLoading} | 
					
						
							|  |  |  |       error={error} | 
					
						
							|  |  |  |       data={data} | 
					
						
							|  |  |  |       repository={repository} | 
					
						
							|  |  |  |       branch={branch} | 
					
						
							|  |  |  |       {...props} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-08-16 13:03:21 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ChangesetsPanelProps = Props & { | 
					
						
							|  |  |  |   error: Error | null; | 
					
						
							|  |  |  |   isLoading: boolean; | 
					
						
							|  |  |  |   data?: ChangesetCollection; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-10 16:41:01 +01:00
										 |  |  | export const ChangesetsPanel: FC<ChangesetsPanelProps> = ({ repository, error, isLoading, data, url, branch }) => { | 
					
						
							| 
									
										
										
										
											2022-08-16 13:03:21 +02:00
										 |  |  |   const page = usePage(); | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  |   const [t] = useTranslation("repos"); | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  |   const changesets = data?._embedded?.changesets; | 
					
						
							| 
									
										
										
										
											2018-09-27 16:29:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |   if (error) { | 
					
						
							|  |  |  |     return <ErrorNotification error={error} />; | 
					
						
							| 
									
										
										
										
											2018-10-17 10:38:46 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-16 17:04:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |   if (isLoading) { | 
					
						
							|  |  |  |     return <Loading />; | 
					
						
							| 
									
										
										
										
											2020-02-28 13:15:27 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  |   if (data && data.pageTotal < page && page > 1) { | 
					
						
							|  |  |  |     return <Redirect to={`${urls.unescapeUrlForRoute(url)}/${data.pageTotal}`} />; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!data || !changesets || changesets.length === 0) { | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  |     return <Notification type="info">{t("changesets.noChangesets")}</Notification>; | 
					
						
							| 
									
										
										
										
											2018-09-18 09:22:08 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  |     <div className="panel"> | 
					
						
							| 
									
										
										
										
											2019-02-01 10:50:05 +01:00
										 |  |  |       <div className="panel-block"> | 
					
						
							| 
									
										
										
										
											2025-02-27 11:11:57 +01:00
										 |  |  |         <ChangesetList repository={repository} changesets={changesets} branch={branch} /> | 
					
						
							| 
									
										
										
										
											2019-02-01 10:50:05 +01:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |       <div className="panel-footer"> | 
					
						
							| 
									
										
										
										
											2022-08-02 10:30:07 +02:00
										 |  |  |         <LinkPaginator collection={data} page={page} /> | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2022-01-20 11:00:49 +01:00
										 |  |  |     </div> | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2018-10-10 19:26:29 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-10-17 10:38:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 08:17:40 +01:00
										 |  |  | export default Changesets; |