Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions locales/en/olm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Show operands in:": "Show operands in:",
"All namespaces": "All namespaces",
"Current namespace only": "Current namespace only"
}
5 changes: 5 additions & 0 deletions locales/ja/olm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Show operands in:": "Show operands in:",
"All namespaces": "All namespaces",
"Current namespace only": "Current namespace only"
}
5 changes: 5 additions & 0 deletions locales/ko/olm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Show operands in:": "Show operands in:",
"All namespaces": "All namespaces",
"Current namespace only": "Current namespace only"
}
5 changes: 5 additions & 0 deletions locales/zh/olm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Show operands in:": "Show operands in:",
"All namespaces": "All namespaces",
"Current namespace only": "Current namespace only"
}
22 changes: 18 additions & 4 deletions src/gitops/components/project/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import { Tbody, Td, Tr } from '@patternfly/react-table';

import { ApplicationKind } from '../../models/ApplicationModel';
import { AppProjectKind, AppProjectModel } from '../../models/AppProjectModel';
import {
ShowOperandsInAllNamespacesRadioGroup,
useShowOperandsInAllNamespaces,
} from '../shared/AllNamespaces';
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';

import { useProjectActionsProvider } from './hooks/useProjectActionsProvider';
Expand All @@ -53,14 +57,20 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
showTitle,
}) => {
const location = useLocation();
const [showOperandsInAllNamespaces] = useShowOperandsInAllNamespaces();
const listAllNamespaces =
location.pathname?.includes('openshift-gitops-operator') && showOperandsInAllNamespaces;
if (listAllNamespaces) {
namespace = null;
}
const [appProjects, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
isList: true,
groupVersionKind: {
group: 'argoproj.io',
kind: 'AppProject',
version: 'v1alpha1',
},
namespaced: true,
namespaced: !listAllNamespaces,
namespace,
});

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

const columnSortConfig = React.useMemo(() => {
const showNamespace = !namespace || namespace === '';
return [
'name',
...(showNamespace ? ['namespace'] : []),
...(!listAllNamespaces || !namespace || namespace === '' ? ['namespace'] : []),
'description',
'applications',
'labels',
'last-updated',
'actions',
].map((key) => ({ key }));
}, [namespace]);
}, [listAllNamespaces, namespace]);

const { searchParams, sortBy, direction, getSortParams } =
useGitOpsDataViewSort(columnSortConfig);
Expand Down Expand Up @@ -195,6 +204,11 @@ const ProjectList: React.FC<ProjectListTabProps> = ({
badge={
location?.pathname?.includes('openshift-gitops-operator') ? null : <DevPreviewBadge />
}
helpText={
location.pathname?.includes('openshift-gitops-operator') ? (
<ShowOperandsInAllNamespacesRadioGroup />
) : null
}
hideFavoriteButton={false}
>
<ListPageCreate groupVersionKind={modelToRef(AppProjectModel)}>
Expand Down
24 changes: 20 additions & 4 deletions src/gitops/components/rollout/RolloutList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import { DataViewTh, DataViewTr } from '@patternfly/react-data-view/dist/esm/Dat
import { CubesIcon, SearchIcon } from '@patternfly/react-icons';
import { Tbody, Td, ThProps, Tr } from '@patternfly/react-table';

import {
ShowOperandsInAllNamespacesRadioGroup,
useShowOperandsInAllNamespaces,
} from '../shared/AllNamespaces';
import { GitOpsDataViewTable, useGitOpsDataViewSort } from '../shared/DataView';

import { useRolloutActionsProvider } from './hooks/useRolloutActionsProvider';
Expand Down Expand Up @@ -73,29 +77,35 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
hideNameLabelFilters,
showTitle,
}) => {
const [showOperandsInAllNamespaces] = useShowOperandsInAllNamespaces();
const listAllNamespaces =
location.pathname?.includes('openshift-gitops-operator') && showOperandsInAllNamespaces;
if (listAllNamespaces) {
namespace = null;
}
const [rollouts, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
isList: true,
groupVersionKind: {
group: 'argoproj.io',
kind: 'Rollout',
version: 'v1alpha1',
},
namespaced: true,
namespaced: !listAllNamespaces,
namespace,
});
const columnSortConfig = React.useMemo(
() =>
[
'name',
...(!namespace ? ['namespace'] : []),
...(!listAllNamespaces || !namespace ? ['namespace'] : []),
'status',
'pods',
'labels',
'selector',
'last-updated',
'actions',
].map((key) => ({ key })),
[namespace],
[listAllNamespaces, namespace],
);

