Skip to content

Commit 5461244

Browse files
committed
Address Atif's review comments, lint, return undefined instead
Signed-off-by: Keith Chong <kykchong@redhat.com>
1 parent 2d5c6a2 commit 5461244

10 files changed

Lines changed: 79 additions & 71 deletions

‎src/gitops/components/application/ApplicationDetailsTab.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { RouteComponentProps } from 'react-router';
33
import classNames from 'classnames';
44

5+
import { useArgoServer } from '@gitops/hooks/useArgoServer';
56
import {
67
ApplicationKind,
78
ApplicationModel,
@@ -11,7 +12,6 @@ import Revision from '@gitops/Revision/Revision';
1112
import HealthStatus from '@gitops/Statuses/HealthStatus';
1213
import { OperationState } from '@gitops/Statuses/OperationState';
1314
import SyncStatus from '@gitops/Statuses/SyncStatus';
14-
import { useArgoServer } from '@gitops/hooks/useArgoServer';
1515
import { getApplicationArgoUrl, getFriendlyClusterName } from '@gitops/utils/gitops';
1616
import { labelControllerNamespaceKey } from '@gitops/utils/gitops';
1717
import { useGitOpsTranslation } from '@gitops/utils/hooks/useGitOpsTranslation';

‎src/gitops/components/application/ApplicationResourcesTab.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as React from 'react';
22
import { RouteComponentProps } from 'react-router';
33
import classNames from 'classnames';
44

5-
import { useResourceActionsProvider } from '@gitops/hooks/useResourceActionsProvider';
65
import { useArgoServer } from '@gitops/hooks/useArgoServer';
6+
import { useResourceActionsProvider } from '@gitops/hooks/useResourceActionsProvider';
77
import HealthStatus from '@gitops/Statuses/HealthStatus';
88
import SyncStatus from '@gitops/Statuses/SyncStatus';
99
import ActionDropDown from '@gitops/utils/components/ActionDropDown/ActionDropDown';
@@ -111,9 +111,7 @@ const ApplicationResourcesTab: React.FC<ApplicationResourcesTabProps> = ({ obj }
111111
</Flex>
112112
<PageBody>
113113
<Flex style={{ marginTop: '15px' }} flex={{ default: 'flexDefault' }}>
114-
<FlexItem>
115-
{argoUrl ? <ArgoCDLink href={argoUrl} /> : <></>}
116-
</FlexItem>
114+
<FlexItem>{argoUrl ? <ArgoCDLink href={argoUrl} /> : <></>}</FlexItem>
117115
</Flex>
118116
<>
119117
{obj.metadata && (

‎src/gitops/components/application/ApplicationSourcesTab.tsx‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as React from 'react';
22
import { RouteComponentProps } from 'react-router';
33

4+
import { useArgoServer } from '@gitops/hooks/useArgoServer';
45
import { ApplicationKind, ApplicationSource } from '@gitops/models/ApplicationModel';
56
import ExternalLink from '@gitops/utils/components/ExternalLink/ExternalLink';
67
import { GitIcon } from '@gitops/utils/components/Icons/GitIcon';
78
import { HelmIcon } from '@gitops/utils/components/Icons/HelmIcon';
89
import { OciIcon } from '@gitops/utils/components/Icons/OciIcon';
9-
import { useArgoServer } from '@gitops/hooks/useArgoServer';
1010
import { ArgoServer, getApplicationArgoUrl } from '@gitops/utils/gitops';
1111
import { t } from '@gitops/utils/hooks/useGitOpsTranslation';
1212
import { repoUrl, revisionUrl } from '@gitops/utils/urls';
@@ -182,6 +182,7 @@ export const useRowsDV = (sources: ApplicationSource[]): DataViewTr[] => {
182182
export const SourceList: React.FC<SourceListProps> = ({ sources, obj, argoServer }) => {
183183
const columns = useColumnsDV();
184184
const rows = useRowsDV(sources);
185+
const argoUrl = getApplicationArgoUrl(argoServer, obj);
185186
const empty = (
186187
<Tbody>
187188
<Tr key="loading" ouiaId="table-tr-loading">
@@ -197,17 +198,19 @@ export const SourceList: React.FC<SourceListProps> = ({ sources, obj, argoServer
197198
);
198199
return (
199200
<>
200-
<ArgoCDLink
201-
href={
202-
getApplicationArgoUrl(argoServer, obj) +
203-
'?resource=&node=argoproj.io%2FApplication%2F' +
204-
obj?.metadata?.namespace +
205-
'%2F' +
206-
obj?.metadata?.name +
207-
'%2F' +
208-
'&tab=parameters'
209-
}
210-
/>
201+
{argoUrl && (
202+
<ArgoCDLink
203+
href={
204+
argoUrl +
205+
'?resource=&node=argoproj.io%2FApplication%2F' +
206+
obj?.metadata?.namespace +
207+
'%2F' +
208+
obj?.metadata?.name +
209+
'%2F' +
210+
'&tab=parameters'
211+
}
212+
/>
213+
)}
211214
<GitOpsDataViewTable
212215
rows={rows}
213216
columns={columns}

‎src/gitops/components/application/ApplicationSyncStatusTab.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import * as React from 'react';
22
import { RouteComponentProps } from 'react-router';
33
import classNames from 'classnames';
44

5+
import { useArgoServer } from '@gitops/hooks/useArgoServer';
56
import { useResourceActionsProvider } from '@gitops/hooks/useResourceActionsProvider';
67
import { OperationState } from '@gitops/Statuses/OperationState';
78
import SyncStatus from '@gitops/Statuses/SyncStatus';
89
import ActionDropDown from '@gitops/utils/components/ActionDropDown/ActionDropDown';
9-
import { useArgoServer } from '@gitops/hooks/useArgoServer';
1010
import { getApplicationArgoUrl, getDuration } from '@gitops/utils/gitops';
1111
import { t } from '@gitops/utils/hooks/useGitOpsTranslation';
1212
import { ApplicationKind, ApplicationResourceStatus } from '@gitops-models/ApplicationModel';

‎src/gitops/components/application/History/History.tsx‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as React from 'react';
22
import { useTranslation } from 'react-i18next';
33

44
import ArgoCDLink from '@gitops/components/shared/ArgoCDLink/ArgoCDLink';
5+
import { useArgoServer } from '@gitops/hooks/useArgoServer';
56
import Revision from '@gitops/Revision/Revision';
67
import ExternalLink from '@gitops/utils/components/ExternalLink/ExternalLink';
7-
import { useArgoServer } from '@gitops/hooks/useArgoServer';
88
import { getApplicationArgoUrl } from '@gitops/utils/gitops';
99
import { repoUrl } from '@gitops/utils/urls';
1010
import { ApplicationHistory, ApplicationKind } from '@gitops-models/ApplicationModel';
@@ -58,17 +58,19 @@ const HistoryList: React.FC<HistoryListProps> = ({ history, obj }) => {
5858

5959
return (
6060
<div>
61-
<ArgoCDLink
62-
href={
63-
argoUrl +
64-
'?resource=&node=argoproj.io%2FApplication%2F' +
65-
obj?.metadata?.namespace +
66-
'%2F' +
67-
obj?.metadata?.name +
68-
'%2F' +
69-
'&view=tree&resource=&operation=false&rollback=0'
70-
}
71-
/>
61+
{argoUrl && (
62+
<ArgoCDLink
63+
href={
64+
argoUrl +
65+
'?resource=&node=argoproj.io%2FApplication%2F' +
66+
obj?.metadata?.namespace +
67+
'%2F' +
68+
obj?.metadata?.name +
69+
'%2F' +
70+
'&view=tree&resource=&operation=false&rollback=0'
71+
}
72+
/>
73+
)}
7274
<GitOpsDataViewTable
7375
rows={rows}
7476
columns={columnsDV}

‎src/gitops/components/application/graph/ApplicationGraphView.tsx‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as React from 'react';
22
import { NavigateFunction, useNavigate } from 'react-router-dom-v5-compat';
33
import { observer } from 'mobx-react';
44

5+
import { useArgoServer } from '@gitops/hooks/useArgoServer';
56
import {
67
ApplicationKind,
78
applicationModelRef,
89
ApplicationResourceStatus,
910
} from '@gitops/models/ApplicationModel';
10-
import { useArgoServer } from '@gitops/hooks/useArgoServer';
1111
import { HealthStatus } from '@gitops/utils/constants';
1212
import { getApplicationArgoUrl } from '@gitops/utils/gitops';
1313
import { t } from '@gitops/utils/hooks/useGitOpsTranslation';
@@ -169,7 +169,7 @@ const customComponentFactory =
169169
}),
170170
'-',
171171
t('View Details'),
172-
t('View in Argo CD'),
172+
...(hrefRef.current ? [t('View in Argo CD')] : []),
173173
]);
174174
}
175175
};
@@ -340,12 +340,12 @@ export const ApplicationGraphView: React.FC<{
340340
const navigate = useNavigate();
341341

342342
const contextMenuParamsRef = React.useRef<ApplicationContextMenuParams>({
343-
application,
344-
navigate,
345-
launchLabelsModal,
346-
launchAnnotationsModal,
347-
launchDeleteModal,
348-
setGroupNodeStates,
343+
application,
344+
navigate,
345+
launchLabelsModal,
346+
launchAnnotationsModal,
347+
launchDeleteModal,
348+
setGroupNodeStates,
349349
});
350350

351351
React.useEffect(() => {

‎src/gitops/hooks/useApplicationActionsProvider.tsx‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,23 @@ export const useApplicationActionsProvider: UseApplicationActionsProvider = (app
151151
},
152152
cta: () => launchDeleteModal(),
153153
},
154-
...(href ? [{
155-
id: 'gitops-action-view-in-argocd',
156-
disabled: href === undefined,
157-
label: t('View in Argo CD'),
158-
accessReview: {
159-
group: ApplicationModel.apiGroup,
160-
verb: 'get' as K8sVerb,
161-
resource: ApplicationModel.plural,
162-
namespace: application?.metadata?.namespace,
163-
},
164-
cta: () => {
165-
window.open(href, '_blank');
166-
}
167-
}] : []
168-
),
154+
...(href
155+
? [
156+
{
157+
id: 'gitops-action-view-in-argocd',
158+
label: t('View in Argo CD'),
159+
accessReview: {
160+
group: ApplicationModel.apiGroup,
161+
verb: 'get' as K8sVerb,
162+
resource: ApplicationModel.plural,
163+
namespace: application?.metadata?.namespace,
164+
},
165+
cta: () => {
166+
window.open(href, '_blank');
167+
},
168+
},
169+
]
170+
: []),
169171
],
170172
[application, navigate, launchLabelsModal, launchAnnotationsModal, launchDeleteModal, href],
171173
);

‎src/gitops/hooks/useResourceActionsProvider.tsx‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,23 @@ export const useResourceActionsProvider: UseResourceActionsProvider = (
5050
const launchDeleteModal = useDeleteModal(placeholderResource);
5151
const actions = React.useMemo(
5252
() => [
53-
{
54-
id: 'gitops-action-view-in-argocd',
55-
disabled: false,
56-
label: t('View in Argo CD'),
57-
accessReview: {
58-
group: ApplicationModel.apiGroup,
59-
verb: 'patch' as K8sVerb,
60-
resource: ApplicationModel.plural,
61-
namespace: application?.metadata?.namespace,
62-
},
63-
cta: () => {
64-
window.open(getResourceURL(argoBaseURL, resource), '_blank');
65-
},
66-
},
53+
...(argoBaseURL
54+
? [
55+
{
56+
id: 'gitops-action-view-in-argocd',
57+
label: t('View in Argo CD'),
58+
accessReview: {
59+
group: ApplicationModel.apiGroup,
60+
verb: 'patch' as K8sVerb,
61+
resource: ApplicationModel.plural,
62+
namespace: application?.metadata?.namespace,
63+
},
64+
cta: () => {
65+
window.open(getResourceURL(argoBaseURL, resource), '_blank');
66+
},
67+
},
68+
]
69+
: []),
6770
// {
6871
// id: 'gitops-action-sync-resource',
6972
// disabled: resource.status==undefined,

‎src/gitops/utils/gitops.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ describe('getApplicationArgoUrl', () => {
1717
).toBe('https://openshift-gitops-server-openshift-gitops/applications/openshift-gitops/guestbook');
1818
});
1919

20-
it('returns empty string when server or app metadata is missing', () => {
21-
expect(getApplicationArgoUrl({ protocol: 'https', host: '' }, {} as any)).toBe('');
20+
it('returns undefined when server or app metadata is missing', () => {
21+
expect(getApplicationArgoUrl({ protocol: 'https', host: '' }, {} as any)).toBe(undefined);
2222
expect(
2323
getApplicationArgoUrl({ protocol: 'https', host: 'openshift-gitops-server-openshift-gitops' }, undefined),
24-
).toBe('');
24+
).toBe(undefined);
2525
});
2626
});
2727

‎src/gitops/utils/gitops.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const getArgoServer = async (model, app: ApplicationKind): Promise<ArgoSe
101101

102102
export const getApplicationArgoUrl = (argoServer: ArgoServer, app?: ApplicationKind): string => {
103103
if (!argoServer.host || !app?.metadata?.name || !app?.metadata?.namespace) {
104-
return '';
104+
return undefined;
105105
}
106106

107107
return `${argoServer.protocol}://${argoServer.host}/applications/${app.metadata.namespace}/${app.metadata.name}`;

0 commit comments

Comments
 (0)