Skip to content

Commit

Permalink
refactor: labels
Browse files Browse the repository at this point in the history
  • Loading branch information
ankormoreankor committed Feb 12, 2025
1 parent 724d211 commit 1528fbc
Show file tree
Hide file tree
Showing 47 changed files with 538 additions and 597 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export const ProjectLabelsList = () => {
return (
<>
<LabelsListPage
className="mx-auto max-w-[812px]"
useTranslationStore={useTranslationsStore}
useLabelsStore={LabelsListStore.useLabelsStore}
createdIn={''}
handleEditLabel={() => {}}
handleDeleteLabel={() => setOpenAlertDeleteDialog(true)}
searchQuery={''}
setSearchQuery={() => {}}
setSearchQuery={noop}
isLoading={false}
labelsListViewProps={{ handleEditLabel: noop, handleDeleteLabel: () => setOpenAlertDeleteDialog(true) }}
/>
<DeleteAlertDialog
open={openAlertDeleteDialog}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export const RepoLabelsList = () => {
return (
<>
<LabelsListPage
className="max-w-[570px] px-0"
useTranslationStore={useTranslationsStore}
useLabelsStore={LabelsListStore.useLabelsStore}
createdIn={''}
handleEditLabel={() => {}}
handleDeleteLabel={() => setOpenAlertDeleteDialog(true)}
searchQuery={''}
setSearchQuery={() => {}}
setSearchQuery={noop}
isLoading={false}
isRepository
labelsListViewProps={{ handleEditLabel: noop, handleDeleteLabel: () => setOpenAlertDeleteDialog(true) }}
/>
<DeleteAlertDialog
open={openAlertDeleteDialog}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const ProjectLabelFormContainer = () => {
isLoading,
error: createError
} = useSaveSpaceLabelMutation(
{
space_ref: space_ref ?? ''
},
{ space_ref: space_ref ?? '' },
{
onSuccess: () => {
onFormCancel()
Expand All @@ -45,18 +43,12 @@ export const ProjectLabelFormContainer = () => {
const onSubmit = (data: CreateLabelFormFields) => {
const { values, ...rest } = data

mutate({
body: {
label: {
...rest
},
values
}
})
mutate({ body: { label: { ...rest }, values } })
}

return (
<LabelFormPage
className="mx-auto w-[610px]"
useLabelsStore={useLabelsStore}
useTranslationStore={useTranslationStore}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export const ProjectLabelsList = () => {
}

const { mutate: deleteSpaceLabel, isLoading: isDeletingSpaceLabel } = useDeleteSpaceLabelMutation(
{
space_ref: space_ref ?? ''
},
{ space_ref: space_ref ?? '' },
{
onSuccess: (_data, variables) => {
setOpenAlertDeleteDialog(false)
Expand All @@ -48,22 +46,20 @@ export const ProjectLabelsList = () => {
}

const handleDeleteLabel = (identifier: string) => {
deleteSpaceLabel({
key: identifier
})
deleteSpaceLabel({ key: identifier })
}

return (
<>
<LabelsListPage
className="mx-auto max-w-[812px]"
useTranslationStore={useTranslationStore}
useLabelsStore={useLabelsStore}
createdIn={space_ref}
handleEditLabel={handleEditLabel}
handleDeleteLabel={handleOpenDeleteDialog}
searchQuery={query}
setSearchQuery={setQuery}
isLoading={isLoading}
labelsListViewProps={{ handleDeleteLabel: handleOpenDeleteDialog, handleEditLabel }}
/>
<DeleteAlertDialog
open={openAlertDeleteDialog}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'

import copy from 'clipboard-copy'
import { isEmpty } from 'lodash-es'
Expand Down Expand Up @@ -64,6 +64,7 @@ import { usePullRequestProviderStore } from './stores/pull-request-provider-stor

export default function PullRequestConversationPage() {
const routes = useRoutes()
const navigate = useNavigate()
const {
pullReqMetadata,
refetchPullReq,
Expand Down Expand Up @@ -139,6 +140,8 @@ export default function PullRequestConversationPage() {
refetchData: refetchActivities
})

const handleEditLabels = () => navigate(routes.toRepoLabels({ spaceId, repoId }))

const { mutateAsync: restoreBranch } = useRestorePullReqSourceBranchMutation({})
const onRestoreBranch = () => {
restoreBranch({
Expand Down Expand Up @@ -217,33 +220,30 @@ export default function PullRequestConversationPage() {
}, [sourceBranch, pullReqMetadata?.merged, pullReqMetadata?.closed])

useEffect(() => {
if (branchError) {
if (pullReqMetadata?.merged || pullReqMetadata?.closed) {
setShowRestoreBranchButton(true)
} else {
setShowDeleteBranchButton(false)
createBranch({
repo_ref: repoRef,
body: {
name: pullReqMetadata?.source_branch || '',
target: pullReqMetadata?.source_sha,
bypass_rules: true,
dry_run_rules: true
}
}).then(res => {
if (res?.body?.rule_violations) {
const { checkIfBypassAllowed } = extractInfoFromRuleViolationArr(res.body?.rule_violations)
if (checkIfBypassAllowed) {
setShowRestoreBranchButton(true)
} else {
setShowRestoreBranchButton(false)
}
} else {
setShowRestoreBranchButton(true)
}
})
}
if (!branchError) return

if (pullReqMetadata?.merged || pullReqMetadata?.closed) {
return setShowRestoreBranchButton(true)
}

setShowDeleteBranchButton(false)
createBranch({
repo_ref: repoRef,
body: {
name: pullReqMetadata?.source_branch || '',
target: pullReqMetadata?.source_sha,
bypass_rules: true,
dry_run_rules: true
}
}).then(res => {
if (res?.body?.rule_violations) {
const { checkIfBypassAllowed } = extractInfoFromRuleViolationArr(res.body?.rule_violations)

return setShowRestoreBranchButton(checkIfBypassAllowed)
}

setShowRestoreBranchButton(true)
})
}, [branchError])

const [activities, setActivities] = useState(activityData)
Expand Down Expand Up @@ -349,16 +349,12 @@ export default function PullRequestConversationPage() {

const handleAddReviewer = (id?: number) => {
reviewerAddPullReq({ repo_ref: repoRef, pullreq_number: prId, body: { reviewer_id: id } })
.then(() => {
refetchReviewers()
})
.then(() => refetchReviewers())
.catch(error => setAddReviewerError(error.message))
}
const handleDeleteReviewer = (id: number) => {
reviewerDeletePullReq({ repo_ref: repoRef, pullreq_number: prId, pullreq_reviewer_id: id })
.then(() => {
refetchReviewers()
})
.then(() => refetchReviewers())
.catch(error => setRemoveReviewerError(error.message))
}
const onPRStateChanged = useCallback(() => {
Expand Down Expand Up @@ -525,14 +521,15 @@ export default function PullRequestConversationPage() {
<SandboxLayout.Column>
<SandboxLayout.Content className="pl-0 pt-0">
{/* TODO: fix handleaction for comment section in panel */}
{rebaseErrorMessage ? (
{rebaseErrorMessage && (
<Alert.Container closable variant="destructive" className="mb-5">
<Alert.Title>Cannot rebase branch</Alert.Title>
<Alert.Description>
<p>{rebaseErrorMessage}</p>
</Alert.Description>
</Alert.Container>
) : null}
)}

<PullRequestPanel
handleRebaseBranch={handleRebaseBranch}
handlePrState={handlePrState}
Expand Down Expand Up @@ -683,6 +680,7 @@ export default function PullRequestConversationPage() {
searchLabelQuery={searchLabel}
setSearchLabelQuery={changeSearchLabel}
addLabel={handleAddLabel}
editLabels={handleEditLabels}
removeLabel={handleRemoveLabel}
useTranslationStore={useTranslationStore}
/>
Expand Down
14 changes: 3 additions & 11 deletions apps/gitness/src/pages-v2/repo/labels/label-form-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export const RepoLabelFormContainer = () => {
isLoading,
error: createError
} = useSaveRepoLabelMutation(
{
repo_ref
},
{ repo_ref },
{
onSuccess: () => {
onFormCancel()
Expand All @@ -41,18 +39,12 @@ export const RepoLabelFormContainer = () => {
const onSubmit = (data: CreateLabelFormFields) => {
const { values, ...rest } = data

mutate({
body: {
label: {
...rest
},
values
}
})
mutate({ body: { label: { ...rest }, values } })
}

return (
<LabelFormPage
className="w-[570px] px-0"
useLabelsStore={useLabelsStore}
useTranslationStore={useTranslationStore}
isLoading={isLoading}
Expand Down
12 changes: 4 additions & 8 deletions apps/gitness/src/pages-v2/repo/labels/labels-list-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const RepoLabelsList = () => {
}

const { mutate: deleteRepoLabel, isLoading: isDeletingRepoLabel } = useDeleteRepoLabelMutation(
{
repo_ref: repo_ref ?? ''
},
{ repo_ref: repo_ref ?? '' },
{
onSuccess: (_data, variables) => {
setOpenAlertDeleteDialog(false)
Expand All @@ -46,9 +44,7 @@ export const RepoLabelsList = () => {
)

const { mutate: deleteSpaceLabel, isLoading: isDeletingSpaceLabel } = useDeleteSpaceLabelMutation(
{
space_ref: space_ref ?? ''
},
{ space_ref: space_ref ?? '' },
{
onSuccess: (_data, variables) => {
setOpenAlertDeleteDialog(false)
Expand All @@ -72,15 +68,15 @@ export const RepoLabelsList = () => {
return (
<>
<LabelsListPage
className="max-w-[570px] px-0"
useTranslationStore={useTranslationStore}
useLabelsStore={useLabelsStore}
createdIn={space_ref}
handleEditLabel={handleEditLabel}
handleDeleteLabel={handleOpenDeleteDialog}
searchQuery={query}
setSearchQuery={setQuery}
isLoading={isLoading}
isRepository
labelsListViewProps={{ widthType: 'small', handleDeleteLabel: handleOpenDeleteDialog, handleEditLabel }}
/>
<DeleteAlertDialog
open={openAlertDeleteDialog}
Expand Down
2 changes: 1 addition & 1 deletion apps/gitness/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Navigate } from 'react-router-dom'

import { Breadcrumb } from '@harnessio/ui/components'
import { Breadcrumb, Text } from '@harnessio/ui/components'
import {
EmptyPage,
ProfileSettingsLayout,
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/locales/en/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pull-requests": "Pull Requests",
"branches": "Branches",
"settings": "Settings",
"descriptionPlaceholder": "Enter a description",
"descriptionPlaceholder": "Enter a short description for the label",
"description": "Description",
"error": "Error:",
"saving": "Saving…",
Expand Down Expand Up @@ -288,12 +288,14 @@
"compareChangesTabOverview": "Overview",
"compareChangesTabCommits": "Commits",
"compareChangesTabChanges": "Changes",
"findOrAddNewValue": "Search or add a new value",
"findOrAddNewValue": "Find or add a new value",
"searchValue": "Search value",
"addValue": "Add new value",
"noLabels": "No labels found",
"labelNotFound": "Label not found",
"labels": "Labels",
"searchLabels": "Search labels",
"noLabels": "No labels found",
"editLabels": "Edit labels",
"deleted": "Deleted",
"deletedComment": "This comment was deleted.",
"reviewers": "Reviewers",
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/locales/es/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pull-requests": "Pull Requests",
"branches": "Branches",
"settings": "Settings",
"descriptionPlaceholder": "Enter a description",
"descriptionPlaceholder": "Enter a short description for the label",
"description": "Description",
"error": "Error:",
"saving": "Saving...",
Expand Down Expand Up @@ -288,12 +288,14 @@
"compareChangesTabOverview": "Resumen",
"compareChangesTabCommits": "Commits",
"compareChangesTabChanges": "Cambios",
"findOrAddNewValue": "Search or add a new value",
"findOrAddNewValue": "Find or add a new value",
"searchValue": "Search value",
"addValue": "Add new value",
"noLabels": "No labels found",
"labelNotFound": "Label not found",
"labels": "Labels",
"searchLabels": "Search labels",
"noLabels": "No labels found",
"editLabels": "Edit labels",
"deleted": "",
"deletedComment": "",
"reviewers": "",
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/locales/fr/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pull-requests": "Requêtes de tirage",
"branches": "Branches",
"settings": "Paramètres",
"descriptionPlaceholder": "Entrez une description",
"descriptionPlaceholder": "Enter a description",
"description": "Description",
"error": "Erreur :",
"saving": "Enregistrement...",
Expand Down Expand Up @@ -291,9 +291,11 @@
"findOrAddNewValue": "Find or add a new value",
"searchValue": "Search value",
"addValue": "Add new value",
"noLabels": "Aucune étiquette trouvée.",
"labelNotFound": "Label not found",
"labels": "Étiquettes",
"searchLabels": "Rechercher des étiquettes..",
"noLabels": "No labels found",
"editLabels": "Edit labels",
"deleted": "Supprimé",
"deletedComment": "Ce commentaire a été supprimé.",
"reviewers": "Réviseurs",
Expand Down
Loading

0 comments on commit 1528fbc

Please sign in to comment.