Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to global NS picker for DNSPolicy #96

Merged
Merged
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
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