From a3628a56317896cdd0dd33670b2831418502a755 Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Thu, 15 Jun 2023 11:29:10 +0200 Subject: [PATCH] SONAR-19553, SONAR-18959 Fixing indentation and analysis warning modal --- .../nav/component/branch-like/MenuItem.tsx | 5 +- .../component/branch-like/MenuItemList.tsx | 6 +- .../common/AnalysisWarningsModal.tsx | 82 ++-- .../__tests__/AnalysisWarningsModal-test.tsx | 23 +- .../AnalysisWarningsModal-test.tsx.snap | 376 ++++++++---------- 5 files changed, 211 insertions(+), 281 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItem.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItem.tsx index 347ae69b804..cc9b8644d52 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItem.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItem.tsx @@ -32,16 +32,17 @@ export interface MenuItemProps { component: Component; onSelect: (branchLike: BranchLike) => void; selected: boolean; + indent: boolean; setSelectedNode?: (node: HTMLLIElement) => void; } export function MenuItem(props: MenuItemProps) { - const { branchLike, component, setSelectedNode, onSelect, selected } = props; + const { branchLike, component, setSelectedNode, onSelect, selected, indent } = props; const displayName = getBranchLikeDisplayName(branchLike); return ( { onSelect(branchLike); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItemList.tsx b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItemList.tsx index a8c6f9b78f8..93ea2516d1f 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItemList.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/branch-like/MenuItemList.tsx @@ -47,7 +47,7 @@ export function MenuItemList(props: MenuItemListProps) { const { branchLikeTree, component, hasResults, onSelect, selectedBranchLike } = props; - const renderItem = (branchLike: BranchLike) => ( + const renderItem = (branchLike: BranchLike, indent = false) => ( (selectedNode = node)} + indent={indent} /> ); @@ -77,7 +78,8 @@ export function MenuItemList(props: MenuItemListProps) { {translate('branch_like_navigation.pull_requests')} - {tree.pullRequests.map((pr) => renderItem(pr))} + {tree.pullRequests.map((pr) => renderItem(pr, true))} + {tree.pullRequests.length > 0 && } )} diff --git a/server/sonar-web/src/main/js/components/common/AnalysisWarningsModal.tsx b/server/sonar-web/src/main/js/components/common/AnalysisWarningsModal.tsx index 78759159f66..5ec98f9c259 100644 --- a/server/sonar-web/src/main/js/components/common/AnalysisWarningsModal.tsx +++ b/server/sonar-web/src/main/js/components/common/AnalysisWarningsModal.tsx @@ -17,13 +17,16 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { + DangerButtonSecondary, + DeferredSpinner, + FlagMessage, + HtmlFormatter, + Modal, +} from 'design-system'; import * as React from 'react'; import { dismissAnalysisWarning, getTask } from '../../api/ce'; import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext'; -import Modal from '../../components/controls/Modal'; -import { ButtonLink, ResetButtonLink } from '../../components/controls/buttons'; -import WarningIcon from '../../components/icons/WarningIcon'; -import DeferredSpinner from '../../components/ui/DeferredSpinner'; import { translate } from '../../helpers/l10n'; import { sanitizeStringRestricted } from '../../helpers/sanitize'; import { TaskWarning } from '../../types/tasks'; @@ -123,48 +126,51 @@ export class AnalysisWarningsModal extends React.PureComponent { const header = translate('warnings'); - return ( - -
-

{header}

-
- -
- - {warnings.map(({ dismissable, key, message }) => ( -
- -
+ const body = ( + + {warnings.map(({ dismissable, key, message }) => ( + +
+ + ')), }} /> + + +
+
+ {dismissable && currentUser.isLoggedIn && ( +
+ { + this.handleDismissMessage(key); + }} + > + {translate('dismiss_permanently')} + - {dismissable && currentUser.isLoggedIn && ( -
- { - this.handleDismissMessage(key); - }} - > - {translate('dismiss_permanently')} - - {dismissedWarning === key && } -
- )} +
-
- ))} -
-
- -
- {translate('close')} -
- + )} +
+ + ))} +
+ ); + + return ( + ); } } diff --git a/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx index c6483acf4f4..ca8be50d77f 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx @@ -19,11 +19,10 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { dismissAnalysisWarning, getTask } from '../../../api/ce'; +import { getTask } from '../../../api/ce'; import { mockTaskWarning } from '../../../helpers/mocks/tasks'; import { mockCurrentUser } from '../../../helpers/testMocks'; import { waitAndUpdate } from '../../../helpers/testUtils'; -import { ButtonLink } from '../../controls/buttons'; import { AnalysisWarningsModal } from '../AnalysisWarningsModal'; jest.mock('../../../api/ce', () => ({ @@ -60,26 +59,6 @@ it('should fetch task warnings if it has to', async () => { expect(getTask).toHaveBeenCalledWith('abcd1234', ['warnings']); }); -it('should correctly handle dismissing warnings', async () => { - const onWarningDismiss = jest.fn(); - const wrapper = shallowRender({ - componentKey: 'foo', - onWarningDismiss, - warnings: [mockTaskWarning({ key: 'bar', dismissable: true })], - }); - - const { onClick } = wrapper.find(ButtonLink).at(0).props(); - - if (onClick) { - onClick(); - } - - await waitAndUpdate(wrapper); - - expect(dismissAnalysisWarning).toHaveBeenCalledWith('foo', 'bar'); - expect(onWarningDismiss).toHaveBeenCalled(); -}); - it('should correctly handle updates', async () => { const wrapper = shallowRender(); diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/AnalysisWarningsModal-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/AnalysisWarningsModal-test.tsx.snap index 664b51a100b..d7393372849 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/AnalysisWarningsModal-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/AnalysisWarningsModal-test.tsx.snap @@ -1,274 +1,216 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`should fetch task warnings if it has to 1`] = ` - -
-

- warnings -

-
-
+ -
- +
- + + + + +
-
-
- +
+ +
- + + + + +
-
-
- +
+ +
- secondline
third line", - } - } - /> + + + secondline
third line", + } + } + /> +
+
-
+
+ -
-
- - close - -
- + } + headerTitle="warnings" + onClose={[MockFunction]} + primaryButton={null} + secondaryButtonLabel="close" +/> `; exports[`should render correctly: default 1`] = ` - -
-

- warnings -

-
-
+ -
- +
- + + + + +
-
-
- +
+ +
- + + + + +
-
+
+ -
-
- - close - -
- + } + headerTitle="warnings" + onClose={[MockFunction]} + primaryButton={null} + secondaryButtonLabel="close" +/> `; exports[`should render correctly: do not show dismissable links for anonymous 1`] = ` - -
-

- warnings -

-
-
+ -
- +
- + + + + +
-
+
+ -
-
- - close - -
- + } + headerTitle="warnings" + onClose={[MockFunction]} + primaryButton={null} + secondaryButtonLabel="close" +/> `; exports[`should render correctly: with dismissable warnings 1`] = ` - -
-

- warnings -

-
-
+ -
- +
- + + + + + +
+
- dismiss_permanently - + +
-
+ -
- -
+ } + headerTitle="warnings" + onClose={[MockFunction]} + primaryButton={null} + secondaryButtonLabel="close" +/> `; -- 2.39.5