const { searchParams, sortBy, direction, getSortParams } =
Expand Down Expand Up @@ -153,7 +163,7 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
<ErrorState
titleText={t('Unable to load data')}
bodyText={t(
'There was an error retrieving applications. Check your connection and reload the page.',
'There was an error retrieving rollouts. Check your connection and reload the page.',
)}
/>
</Td>
Expand All @@ -164,6 +174,7 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
const topologyUrl = namespace
? '/topology/ns/' + namespace + '?view=graph'
: '/topology/all-namespaces?view=graph';

return (
<>
{showTitle == undefined && (
Expand All @@ -172,6 +183,11 @@ const RolloutList: React.FC<RolloutListTabProps> = ({
badge={
location.pathname?.includes('openshift-gitops-operator') ? null : <DevPreviewBadge />
}
helpText={
location.pathname?.includes('openshift-gitops-operator') ? (
<ShowOperandsInAllNamespacesRadioGroup />
) : null
}
>
<ListPageCreate groupVersionKind={modelToRef(RolloutModel)}>
{t('Create Rollout')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ const Metrics: React.FC<MetricsProps> = ({ arInfo }) => {
}
return (
<>
<DescriptionList
isHorizontal
isCompact
className="gitops_plugin__tight_description_list"
>
<DescriptionList isHorizontal isCompact className="gitops_plugin__tight_description_list">
<DescriptionListGroup>
<DescriptionListTerm>Started At:</DescriptionListTerm>
<DescriptionListDescription>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';

import { t } from '@gitops/utils/hooks/useGitOpsTranslation';
import { useShowOperandsInAllNamespaces } from '@gitops-shared/AllNamespaces/useShowOperandsInAllNamespaces';
import { Form, FormGroup, Radio } from '@patternfly/react-core';

export const ShowOperandsInAllNamespacesRadioGroup: React.FC = () => {
const [showOperandsInAllNamespaces, setShowOperandsInAllNamespaces] =
useShowOperandsInAllNamespaces();
return (
<Form isHorizontal>
<FormGroup
role="radiogroup"
fieldId="show-operands"
label={t('olm~Show operands in:')}
isInline
hasNoPaddingTop
>
<Radio
id="all-namespaces"
name="show-operands"
value="true"
label={t('olm~All namespaces')}
onChange={() => setShowOperandsInAllNamespaces(true)}
isChecked={showOperandsInAllNamespaces}
data-checked-state={showOperandsInAllNamespaces}
/>
<Radio
id="current-namespace-only"
name="show-operands"
value="false"
label={t('olm~Current namespace only')}
onChange={() => setShowOperandsInAllNamespaces(false)}
isChecked={!showOperandsInAllNamespaces}
data-checked-state={!showOperandsInAllNamespaces}
/>
</FormGroup>
</Form>
);
};
2 changes: 2 additions & 0 deletions src/gitops/components/shared/AllNamespaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ShowOperandsInAllNamespacesRadioGroup';
export * from './useShowOperandsInAllNamespaces';
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback } from 'react';
import { RootStateOrAny, useDispatch, useSelector } from 'react-redux';
import { action } from 'typesafe-actions';
type UseShowOperandsInAllNamespaces = () => [boolean, (value: boolean) => void];

// This hook can be used to consume and update the showOperandsInAllNamespaces redux state
export const useShowOperandsInAllNamespaces: UseShowOperandsInAllNamespaces = () => {
const dispatch = useDispatch();
const showOperandsInAllNamespaces = useSelector((state: RootStateOrAny) =>
state.UI.get('showOperandsInAllNamespaces'),
);
const setShowOperandsInAllNamespaces = useCallback(
(value: boolean) => dispatch(uiActionsSetShowOperandsInAllNamespaces(value)),
[dispatch],
);
return [showOperandsInAllNamespaces, setShowOperandsInAllNamespaces];
};

export enum ActionType {
SetShowOperandsInAllNamespaces = 'setShowOperandsInAllNamespaces',
}

export const uiActionsSetShowOperandsInAllNamespaces = (value: boolean) => {
return action(ActionType.SetShowOperandsInAllNamespaces, { value });
};
37 changes: 34 additions & 3 deletions src/gitops/components/shared/ApplicationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useK8sWatchResource,
useListPageFilter,
} from '@openshift-console/dynamic-plugin-sdk';
import { ErrorState } from '@patternfly/react-component-groups';
import { EmptyState, EmptyStateBody, Flex, FlexItem, Spinner } from '@patternfly/react-core';
import { DataViewTh, DataViewTr } from '@patternfly/react-data-view/dist/esm/DataViewTable';
import { CubesIcon } from '@patternfly/react-icons';
Expand All @@ -35,6 +36,10 @@ import ActionsDropdown from '../../utils/components/ActionDropDown/ActionDropDow
import { isApplicationRefreshing } from '../../utils/gitops';
import { modelToGroupVersionKind, modelToRef } from '../../utils/utils';

import {
ShowOperandsInAllNamespacesRadioGroup,
useShowOperandsInAllNamespaces,
} from './AllNamespaces';
import { GitOpsDataViewTable, useGitOpsDataViewSort } from './DataView';

interface ApplicationProps {
Expand Down Expand Up @@ -72,14 +77,20 @@ const ApplicationList: React.FC<ApplicationProps> = ({
hideNameLabelFilters,
showTitle,
}) => {
const [showOperandsInAllNamespaces] = useShowOperandsInAllNamespaces();
const listAllNamespaces =
location.pathname?.includes('openshift-gitops-operator') && showOperandsInAllNamespaces;
if (listAllNamespaces) {
namespace = null;
}
const [applications, loaded, loadError] = useK8sWatchResource<K8sResourceCommon[]>({
isList: true,
groupVersionKind: {
group: 'argoproj.io',
kind: 'Application',
version: 'v1alpha1',
},
namespaced: true,
namespaced: !listAllNamespaces,
namespace,
});

Expand All @@ -88,14 +99,14 @@ const ApplicationList: React.FC<ApplicationProps> = ({
() =>
[
'name',
...(!namespace ? ['namespace'] : []),
...(!listAllNamespaces || !namespace ? ['namespace'] : []),
'sync-status',
'health-status',
'revision',
'project',
'actions',
].map((key) => ({ key })),
[namespace],
[listAllNamespaces, namespace],
);

const { searchParams, sortBy, direction, getSortParams } =
Expand Down Expand Up @@ -173,6 +184,20 @@ const ApplicationList: React.FC<ApplicationProps> = ({
</Tr>
</Tbody>
);
const error = loadError && (
<Tbody>
<Tr key="loading" ouiaId={'table-tr-loading'}>
<Td colSpan={columnsDV.length}>
<ErrorState
titleText={t('Unable to load data')}
bodyText={t(
'There was an error retrieving applications. Check your connection and reload the page.',
)}
/>
</Td>
</Tr>
</Tbody>
);
return (
<div>
{showTitle == undefined && (project == undefined || appset == undefined) && (
Expand All @@ -181,6 +206,11 @@ const ApplicationList: React.FC<ApplicationProps> = ({
badge={
location.pathname?.includes('openshift-gitops-operator') ? null : <DevPreviewBadge />
}
helpText={
location.pathname?.includes('openshift-gitops-operator') ? (
<ShowOperandsInAllNamespacesRadioGroup />
) : null
}
hideFavoriteButton={false}
>
<ListPageCreate groupVersionKind={modelToRef(ApplicationModel)}>
Expand All @@ -203,6 +233,7 @@ const ApplicationList: React.FC<ApplicationProps> = ({
rows={rows}
isEmpty={filteredBySearch.length === 0}
emptyState={empty}
errorState={error || undefined}
isError={!!loadError}
/>
</ListPageBody>
Expand Down
Loading