Title,
} from 'design-system';
import * as React from 'react';
-import { isMainBranch } from '../../helpers/branch-like';
+import { useNavigate } from 'react-router-dom';
+import { getBranchLikeQuery, isMainBranch } from '../../helpers/branch-like';
import { translate } from '../../helpers/l10n';
import { getBaseUrl } from '../../helpers/system';
import { getProjectTutorialLocation } from '../../helpers/urls';
import { useBranchesQuery } from '../../queries/branch';
import { AlmKeys, AlmSettingsInstance, ProjectAlmBindingResponse } from '../../types/alm-settings';
-import { MainBranch } from '../../types/branch-like';
+import { BranchLike, MainBranch } from '../../types/branch-like';
import { Component } from '../../types/types';
import { LoggedInUser } from '../../types/users';
import { Alert } from '../ui/Alert';
);
}
+const CHECKING_NEW_BRANCH = 5_000;
+
export default function TutorialSelectionRenderer(props: TutorialSelectionRendererProps) {
const {
almBinding,
willRefreshAutomatically,
} = props;
- const { data: { branchLikes } = { branchLikes: [] } } = useBranchesQuery(component);
+ const { data: { branchLikes } = { branchLikes: [] as BranchLike[] } } = useBranchesQuery(
+ component,
+ CHECKING_NEW_BRANCH,
+ );
+
+ const navigate = useNavigate();
+
+ const firstAnalysedBranch = branchLikes.find((b) => b.analysisDate !== undefined);
+
+ if (firstAnalysedBranch) {
+ navigate({
+ pathname: '/dashboard',
+ search: new URLSearchParams({
+ id: component.key,
+ ...getBranchLikeQuery(firstAnalysedBranch),
+ }).toString(),
+ });
+ }
const mainBranchName =
(branchLikes.find((b) => isMainBranch(b)) as MainBranch | undefined)?.name ||
import * as React from 'react';
import { getScannableProjects } from '../../../api/components';
import AlmSettingsServiceMock from '../../../api/mocks/AlmSettingsServiceMock';
+import BranchesServiceMock from '../../../api/mocks/BranchesServiceMock';
import SettingsServiceMock from '../../../api/mocks/SettingsServiceMock';
import UserTokensMock from '../../../api/mocks/UserTokensMock';
import { mockComponent } from '../../../helpers/mocks/component';
jest.mock('../../../api/user-tokens');
-jest.mock('../../../api/branches');
-
jest.mock('../../../helpers/urls', () => ({
...jest.requireActual('../../../helpers/urls'),
getHostUrl: jest.fn().mockReturnValue('http://host.url'),
let settingsMock: SettingsServiceMock;
let tokenMock: UserTokensMock;
let almMock: AlmSettingsServiceMock;
+let branchesMock: BranchesServiceMock;
beforeAll(() => {
settingsMock = new SettingsServiceMock();
tokenMock = new UserTokensMock();
almMock = new AlmSettingsServiceMock();
+ branchesMock = new BranchesServiceMock();
});
afterEach(() => {
tokenMock.reset();
settingsMock.reset();
almMock.reset();
+ branchesMock.reset();
});
-beforeEach(jest.clearAllMocks);
+beforeEach(() => {
+ branchesMock.emptyBranchesAndPullRequest();
+ jest.clearAllMocks();
+});
const ui = {
loading: byLabelText('loading'),
return { componentKey, query: {} };
}
-export function useBranchesQuery(component?: Component) {
+export function useBranchesQuery(component?: Component, refetchInterval?: number) {
const features = useContext(AvailableFeaturesContext);
const key = useBranchesQueryKey(InnerState.Details);
return useQuery({
},
// The check of the key must desapear once component state is in react-query
enabled: !!component && component.key === key[1],
- staleTime: BRANCHES_STALE_TIME,
+ staleTime: refetchInterval ?? BRANCHES_STALE_TIME,
+ refetchInterval,
});
}