From 4d40502060be619f5862701e3dc6831460883926 Mon Sep 17 00:00:00 2001 From: Lokananda Prabhu Date: Thu, 17 Oct 2024 17:42:30 +0530 Subject: [PATCH 1/2] Removed All option in project dropdown in overview page for users don't have access --- console-extensions.json | 37 +++++++++++++++---- .../pipelines-overview/NamespaceDropdown.tsx | 12 ++++-- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/console-extensions.json b/console-extensions.json index 100ae3a7..8419e1ff 100644 --- a/console-extensions.json +++ b/console-extensions.json @@ -144,10 +144,7 @@ "type": "console.page/route", "properties": { "exact": true, - "path": [ - "/pipelines-overview/ns/:ns", - "/pipelines-overview/all-namespaces" - ], + "path": ["/pipelines-overview/ns/:ns"], "component": { "$codeRef": "pipelinesComponent.PipelinesOverviewPage" } @@ -160,10 +157,7 @@ "type": "console.page/route", "properties": { "exact": true, - "path": [ - "/pipelines-overview/ns/:ns", - "/pipelines-overview/all-namespaces" - ], + "path": ["/pipelines-overview/ns/:ns"], "component": { "$codeRef": "pipelinesComponent.PipelinesOverviewPageK8s" } @@ -173,6 +167,33 @@ "disallowed": ["PIPELINE_TEKTON_RESULT_INSTALLED"] } }, + { + "type": "console.page/route", + "properties": { + "exact": true, + "path": ["/pipelines-overview/all-namespaces"], + "component": { + "$codeRef": "pipelinesComponent.PipelinesOverviewPage" + } + }, + "flags": { + "required": ["PIPELINE_TEKTON_RESULT_INSTALLED", "CAN_LIST_NS"] + } + }, + { + "type": "console.page/route", + "properties": { + "exact": true, + "path": ["/pipelines-overview/all-namespaces"], + "component": { + "$codeRef": "pipelinesComponent.PipelinesOverviewPageK8s" + } + }, + "flags": { + "required": ["OPENSHIFT_PIPELINE", "CAN_LIST_NS"], + "disallowed": ["PIPELINE_TEKTON_RESULT_INSTALLED"] + } + }, { "type": "console.navigation/href", "properties": { diff --git a/src/components/pipelines-overview/NamespaceDropdown.tsx b/src/components/pipelines-overview/NamespaceDropdown.tsx index 8d400d87..b2f43dd3 100644 --- a/src/components/pipelines-overview/NamespaceDropdown.tsx +++ b/src/components/pipelines-overview/NamespaceDropdown.tsx @@ -11,9 +11,13 @@ import { alphanumericCompare } from './utils'; import { useTranslation } from 'react-i18next'; import './PipelinesOverview.scss'; -import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; +import { + useFlag, + useK8sWatchResource, +} from '@openshift-console/dynamic-plugin-sdk'; import { Project } from '../../types/openshift'; import { ALL_NAMESPACES_KEY } from '../../consts'; +import { FLAGS } from '../../types'; interface NameSpaceDropdownProps { selected: string; @@ -26,6 +30,7 @@ const NameSpaceDropdown: React.FC = ({ }) => { const { t } = useTranslation('plugin__pipelines-console-plugin'); const [isOpen, setValue] = React.useState(false); + const canListNS = useFlag(FLAGS.CAN_LIST_NS); const toggleIsOpen = React.useCallback(() => setValue((v) => !v), []); const setClosed = React.useCallback(() => setValue(false), []); @@ -53,8 +58,9 @@ const NameSpaceDropdown: React.FC = ({ items.push({ title: selected, key: selected }); // Add current namespace if it isn't included } items.sort((a, b) => alphanumericCompare(a.title, b.title)); - - items.unshift({ title: allNamespacesTitle, key: ALL_NAMESPACES_KEY }); + if (canListNS) { + items.unshift({ title: allNamespacesTitle, key: ALL_NAMESPACES_KEY }); + } return items; }, [projects, projectsLoaded]); From ef9945466a28e230c69e9f9aa9bd1919a11781c9 Mon Sep 17 00:00:00 2001 From: Lokananda Prabhu Date: Thu, 24 Oct 2024 15:04:26 +0530 Subject: [PATCH 2/2] Added project select page for non-admin user for all namespace --- console-extensions.json | 37 ++++--------------- .../PipelinesOverviewPage.tsx | 34 +++++++++++------ .../PipelinesOverviewPageK8s.tsx | 32 ++++++++++------ .../projects-list/AllProjectsPage.tsx | 8 +++- 4 files changed, 57 insertions(+), 54 deletions(-) diff --git a/console-extensions.json b/console-extensions.json index 8419e1ff..100ae3a7 100644 --- a/console-extensions.json +++ b/console-extensions.json @@ -144,7 +144,10 @@ "type": "console.page/route", "properties": { "exact": true, - "path": ["/pipelines-overview/ns/:ns"], + "path": [ + "/pipelines-overview/ns/:ns", + "/pipelines-overview/all-namespaces" + ], "component": { "$codeRef": "pipelinesComponent.PipelinesOverviewPage" } @@ -157,7 +160,10 @@ "type": "console.page/route", "properties": { "exact": true, - "path": ["/pipelines-overview/ns/:ns"], + "path": [ + "/pipelines-overview/ns/:ns", + "/pipelines-overview/all-namespaces" + ], "component": { "$codeRef": "pipelinesComponent.PipelinesOverviewPageK8s" } @@ -167,33 +173,6 @@ "disallowed": ["PIPELINE_TEKTON_RESULT_INSTALLED"] } }, - { - "type": "console.page/route", - "properties": { - "exact": true, - "path": ["/pipelines-overview/all-namespaces"], - "component": { - "$codeRef": "pipelinesComponent.PipelinesOverviewPage" - } - }, - "flags": { - "required": ["PIPELINE_TEKTON_RESULT_INSTALLED", "CAN_LIST_NS"] - } - }, - { - "type": "console.page/route", - "properties": { - "exact": true, - "path": ["/pipelines-overview/all-namespaces"], - "component": { - "$codeRef": "pipelinesComponent.PipelinesOverviewPageK8s" - } - }, - "flags": { - "required": ["OPENSHIFT_PIPELINE", "CAN_LIST_NS"], - "disallowed": ["PIPELINE_TEKTON_RESULT_INSTALLED"] - } - }, { "type": "console.navigation/href", "properties": { diff --git a/src/components/pipelines-overview/PipelinesOverviewPage.tsx b/src/components/pipelines-overview/PipelinesOverviewPage.tsx index 0e719df6..85b5b329 100644 --- a/src/components/pipelines-overview/PipelinesOverviewPage.tsx +++ b/src/components/pipelines-overview/PipelinesOverviewPage.tsx @@ -1,7 +1,11 @@ import * as React from 'react'; import { useTranslation } from 'react-i18next'; -import PipelineRunsStatusCard from './PipelineRunsStatusCard'; import { Flex, FlexItem } from '@patternfly/react-core'; +import PipelineRunsStatusCard from './PipelineRunsStatusCard'; +import { + useActiveNamespace, + useFlag, +} from '@openshift-console/dynamic-plugin-sdk'; import PipelinesRunsDurationCard from './PipelineRunsDurationCard'; import PipelinesRunsTotalCard from './PipelineRunsTotalCard'; import PipelinesRunsNumbersChart from './PipelineRunsNumbersChart'; @@ -11,19 +15,18 @@ import PipelineRunsListPage from './list-pages/PipelineRunsListPage'; import TimeRangeDropdown from './TimeRangeDropdown'; import RefreshDropdown from './RefreshDropdown'; import { IntervalOptions, TimeRangeOptions, useQueryParams } from './utils'; -import { useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk'; +import { ALL_NAMESPACES_KEY } from '../../consts'; +import AllProjectsPage from '../projects-list/AllProjectsPage'; +import { FLAGS } from '../../types'; const PipelinesOverviewPage: React.FC = () => { const { t } = useTranslation('plugin__pipelines-console-plugin'); + const canListNS = useFlag(FLAGS.CAN_LIST_NS); const [activeNamespace, setActiveNamespace] = useActiveNamespace(); - const [namespace, setNamespace] = React.useState(activeNamespace); const [timespan, setTimespan] = React.useState(parsePrometheusDuration('1d')); const [interval, setInterval] = React.useState( parsePrometheusDuration('30s'), ); - React.useEffect(() => { - setActiveNamespace(namespace); - }, [namespace]); useQueryParams({ key: 'refreshinterval', @@ -45,6 +48,10 @@ const PipelinesOverviewPage: React.FC = () => { loadFormat: parsePrometheusDuration, }); + if (!canListNS && activeNamespace === ALL_NAMESPACES_KEY) { + return ; + } + return ( <>
@@ -54,7 +61,10 @@ const PipelinesOverviewPage: React.FC = () => {
- + @@ -68,7 +78,7 @@ const PipelinesOverviewPage: React.FC = () => { timespan={timespan} domain={{ y: [0, 100] }} bordered={true} - namespace={namespace} + namespace={activeNamespace} interval={interval} /> @@ -79,7 +89,7 @@ const PipelinesOverviewPage: React.FC = () => { className="pipelines-overview__cards" > { className="pipelines-overview__cards" > { className="pipelines-overview__cards" > {
diff --git a/src/components/pipelines-overview/PipelinesOverviewPageK8s.tsx b/src/components/pipelines-overview/PipelinesOverviewPageK8s.tsx index 60e95872..b0ff9837 100644 --- a/src/components/pipelines-overview/PipelinesOverviewPageK8s.tsx +++ b/src/components/pipelines-overview/PipelinesOverviewPageK8s.tsx @@ -1,31 +1,34 @@ import * as React from 'react'; import { useTranslation } from 'react-i18next'; import { Flex, FlexItem } from '@patternfly/react-core'; +import { + useActiveNamespace, + useFlag, +} from '@openshift-console/dynamic-plugin-sdk'; import { formatPrometheusDuration, parsePrometheusDuration } from './dateTime'; import NameSpaceDropdown from './NamespaceDropdown'; import TimeRangeDropdown from './TimeRangeDropdown'; import RefreshDropdown from './RefreshDropdown'; import { IntervalOptions, TimeRangeOptionsK8s, useQueryParams } from './utils'; -import { useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk'; import PipelineRunsStatusCardK8s from './PipelineRunsStatusCardK8s'; import PipelineRunsNumbersChartK8s from './PipelineRunsNumbersChartK8s'; import PipelineRunsTotalCardK8s from './PipelineRunsTotalCardK8s'; import PipelineRunsDurationCardK8s from './PipelineRunsDurationCardK8s'; import PipelineRunsListPageK8s from './list-pages/PipelineRunsListPageK8s'; import { K8sDataLimitationAlert } from './K8sDataLimitationAlert'; +import { FLAGS } from '../../types'; +import { ALL_NAMESPACES_KEY } from '../../consts'; +import AllProjectsPage from '../projects-list/AllProjectsPage'; import './PipelinesOverview.scss'; const PipelinesOverviewPageK8s: React.FC = () => { const { t } = useTranslation('plugin__pipelines-console-plugin'); + const canListNS = useFlag(FLAGS.CAN_LIST_NS); const [activeNamespace, setActiveNamespace] = useActiveNamespace(); - const [namespace, setNamespace] = React.useState(activeNamespace); const [timespan, setTimespan] = React.useState(parsePrometheusDuration('1d')); const [interval, setInterval] = React.useState( parsePrometheusDuration('30s'), ); - React.useEffect(() => { - setActiveNamespace(namespace); - }, [namespace]); useQueryParams({ key: 'refreshinterval', @@ -47,6 +50,10 @@ const PipelinesOverviewPageK8s: React.FC = () => { loadFormat: parsePrometheusDuration, }); + if (!canListNS && activeNamespace === ALL_NAMESPACES_KEY) { + return ; + } + return ( <>
@@ -59,7 +66,10 @@ const PipelinesOverviewPageK8s: React.FC = () => {
- + @@ -73,7 +83,7 @@ const PipelinesOverviewPageK8s: React.FC = () => { timespan={timespan} domain={{ y: [0, 100] }} bordered={true} - namespace={namespace} + namespace={activeNamespace} interval={interval} /> @@ -84,7 +94,7 @@ const PipelinesOverviewPageK8s: React.FC = () => { className="pipelines-overview__cards" > { className="pipelines-overview__cards" > { className="pipelines-overview__cards" > {
diff --git a/src/components/projects-list/AllProjectsPage.tsx b/src/components/projects-list/AllProjectsPage.tsx index bdb7643a..90640475 100644 --- a/src/components/projects-list/AllProjectsPage.tsx +++ b/src/components/projects-list/AllProjectsPage.tsx @@ -10,11 +10,15 @@ import { useTranslation } from 'react-i18next'; import ProjectsList from './ProjectsList'; import './AllProjectsPage.scss'; -const AllProjectsPage = () => { +interface AllProjectsPageProps { + pageTitle?: string; +} + +const AllProjectsPage: React.FC = ({ pageTitle }) => { const { t } = useTranslation('plugin__pipelines-console-plugin'); return ( <> - + {t('Select a Project to view its details')}