Skip to content

Commit 26311b3

Browse files
committed
Show All Namespaces or Current Namespace Only option (#8535)
Signed-off-by: Keith Chong <kykchong@redhat.com>
1 parent 39991aa commit 26311b3

File tree

12 files changed

+179
-19
lines changed

12 files changed

+179
-19
lines changed

locales/en/olm.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Show operands in:": "Show operands in:",
3+
"All namespaces": "All namespaces",
4+
"Current namespace only": "Current namespace only"
5+
}

locales/ja/olm.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Show operands in:": "Show operands in:",
3+
"All namespaces": "All namespaces",
4+
"Current namespace only": "Current namespace only"
5+
}

locales/ko/olm.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Show operands in:": "Show operands in:",
3+
"All namespaces": "All namespaces",
4+
"Current namespace only": "Current namespace only"
5+
}

locales/zh/olm.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Show operands in:": "Show operands in:",
3+
"All namespaces": "All namespaces",
4+
"Current namespace only": "Current namespace only"
5+
}

src/gitops/components/project/ProjectList.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ import { Tbody, Td, Tr } from '@patternfly/react-table';
3535

3636
import { ApplicationKind } from '../../models/ApplicationModel';
3737
import { AppProjectKind, AppProjectModel } from '../../models/AppProjectModel';
38+
import {
39+
ShowOperandsInAllNamespacesRadioGroup,
40+
useShowOperandsInAllNamespaces,
41+
} from '../shared/AllNamespaces';
3842
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';
3943

4044
import { useProjectActionsProvider } from './hooks/useProjectActionsProvider';
@@ -53,14 +57,20 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
5357
showTitle,
5458
}) => {
5559
const location = useLocation();
60+
const [showOperandsInAllNamespaces] = useShowOperandsInAllNamespaces();
61+
const listAllNamespaces =
62+
location.pathname?.includes('openshift-gitops-operator') && showOperandsInAllNamespaces;
63+
if (listAllNamespaces) {
64+
namespace = null;
65+
}
5666
const [appProjects, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
5767
isList: true,
5868
groupVersionKind: {
5969
group: 'argoproj.io',
6070
kind: 'AppProject',
6171
version: 'v1alpha1',
6272
},
63-
namespaced: true,
73+
namespaced: !listAllNamespaces,
6474
namespace,
6575
});
6676

@@ -77,17 +87,16 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
7787
});
7888

7989
const columnSortConfig = React.useMemo(() => {
80-
const showNamespace = !namespace || namespace === '';
8190
return [
8291
'name',
83-
...(showNamespace ? ['namespace'] : []),
92+
...(!listAllNamespaces || !namespace || namespace === '' ? ['namespace'] : []),
8493
'description',
8594
'applications',
8695
'labels',
8796
'last-updated',
8897
'actions',
8998
].map((key) => ({ key }));
90-
}, [namespace]);
99+
}, [listAllNamespaces, namespace]);
91100

92101
const { searchParams, sortBy, direction, getSortParams } =
93102
useGitOpsDataViewSort(columnSortConfig);
@@ -195,6 +204,11 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
195204
badge={
196205
location?.pathname?.includes('openshift-gitops-operator') ? null : <DevPreviewBadge />
197206
}
207+
helpText={
208+
location.pathname?.includes('openshift-gitops-operator') ? (
209+
<ShowOperandsInAllNamespacesRadioGroup />
210+
) : null
211+
}
198212
hideFavoriteButton={false}
199213
>
200214
<ListPageCreate groupVersionKind={modelToRef(AppProjectModel)}>

src/gitops/components/rollout/RolloutList.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import { DataViewTh, DataViewTr } from '@patternfly/react-data-view/dist/esm/Dat
3434
import { CubesIcon, SearchIcon } from '@patternfly/react-icons';
3535
import { Tbody, Td, ThProps, Tr } from '@patternfly/react-table';
3636

37+
import {
38+
ShowOperandsInAllNamespacesRadioGroup,
39+
useShowOperandsInAllNamespaces,
40+
} from '../shared/AllNamespaces';
3741
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';
3842

3943
import { useRolloutActionsProvider } from './hooks/useRolloutActionsProvider';
@@ -73,29 +77,35 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
7377
hideNameLabelFilters,
7478
showTitle,
7579
}) => {
80+
const [showOperandsInAllNamespaces] = useShowOperandsInAllNamespaces();
81+
const listAllNamespaces =
82+
location.pathname?.includes('openshift-gitops-operator') && showOperandsInAllNamespaces;
83+
if (listAllNamespaces) {
84+
namespace = null;
85+
}
7686
const [rollouts, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
7787
isList: true,
7888
groupVersionKind: {
7989
group: 'argoproj.io',
8090
kind: 'Rollout',
8191
version: 'v1alpha1',
8292
},
83-
namespaced: true,
93+
namespaced: !listAllNamespaces,
8494
namespace,
8595
});
8696
const columnSortConfig = React.useMemo(
8797
() =>
8898
[
8999
'name',
90-
...(!namespace ? ['namespace'] : []),
100+
...(!listAllNamespaces || !namespace ? ['namespace'] : []),
91101
'status',
92102
'pods',
93103
'labels',
94104
'selector',
95105
'last-updated',
96106
'actions',
97107
].map((key) => ({ key })),
98-
[namespace],
108+
[listAllNamespaces, namespace],
99109
);
100110

