diff --git a/.github/workflows/i18n.yaml b/.github/workflows/i18n.yaml index e566c6b..8fb4212 100644 --- a/.github/workflows/i18n.yaml +++ b/.github/workflows/i18n.yaml @@ -29,6 +29,7 @@ jobs: run: | if [[ $(git status --porcelain) ]]; then echo "i18n generation caused changes, failing the build." + git diff exit 1 else echo "No changes detected." diff --git a/locales/en/plugin__kuadrant-console-plugin.json b/locales/en/plugin__kuadrant-console-plugin.json index 459ecc9..e66a35e 100644 --- a/locales/en/plugin__kuadrant-console-plugin.json +++ b/locales/en/plugin__kuadrant-console-plugin.json @@ -19,6 +19,8 @@ "Create": "Create", "Create AuthPolicy": "Create AuthPolicy", "Create DNS Policy": "Create DNS Policy", + "Create Gateway": "Create Gateway", + "Create HTTPRoute": "Create HTTPRoute", "Create Policies in": "Create Policies in", "Create Policy": "Create Policy", "Create RateLimit Policy": "Create RateLimit Policy", diff --git a/src/components/KuadrantOverviewPage.tsx b/src/components/KuadrantOverviewPage.tsx index 4dd2c09..2e9c669 100644 --- a/src/components/KuadrantOverviewPage.tsx +++ b/src/components/KuadrantOverviewPage.tsx @@ -22,6 +22,7 @@ import { DropdownItem, DropdownList, MenuToggle, + Button, } from '@patternfly/react-core'; import { GlobeIcon, @@ -37,16 +38,38 @@ import ResourceList from './ResourceList'; import { sortable } from '@patternfly/react-table'; import { INTERNAL_LINKS, EXTERNAL_LINKS } from '../constants/links'; import resourceGVKMapping from '../utils/latest'; +import { useHistory } from 'react-router-dom'; +export type MenuToggleElement = HTMLDivElement | HTMLButtonElement; + +interface Resource { + name: string; + gvk: { + group: string; + version: string; + kind: string; + }; +} +export const resources: Resource[] = [ + { name: 'AuthPolicies', gvk: resourceGVKMapping['AuthPolicy'] }, + { name: 'DNSPolicies', gvk: resourceGVKMapping['DNSPolicy'] }, + { name: 'RateLimitPolicies', gvk: resourceGVKMapping['RateLimitPolicy'] }, + { name: 'TLSPolicies', gvk: resourceGVKMapping['TLSPolicy'] }, +]; const KuadrantOverviewPage: React.FC = () => { + const history = useHistory(); const { t } = useTranslation('plugin__kuadrant-console-plugin'); const { ns } = useParams<{ ns: string }>(); const [activeNamespace, setActiveNamespace] = useActiveNamespace(); const [isExpanded, setIsExpanded] = React.useState(true); const [isOpen, setIsOpen] = React.useState(false); + const [isCreateOpen, setIsCreateOpen] = React.useState(false); const [hideCard, setHideCard] = React.useState( sessionStorage.getItem('hideGettingStarted') === 'true', ); + const onToggleClick = () => { + setIsCreateOpen(!isCreateOpen); + }; React.useEffect(() => { if (ns && ns !== activeNamespace) { @@ -118,6 +141,30 @@ const KuadrantOverviewPage: React.FC = () => { }, ]; + const handleCreateResource = (resource) => { + const resolvedNamespace = activeNamespace === '#ALL_NS#' ? 'default' : activeNamespace; + + if (resource === 'Gateway') { + const gateway = resourceGVKMapping['Gateway']; + history.push( + `/k8s/ns/${resolvedNamespace}/${gateway.group}~${gateway.version}~${gateway.kind}/~new`, + ); + } else { + const httpRoute = resourceGVKMapping['HTTPRoute']; + history.push( + `/k8s/ns/${resolvedNamespace}/${httpRoute.group}~${httpRoute.version}~${httpRoute.kind}/~new`, + ); + } + }; + + 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); + }; + return ( <> @@ -288,6 +335,37 @@ const KuadrantOverviewPage: React.FC = () => { {t('Policies')} + ) => ( + + {t('Create Policy')} + + )} + > + + + {t('AuthPolicy')} + + + {t('RateLimitPolicy')} + + + {t('DNSPolicy')} + + + {t('TLSPolicy')} + + + { - {t('Gateways')} + { {t('APIs / HTTPRoutes')} +