LandingPage/ImagesTable/Wizard: Remove all insights global calls

This commit replaces all calls to the insights.chrome global with calls
to the useChrome() hook (or the useGetEnvironment() custom hook that
wraps useChrome()).
This commit is contained in:
lucasgarfield 2023-04-26 16:40:54 +02:00 committed by Lucas Garfield
parent ef1d077c2e
commit 7bca4c7438
10 changed files with 55 additions and 98 deletions

View file

@ -302,7 +302,7 @@ const getPackageDescription = async (
};
// map the compose request object to the expected form state
const requestToState = (composeRequest, distroInfo, isBeta) => {
const requestToState = (composeRequest, distroInfo, isBeta, isProd) => {
if (composeRequest) {
const imageRequest = composeRequest.image_requests[0];
const uploadRequest = imageRequest.upload_request;
@ -461,7 +461,7 @@ const requestToState = (composeRequest, distroInfo, isBeta) => {
formState['subscription-activation-key'] = subscription['activation-key'];
formState['subscription-organization-id'] = subscription.organization;
if (insights.chrome.isProd()) {
if (isProd) {
formState['subscription-server-url'] = 'subscription.rhsm.redhat.com';
formState['subscription-base-url'] = 'https://cdn.redhat.com/';
} else {
@ -544,11 +544,16 @@ const CreateImageWizard = () => {
// This will occur if 'Recreate image' is clicked
const initialStep = compose?.request ? 'review' : undefined;
const { isBeta } = useGetEnvironment();
const { isBeta, isProd } = useGetEnvironment();
const awsTarget = isBeta() ? awsTargetBeta : awsTargetStable;
const msAzureTarget = isBeta() ? msAzureTargetBeta : msAzureTargetStable;
let initialState = requestToState(composeRequest, distroInfo, isBeta());
let initialState = requestToState(
composeRequest,
distroInfo,
isBeta(),
isProd()
);
const stepHistory = formStepHistory(composeRequest, isBeta());
initialState

View file

@ -13,8 +13,10 @@ import {
import PropTypes from 'prop-types';
import { useGetActivationKeysQuery } from '../../../store/apiSlice';
import { useGetEnvironment } from '../../../Utilities/useGetEnvironment';
const ActivationKeys = ({ label, isRequired, ...props }) => {
const { isProd } = useGetEnvironment();
const { change, getState } = useFormApi();
const { input } = useFieldApi(props);
const [isOpen, setIsOpen] = useState(false);
@ -31,7 +33,7 @@ const ActivationKeys = ({ label, isRequired, ...props }) => {
} = useGetActivationKeysQuery();
useEffect(() => {
if (insights.chrome.isProd()) {
if (isProd()) {
change('subscription-server-url', 'subscription.rhsm.redhat.com');
change('subscription-base-url', 'https://cdn.redhat.com/');
} else {

View file

@ -7,6 +7,7 @@ import {
TextContent,
TextVariants,
} from '@patternfly/react-core';
import { useChrome } from '@redhat-cloud-services/frontend-components/useChrome';
import {
ContentList,
@ -24,6 +25,7 @@ import {
import isRhel from '../../../Utilities/isRhel';
const ReviewStep = () => {
const { auth } = useChrome();
const [isExpandedImageOutput, setIsExpandedImageOutput] = useState(false);
const [isExpandedTargetEnvs, setIsExpandedTargetEnvs] = useState(false);
const [isExpandedFSC, setIsExpandedFSC] = useState(false);
@ -36,7 +38,7 @@ const ReviewStep = () => {
const registerSystem = getState()?.values?.['register-system'];
if (registerSystem?.startsWith('register-now')) {
(async () => {
const userData = await insights?.chrome?.auth?.getUser();
const userData = await auth?.getUser();
const id = userData?.identity?.internal?.org_id;
change('subscription-organization-id', id);
})();

View file

@ -11,6 +11,7 @@ import {
Title,
} from '@patternfly/react-core';
import { ExternalLinkAltIcon, HelpIcon } from '@patternfly/react-icons';
import { useChrome } from '@redhat-cloud-services/frontend-components/useChrome';
import StepTemplate from './stepTemplate';
@ -18,10 +19,11 @@ import CustomButtons from '../formComponents/CustomButtons';
const PopoverActivation = () => {
const [orgId, setOrgId] = useState(null);
const { auth } = useChrome();
useEffect(() => {
(async () => {
const userData = await insights?.chrome?.auth?.getUser();
const userData = await auth?.getUser();
const id = userData?.identity?.internal?.org_id;
setOrgId(id);
})();