From 2d11f9bf663190db3931fcc013525ea43f3a5ca1 Mon Sep 17 00:00:00 2001 From: Jason Madigan Date: Thu, 17 Oct 2024 17:37:57 +0100 Subject: [PATCH] Create button for the All Policies page Signed-off-by: Jason Madigan --- .../en/plugin__kuadrant-console-plugin.json | 3 +- src/components/KuadrantPoliciesPage.tsx | 86 ++++++++++++++++--- src/components/kuadrant.css | 4 + 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/locales/en/plugin__kuadrant-console-plugin.json b/locales/en/plugin__kuadrant-console-plugin.json index c5976ef..fb4f0bf 100644 --- a/locales/en/plugin__kuadrant-console-plugin.json +++ b/locales/en/plugin__kuadrant-console-plugin.json @@ -112,5 +112,6 @@ "View Documentation": "View Documentation", "Visit the blog": "Visit the blog", "YAML View": "YAML View", - "You can view and create HTTPRoutes": "You can view and create HTTPRoutes" + "You can view and create HTTPRoutes": "You can view and create HTTPRoutes", + "Create Policy": "Create Policy" } \ No newline at end of file diff --git a/src/components/KuadrantPoliciesPage.tsx b/src/components/KuadrantPoliciesPage.tsx index 6d9f7e6..9051b3c 100644 --- a/src/components/KuadrantPoliciesPage.tsx +++ b/src/components/KuadrantPoliciesPage.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; -import { useParams } from 'react-router-dom'; +import { useState } from 'react'; +import { useParams, useHistory } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { sortable } from '@patternfly/react-table'; import { @@ -10,11 +11,19 @@ import { useActiveNamespace, useActivePerspective, ListPageCreateLink, - ListPageBody + ListPageBody, } from '@openshift-console/dynamic-plugin-sdk'; import { Title } from '@patternfly/react-core'; -import { Alert, AlertGroup } from '@patternfly/react-core'; +import { + Alert, + AlertGroup, + Dropdown, + DropdownItem, + DropdownList, + MenuToggle, + MenuToggleElement, +} from '@patternfly/react-core'; import ResourceList from './ResourceList'; import './kuadrant.css'; import resourceGVKMapping from '../utils/latest'; @@ -42,6 +51,20 @@ export const AllPoliciesListPage: React.FC<{ paginationLimit?: number; }> = ({ activeNamespace, columns, showAlertGroup = false, paginationLimit }) => { const { t } = useTranslation('plugin__kuadrant-console-plugin'); + const history = useHistory(); + const [isOpen, setIsOpen] = useState(false); + + const onToggleClick = () => { + setIsOpen(!isOpen); + }; + + const onMenuSelect = (_event: React.MouseEvent, policyType: string) => { + const resource = resourceGVKMapping[policyType]; + const resolvedNamespace = activeNamespace === '#ALL_NS#' ? 'default' : activeNamespace; + const targetUrl = `/k8s/ns/${resolvedNamespace}/${resource.group}~${resource.version}~${resource.kind}/~new`; + history.push(targetUrl); + setIsOpen(false); // Close the dropdown after selecting an option + }; return ( <> @@ -53,18 +76,57 @@ export const AllPoliciesListPage: React.FC<{ )} - r.gvk)} - namespace={activeNamespace} - columns={columns} - paginationLimit={paginationLimit} - /> + +
+ + +
+ ) => ( + + {t('Create Policy')} + + )} + > + + + {t('AuthPolicy')} + + + {t('RateLimitPolicy')} + + + {t('DNSPolicy')} + + + {t('TLSPolicy')} + + + +
+
); }; -const PoliciesListPage: React.FC<{ resource: Resource; activeNamespace: string }> = ({ resource, activeNamespace }) => { +const PoliciesListPage: React.FC<{ resource: Resource; activeNamespace: string }> = ({ + resource, + activeNamespace, +}) => { const { t } = useTranslation('plugin__kuadrant-console-plugin'); const resolvedNamespace = activeNamespace === '#ALL_NS#' ? 'default' : activeNamespace; @@ -80,7 +142,9 @@ const PoliciesListPage: React.FC<{ resource: Resource; activeNamespace: string }
- + {t(`plugin__kuadrant-console-plugin~Create ${resource.gvk.kind}`)}
diff --git a/src/components/kuadrant.css b/src/components/kuadrant.css index e4dc2b0..4d9e567 100644 --- a/src/components/kuadrant.css +++ b/src/components/kuadrant.css @@ -158,4 +158,8 @@ .kuadrant-pagination-left { display: flex; justify-content: flex-start; +} + +.kuadrant-policy-list-body { + width: 100%; } \ No newline at end of file