From 724822959135314e6fec9b6d4f209fbb017bf3f0 Mon Sep 17 00:00:00 2001 From: Sanskar Date: Thu, 23 Jan 2025 11:27:54 -0800 Subject: [PATCH] Bug fixes #3 (#810) * feat: password/signin fixes * chore: rebase * feat: fix webhook flicker * feat: add rule + disbale btn fix * fix: edit button * fix: tsc/lint * fix: tsc --- .../repo-webhooks-list/repo-webhooks-list.tsx | 5 ++- .../repo/repo-settings-general-container.tsx | 2 +- .../src/pages-v2/webhooks/webhook-list.tsx | 19 ++++----- apps/gitness/src/routes.tsx | 4 +- .../src/utils/repo-branch-rules-utils.ts | 17 ++++++-- packages/ui/locales/en/views.json | 2 + packages/ui/locales/es/views.json | 2 + packages/ui/locales/fr/views.json | 2 + .../git-commit-dialog/git-commit-dialog.tsx | 2 +- packages/ui/src/views/auth/signin-page.tsx | 5 +-- .../profile-settings-general-page.tsx | 6 +-- .../components/repo-branch-rules-data.tsx | 8 ++++ .../repo-branch-settings-rules-page.tsx | 4 +- .../src/views/repo/repo-branch-rules/types.ts | 5 ++- .../ui/src/views/repo/repo-list/repo-list.tsx | 14 +++++-- .../repo-summary/components/summary-panel.tsx | 19 ++++++++- .../views/repo/repo-summary/repo-summary.tsx | 3 ++ .../webhook-list/repo-webhook-list-page.tsx | 40 +++++++++---------- .../views/repo/webhooks/webhook-list/types.ts | 3 ++ 19 files changed, 105 insertions(+), 57 deletions(-) diff --git a/apps/design-system/src/subjects/views/repo-webhooks-list/repo-webhooks-list.tsx b/apps/design-system/src/subjects/views/repo-webhooks-list/repo-webhooks-list.tsx index cc67339f6..11961aa73 100644 --- a/apps/design-system/src/subjects/views/repo-webhooks-list/repo-webhooks-list.tsx +++ b/apps/design-system/src/subjects/views/repo-webhooks-list/repo-webhooks-list.tsx @@ -1,6 +1,6 @@ import { useCallback, useState } from 'react' -import { useTranslationsStore } from '@utils/viewUtils.ts' +import { noop, useTranslationsStore } from '@utils/viewUtils.ts' import { DeleteAlertDialog } from '@harnessio/ui/components' import { RepoWebhookListPage } from '@harnessio/ui/views' @@ -27,6 +27,9 @@ export const RepoWebhooksList = () => { useWebhookStore={repoWebhooksListStore.useWebhookStore} useTranslationStore={useTranslationsStore} openDeleteWebhookDialog={openDeleteWebhookDialog} + setSearchQuery={noop} + searchQuery={null} + webhookLoading={false} /> { } const handleRuleClick = (identifier: string) => { - navigate(routes.toRepoBranchRule({ spaceId, repoId: repoName, identifier })) + navigate(routes.toRepoBranchRules({ spaceId, repoId: repoName, identifier })) } const handleDeleteRule = (ruleIdentifier: string) => { diff --git a/apps/gitness/src/pages-v2/webhooks/webhook-list.tsx b/apps/gitness/src/pages-v2/webhooks/webhook-list.tsx index 7ce230676..6770be074 100644 --- a/apps/gitness/src/pages-v2/webhooks/webhook-list.tsx +++ b/apps/gitness/src/pages-v2/webhooks/webhook-list.tsx @@ -1,6 +1,7 @@ import { useCallback, useEffect, useState } from 'react' import { useQueryClient } from '@tanstack/react-query' +import { useQueryState } from 'nuqs' import { DeleteRepoWebhookErrorResponse, @@ -12,15 +13,15 @@ import { RepoWebhookListPage } from '@harnessio/ui/views' import { useGetRepoRef } from '../../framework/hooks/useGetRepoPath' import usePaginationQueryStateWithStore from '../../hooks/use-pagination-query-state-with-store' -import { useDebouncedQueryState } from '../../hooks/useDebouncedQueryState' import { useTranslationStore } from '../../i18n/stores/i18n-store' import { getErrorMessage } from '../../utils/error-utils' import { useWebhookStore } from './stores/webhook-store' export default function WebhookListPage() { const repoRef = useGetRepoRef() ?? '' - const { setWebhooks, page, setPage, setWebhookLoading, setError } = useWebhookStore() - const [query] = useDebouncedQueryState('query') + const { setWebhooks, page, setPage, setError } = useWebhookStore() + const [query, setQuery] = useQueryState('query') + const queryClient = useQueryClient() const [apiError, setApiError] = useState<{ type: string; message: string } | null>(null) @@ -41,7 +42,7 @@ export default function WebhookListPage() { { queryParams: { page: queryPage, - query + query: query ?? '' }, repo_ref: repoRef }, @@ -90,18 +91,11 @@ export default function WebhookListPage() { useEffect(() => { if (webhookData) { setWebhooks(webhookData, headers) - setWebhookLoading(false) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [webhookData, headers, setWebhooks]) - useEffect(() => { - if (isFetching) { - setWebhookLoading(isFetching) - } - }, [isFetching, setWebhookLoading]) - useEffect(() => { if (isError && error !== undefined) { setError(getErrorMessage(error)) @@ -114,6 +108,9 @@ export default function WebhookListPage() { useWebhookStore={useWebhookStore} useTranslationStore={useTranslationStore} openDeleteWebhookDialog={openDeleteWebhookDialog} + searchQuery={query} + setSearchQuery={setQuery} + webhookLoading={isFetching} /> , + element: , handle: { breadcrumb: ({ commitSHA }: { commitSHA: string }) => ( <> @@ -121,7 +121,7 @@ const repoRoutes: CustomRouteObject[] = [ index: true, element: ( - + ) } diff --git a/apps/gitness/src/utils/repo-branch-rules-utils.ts b/apps/gitness/src/utils/repo-branch-rules-utils.ts index 5501a8610..3cddfb903 100644 --- a/apps/gitness/src/utils/repo-branch-rules-utils.ts +++ b/apps/gitness/src/utils/repo-branch-rules-utils.ts @@ -5,8 +5,13 @@ import { RepoRuleAddRequestBody, RepoRuleGetOkResponse } from '@harnessio/code-service-client' -import { RepoBranchSettingsFormFields } from '@harnessio/ui/views' -import { BranchRuleId, MergeStrategy, PatternsButtonType, Rule } from '@harnessio/views' +import { + BranchRuleId, + MergeStrategy, + PatternsButtonType, + RepoBranchSettingsFormFields, + Rule +} from '@harnessio/ui/views' const ruleIds = [ BranchRuleId.REQUIRE_LATEST_COMMIT, @@ -18,7 +23,8 @@ const ruleIds = [ BranchRuleId.BLOCK_BRANCH_CREATION, BranchRuleId.BLOCK_BRANCH_DELETION, BranchRuleId.REQUIRE_PULL_REQUEST, - BranchRuleId.REQUIRE_CODE_REVIEW + BranchRuleId.REQUIRE_CODE_REVIEW, + BranchRuleId.REQUIRE_CODE_OWNERS ] // Util to transform API response into expected-form format for branch-rules-edit @@ -67,6 +73,9 @@ const extractBranchRules = (data: RepoRuleGetOkResponse): Rule[] => { checked = (definition?.pullreq?.approvals?.require_minimum_count ?? 0) > 0 input = definition?.pullreq?.approvals?.require_minimum_count?.toString() || '' break + case BranchRuleId.REQUIRE_CODE_OWNERS: + checked = definition?.pullreq?.approvals?.require_code_owners || false + break default: continue } @@ -163,7 +172,7 @@ export const transformFormOutput = (formOutput: RepoBranchSettingsFormFields): R }, pullreq: { approvals: { - require_code_owners: true, + require_code_owners: rulesMap[BranchRuleId.REQUIRE_CODE_OWNERS]?.checked || false, require_latest_commit: rulesMap[BranchRuleId.REQUIRE_LATEST_COMMIT]?.checked || false, require_no_change_request: rulesMap[BranchRuleId.REQUIRE_NO_CHANGE_REQUEST]?.checked || false, require_minimum_count: rulesMap[BranchRuleId.REQUIRE_CODE_REVIEW].checked diff --git a/packages/ui/locales/en/views.json b/packages/ui/locales/en/views.json index 8b67acdaa..431688b76 100644 --- a/packages/ui/locales/en/views.json +++ b/packages/ui/locales/en/views.json @@ -54,6 +54,8 @@ "RequirePullRequestDescription": "Do not allow any changes to matching branches without a pull request", "RequireCodeReview": "Require a minimum number of reviewers", "RequireCodeReviewDescription": "Require approval on pull requests from a minimum number of reviewers", + "RequireCodeOwners": "Require review from code owners", + "RequireCodeOwnersDescription": "Require approval on pull requests from one reviewer for each Code Owner rule", "enableRule": "Enable the rule", "enableRuleDescription": "By enabling the toggle, the branch rule will be enforced.", "enterRuleName": "Enter the rule name here", diff --git a/packages/ui/locales/es/views.json b/packages/ui/locales/es/views.json index ea9e9d5d3..1cdfa4bf8 100644 --- a/packages/ui/locales/es/views.json +++ b/packages/ui/locales/es/views.json @@ -54,6 +54,8 @@ "RequirePullRequestDescription": "Do not allow any changes to matching branches without a pull request", "RequireCodeReview": "Require a minimum number of reviewers", "RequireCodeReviewDescription": "Require approval on pull requests from a minimum number of reviewers", + "RequireCodeOwners": "Require review from code owners", + "RequireCodeOwnersDescription": "Require approval on pull requests from one reviewer for each Code Owner rule", "enableRule": "Enable the rule", "enableRuleDescription": "By enabling the toggle, the branch rule will be enforced.", "enterRuleName": "Enter the rule name here", diff --git a/packages/ui/locales/fr/views.json b/packages/ui/locales/fr/views.json index 7acb8ce60..5dcae9c31 100644 --- a/packages/ui/locales/fr/views.json +++ b/packages/ui/locales/fr/views.json @@ -54,6 +54,8 @@ "RequirePullRequestDescription": "Interdire les modifications directes sur les branches sans requête de tirage", "RequireCodeReview": "Exiger un minimum de réviseurs", "RequireCodeReviewDescription": "Les requêtes de tirage doivent être approuvées par un nombre minimal de réviseurs", + "RequireCodeOwners": "Require review from code owners", + "RequireCodeOwnersDescription": "Require approval on pull requests from one reviewer for each Code Owner rule", "enableRule": "Activer la règle", "enableRuleDescription": "En activant cette option, la règle sera appliquée.", "enterRuleName": "Enter the rule name here", diff --git a/packages/ui/src/components/git-commit-dialog/git-commit-dialog.tsx b/packages/ui/src/components/git-commit-dialog/git-commit-dialog.tsx index 89fb13db4..8316439fd 100644 --- a/packages/ui/src/components/git-commit-dialog/git-commit-dialog.tsx +++ b/packages/ui/src/components/git-commit-dialog/git-commit-dialog.tsx @@ -208,7 +208,7 @@ export const GitCommitDialog: FC = ({ /> {violation && ( - + {bypassable ? commitToGitRefValue === CommitToGitRefOption.DIRECTLY ? 'Some rules will be bypassed to commit directly' diff --git a/packages/ui/src/views/auth/signin-page.tsx b/packages/ui/src/views/auth/signin-page.tsx index 2b9e46597..71e6d15aa 100644 --- a/packages/ui/src/views/auth/signin-page.tsx +++ b/packages/ui/src/views/auth/signin-page.tsx @@ -22,7 +22,7 @@ export interface SignInData { } const signInSchema = z.object({ - email: z.string().email({ message: 'Invalid email address' }), + email: z.string(), password: z.string().min(1, { message: 'The field can’t be blank' }) }) @@ -90,8 +90,7 @@ export function SignInPage({ handleSignIn, isLoading, error }: SignInPageProps)
data.newPassword === data.confirmPassword, { diff --git a/packages/ui/src/views/repo/repo-branch-rules/components/repo-branch-rules-data.tsx b/packages/ui/src/views/repo/repo-branch-rules/components/repo-branch-rules-data.tsx index d86c95847..8f19a8f9c 100644 --- a/packages/ui/src/views/repo/repo-branch-rules/components/repo-branch-rules-data.tsx +++ b/packages/ui/src/views/repo/repo-branch-rules/components/repo-branch-rules-data.tsx @@ -101,5 +101,13 @@ export const getBranchRules = (t: TFunction): BranchRuleType[] => [ 'Require approval on pull requests from a minimum number of reviewers' ), hasInput: true + }, + { + id: BranchRuleId.REQUIRE_CODE_OWNERS, + label: t('views:repos.RequireCodeOwners', 'Require review from code owners'), + description: t( + 'views:repos.RequireCodeOwnersDescription', + 'Require approval on pull requests from one reviewer for each Code Owner rule' + ) } ] diff --git a/packages/ui/src/views/repo/repo-branch-rules/repo-branch-settings-rules-page.tsx b/packages/ui/src/views/repo/repo-branch-rules/repo-branch-settings-rules-page.tsx index 92b0484b4..0c03a56fd 100644 --- a/packages/ui/src/views/repo/repo-branch-rules/repo-branch-settings-rules-page.tsx +++ b/packages/ui/src/views/repo/repo-branch-rules/repo-branch-settings-rules-page.tsx @@ -62,7 +62,7 @@ export const RepoBranchSettingsRulesPage: FC = setValue, watch, reset, - formState: { errors, isValid } + formState: { errors } } = useForm({ resolver: zodResolver(repoBranchSettingsFormSchema), mode: 'onChange', @@ -156,7 +156,7 @@ export const RepoBranchSettingsRulesPage: FC =
-