diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2022-02-24 15:46:39 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-25 20:02:53 +0000 |
commit | 9828d4922ec6064d0c7814b285a639ef1f838de4 (patch) | |
tree | cd5f0b1c6e37de6f813da4c2dd37237e35a4797a | |
parent | 94442288494a88432bdc8188f6b3f152ed8fb988 (diff) | |
download | sonarqube-9828d4922ec6064d0c7814b285a639ef1f838de4.tar.gz sonarqube-9828d4922ec6064d0c7814b285a639ef1f838de4.zip |
SONAR-16006 Propagate setting update to update local state
15 files changed, 92 insertions, 31 deletions
diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeRow.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeRow.tsx index e9e3e387034..5a37613cc24 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeRow.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeRow.tsx @@ -39,10 +39,11 @@ export interface BranchLikeRowProps { displayPurgeSetting?: boolean; onDelete: () => void; onRename: () => void; + onUpdatePurgeSetting: () => void; } export function BranchLikeRow(props: BranchLikeRowProps) { - const { branchLike, component, displayPurgeSetting, onDelete, onRename } = props; + const { branchLike, component, displayPurgeSetting } = props; const branchLikeDisplayName = getBranchLikeDisplayName(branchLike); return ( @@ -62,17 +63,21 @@ export function BranchLikeRow(props: BranchLikeRowProps) { <td className="nowrap">{<DateFromNow date={branchLike.analysisDate} />}</td> {displayPurgeSetting && isBranch(branchLike) && ( <td className="nowrap js-test-purge-toggle-container"> - <BranchPurgeSetting branch={branchLike} component={component} /> + <BranchPurgeSetting + branch={branchLike} + component={component} + onUpdatePurgeSetting={props.onUpdatePurgeSetting} + /> </td> )} <td className="nowrap"> <ActionsDropdown> {isMainBranch(branchLike) ? ( - <ActionsDropdownItem className="js-rename" onClick={onRename}> + <ActionsDropdownItem className="js-rename" onClick={props.onRename}> {translate('project_branch_pull_request.branch.rename')} </ActionsDropdownItem> ) : ( - <ActionsDropdownItem className="js-delete" destructive={true} onClick={onDelete}> + <ActionsDropdownItem className="js-delete" destructive={true} onClick={props.onDelete}> {translate( isPullRequest(branchLike) ? 'project_branch_pull_request.pull_request.delete' diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTable.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTable.tsx index 0e050e26be7..a9cb25fe99a 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTable.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTable.tsx @@ -31,11 +31,12 @@ export interface BranchLikeTableProps { displayPurgeSetting?: boolean; onDelete: (branchLike: BranchLike) => void; onRename: (branchLike: BranchLike) => void; + onUpdatePurgeSetting: () => void; title: string; } export function BranchLikeTable(props: BranchLikeTableProps) { - const { branchLikes, component, displayPurgeSetting, onDelete, onRename, title } = props; + const { branchLikes, component, displayPurgeSetting, title } = props; return ( <div className="boxed-group boxed-group-inner"> @@ -78,8 +79,9 @@ export function BranchLikeTable(props: BranchLikeTableProps) { component={component} displayPurgeSetting={displayPurgeSetting} key={getBranchLikeKey(branchLike)} - onDelete={() => onDelete(branchLike)} - onRename={() => onRename(branchLike)} + onDelete={() => props.onDelete(branchLike)} + onRename={() => props.onRename(branchLike)} + onUpdatePurgeSetting={props.onUpdatePurgeSetting} /> ))} </tbody> diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx index 3da464895af..02ea904266f 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx @@ -80,18 +80,28 @@ const TABS = [ export default class BranchLikeTabs extends React.PureComponent<Props, State> { state: State = { currentTab: Tabs.Branch }; - onTabSelect = (currentTab: Tabs) => { + handleTabSelect = (currentTab: Tabs) => { this.setState({ currentTab }); }; - onDeleteBranchLike = (branchLike: BranchLike) => this.setState({ deleting: branchLike }); + handleDeleteBranchLike = (branchLike: BranchLike) => { + this.setState({ deleting: branchLike }); + }; + + handleRenameBranchLike = (branchLike: BranchLike) => { + this.setState({ renaming: branchLike }); + }; - onRenameBranchLike = (branchLike: BranchLike) => this.setState({ renaming: branchLike }); + handleUpdatePurgeSetting = () => { + this.props.onBranchesChange(); + }; - onClose = () => this.setState({ deleting: undefined, renaming: undefined }); + handleClose = () => { + this.setState({ deleting: undefined, renaming: undefined }); + }; - onModalActionFulfilled = () => { - this.onClose(); + handleModalActionFulfilled = () => { + this.handleClose(); this.props.onBranchesChange(); }; @@ -113,7 +123,7 @@ export default class BranchLikeTabs extends React.PureComponent<Props, State> { <> <BoxedTabs className="branch-like-tabs" - onSelect={this.onTabSelect} + onSelect={this.handleTabSelect} selected={currentTab} tabs={TABS} /> @@ -122,8 +132,9 @@ export default class BranchLikeTabs extends React.PureComponent<Props, State> { branchLikes={branchLikesToDisplay} component={component} displayPurgeSetting={isBranchMode} - onDelete={this.onDeleteBranchLike} - onRename={this.onRenameBranchLike} + onDelete={this.handleDeleteBranchLike} + onRename={this.handleRenameBranchLike} + onUpdatePurgeSetting={this.handleUpdatePurgeSetting} title={title} /> @@ -131,8 +142,8 @@ export default class BranchLikeTabs extends React.PureComponent<Props, State> { <DeleteBranchModal branchLike={deleting} component={component} - onClose={this.onClose} - onDelete={this.onModalActionFulfilled} + onClose={this.handleClose} + onDelete={this.handleModalActionFulfilled} /> )} @@ -140,8 +151,8 @@ export default class BranchLikeTabs extends React.PureComponent<Props, State> { <RenameBranchModal branch={renaming} component={component} - onClose={this.onClose} - onRename={this.onModalActionFulfilled} + onClose={this.handleClose} + onRename={this.handleModalActionFulfilled} /> )} </> diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx index 747448df796..e692fa46a03 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchPurgeSetting.tsx @@ -30,6 +30,7 @@ import { Component } from '../../../types/types'; interface Props { branch: Branch; component: Component; + onUpdatePurgeSetting: () => void; } interface State { @@ -68,6 +69,7 @@ export default class BranchPurgeSetting extends React.PureComponent<Props, State excludedFromPurge: newValue, loading: false }); + this.props.onUpdatePurgeSetting(); } }) .catch(() => { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/App.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/ProjectBranchesApp.tsx index ef56a1e3265..fbb5c222e65 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/ProjectBranchesApp.tsx @@ -24,14 +24,14 @@ import { Component } from '../../../types/types'; import BranchLikeTabs from './BranchLikeTabs'; import LifetimeInformation from './LifetimeInformation'; -export interface AppProps { +export interface ProjectBranchesAppProps { branchLikes: BranchLike[]; component: Component; onBranchesChange: () => void; } -export function App(props: AppProps) { - const { branchLikes, component, onBranchesChange } = props; +export function ProjectBranchesApp(props: ProjectBranchesAppProps) { + const { branchLikes, component } = props; return ( <div className="page page-limited" id="project-branch-like"> @@ -43,10 +43,10 @@ export function App(props: AppProps) { <BranchLikeTabs branchLikes={branchLikes} component={component} - onBranchesChange={onBranchesChange} + onBranchesChange={props.onBranchesChange} /> </div> ); } -export default React.memo(App); +export default React.memo(ProjectBranchesApp); diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeRow-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeRow-test.tsx index 962ba9f2e84..6f0c6566201 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeRow-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeRow-test.tsx @@ -45,6 +45,7 @@ function shallowRender(props?: Partial<BranchLikeRowProps>) { component={mockComponent()} onDelete={jest.fn()} onRename={jest.fn()} + onUpdatePurgeSetting={jest.fn()} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTable-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTable-test.tsx index b0997eac3ce..cfec0e87bc5 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTable-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTable-test.tsx @@ -68,6 +68,7 @@ function shallowRender(props?: Partial<BranchLikeTableProps>) { component={mockComponent()} onDelete={jest.fn()} onRename={jest.fn()} + onUpdatePurgeSetting={jest.fn()} title="title" {...props} /> diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx index 314297cf5b4..1bf9474e8d3 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx @@ -117,6 +117,18 @@ it('should NOT render renaming modal for non-main branch', () => { expect(wrapper.find(RenameBranchModal).exists()).toBe(false); }); +it('should correctly propagate an update of purge settings', () => { + const onBranchesChange = jest.fn(); + const wrapper = shallowRender({ onBranchesChange }); + + wrapper + .find(BranchLikeTable) + .props() + .onUpdatePurgeSetting(); + + expect(onBranchesChange).toBeCalled(); +}); + function shallowRender(props: Partial<BranchLikeTabs['props']> = {}) { return shallow<BranchLikeTabs>( <BranchLikeTabs diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx index 491d9117517..9b3aa83041a 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx @@ -23,6 +23,7 @@ import { excludeBranchFromPurge } from '../../../../api/branches'; import Toggle from '../../../../components/controls/Toggle'; import { mockBranch, mockMainBranch } from '../../../../helpers/mocks/branch-like'; import { mockComponent } from '../../../../helpers/mocks/component'; +import { waitAndUpdate } from '../../../../helpers/testUtils'; import BranchPurgeSetting from '../BranchPurgeSetting'; jest.mock('../../../../api/branches', () => ({ @@ -43,8 +44,9 @@ it('should render correctly for a main branch', () => { expect(wrapper.state().excludedFromPurge).toBe(true); }); -it('should correctly call the webservice if the user changes the value', () => { - const wrapper = shallowRender(); +it('should correctly call the webservice if the user changes the value', async () => { + const onUpdatePurgeSetting = jest.fn(); + const wrapper = shallowRender({ onUpdatePurgeSetting }); expect(wrapper.state().excludedFromPurge).toBe(true); const { onChange } = wrapper.find(Toggle).props(); @@ -52,6 +54,8 @@ it('should correctly call the webservice if the user changes the value', () => { onChange!(false); expect(excludeBranchFromPurge).toHaveBeenCalled(); expect(wrapper.state().excludedFromPurge).toBe(true); + await waitAndUpdate(wrapper); + expect(onUpdatePurgeSetting).toBeCalled(); }); function shallowRender(props?: Partial<BranchPurgeSetting['props']>) { @@ -59,6 +63,7 @@ function shallowRender(props?: Partial<BranchPurgeSetting['props']>) { <BranchPurgeSetting branch={mockBranch({ excludedFromPurge: true })} component={mockComponent()} + onUpdatePurgeSetting={jest.fn()} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/ProjectBranchesApp-test.tsx index e3457f6dfbe..e06c159cfe1 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/ProjectBranchesApp-test.tsx @@ -21,8 +21,8 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockSetOfBranchAndPullRequest } from '../../../../helpers/mocks/branch-like'; import { mockComponent } from '../../../../helpers/mocks/component'; -import { App, AppProps } from '../App'; import BranchLikeTabs from '../BranchLikeTabs'; +import { ProjectBranchesApp, ProjectBranchesAppProps } from '../ProjectBranchesApp'; it('should render correctly', () => { const wrapper = shallowRender(); @@ -41,9 +41,9 @@ it('should properly notify that a branch or a pr has been changed/deleted', () = expect(onBranchesChange).toHaveBeenCalled(); }); -function shallowRender(props?: Partial<AppProps>) { +function shallowRender(props?: Partial<ProjectBranchesAppProps>) { return shallow( - <App + <ProjectBranchesApp branchLikes={mockSetOfBranchAndPullRequest()} component={mockComponent()} onBranchesChange={jest.fn()} diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeRow-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeRow-test.tsx.snap index 4051fc8e683..a39fb5dd0ec 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeRow-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeRow-test.tsx.snap @@ -79,6 +79,7 @@ exports[`should render correctly for branch 1`] = ` "tags": Array [], } } + onUpdatePurgeSetting={[MockFunction]} /> </td> <td @@ -182,6 +183,7 @@ exports[`should render correctly for main branch 1`] = ` "tags": Array [], } } + onUpdatePurgeSetting={[MockFunction]} /> </td> <td diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTable-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTable-test.tsx.snap index d36f7abd252..ca96018dc50 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTable-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTable-test.tsx.snap @@ -81,6 +81,7 @@ exports[`should render correctly 1`] = ` key="branch-branch-11" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -116,6 +117,7 @@ exports[`should render correctly 1`] = ` key="branch-branch-1" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -151,6 +153,7 @@ exports[`should render correctly 1`] = ` key="branch-master" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -188,6 +191,7 @@ exports[`should render correctly 1`] = ` key="pull-request-1" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -223,6 +227,7 @@ exports[`should render correctly 1`] = ` key="branch-branch-12" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -260,6 +265,7 @@ exports[`should render correctly 1`] = ` key="pull-request-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -295,6 +301,7 @@ exports[`should render correctly 1`] = ` key="branch-branch-3" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -330,6 +337,7 @@ exports[`should render correctly 1`] = ` key="branch-branch-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -368,6 +376,7 @@ exports[`should render correctly 1`] = ` key="pull-request-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> </tbody> </table> @@ -476,6 +485,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-branch-11" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -512,6 +522,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-branch-1" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -548,6 +559,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-master" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -586,6 +598,7 @@ exports[`should render purge setting correctly 1`] = ` key="pull-request-1" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -622,6 +635,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-branch-12" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -660,6 +674,7 @@ exports[`should render purge setting correctly 1`] = ` key="pull-request-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -696,6 +711,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-branch-3" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -732,6 +748,7 @@ exports[`should render purge setting correctly 1`] = ` key="branch-branch-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> <Memo(BranchLikeRow) branchLike={ @@ -771,6 +788,7 @@ exports[`should render purge setting correctly 1`] = ` key="pull-request-2" onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[MockFunction]} /> </tbody> </table> diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTabs-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTabs-test.tsx.snap index 6402767dc72..5ad71478b28 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTabs-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchLikeTabs-test.tsx.snap @@ -99,6 +99,7 @@ exports[`should render all tabs correctly 1`] = ` displayPurgeSetting={true} onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[Function]} title="project_branch_pull_request.table.branch" /> </Fragment> @@ -192,6 +193,7 @@ exports[`should render all tabs correctly 2`] = ` displayPurgeSetting={false} onDelete={[Function]} onRename={[Function]} + onUpdatePurgeSetting={[Function]} title="project_branch_pull_request.table.pull_request" /> </Fragment> diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/ProjectBranchesApp-test.tsx.snap index e673ebd9ff5..e673ebd9ff5 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/ProjectBranchesApp-test.tsx.snap diff --git a/server/sonar-web/src/main/js/apps/projectBranches/routes.ts b/server/sonar-web/src/main/js/apps/projectBranches/routes.ts index 9d8f2bd42e4..58d607edaa5 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/routes.ts +++ b/server/sonar-web/src/main/js/apps/projectBranches/routes.ts @@ -21,7 +21,7 @@ import { lazyLoadComponent } from '../../components/lazyLoadComponent'; const routes = [ { - indexRoute: { component: lazyLoadComponent(() => import('./components/App')) } + indexRoute: { component: lazyLoadComponent(() => import('./components/ProjectBranchesApp')) } } ]; |