Skip to content

Commit 40e0b3d

Browse files
committed
Merge branch 'main' into KFLUXUI-125
2 parents 85ad487 + e55ad69 commit 40e0b3d

File tree

61 files changed

+289
-292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+289
-292
lines changed

config/jest.setup.js

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jest.mock('react-router-dom', () => ({
1919
...jest.requireActual('react-router-dom'),
2020
}));
2121

22-
jest.mock('../src/components/Workspace/useWorkspaceInfo', () => ({
23-
__esModule: true,
24-
...jest.requireActual('../src/components/Workspace/useWorkspaceInfo'),
25-
}));
26-
2722
jest.mock('../src/shared/providers/Namespace/useNamespaceInfo', () => ({
2823
__esModule: true,
2924
...jest.requireActual('../src/shared/providers/Namespace/useNamespaceInfo'),

src/AppRoot/AppSideBar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const AppSideBar: React.FC<{ isOpen: boolean }> = ({ isOpen }) => {
8080

8181
<NavItem
8282
className={css({ 'app-side-bar__nav-item--disabled': disabled })}
83-
isActive={isActive(`/workspaces/${namespace}/access`)}
83+
isActive={isActive(USER_ACCESS_LIST_PAGE.createPath({ workspaceName: namespace }))}
8484
>
8585
<NavLink
8686
to={

src/components/Activity/ActivityTab.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { useNavigate, useParams } from 'react-router-dom';
33
import { Tab, Tabs, TabTitleText, Text, Title } from '@patternfly/react-core';
4+
import { APPLICATION_ACTIVITY_PATH } from '@routes/paths';
45
import { useLocalStorage } from '../../hooks/useLocalStorage';
56
import { RouterParams } from '../../routes/utils';
67
import CommitsListView from '../Commits/CommitsListPage/CommitsListView';
@@ -19,7 +20,8 @@ export const ActivityTab: React.FC = () => {
1920
const currentTab = activityTab || lastSelectedTab || 'latest-commits';
2021

2122
const getActivityTabRoute = React.useCallback(
22-
(tab: string) => `/workspaces/${workspaceName}/applications/${applicationName}/activity/${tab}`,
23+
(tab: string) =>
24+
`${APPLICATION_ACTIVITY_PATH.createPath({ workspaceName, applicationName })}/${tab}`,
2325
[applicationName, workspaceName],
2426
);
2527

src/components/Activity/__tests__/ActivityTab.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ jest.mock('react-router-dom', () => {
1212
};
1313
});
1414

15-
jest.mock('../../Workspace/useWorkspaceInfo', () => ({
16-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'test-ns', workspace: 'test-ws' })),
17-
}));
18-
1915
jest.mock('../../../hooks/useTektonResults');
2016
jest.mock('../../../hooks/usePipelineRuns', () => ({
2117
usePipelineRuns: jest.fn(() => [

src/components/ApplicationDetails/tabs/overview/visualization/hooks/__tests__/useAppIntegrationTestNodes.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { renderHook } from '@testing-library/react-hooks';
22
import { useComponents } from '../../../../../../../hooks/useComponents';
33
import { useLatestIntegrationTestPipelines } from '../../../../../../../hooks/useLatestIntegrationTestPipelines';
4-
import {
5-
createK8sWatchResourceMock,
6-
createUseWorkspaceInfoMock,
7-
} from '../../../../../../../utils/test-utils';
4+
import { createK8sWatchResourceMock } from '../../../../../../../utils/test-utils';
85
import { mockIntegrationTestScenariosData } from '../../../../../__data__';
96
import { testPipelineRuns } from '../__data__/test-pipeline-data';
107
import { useAppApplicationTestNodes } from '../useAppApplicationTestNodes';
@@ -22,7 +19,6 @@ const useComponentsMock = useComponents as jest.Mock;
2219
const useLatestIntegrationTestPipelinesMock = useLatestIntegrationTestPipelines as jest.Mock;
2320

2421
describe('useAppApplicationTestNodes', () => {
25-
createUseWorkspaceInfoMock({ namespace: 'test-ns', workspace: 'test-ws' });
2622
beforeEach(() => {
2723
useK8sWatchResourceMock.mockReset();
2824
useK8sWatchResourceMock.mockReturnValue([mockIntegrationTestScenariosData, true]);

src/components/ApplicationDetails/tabs/overview/visualization/hooks/useAppWorkflowData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
Model,
66
PipelineNodeModel,
77
} from '@patternfly/react-topology';
8+
import { useNamespace } from '~/shared/providers/Namespace';
89
import { runStatus } from '../../../../../../utils/pipeline-utils';
9-
import { useWorkspaceInfo } from '../../../../../Workspace/useWorkspaceInfo';
1010
import { NodeType } from '../const';
1111
import { WorkflowNodeType } from '../types';
1212
import { groupToPipelineNode, worstWorkflowStatus } from '../utils/node-utils';
@@ -19,7 +19,7 @@ export const useAppWorkflowData = (
1919
applicationName: string,
2020
expanded: boolean,
2121
): [model: Model, loaded: boolean, errors: unknown[]] => {
22-
const { namespace } = useWorkspaceInfo();
22+
const namespace = useNamespace();
2323
const [componentNodes, componentGroup, componentTasks, componentsLoaded, componentsErrors] =
2424
useAppComponentsNodes(namespace, applicationName, [], expanded);
2525
const [buildNodes, buildGroup, buildTasks, buildsLoaded, buildsErrors] = useAppBuildNodes(

src/components/ApplicationDetails/tabs/overview/visualization/nodes/WorkflowNode.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
useCombineRefs,
1111
useHover,
1212
} from '@patternfly/react-topology';
13+
import { useNamespace } from '~/shared/providers/Namespace';
1314
import { runStatusToRunStatus } from '../../../../../topology/utils';
14-
import { useWorkspaceInfo } from '../../../../../Workspace/useWorkspaceInfo';
1515
import { WorkflowNodeModelData } from '../types';
1616
import { getWorkflowNodeIcon } from '../utils/node-icon-utils';
1717
import { getLinksForElement } from '../utils/node-utils';
@@ -25,7 +25,7 @@ type WorkflowNodeProps = {
2525

2626
const WorkflowNode: React.FC<React.PropsWithChildren<WorkflowNodeProps>> = ({ element }) => {
2727
const navigate = useNavigate();
28-
const { workspace } = useWorkspaceInfo();
28+
const namespace = useNamespace();
2929
const [tipHover, setTipHover] = React.useState<boolean>(false);
3030
const [tipVisible, setTipVisible] = React.useState<boolean>(false);
3131
const [hover, hoverRef] = useHover();
@@ -35,8 +35,8 @@ const WorkflowNode: React.FC<React.PropsWithChildren<WorkflowNodeProps>> = ({ el
3535
const outerRef = useCombineRefs(hoverRef, triggerRef);
3636

3737
const setActiveTab = React.useCallback(() => {
38-
navigate(getLinksForElement(element, workspace).elementRef);
39-
}, [element, navigate, workspace]);
38+
navigate(getLinksForElement(element, namespace).elementRef);
39+
}, [element, navigate, namespace]);
4040

4141
React.useEffect(() => {
4242
let canceled = false;

src/components/ApplicationDetails/tabs/overview/visualization/nodes/WorkflowNodeTipContent.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PipelineNodeModel,
1111
} from '@patternfly/react-topology';
1212
import pipelineStyles from '@patternfly/react-topology/dist/esm/css/topology-pipelines';
13-
import { useWorkspaceInfo } from '../../../../../Workspace/useWorkspaceInfo';
13+
import { useNamespace } from '~/shared/providers/Namespace';
1414
import { WorkflowNodeModelData, WorkflowNodeType } from '../types';
1515
import { getLinksForElement, statusToRunStatus, TYPE_DESCRIPTIONS } from '../utils/node-utils';
1616
import './WorkflowNodeTipContent.scss';
@@ -24,8 +24,8 @@ const WorkflowNodeTipContent: React.FC<React.PropsWithChildren<WorkflowNodeTipCo
2424
}) => {
2525
const { workflowType, children } = element.getData();
2626
const label = element.getLabel();
27-
const { workspace } = useWorkspaceInfo();
28-
const { elementRef, pipelinesRef, appRef } = getLinksForElement(element, workspace);
27+
const namespace = useNamespace();
28+
const { elementRef, pipelinesRef, appRef } = getLinksForElement(element, namespace);
2929

3030
const links = React.useMemo(() => {
3131
switch (workflowType) {

src/components/ApplicationDetails/tabs/overview/visualization/nodes/__tests__/WorkflowNodeTipContent.spec.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
} from '@patternfly/react-topology';
88
import { Matcher, screen } from '@testing-library/react';
99
import { renderHook } from '@testing-library/react-hooks';
10-
import { createUseWorkspaceInfoMock, routerRenderer } from '../../../../../../../utils/test-utils';
10+
import { mockUseNamespaceHook } from '~/unit-test-utils/mock-namespace';
11+
import { routerRenderer } from '../../../../../../../utils/test-utils';
1112
import { layoutFactory, PipelineLayout } from '../../../../../../topology/factories';
1213
import { mockComponentsData } from '../../../../../__data__';
1314
import { getMockWorkflows } from '../../../../../__data__/WorkflowTestUtils';
@@ -20,7 +21,7 @@ import WorkflowNodeTipContent from '../WorkflowNodeTipContent';
2021
const { workflowMocks, applyWorkflowMocks } = getMockWorkflows();
2122

2223
describe('WorkflowNode', () => {
23-
createUseWorkspaceInfoMock({ namespace: 'test-ns', workspace: 'test-ws' });
24+
mockUseNamespaceHook('test-ns');
2425
beforeEach(() => {
2526
applyWorkflowMocks(workflowMocks);
2627

@@ -69,7 +70,7 @@ describe('WorkflowNode', () => {
6970
expect(
7071
screen.getByText(TYPE_DESCRIPTIONS[mockElement.getData().workflowType] as Matcher),
7172
).toBeInTheDocument();
72-
let linkData = getLinkDataForElement(mockElement, 'test-ws');
73+
let linkData = getLinkDataForElement(mockElement, 'test-ns');
7374
expect(linkData.tab).toBe('components');
7475
expect(linkData.filter).toBeUndefined();
7576
expect(screen.getAllByTestId('child-row')).toHaveLength(mockComponentsData.length);
@@ -93,7 +94,7 @@ describe('WorkflowNode', () => {
9394
).toBeInTheDocument();
9495

9596
expect(screen.getByTestId('element-link')).toBeVisible();
96-
linkData = getLinkDataForElement(mockElement, 'test-ws');
97+
linkData = getLinkDataForElement(mockElement, 'test-ns');
9798
expect(linkData.tab).toBe('integrationtests');
9899
expect(linkData.filter).toBeUndefined();
99100

@@ -120,10 +121,10 @@ describe('WorkflowNode', () => {
120121
).toBeInTheDocument();
121122
const link = screen.getByTestId('element-link');
122123
expect(link).toBeVisible();
123-
const linkData = getLinkDataForElement(mockElement, 'test-ws');
124+
const linkData = getLinkDataForElement(mockElement, 'test-ns');
124125
expect(linkData.tab).toBe(`components/${mockElement.getLabel()}`);
125126
expect(linkData.filter).toBeUndefined();
126-
const buildLinkData = getLinkDataForElement(mockBuildElement, 'test-ws');
127+
const buildLinkData = getLinkDataForElement(mockBuildElement, 'test-ns');
127128
expect(buildLinkData.tab).toBe('activity/pipelineruns');
128129
expect(buildLinkData.filter.name).toBe('name');
129130
expect(buildLinkData.filter.value).toBe(mockBuildElement.getData().resources[0].metadata.name);

src/components/ApplicationDetails/tabs/overview/visualization/utils/node-utils.ts

+27-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { Node, PipelineNodeModel, RunStatus } from '@patternfly/react-topology';
2+
import {
3+
APPLICATION_DETAILS_PATH,
4+
APPLICATION_RELEASE_DETAILS_PATH,
5+
INTEGRATION_TEST_DETAILS_PATH,
6+
PIPELINERUN_LIST_PATH,
7+
} from '@routes/paths';
28
import { PipelineRunLabel } from '../../../../../../consts/pipelinerun';
39
import { ComponentKind, PipelineRunKind } from '../../../../../../types';
410
import { GitOpsDeploymentHealthStatus } from '../../../../../../types/gitops-deployment';
@@ -76,7 +82,7 @@ export const statusToRunStatus = (status: string): RunStatus => {
7682

7783
export const getLinkDataForElement = (
7884
element: Node<PipelineNodeModel, WorkflowNodeModelData>,
79-
workspace: string,
85+
namespace: string,
8086
): { tab?: string; path?: string; filter?: { name: string; value: string } } => {
8187
const { workflowType, isDisabled, groupNode, status, resources } = element.getData();
8288
const label = element.getLabel();
@@ -107,19 +113,23 @@ export const getLinkDataForElement = (
107113
case WorkflowNodeType.APPLICATION_TEST:
108114
return !groupNode && !isDisabled
109115
? {
110-
path: `/workspaces/${workspace}/applications/${
111-
element.getData().application
112-
}/integrationtests/${label}`,
116+
path: INTEGRATION_TEST_DETAILS_PATH.createPath({
117+
workspaceName: namespace,
118+
applicationName: element.getData().application,
119+
integrationTestName: label,
120+
}),
113121
}
114122
: {
115123
tab: 'integrationtests',
116124
};
117125
case WorkflowNodeType.RELEASE:
118126
return !groupNode && !isDisabled
119127
? {
120-
path: `/workspaces/${workspace}/applications/${
121-
element.getData().application
122-
}/releases/${label}`,
128+
path: APPLICATION_RELEASE_DETAILS_PATH.createPath({
129+
workspaceName: namespace,
130+
applicationName: element.getData().application,
131+
releaseName: label,
132+
}),
123133
}
124134
: { tab: 'releases' };
125135
default:
@@ -131,17 +141,23 @@ export const getLinkDataForElement = (
131141

132142
export const getLinksForElement = (
133143
element: Node<PipelineNodeModel, WorkflowNodeModelData>,
134-
workspace: string,
144+
namespace: string,
135145
): { elementRef: string; pipelinesRef: string; appRef: string } => {
136-
const linkData = getLinkDataForElement(element, workspace);
146+
const linkData = getLinkDataForElement(element, namespace);
137147

138-
const appPath = `/workspaces/${workspace}/applications/${element.getData().application}`;
148+
const appPath = APPLICATION_DETAILS_PATH.createPath({
149+
workspaceName: namespace,
150+
applicationName: element.getData().application,
151+
});
139152
const tabPath = linkData.tab ? `/${linkData.tab}` : '';
140153
const filter = linkData.filter ? `?${linkData.filter.name}=${linkData.filter.value}` : '';
141154

142155
return {
143156
elementRef: linkData.path ? linkData.path : `${appPath}${tabPath}${filter}`,
144-
pipelinesRef: `${appPath}/activity/pipelineruns`,
157+
pipelinesRef: PIPELINERUN_LIST_PATH.createPath({
158+
workspaceName: namespace,
159+
applicationName: element.getData().application,
160+
}),
145161
appRef: appPath,
146162
};
147163
};

src/components/Applications/__tests__/ApplicationListRow.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ jest.mock('../../../utils/rbac', () => ({
1111
useAccessReviewForModel: jest.fn(() => [true, true]),
1212
}));
1313

14-
jest.mock('../../Workspace/useWorkspaceInfo', () => ({
15-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'test-ns', workspace: 'test-ws' })),
16-
}));
17-
1814
const application: ApplicationKind = {
1915
kind: 'Application',
2016
apiVersion: 'appstudio.redhat.com/v1alpha1',

src/components/Commits/CommitDetails/visualization/__tests__/CommitVisualization.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ import CommitVisualization from '../CommitVisualization';
2121

2222
jest.mock('../../../../../hooks/useTektonResults');
2323

24-
jest.mock('../../../../Workspace/useWorkspaceInfo', () => ({
25-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'test-ns', workspace: 'test-ws' })),
26-
}));
27-
2824
jest.mock('../../../../../hooks/usePipelineRuns', () => ({
2925
usePipelineRunsForCommit: jest.fn(),
3026
}));

src/components/Commits/CommitsListPage/__tests__/CommitsListView.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ jest.mock('react-router-dom', () => ({
2323
useSearchParams: () => React.useState(() => new URLSearchParams()),
2424
}));
2525

26-
jest.mock('../../../Workspace/useWorkspaceInfo', () => ({
27-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'test-ns', workspace: 'test-ws' })),
28-
}));
29-
3026
jest.mock('../../commit-status', () => ({
3127
useCommitStatus: () => ['-', true],
3228
}));

src/components/ComponentRelation/__tests__/ComponentRelationModal.spec.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ jest.mock('../../../hooks/useComponents', () => ({
1212
useAllComponents: jest.fn(() => [componentCRMocks, true, null]),
1313
}));
1414

15-
jest.mock('../../Workspace/useWorkspaceInfo', () => ({
16-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'asd', workspace: 'def' })),
17-
}));
18-
1915
jest.mock('../../../utils/analytics', () => ({
2016
...jest.requireActual('../../../utils/analytics'),
2117
useTrackEvent: jest.fn(() => () => {}),

src/components/ComponentRelation/__tests__/useNudgeData.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ jest.mock('../../../hooks/useComponents', () => ({
99
useAllComponents: jest.fn(() => [componentCRMocks, true, null]),
1010
}));
1111

12-
jest.mock('../../Workspace/useWorkspaceInfo', () => ({
13-
useWorkspaceInfo: jest.fn(() => ({ namespace: 'ns' })),
14-
}));
15-
1612
const mockUseComponent = useComponents as jest.Mock;
1713

1814
describe('useNudgeData', () => {

src/components/Components/ComponentDetails/tabs/__tests__/ComponentDetailsTab.spec.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import { useTaskRuns } from '../../../../../hooks/useTaskRuns';
99
import {
1010
createUseParamsMock,
11-
createUseWorkspaceInfoMock,
1211
renderWithQueryClientAndRouter,
1312
} from '../../../../../utils/test-utils';
1413
import { useModalLauncher } from '../../../../modal/ModalProvider';
@@ -61,7 +60,6 @@ describe('ComponentDetailTab', () => {
6160
let navigateMock: jest.Mock;
6261
const showModalMock = jest.fn();
6362

64-
createUseWorkspaceInfoMock({ namespace: 'test-ns', workspace: 'test-ws' });
6563
createUseParamsMock({
6664
applicationName: 'test-application',
6765
componentName: 'human-resources',

src/components/CustomizedPipeline/ComponentPACStateLabel.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as React from 'react';
22
import { Label, Skeleton, Tooltip } from '@patternfly/react-core';
3+
import { useNamespace } from '~/shared/providers/Namespace';
34
import usePACState, { PACState } from '../../hooks/usePACState';
45
import { ComponentKind } from '../../types';
56
import { useTrackEvent, TrackEvents } from '../../utils/analytics';
67
import { useComponentBuildStatus } from '../../utils/component-utils';
78
import { useModalLauncher } from '../modal/ModalProvider';
8-
import { useWorkspaceInfo } from '../Workspace/useWorkspaceInfo';
99
import { createCustomizeComponentPipelineModalLauncher } from './CustomizePipelinesModal';
1010

1111
type Props = {
@@ -18,7 +18,7 @@ type Props = {
1818
const ComponentPACStateLabelInner: React.FC<
1919
React.PropsWithChildren<Props & { pacState: PACState }>
2020
> = ({ component, onStateChange, enableAction, pacState }) => {
21-
const { workspace } = useWorkspaceInfo();
21+
const namespace = useNamespace();
2222
const track = useTrackEvent();
2323
const showModal = useModalLauncher();
2424
const buildStatus = useComponentBuildStatus(component);
@@ -39,7 +39,7 @@ const ComponentPACStateLabelInner: React.FC<
3939
link_location: 'component-list-label',
4040
component_name: component.metadata.name,
4141
app_name: component.spec.application,
42-
workspace,
42+
namespace,
4343
});
4444
showModal(
4545
createCustomizeComponentPipelineModalLauncher(
@@ -55,7 +55,7 @@ const ComponentPACStateLabelInner: React.FC<
5555
component.metadata.name,
5656
component.metadata.namespace,
5757
component.spec.application,
58-
workspace,
58+
namespace,
5959
track,
6060
],
6161
);

0 commit comments

Comments
 (0)