mirror of
https://github.com/ansible/awx.git
synced 2026-01-27 08:31:28 -03:30
Adds logic to recursively fetch input sources in the model method. This way we don't have to duplicate this logic every place that calls the method.
This commit is contained in:
parent
e7cd9bbb98
commit
a1d1a1078b
@ -20,10 +20,31 @@ class Credentials extends Base {
|
||||
return this.http.options(`${this.baseUrl}${id}/access_list/`);
|
||||
}
|
||||
|
||||
readInputSources(id, params) {
|
||||
return this.http.get(`${this.baseUrl}${id}/input_sources/`, {
|
||||
params,
|
||||
});
|
||||
readInputSources(id) {
|
||||
const fetchInputSources = async (pageNo = 1, inputSources = []) => {
|
||||
try {
|
||||
const { data } = await this.http.get(
|
||||
`${this.baseUrl}${id}/input_sources/`,
|
||||
{
|
||||
params: {
|
||||
page: pageNo,
|
||||
page_size: 200,
|
||||
},
|
||||
}
|
||||
);
|
||||
if (data.next) {
|
||||
return fetchInputSources(
|
||||
pageNo + 1,
|
||||
inputSources.concat(data.results)
|
||||
);
|
||||
}
|
||||
return Promise.resolve(inputSources.concat(data.results));
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
return fetchInputSources();
|
||||
}
|
||||
|
||||
test(id, data) {
|
||||
|
||||
@ -64,12 +64,10 @@ function CredentialDetail({ i18n, credential }) {
|
||||
{
|
||||
data: { inputs: credentialTypeInputs, managed_by_tower },
|
||||
},
|
||||
{
|
||||
data: { results: loadedInputSources },
|
||||
},
|
||||
loadedInputSources,
|
||||
] = await Promise.all([
|
||||
CredentialTypesAPI.readDetail(credential_type.id),
|
||||
CredentialsAPI.readInputSources(credentialId, { page_size: 200 }),
|
||||
CredentialsAPI.readInputSources(credentialId),
|
||||
]);
|
||||
|
||||
setFields(credentialTypeInputs.fields || []);
|
||||
|
||||
@ -37,11 +37,7 @@ CredentialTypesAPI.readDetail.mockResolvedValue({
|
||||
data: mockCredentialType,
|
||||
});
|
||||
|
||||
CredentialsAPI.readInputSources.mockResolvedValue({
|
||||
data: {
|
||||
results: [mockInputSource],
|
||||
},
|
||||
});
|
||||
CredentialsAPI.readInputSources.mockResolvedValue([mockInputSource]);
|
||||
|
||||
function expectDetailToMatch(wrapper, label, value) {
|
||||
const detail = wrapper.find(`Detail[label="${label}"]`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user