101111
const { searchParams, sortBy, direction, getSortParams } =
@@ -153,7 +163,7 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
153163
<ErrorState
154164
titleText={t('Unable to load data')}
155165
bodyText={t(
156-
'There was an error retrieving applications. Check your connection and reload the page.',
166+
'There was an error retrieving rollouts. Check your connection and reload the page.',
157167
)}
158168
/>
159169
</Td>
@@ -164,6 +174,7 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
164174
const topologyUrl = namespace
165175
? '/topology/ns/' + namespace + '?view=graph'
166176
: '/topology/all-namespaces?view=graph';
177+
167178
return (
168179
<>
169180
{showTitle == undefined && (
@@ -172,6 +183,11 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
172183
badge={
173184
location.pathname?.includes('openshift-gitops-operator') ? null : <DevPreviewBadge />
174185
}
186+
helpText={
187+
location.pathname?.includes('openshift-gitops-operator') ? (
188+
<ShowOperandsInAllNamespacesRadioGroup />
189+
) : null
190+
}
175191
>
176192
<ListPageCreate groupVersionKind={modelToRef(RolloutModel)}>
177193
{t('Create Rollout')}

src/gitops/components/rollout/components/AnalysisRunStatus/AnalysisRunStatus.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ const Metrics: React.FC<MetricsProps> = ({ arInfo }) => {
101101
}
102102
return (
103103
<>
104-
<DescriptionList
105-
isHorizontal
106-
isCompact
107-
className="gitops_plugin__tight_description_list"
108-
>
104+
<DescriptionList isHorizontal isCompact className="gitops_plugin__tight_description_list">
109105
<DescriptionListGroup>
110106
<DescriptionListTerm>Started At:</DescriptionListTerm>
111107
<DescriptionListDescription>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react';
2+
3+
import { t } from '@gitops/utils/hooks/useGitOpsTranslation';
4+
import { useShowOperandsInAllNamespaces } from '@gitops-shared/AllNamespaces/useShowOperandsInAllNamespaces';
5+
import { Form, FormGroup, Radio } from '@patternfly/react-core';
6+
7+
export const ShowOperandsInAllNamespacesRadioGroup: React.FC = () => {
8+
const [showOperandsInAllNamespaces, setShowOperandsInAllNamespaces] =
9+
useShowOperandsInAllNamespaces();
10+
return (
11+
<Form isHorizontal>
12+
<FormGroup
13+
role="radiogroup"
14+
fieldId="show-operands"
15+
label={t('olm~Show operands in:')}
16+
isInline
17+
hasNoPaddingTop
18+
>
19+
<Radio
20+
id="all-namespaces"
21+
name="show-operands"
22+
value="true"
23+
label={t('olm~All namespaces')}
24+
onChange={() => setShowOperandsInAllNamespaces(true)}
25+
isChecked={showOperandsInAllNamespaces}
26+
data-checked-state={showOperandsInAllNamespaces}
27+
/>
28+
<Radio
29+
id="current-namespace-only"
30+
name="show-operands"
31+
value="false"
32+
label={t('olm~Current namespace only')}
33+
onChange={() => setShowOperandsInAllNamespaces(false)}
34+
isChecked={!showOperandsInAllNamespaces}
35+
data-checked-state={!showOperandsInAllNamespaces}
36+
/>
37+
</FormGroup>
38+
</Form>
39+
);
40+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './ShowOperandsInAllNamespacesRadioGroup';
2+
export * from './useShowOperandsInAllNamespaces';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useCallback } from 'react';
2+
import { RootStateOrAny, useDispatch, useSelector } from 'react-redux';
3+
import { action } from 'typesafe-actions';
4+
type UseShowOperandsInAllNamespaces = () => [boolean, (value: boolean) => void];
5+
6+
// This hook can be used to consume and update the showOperandsInAllNamespaces redux state
7+
export const useShowOperandsInAllNamespaces: UseShowOperandsInAllNamespaces = () => {
8+
const dispatch = useDispatch();
9+
const showOperandsInAllNamespaces = useSelector((state: RootStateOrAny) =>
10+
state.UI.get('showOperandsInAllNamespaces'),
11+
);
12+
const setShowOperandsInAllNamespaces = useCallback(
13+
(value: boolean) => dispatch(uiActionsSetShowOperandsInAllNamespaces(value)),
14+
[dispatch],
15+
);
16+
return [showOperandsInAllNamespaces, setShowOperandsInAllNamespaces];
17+
};
18+
19+
export enum ActionType {
20+
SetShowOperandsInAllNamespaces = 'setShowOperandsInAllNamespaces',
21+
}
22+
23+
export const uiActionsSetShowOperandsInAllNamespaces = (value: boolean) => {
24+
return action(ActionType.SetShowOperandsInAllNamespaces, { value });
25+
};

0 commit comments

Comments
 (0)