Merge pull request #11794 from jainnikhil30/fix_credential_types_drop_down

Allow more than 400 credential types in drop down while adding new credential
This commit is contained in:
Tiago Góes 2022-02-23 16:08:28 -03:00 committed by GitHub
commit 6af294e9a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,20 @@ import {
import useRequest from 'hooks/useRequest';
import CredentialForm from '../shared/CredentialForm';
const fetchCredentialTypes = async (pageNo = 1, credentialTypes = []) => {
const { data } = await CredentialTypesAPI.read({
page_size: 200,
page: pageNo,
});
if (data.next) {
return fetchCredentialTypes(
pageNo + 1,
credentialTypes.concat(data.results)
);
}
return credentialTypes.concat(data.results);
};
function CredentialAdd({ me }) {
const history = useHistory();
@ -76,6 +90,7 @@ function CredentialAdd({ me }) {
history.push(`/credentials/${credentialId}/details`);
}
}, [credentialId, history]);
const {
isLoading,
error,
@ -83,18 +98,7 @@ function CredentialAdd({ me }) {
result,
} = useRequest(
useCallback(async () => {
const { data } = await CredentialTypesAPI.read({ page_size: 200 });
const credTypes = data.results;
if (data.next && data.next.includes('page=2')) {
const {
data: { results },
} = await CredentialTypesAPI.read({
page_size: 200,
page: 2,
});
credTypes.concat(results);
}
const credTypes = await fetchCredentialTypes();
const creds = credTypes.reduce((credentialTypesMap, credentialType) => {
credentialTypesMap[credentialType.id] = credentialType;
return credentialTypesMap;