Skip to content

Commit

Permalink
[#269] remove the ingressDomain field
Browse files Browse the repository at this point in the history
The ingress domain can be retrieved from the cluster configuration
instead of asking the user to fill in the information themselves.
This removes a confusing field from the formview.

This resolves one of the feedback points from @brusdev during the
plugin presentation.
  • Loading branch information
lavocatt committed Aug 14, 2024
1 parent 10884b4 commit 9659265
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/brokers/add-broker/AddBroker.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../reducers/7.12/reducer';
import { AddBrokerResourceValues } from '../../reducers/7.12/import-types';
import { useNavigate, useParams } from 'react-router-dom-v5-compat';
import { UseGetIngressDomain } from '../../k8s/customHooks';

export interface AddBrokerProps {
initialValues: AddBrokerResourceValues;
Expand Down Expand Up @@ -54,6 +55,16 @@ export const AddBrokerPage: FC = () => {
setPrevNamespace(namespace);
}

const { clusterDomain, isLoading } = UseGetIngressDomain();
const [isDomainSet, setIsDomainSet] = useState(false);
if (!isLoading && !isDomainSet) {
dispatch({
operation: ArtemisReducerOperations.setIngressDomain,
payload: clusterDomain,
});
setIsDomainSet(true);
}

return (
<BrokerCreationFormState.Provider value={brokerModel}>
<BrokerCreationFormDispatch.Provider value={dispatch}>
Expand Down
16 changes: 14 additions & 2 deletions src/brokers/update-broker/UpdateBroker.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AddBroker } from '../add-broker/AddBroker.component';
import { Loading } from '../../shared-components/Loading/Loading';
import { AMQBrokerModel } from '../../k8s/models';
import { BrokerCR } from '../../k8s/types';
import { UseGetIngressDomain } from '../../k8s/customHooks';
import {
ArtemisReducerOperations,
BrokerCreationFormDispatch,
Expand All @@ -20,7 +21,7 @@ export const UpdateBrokerPage: FC = () => {

//states
const [notification, setNotification] = useState(defaultNotification);
const [loading, setLoading] = useState<boolean>(false);
const [loadingBrokerCR, setLoading] = useState<boolean>(false);

const crState = getArtemisCRState(name, namespace);

Expand Down Expand Up @@ -69,7 +70,18 @@ export const UpdateBrokerPage: FC = () => {
if (name) k8sGetBroker();
}, [name]);

if (loading && !notification.title) return <Loading />;
const { clusterDomain, isLoading: isLoadingClusterDomain } =
UseGetIngressDomain();
const [isDomainSet, setIsDomainSet] = useState(false);
if (!loadingBrokerCR && !isLoadingClusterDomain && !isDomainSet) {
dispatch({
operation: ArtemisReducerOperations.setIngressDomain,
payload: clusterDomain,
});
setIsDomainSet(true);
}

if (loadingBrokerCR && !notification.title) return <Loading />;

if (!brokerModel.cr.spec?.deploymentPlan) {
return <Loading />;
Expand Down
36 changes: 36 additions & 0 deletions src/k8s/customHooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useState } from 'react';
import { Ingress } from './types';
import { k8sGet } from '@openshift-console/dynamic-plugin-sdk';
import { IngressDomainModel } from './models';

export const UseGetIngressDomain = (): {
clusterDomain: string;
isLoading: boolean;
error: string;
} => {
const [domain, setDomain] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string>('');

const k8sGetBroker = () => {
setLoading(true);
k8sGet({ model: IngressDomainModel, name: 'cluster' })
.then((ing: Ingress) => {
setDomain(ing.spec.domain);
})
.catch((e) => {
setError(e.message);
})
.finally(() => {
setLoading(false);
});
};

const [isFirstMount, setIsFirstMount] = useState(true);
if (isFirstMount) {
k8sGetBroker();
setIsFirstMount(false);
}

return { clusterDomain: domain, isLoading: loading, error: error };
};
11 changes: 11 additions & 0 deletions src/k8s/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,14 @@ export const SecretModel: K8sModel = {
namespaced: false,
crd: true,
};

export const IngressDomainModel: K8sModel = {
apiGroup: 'config.openshift.io',
apiVersion: 'v1',
kind: 'Ingress',
label: 'ingress',
plural: 'ingresses',
labelPlural: 'ingresses',
abbr: 'I',
namespaced: false,
};
11 changes: 11 additions & 0 deletions src/k8s/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,14 @@ export type SecretResource = K8sResource & {
'tls.key'?: string;
};
};

export type Ingress = K8sResource & {
spec: {
domain: string;
loadBalancer: {
platform: {
type: string;
};
};
};
};
6 changes: 5 additions & 1 deletion src/reducers/7.12/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,11 @@ describe('test the creation broker reducer', () => {
const stateWith1Acceptor = artemisCrReducer(initialState, {
operation: ArtemisReducerOperations.addAcceptor,
});
const stateWithPEM = artemisCrReducer(stateWith1Acceptor, {
const stateWithIngressDomain = artemisCrReducer(stateWith1Acceptor, {
operation: ArtemisReducerOperations.setIngressDomain,
payload: 'apps-crc.testing',
});
const stateWithPEM = artemisCrReducer(stateWithIngressDomain, {
operation: ArtemisReducerOperations.activatePEMGenerationForAcceptor,
payload: {
acceptor: 'acceptors0',
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/7.12/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const newArtemisCRState = (namespace: string): FormState => {
spec: {
adminUser: 'admin',
adminPassword: 'admin',
ingressDomain: 'apps-crc.testing',
ingressDomain: '',
console: {
expose: true,
},
Expand Down
14 changes: 0 additions & 14 deletions src/shared-components/FormView/FormView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,6 @@ export const FormView: FC<FormViewProps> = ({
plusBtnAriaLabel="plus"
/>
</FormGroup>
<FormGroup label="ingressDomain" fieldId="horizontal-form-Domain">
<TextInput
label="Ingress Domain"
name={'ingressDomain'}
id={'ingressDomain'}
value={cr.spec?.ingressDomain}
onChange={(v) =>
dispatch({
operation: ArtemisReducerOperations.setIngressDomain,
payload: v,
})
}
/>
</FormGroup>
<FormGroup label="Broker Properties">
<InputGroup>
<InputGroupText id="broker-version" className=".pf-u-w-initial">
Expand Down

0 comments on commit 9659265

Please sign in to comment.