Skip to content

Commit

Permalink
Switch to global NS picker for DNSPolicy
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Madigan <[email protected]>
  • Loading branch information
jasonmadigan committed Oct 10, 2024
1 parent 54ff068 commit fcf5b36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/components/KuadrantDNSPolicyCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import {
} from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import './kuadrant.css';
import { ResourceYAMLEditor, getGroupVersionKindForResource, useK8sModel } from '@openshift-console/dynamic-plugin-sdk';
import { ResourceYAMLEditor, getGroupVersionKindForResource, useK8sModel, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
import { useHistory } from 'react-router-dom';
import { LoadBalancing, HealthCheck } from './dnspolicy/types'
import LoadBalancingField from './dnspolicy/LoadBalancingField';
import HealthCheckField from './dnspolicy/HealthCheckField';
// import getModelFromResource from '../utils/getModelFromResource';
import { Gateway } from './gateway/types';
import GatewaySelect from './gateway/GatewaySelect';
import NamespaceSelect from './namespace/NamespaceSelect';
// import { removeUndefinedFields, convertMatchLabelsArrayToObject } from '../utils/modelUtils';
import yaml from 'js-yaml';
import KuadrantCreateUpdate from './KuadrantCreateUpdate'
Expand All @@ -40,7 +39,7 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => {
const { t } = useTranslation('plugin__console-plugin-template');
const [createView, setCreateView] = React.useState<'form' | 'yaml'>('form');
const [policyName, setPolicyName] = React.useState('');
const [selectedNamespace, setSelectedNamespace] = React.useState('');
const [selectedNamespace] = useActiveNamespace();
const [selectedGateway, setSelectedGateway] = React.useState<Gateway>({ name: '', namespace: '' });
const [loadBalancing, setLoadBalancing] = React.useState<LoadBalancing>({ geo: '', weight: 0, defaultGeo: true });
const [healthCheck, setHealthCheck] = React.useState<HealthCheck>({ endpoint: '', failureThreshold: null, port: null, protocol: 'HTTP', });
Expand Down Expand Up @@ -113,7 +112,6 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => {
try {
const parsedYaml = yaml.load(yamlInput)
setPolicyName(parsedYaml.metadata?.name || '');
setSelectedNamespace(parsedYaml.metadata?.namespace || '');
setSelectedGateway({ name: parsedYaml.spec?.targetRef?.name || '', namespace: parsedYaml.metadata?.namespace || '' });
const endpoint = (parsedYaml.spec?.healthCheck.endpoint || '');
const failureThreshold = (parsedYaml.spec?.healthCheck.failureThreshold || '');
Expand Down Expand Up @@ -326,7 +324,6 @@ const KuadrantDNSPolicyCreatePage: React.FC = () => {
</HelperText>
</FormHelperText>
</FormGroup>
<NamespaceSelect selectedNamespace={selectedNamespace} onChange={setSelectedNamespace} formDisabled={false} />
<GatewaySelect selectedGateway={selectedGateway} onChange={setSelectedGateway} />
<FormGroup label={t('Provider Ref')} isRequired fieldId="Provider-ref">
<TextInput
Expand Down
9 changes: 5 additions & 4 deletions src/components/KuadrantPoliciesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
K8sResourceCommon,
useActiveNamespace,
useActivePerspective,
ListPageCreate,
ListPageCreateLink,
ListPageBody
} from '@openshift-console/dynamic-plugin-sdk';

Expand Down Expand Up @@ -65,6 +65,7 @@ export const AllPoliciesListPage: React.FC<{

const PoliciesListPage: React.FC<{ resource: Resource; activeNamespace: string }> = ({ resource, activeNamespace }) => {
const { t } = useTranslation();
const resolvedNamespace = activeNamespace === '#ALL_NS#' ? 'default' : activeNamespace;

return (
<>
Expand All @@ -77,9 +78,9 @@ const PoliciesListPage: React.FC<{ resource: Resource; activeNamespace: string }
</AlertGroup>
<div className="co-m-nav-title--row">
<ResourceList resources={[resource.gvk]} namespace={activeNamespace} />
<ListPageCreate groupVersionKind={resource.gvk}>
{t(`plugin__console-plugin-template~Create ${resource.gvk.kind}`)}
</ListPageCreate>
<ListPageCreateLink to={`/k8s/ns/${resolvedNamespace}/${resource.gvk.group}~${resource.gvk.version}~${resource.gvk.kind}/~new`}>
{t(`plugin__console-plugin-template~Create ${resource.gvk.kind}`)}
</ListPageCreateLink>
</div>
</ListPageBody>
</>
Expand Down

0 comments on commit fcf5b36

Please sign in to comment.