From 53cdb3e20b60a6c0e4e9954959119496c80e2a10 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Thu, 5 May 2022 15:51:02 +0200 Subject: [PATCH] SONAR-16207 Share code with Governance extension at build time --- server/sonar-web/src/main/js/api/time-machine.ts | 2 +- .../src/main/js/app/components/extensions/Extension.tsx | 6 +++++- .../app/components/extensions/__tests__/Extension-test.tsx | 1 + .../__tests__/__snapshots__/Extension-test.tsx.snap | 2 ++ .../sonar-web/src/main/js/components/charts/DonutChart.tsx | 2 +- server/sonar-web/src/main/js/helpers/testUtils.ts | 6 +++++- server/sonar-web/src/main/js/types/extension.ts | 5 ++++- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/server/sonar-web/src/main/js/api/time-machine.ts b/server/sonar-web/src/main/js/api/time-machine.ts index f6e7ee3da68..0f9f592cd71 100644 --- a/server/sonar-web/src/main/js/api/time-machine.ts +++ b/server/sonar-web/src/main/js/api/time-machine.ts @@ -22,7 +22,7 @@ import { getJSON } from '../helpers/request'; import { BranchParameters } from '../types/branch-like'; import { Paging } from '../types/types'; -interface TimeMachineResponse { +export interface TimeMachineResponse { measures: { metric: string; history: Array<{ date: string; value?: string }>; diff --git a/server/sonar-web/src/main/js/app/components/extensions/Extension.tsx b/server/sonar-web/src/main/js/app/components/extensions/Extension.tsx index e13e596fd83..e7fc3f0a962 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/Extension.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/Extension.tsx @@ -29,7 +29,7 @@ import { getBaseUrl } from '../../../helpers/system'; import { AppState } from '../../../types/appstate'; import { ExtensionStartMethod } from '../../../types/extension'; import { Dict, Extension as TypeExtension } from '../../../types/types'; -import { CurrentUser } from '../../../types/users'; +import { CurrentUser, HomePage } from '../../../types/users'; import * as theme from '../../theme'; import withAppStateContext from '../app-state/withAppStateContext'; import withCurrentUserContext from '../current-user/withCurrentUserContext'; @@ -41,6 +41,7 @@ interface Props extends WrappedComponentProps { location: Location; options?: Dict; router: Router; + updateCurrentUserHomepage: (homepage: HomePage) => void; } interface State { @@ -80,6 +81,9 @@ export class Extension extends React.PureComponent { theme, baseUrl: getBaseUrl(), l10nBundle: getCurrentL10nBundle(), + // See SONAR-16207 and core-extension-governance/src/main/js/portfolios/components/Header.tsx + // for more information on why we're passing this as a prop to an extension. + updateCurrentUserHomepage: this.props.updateCurrentUserHomepage, ...this.props.options }); diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx index 3001705b905..7f2166da2be 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx @@ -97,6 +97,7 @@ function shallowRender(props: Partial = {}) { intl={{} as IntlShape} location={mockLocation()} router={mockRouter()} + updateCurrentUserHomepage={jest.fn()} {...props} /> ); diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap index 4821cb22c56..183e24e1dfc 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/Extension-test.tsx.snap @@ -49,6 +49,7 @@ exports[`should render React extensions correctly 1`] = ` "setRouteLeaveHook": [MockFunction], } } + updateCurrentUserHomepage={[MockFunction]} >
('onChange')(value); diff --git a/server/sonar-web/src/main/js/types/extension.ts b/server/sonar-web/src/main/js/types/extension.ts index 3defc91892d..ccc7c6656c3 100644 --- a/server/sonar-web/src/main/js/types/extension.ts +++ b/server/sonar-web/src/main/js/types/extension.ts @@ -22,7 +22,7 @@ import { Location, Router } from '../components/hoc/withRouter'; import { AppState } from './appstate'; import { L10nBundle } from './l10nBundle'; import { Component, Dict } from './types'; -import { CurrentUser } from './users'; +import { CurrentUser, HomePage } from './users'; export enum AdminPageExtension { GovernanceConsole = 'governance/views_console' @@ -55,6 +55,9 @@ export interface ExtensionStartMethodParameter { }; baseUrl: string; l10nBundle: L10nBundle; + // See SONAR-16207 and core-extension-governance/src/main/js/portfolios/components/Header.tsx + // for more information on why we're passing this as a prop to an extension. + updateCurrentUserHomepage: (homepage: HomePage) => void; } export type ExtensionStartMethodReturnType = React.ReactNode | Function | void | undefined | null; -- 2.39.5