mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 00:08:44 -03:30
Pass config request through to subscription edit
This commit is contained in:
@@ -22,13 +22,7 @@ export const useConfig = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ConfigProvider = ({ children }) => {
|
export const ConfigProvider = ({ children }) => {
|
||||||
const {
|
const { error: configError, isLoading, request, result: config } = useRequest(
|
||||||
error: configError,
|
|
||||||
isLoading,
|
|
||||||
request,
|
|
||||||
result: config,
|
|
||||||
setValue: setConfig,
|
|
||||||
} = useRequest(
|
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
const [
|
const [
|
||||||
{ data },
|
{ data },
|
||||||
@@ -55,10 +49,10 @@ export const ConfigProvider = ({ children }) => {
|
|||||||
}
|
}
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
const value = useMemo(() => ({ ...config, isLoading, setConfig }), [
|
const value = useMemo(() => ({ ...config, request, isLoading }), [
|
||||||
config,
|
config,
|
||||||
|
request,
|
||||||
isLoading,
|
isLoading,
|
||||||
setConfig,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
WizardContextConsumer,
|
WizardContextConsumer,
|
||||||
WizardFooter,
|
WizardFooter,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import { ConfigAPI, SettingsAPI, MeAPI, RootAPI } from '../../../../api';
|
import { ConfigAPI, SettingsAPI, RootAPI } from '../../../../api';
|
||||||
import useRequest, { useDismissableError } from '../../../../util/useRequest';
|
import useRequest, { useDismissableError } from '../../../../util/useRequest';
|
||||||
import ContentLoading from '../../../../components/ContentLoading';
|
import ContentLoading from '../../../../components/ContentLoading';
|
||||||
import ContentError from '../../../../components/ContentError';
|
import ContentError from '../../../../components/ContentError';
|
||||||
@@ -91,7 +91,7 @@ const CustomFooter = ({ isSubmitLoading }) => {
|
|||||||
|
|
||||||
function SubscriptionEdit() {
|
function SubscriptionEdit() {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { license_info, setConfig } = useConfig();
|
const { request: updateConfig, license_info } = useConfig();
|
||||||
const hasValidKey = Boolean(license_info?.valid_key);
|
const hasValidKey = Boolean(license_info?.valid_key);
|
||||||
const subscriptionMgmtRoute = useRouteMatch({
|
const subscriptionMgmtRoute = useRouteMatch({
|
||||||
path: '/subscription_management',
|
path: '/subscription_management',
|
||||||
@@ -164,16 +164,7 @@ function SubscriptionEdit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [
|
await updateConfig();
|
||||||
{ data },
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
results: [me],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
] = await Promise.all([ConfigAPI.read(), MeAPI.read()]);
|
|
||||||
const newConfig = { ...data, me };
|
|
||||||
setConfig(newConfig);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const emptyConfig = {
|
|||||||
license_info: {
|
license_info: {
|
||||||
valid_key: false,
|
valid_key: false,
|
||||||
},
|
},
|
||||||
setConfig: jest.fn(),
|
request: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('<SubscriptionEdit />', () => {
|
describe('<SubscriptionEdit />', () => {
|
||||||
@@ -268,7 +268,7 @@ describe('<SubscriptionEdit />', () => {
|
|||||||
context: {
|
context: {
|
||||||
config: {
|
config: {
|
||||||
mockConfig,
|
mockConfig,
|
||||||
setConfig: jest.fn(),
|
request: jest.fn(),
|
||||||
},
|
},
|
||||||
me: {
|
me: {
|
||||||
is_superuser: true,
|
is_superuser: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user